instruction stringlengths 21 27.8k | chosen stringlengths 18 28.2k | rejected stringlengths 18 33.6k | __index_level_0__ int64 0 50k |
|---|---|---|---|
<p>How do I generate an ETag HTTP header for a resource file?</p>
| <p>An etag is an arbitrary string that the server sends to the client that the client will send back to the server the next time the file is requested.</p>
<p>The etag should be computable on the server based on the file. Sort of like a checksum, but you might not want to checksum every file sending it out.</p>
<pre><... | <p>I would recommend not using them and going for last-modified headers instead.</p>
<p>Askapache has a useful article on this. (as they do pretty much everything it seems!)</p>
<p><a href="http://www.askapache.com/htaccess/apache-speed-etags.html" rel="nofollow noreferrer">http://www.askapache.com/htaccess/apache-sp... | 2,652 |
<p>What is the average time that it would take a complete novice, whose background is mostly Windows XP, to go through the FreeBSD handbook and get sufficient mastery to setup a server from the ground up?</p>
| <p>It's impossible to say. Not only is it highly dependent upon what sort of person you are, but it also depends on what exactly you are doing and how you define "sufficient mastery". Being able to get Apache operational is a simple matter of following step-by-step tutorials, you could do that in a matter of hours. ... | <p>Depends on your reading speed :-)
Depends on your needs (I mean: what kind of server).
Once upon a time I did this - installing a FreeBSD on x86- (although I had some Linux knowledge already at that time), and it took me 3 hours, mainly that much time, because I was working on another machine in parallel. </p>
| 14,691 |
<p>I'm currently working on a Google Maps project and am implementing a search function. In my search function I'm trying to have content on the side listing which search makers that were just added to the map correspond to each hall. However in assembling this string I run into a problem where my <code>side_bar_html</... | <p>So my understanding of your problem is that <code>side_bar_html</code> is set during the <code>onreadystatechange</code> function call, but you're not seeing it being set unless you alert it.</p>
<p>Here's what's probably happening: the Ajax request takes some time to happen. When you call <code>req.send(null)</co... | <p>add the code below to the end of your onreadystatechange function (within the if statement checking for a value of 4). e.g:</p>
<pre><code>request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = GXml.parse(request.responseText);
var points = xmlDoc.documentElement.get... | 36,058 |
<p>I’m writing a test that expects to receive an event from an object that it is calling. Specifically, I am calling out to an object that connects to an AIX machine via SSH (using the open source Granados project), then disconnecting, and I want to make sure I receive the OnConnectionClosed event that is being raised ... | <p>Use the WaitHandle classes in the System.Threading namespace. Either, AutoResetEvent or ManualResetEvent. The difference between the two is that AutoResetEvent lets one thread proceed each time it is set, while ManualResetEvent releases all waiting threads on set.</p>
<p>The reason your example doesn't work has to ... | <p>Not exactly what you arr asking about, but you may find some workable solutions or at least ideas by checking out the MS Research project called <a href="http://research.microsoft.com/projects/CHESS" rel="nofollow noreferrer">CHESS</a>. It's for multithreaded concurrency testing in .net.</p>
| 27,037 |
<p>How do I setup TeamCity 4.0 so that I can access it over port 443 on the internet? e.g. <a href="https://teamcity.mydomain.com" rel="nofollow noreferrer">https://teamcity.mydomain.com</a></p>
<p>I am running IIS 7 on the same server that TeamCity is installed. I see two options:</p>
<ol>
<li><p>Setup TeamCity to... | <p>It requires configuring the bundled Tomcat server for https. See here:</p>
<p><a href="http://confluence.jetbrains.net/display/TCD65/Using+HTTPS+to+access+TeamCity+server" rel="noreferrer">http://confluence.jetbrains.net/display/TCD65/Using+HTTPS+to+access+TeamCity+server</a></p>
<p>and here:</p>
<p><a href="htt... | <p>Make sure you also use load these 2 modules</p>
<pre><code>LoadModule proxy_module bin/mod_proxy.so
LoadModule proxy_http_module bin/mod_proxy_http.so
ProxyPass /TeamCity http://localhost/TeamCity
ProxyPassReverse /TeamCity http://localhost/TeamCity
</code></pre>
| 42,983 |
<p>I have HTML code like this :</p>
<pre><code><div>
<a>Link A1</a>
<a>Link A2</a>
<a>Link A3</a>
</div>
<div>
<a>Link B1</a>
<a>Link B2</a>
<a>Link B3</a>
</div>
</code></pre>
<p... | <p>Fortunately, jQuery selectors allow you much more freedom:</p>
<pre><code>$("div a").click( function(event)
{
var clicked = $(this); // jQuery wrapper for clicked element
// ... click-specific code goes here ...
});
</code></pre>
<p>...will attach the specified callback to each <code><a></code> contain... | <p>To select the sibling, you'd need something like:</p>
<pre><code>$(this).next();
</code></pre>
<p>So, Shog9's comment is not correct. First of all, you'd need to name the variable "clicked" outside of the div click function, otherwise, it is lost after the click occurs.</p>
<pre><code>var clicked;
$("div a").cli... | 47,209 |
<p>I am working through some of the exercises in The C++ Programming Language by Bjarne Stroustrup. I am confused by problem 11 at the end of Chapter 12:</p>
<blockquote>(*5) Design and implement a library for writing event-driven simulations. Hint: <task.h>. ... An object of class task should be able to save... | <blockquote>
<p>Hint: <task.h>.</p>
</blockquote>
<p>is a reference to an old cooperative multi-tasking library that shipped with <a href="http://www.softwarepreservation.org/projects/c_plus_plus#release_e" rel="nofollow noreferrer">early versions of CFront</a> (you can also download at that page).</p>
<p>If ... | <p>In the paper linked to by "me.yahoo.com/..." which describes the task.h class:</p>
<ol>
<li>Tasks execute in parallel</li>
<li>A task may be suspended and resumed later</li>
</ol>
<p>The library is described as a method of multiprogramming.</p>
<p><strong>Is it possible to do this without using threads or separat... | 48,319 |
<p>We have a number of web-apps running on IIS 6 in a cluster of machines. One of those machines is also a state server for the cluster. We do not use sticky IP's.</p>
<p>When we need to take down the state server machine this requires the entire cluster to be offline for a few minutes while it's switched from one mac... | <p>You could use <a href="http://msdn.microsoft.com/en-us/library/dd187409.aspx" rel="nofollow noreferrer">Velocity</a>, which is a distributed caching technology from Microsoft. You would install the cache on two or more servers. Then you would <a href="http://blogs.msdn.com/velocity/archive/2008/10/29/changes-to-sess... | <p>You could use the SQL server option to store state. I've used this in the past and it works well as long as the ASPState table it creates is in memory. I don't know how well it would scale as an on-disk table.</p>
<p>If SQL server is not an option for whatever reason, you could use your load balancer to create a vi... | 9,105 |
<p>What are the alternative "design methods" to the Model View Controller? MVC seems to be popular (SO was built with it, I know that much) but is it the only method used?</p>
| <p>There are many others:</p>
<ul>
<li><p><a href="http://en.wikipedia.org/wiki/Model_View_Presenter" rel="noreferrer">Model View Presenter (MVP)</a></p>
<ul>
<li><a href="http://www.martinfowler.com/eaaDev/SupervisingPresenter.html" rel="noreferrer">Supervising Controller</a></li>
<li><a href="http://www.martinfowle... | <p>We use not so much an alternative but a hybrid called <a href="https://stackoverflow.com/questions/140098/is-mvc-ars-preferable-to-classic-mvc-to-prevent-overloading">MVC-ARS</a>.</p>
| 17,156 |
<p>I know that I need to tell my UITextField to resign first responder when I want to dismis the keyboard, but I'm not sure how to know when the user has pressed the "Done" key on the keyboard. Is there a notification I can watch for?</p>
| <p>I set the delegate of the <code>UITextField</code> to my <code>ViewController</code> class. </p>
<p>In that class I implemented this method as following:</p>
<pre><code>- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
</code></pre>
| <pre><code>textField.returnKeyType = UIReturnKeyDone;
</code></pre>
| 34,557 |
<p>I'm new to Flex, although not new to programming. I want to write a generic event handler that will be called by all my textinput boxes when they receive focus. When they have focus, I want to change the colour of the textinput box. When they lose focus, I want to restore the "inactive" color profile. I could writ... | <p>You should subclass TextInput and handle the focus events in there. I think this would be the simplest way to achieve what you are looking for without having any complex code.</p>
| <p>If you want to change the look of the focused input box, you can do this by setting the <code>focusSkin</code> property. If you want this to happen globally, you can put a style declaration in your CSS file. </p>
<p>In this CSS example I'm replacing the default focusSkin (<code>mx.skins.halo.HaloFocusRect</code>) w... | 27,248 |
<p>Is it possible to change a sql server instance name? Or is it something that can only be set during installation?</p>
| <p>To the best of my knowledge, they can only be changed at install time. You might be able to change the name with the installer package while keeping the current info. I would make backups of all of your databases and then try this.</p>
<p>On another note, changing instance names will just cause you so many headac... | <p>You can't rename the <b>instance</b> but you can rename a server (sql2000 only) - does that help at all?</p>
<p>Have a look at:</p>
<pre><code>sp_dropserver 'oldname', 'droplogins'
</code></pre>
<p>and then;</p>
<pre><code>sp_addserver 'newname', local
</code></pre>
<p>Be aware that if there are any jobs runnin... | 43,030 |
<p>It will be important for developers wanting to develop for the chrome browser to be able to review existing bugs (to avoid too much pulling-out of hair), and to add new ones (to improve the thing). Yet I can't seem to find the bug tracking for this project. It <em>is</em> open source, right?</p>
| <p>Google is calling it <a href="http://code.google.com/chromium/" rel="noreferrer">Chromium</a> on Google Code</p>
<p>The <a href="http://dev.chromium.org/for-testers/bug-reporting-guidelines" rel="noreferrer">Chromium Bug Reporting Page</a> is there and has the link to submit bugs listed. (Google Account Required)</... | <p>From the <a href="http://www.google.com/support/chrome/bin/answer.py?answer=95760&query=bug&topic=&type=" rel="nofollow noreferrer">Google Site</a></p>
<ol>
<li>Click the Page menu page menu.</li>
<li>Select Report a bug or broken website.</li>
<li>Choose an issue type from the drop-down menu. The web a... | 6,194 |
<p>I'm trying to do 'Attach to Process' for debugging in Visual Studio 2008 and I can't figure out what process to attach to. Help.</p>
| <p>Indeed it is still w3wp.exe - You'll need to check the '<strong>Show processes in all sessions</strong>' option to get it to show up though.</p>
<p>(It caught me out for a while too.)</p>
| <p>Isn't it w3wp.exe?</p>
| 8,599 |
<p>I'm using the jQuery Form plugin to upload an image. I've assigned a fade animation to happen the <code>beforeSubmit</code> callback, but as I'm running locally, it doesn't have time to finish before the <code>success</code> function is called. </p>
<p>I am using a callback function in my <code>fade();</code> call ... | <p>I think you may be getting too fancy with those fade animations :)... In the beforeSubmit the fadeOut is setup but the function returns immediately causing the submit to happen. I guess the upload is happening under 3 seconds causing the new image to appear before your animations are complete.</p>
<p>So if you real... | <p>Even though the beforeSubmit callback is called before submitting the form, the userImage.fadeOut function is synchronous (i.e. it spawns a separate thread of execution to execute the fade animation then it continues execution) and it returns immediately. The fade animation takes 1.5 seconds to complete and as you a... | 16,570 |
<p>I need to create an object which exposes an <code>IDictionary<K,V></code> interface, but I don't want to fill in the entire interface implemntation.</p>
<p>It would be nice to have the equivalent of Java's AbstractDictionary, which leaves you very little to impelment a complete dictionary (HashMap, in Java):<... | <p><code>System.Collections.Generic</code> namespace contains three implementations of <code>IDictionary<K,V></code>: <code>Dictionary<TKey, TValue></code>, <code>SortedDictionary<TKey, TValue></code> and <code>SortedList<TKey, TValue></code>.</p>
| <p>If I'm building my own dictionary class, I inherit from System.Collections.ObjectModel.KeyedCollection. </p>
<p>EDIT for all those who don't understand API design.</p>
<p>You should never, ever return a generic List or Dictionary from a public property or function. Insead you should return a class specially built... | 44,119 |
<p>How do you define your UserControls as being in a namespace below the project namespace, ie. [RootNameSpace].[SubSectionOfProgram].Controls?</p>
<p><strong>Edit due to camainc's answer:</strong> I also have a constraint that I have to have all the code in a single project.</p>
<p><strong>Edit to finalise question:... | <p>I'm not sure if this is what you are asking, but this is how we do it.</p>
<p>We namespace all of our projects in a consistent manner, user controls are no different. We also namespace using the project settings window, although you could do it through a combination of the project window and in code.</p>
<p>Each s... | <p>Do you mean you want to be able to access user controls at runtime (in code) via </p>
<blockquote>
<p><code>[ProjectNamespace].[YourSpecialNamespace].Controls</code></p>
</blockquote>
<p>rather than the default of </p>
<blockquote>
<p><code>[ProjectNamespace].Controls</code></p>
</blockquote>
<p>? Because I ... | 8,808 |
<p>I have an AdvancedDataGrid that uses customer grouping of data. Not all of the groups will be at the same level in the hierarchy, and groups can contain both groups and members. We have a sort callback, but it's not being called except for groups at the leaf-most levels. See code below for an example -- expand all o... | <p>It seems as if the first row contains null data or an empty string, and the advanceddatagrid is set to use grouped data, then the sort function doesn't get called.</p>
<p>it's a bit of a hack, yes, but if you can put in an unrealistic (say 1/1/1770), constant piece of data that you could insert at the database/file... | <p>This has something to do with the logic of the SortCompareFunction.</p>
<p>Put <code>dob:"01/01/1970"</code> for all the group nodes and the sort works as expected, is that correct?</p>
| 18,776 |
<p>I am looking for a good, free (preferred) screen sharing program that works well for pair programming and code review sessions for Windows (Vista x64, Server 2008). It should allow either person take control of the screen and be fairly responsive for text editing over decent broadband connections. Additional feature... | <p><a href="http://connect.microsoft.com/site/sitehome.aspx?SiteID=94" rel="nofollow noreferrer">Windows Shared View</a> works for me. It allows you to only share certain windows and even shows where your "attendees" mouse is. It would be best to use that in connection with some sort of voip connection so that you do... | <p>Would a VNC client not do the trick, combined with a one of those screen overlay apps people use for presentations (screenpen rings a bell)?</p>
| 37,009 |
<p>I'm looking for a table or list of standard time estimations for developments in ABAP, something customizable in some variables according to the development team, complexity of project, etc...</p>
<p>Something similar to:</p>
<pre><code>Simple Module Pool -> 10 hours
Complex Module Pool -> 30 hours
Definition ... | <p>If I am reading this right, you are looking for a something to estimate how long it would take someone to program an application. I would doubt an official table actually exists. </p>
<p>Development time is highly variable. Programmer experience, complexity of requirements, clarity of requirements, and dozens of ot... | <p>Let me guess... you're a project manager?</p>
<p>There is no "one way" in programming, especially not in the highly specialized world of ABAP.</p>
| 36,022 |
<p>I need to run a Java application, which we are trying to port to Java 6, on an NT box.</p>
<p>I manage to run java 5 on it (although not officially supported), but when I try to run java 6 I get the following error:</p>
<pre><code>Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jre... | <p>OK, Thanks for all the viewers and to @Roel Spiker and @Partyzant for their answers.</p>
<p><strong>It can't be done.</strong> Not unless you install windows2000 on the NT box. This is because awt.dll fr J6SE uses new methods in User32.dll, which is part of the windows OS (linked to kernel.dll et al). Use the dll ... | <p>Java SE 6 <a href="http://java.sun.com/javase/6/webnotes/install/system-configurations.html" rel="nofollow noreferrer">requires</a> at least Windows 2000.</p>
| 18,397 |
<p>Is there any way that my script can retrieve metadata values that are declared in its own header? I don't see anything promising in the API, except perhaps <code>GM_getValue()</code>. That would of course involve a special name syntax. I have tried, for example: <code>GM_getValue("@name")</code>.</p>
<p>The motivat... | <p><strong>This answer is out of date :</strong> As of Greasemonkey 0.9.16 (Feb 2012) please see <a href="https://stackoverflow.com/a/10475344/1820">Brock's answer</a> regarding <code>GM_info</code></p>
<hr>
<p>Yes. A very simple example is:</p>
<pre><code>var metadata=<>
// ==UserScript==
// @name ... | <p>Building on Athena's answer, here is my generalized solution that yields an object of name/value pairs, each representing a metadata property. Note that certain properties can have multiple values, (@include, @exclude, @require, @resource), therefore my parser captures those as Arrays - or in the case of @resource, ... | 13,016 |
<p>Most of my experience is on the MSFT stack, but I am now working on a side project, helping someone with a personal site with cheap hosting that is built on the LAMP stack. My options for installing extras are limited, so I'm wondering about how to write my data access code without embedding raw queries in the .php... | <p>Take a look at the <a href="http://framework.zend.com" rel="nofollow noreferrer">Zend Framework</a>, specifically Zend_Db. It has a Database Abstraction layer that doesn't require anything other than the MySQLi extension to be installed and isn't a full-blown ORM model.</p>
| <p>I would try a framework. <em>Zend Framework</em> has been cited. <a href="http://www.symfony-project.org/" rel="nofollow noreferrer">Symfony</a> seems interesting. It's based on ideas from <em>Ruby on Rails</em>.</p>
| 4,226 |
<p>I have a problem applying the <code>DebuggerDisplay</code> attribute on a generic class:</p>
<pre><code>[DebuggerDisplay("--foo--")]
class Foo
{
}
[DebuggerDisplay("Bar: {t}")]
class Bar<T>
{
public T t;
}
</code></pre>
<p>When inspecting an object of type <code>Bar<Foo></code> I would expect it t... | <p>The DebuggerDisplay attribute is not recursive. The {} inside the string essentially say evaluate this expression and display the result inline. The string for the inner result is calculated as if there was no DebuggerDisplay attribute in play for type or member. That is why you see {Foo} instead of --foo--. </p... | <p><em>[Disclaimer: I'm affiliated with OzCode]</em></p>
<p>You can use OzCode's Reveal feature which supports nested/recursive debug information.
<a href="https://i.stack.imgur.com/hWlRv.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hWlRv.gif" alt="enter image description here"></a><br>
Once you... | 32,332 |
<p>I need to use C++ to read in text with spaces, followed by a numeric value.</p>
<p>For example, data that looks like:</p>
<pre><code>text1
1.0
text two
2.1
text2 again
3.1
</code></pre>
<p>can't be read in with 2 <code>"infile >>"</code> statements. I'm not having any luck with <code>getline</code>
either... | <p>The standard IO library isn't going to do this for you alone, you need some sort of simple parsing of the data to determine where the text ends and the numeric value begins. If you can make some simplifying assumptions (like saying there is exactly one text/number pair per line, and minimal error recovery) it wouldn... | <p>If you can be sure that your input is well-formed, you can try something like this sample:</p>
<pre><code>#include <iostream>
#include <sstream>
int main()
{
std::istringstream iss("text1 1.0 text two 2.1 text2 again 3.1");
for ( ;; )
{
double x;
if ( iss >> x )
... | 38,888 |
<p>Basically I'm trying to accomplish the same thing that "mailto:bgates@microsoft.com" does in Internet Explorer Mobile.</p>
<p>But I want to be able to do it from a managed Windows Mobile application. I don't want to send an email pro grammatically in the background.</p>
<p>I want to be able to create the email in ... | <p>I assume you use C#. You add a reference to System.Diagnostics and then write the following code:</p>
<pre><code>ProcessStartInfo psi =
new ProcessStartInfo("mailto:bla@bla.com?subject=MySubject", "");
Process.Start(psi);
</code></pre>
<p>This will start the default email client on your mobile device.</p>
<p>T... | <p>You can also use Microsoft.WindowsMobile.PocketOutlook.MessagingApplication.DisplayComposeForm like so:</p>
<pre><code>OutlookSession sess = new OutlookSession();
EmailAccountCollection accounts = sess.EmailAccounts;
//Contains all accounts on the device
//I'll just choose the first one -- you might want to ask t... | 20,992 |
<p>I recently inherited a database on which one of the tables has the primary key composed of encoded values (Part1*1000 + Part2).<br>
I normalized that column, but I cannot change the old values.
So now I have</p>
<pre><code>select ID from table order by ID
ID
100001
100002
101001
...
</code></pre>
<p>I want to find... | <pre><code>select ID +1 From Table t1
where not exists (select * from Table t2 where t1.id +1 = t2.id);
</code></pre>
<p>not sure if this version would be faster than the one you mentioned originally.</p>
| <p>This will give you the complete picture, where <strong>'Bottom'</strong> stands for <strong>gap start</strong> and <strong>'Top'</strong> stands for <strong>gap end</strong>:</p>
<pre><code> select *
from
(
(select <COL>+1 as id, 'Bottom' AS 'Pos' from <TABLENAME> /*where <CONDITI... | 21,037 |
<p>I have a real question.</p>
<p>I have a database with the schema as follows:</p>
<p><strong>item</strong></p>
<ul>
<li>id </li>
<li>description</li>
<li>other junk</li>
</ul>
<p><strong>tag</strong></p>
<ul>
<li>id</li>
<li>name</li>
</ul>
<p><strong>item2tag</strong></p>
<ul>
<li>item_id</li>
<li>tag_id</li>... | <p>Well, you can look at linear algebra to give a n dimensional vector to each item, and then compute the distance between items to find the closest items, but that's pretty complex with even small data sets.</p>
<p>Which is why Google came up with Map Reduce. This will probably be your best bet, but even then it's n... | <p>Given your representation of item-tag relationship as vectors,
What you have is an instance of <a href="http://en.wikipedia.org/wiki/Nearest_neighbor_search" rel="nofollow noreferrer">nearest-neighbor search</a>.
You may find pointers in the field of <a href="http://en.wikipedia.org/wiki/Collaborative_filtering" re... | 40,881 |
<p>I have this CTC i3 printer; when I print square test prints, as it moves along the Y-axis back to zero (front). It extrudes lines but very thin or none at all.</p>
<p>But opposite direction along the Y axis is 100 % </p>
<p><img src="https://i.stack.imgur.com/BChHj.jpg" alt="enter image description here"></p>... | <p>Without images of the problem it is difficult to diagnose, but, the described symptoms sounds as if the nozzle is too close to the bed. If the nozzle is too close to the bed, and the extruder not strong enough, the filament flow is very limited due to pressure caused by a very small opening between the nozzle and th... | <p>Clearly you're having an extrusion problem. Extrusion problems usually come either from a clogged nozzle (as @Adam S. said) or from the extruder it self. To determine where the problem is located I would first do a flow rate test using <a href="https://www.youtube.com/watch?v=lWBkPIXTOlo&feature=emb_logo" rel="n... | 1,661 |
<p>As as part of my daily routine, I have the misfortune of administering an ancient, once "just internal" JSP web application that relies on the following authentication schema:</p>
<pre><code>...
// Validate the user name and password.
if ((user != null) && (password != null) && (
(user.equals("... | <p>It is hard to understand the exact scheme you are thinking about but I assume the password is coming in from a request and you want to calculate the MD5 hash in a JSP that the request is being sent to. After that you can compare it to the pre-computed MD5 version. You could even be more secure if it isn't being done... | <p>First of all you should move that logic from jsp to a separate class.</p>
<p>Second, you shouldn't keep plain text password anywhere in the code. Use some kind of one way hash function (md5, sha1, ...) and keep only password hashes.</p>
<p>When checking for user password, first hash it and then compare hashes.</p>... | 39,757 |
<p>Is there a better way to profile code then:</p>
<pre><code>$start1 = microtime(TRUE);
for($i=0;$i<count($array);$i++)
{
//do something
}
$time1 = microtime(TRUE) - $start1;
</code></pre>
| <p>Xdebug or Zend Debugger if you have some difficulty to install Xdebug.</p>
<p>Their profiler will time everything for you without any modification of your code.</p>
<p><a href="http://www.xdebug.org/" rel="nofollow noreferrer">http://www.xdebug.org/</a></p>
<p><a href="http://www.zend.com/en/community/pdt" rel="n... | <p>Without using an external tool, I would say you've done the best you can.</p>
<p>If you want to use a tool built for the purpose, the other answers are dead-on.</p>
| 22,570 |
<p>In the Linux kernel, given the <code>task_struct</code>'s <code>mm</code> I can access the process's list of <code>vm_area_struct</code>s. Given these <code>vm_area_struct</code>s, how do I get the <code>struct page</code>s which actually correspond to this vma? </p>
<p>I tried looking for functions in mm/memory.c ... | <p>From your comment to another answer (edit: the other answer seems to have been deleted), it seems you want to read from user space. The function to get the user space pages would be <a href="http://lwn.net/Articles/28548/" rel="nofollow noreferrer"><code>get_user_pages()</code></a>, but that is most probably not wha... | <p>I don't have the direct answer off-hand, but it won't take you long to navigate the structures by using lxr.linux.no</p>
<p>Given you already have the struct you want to start from, take a look from <a href="http://lxr.linux.no/linux+v2.6.29/+code=vm_area_struct" rel="nofollow noreferrer">http://lxr.linux.no/linux+... | 38,409 |
<p>I am building a project using Visual Studio. The project has a dependency on a lib file generated by another project. This project is there is the parent directory of the actual project I am building. </p>
<p>To be more clear,
I have a "ParentDir" which has two subDirectories Project1 and Project2 under it.
Now P... | <p>Add the dependant project to your solution and set it as a dependency of the other project using project properties. Then it just magically works ;).</p>
<p>A solution is just a file that describes a set of related (interconnected) projects and the relation between them, so this is the correct way of doing it.</p>
| <p>I think Visual Studio does not expand the relative path properly when the ".." is placed somewhere in the middle of the path string. It only knows how to expand ..{sub-path}.</p>
| 16,086 |
<p>I created a NamedTemporaryFile, added some content in it and now I want to save it into a model FileField. </p>
<p>The problem is that I get a SuspiciousOperation because the tmp directory is not within the FileSystemStorage directory.</p>
<p>What's the proper way to do this?</p>
| <p>You want django to check it for you because it ensures file is put inside MEDIA_ROOT dir so it's accessible for download.</p>
<p>In any case you want to put files outside MEDIA_ROOT (in this case '/tmp') you should do something like this:</p>
<pre><code>from django.core.files.storage import FileSystemStorage
fs = ... | <p>I ended up doing the oposite way romke explains: I'm creating the temporary file in the MEDIA_ROOT.</p>
<p>Another solution could be working with the file in /tmp and then moving it to MEDIA_ROOT.</p>
<p>My initial confusion comes from the way forms are working with uploaded files: they are located in the /tmp dir... | 49,638 |
<p>We all know that premature optimization is the root of all evil because it leads to unreadable/unmaintainable code. Even worse is pessimization, when someone implements an "optimization" because they <em>think</em> it will be faster, but it ends up being slower, as well as being buggy, unmaintainable, etc. What is... | <p>I think the phrase "premature optimization is the root of all evil" is way, way over used. For many projects, it has become an excuse not to take performance into account until late in a project. </p>
<p>This phrase is often a crutch for people to avoid work. I see this phrase used when people should really sa... | <p>Any significant optimization effort that isn't based on triaged reports from a profiler tool earns a big WTF from me.</p>
| 40,206 |
<p>I see many different Java terms floating around. I need to install the JDK 1.6. It was my understanding that Java 6 == Java 1.6. However, when I install Java SE 6, I get a JVM that reports as version 11.0! Who can solve the madness?</p>
| <ul>
<li>JDK - Java Development Kit</li>
<li>JRE - Java Runtime Environment</li>
<li>Java SE - Java Standard Edition</li>
</ul>
<p>SE defines a set of capabilities and functionalities; there are more complex editions (Enterprise Edition – EE) and simpler ones (Micro Edition – ME – for mobile environments).</p>
<p>The... | <p>With the release of Java 5, the product version was made distinct from the developer version as described <a href="http://java.sun.com/j2se/1.5.0/docs/relnotes/version-5.0.html" rel="nofollow noreferrer">here</a></p>
<h2>Version 1.5.0 or 5.0?</h2>
<p>Both version numbers "1.5.0" and "5.0" are use... | 31,174 |
<p>I use an sql server regularly and have recently been getting frustrated by the performance. It would be difficult for me to get direct access to find out the hardware so:</p>
<p>Is there a direct way in management studio to assess performance or find out the exact hardware.</p>
<p>Alternatively does someone have a... | <p>IF you are on 2005:</p>
<p>SELECT * FROM sys.dm_os_performance_counters</p>
<p>That will give you some sql only stats. You will not find much info about the machine without at least terminal access. In the sql startup log you can see some info on processors as well.</p>
| <p>You also might try updating your references in your server. I had an issue a while back that 1 query returned in 100ms and an identical query in 5+ minutes and the only difference between the 2 was a Capital letter in the table name in my query (whih obviously shouldn't matter).</p>
<p>After some searching and <a ... | 36,596 |
<p>I have a sorted collection of objects (it can be either SortedList or SortedDictionary, I will use it mainly for reading so add performance is not that important). How can I get the i-th value?</p>
<p>So e.g. when I have numbers 1, 2, 3, 4, 5 in the collection and I want the median (so 3 in this example), how can I... | <p>You can use code like </p>
<pre><code>list.Values[index]
</code></pre>
<p>for a sorted list. </p>
<p>The easiest way with a SortedDictonary would be to use the ElementAt() method:</p>
<pre><code>dict.ElementAt(index).Value
</code></pre>
<p>However, this is slower than in the list case.</p>
<p>In either case, ... | <p>If you need to get an element by index in a SortedDictionary many times, the performance is miserable. Make a new SortedList with the SortedDictionary as input and access the SortedList. Runs many, many times faster.</p>
| 28,985 |
<p>My question is simple; is it possible to over object-orient your code? </p>
<p>How much is too much? At what point are you giving up readability and maintainability for the sake of OO? </p>
<p>I am a huge OO person but sometimes I wonder if I am over-complicating my code.... </p>
<p>Thoughts?</p>
| <blockquote>
<p>is it possible to over object-orient your code</p>
</blockquote>
<p>Yes</p>
| <p>I guess it is possible, but its hard to answer your in abstract terms (no pun intended). Give an example of over OO.</p>
| 7,793 |
<p>The code is rather long yet simple:</p>
<ul>
<li>100 leaky JavaScript objects are created.</li>
<li>10 leaky elements are created from the JS objects.</li>
<li>1 element is removed and 1 is added 10000 times.</li>
</ul>
<p>I assume that the <code>detachEvent</code> call is not functioning properly.
Also, if you chan... | <p>looks like you're pushing stuff onto the eventParams array inside CreateLeakyEle, but never removing it? Is that right?</p>
| <p>If you take a look at your code, you should notice that in each eventParams object stored in your eventParams array, you have references to the objects, but you never empty out your array. Try clearing out your array...</p>
| 33,934 |
<p>I have to present some 'process' or 'flow' of the application at work on friday. I was hoping to prepare a flow chart before I begin the hands on demo. </p>
<p>Any suggestions for freeware sw to make simple flowcharts on Windows?</p>
| <p><a href="http://live.gnome.org/Dia" rel="noreferrer">Dia</a> might be worth looking at.</p>
<blockquote>
<p>It can be used to draw many different kinds of diagrams. It currently
has special objects to help draw entity relationship diagrams, UML
diagrams, flowcharts, network diagrams, and many other diagrams. ... | <p>If you have Microsoft Word or Excel you can select Insert|Shapes|Flowchart to create a Flowchart. I know it is not free but if you have Microsoft Office already, it may be an option.</p>
| 46,723 |
<p>How do you tell if a function in JavaScript is defined?</p>
<p>I want to do something like this</p>
<pre><code>function something_cool(text, callback) {
alert(text);
if( callback != null ) callback();
}
</code></pre>
<p>But it gets me a</p>
<blockquote>
<p>callback is not a function</p>
</blockquote>
... | <pre><code>typeof callback === "function"
</code></pre>
| <p>One-line solution:</p>
<pre><code>function something_cool(text, callback){
callback && callback();
}
</code></pre>
| 11,132 |
<p>I have the following program:</p>
<pre><code>~/test> cat test.cc
int main()
{
int i = 3;
int j = __sync_add_and_fetch(&i, 1);
return 0;
}
</code></pre>
<p>I'm compiling this program using GCC 4.2.2 on Linux running on a multi-cpu 64-bit Intel machine:</p>
<pre><code>~/test> uname --all
Linux doom ... | <p>From the <a href="http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html#Atomic-Builtins" rel="noreferrer">GCC page on Atomic Builtins</a>:</p>
<blockquote>
<p>Not all operations are supported by
all target processors. If a particular
operation cannot be implemented on the
target processor, a warn... | <p>From the <a href="http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html#Atomic-Builtins" rel="noreferrer">GCC page on Atomic Builtins</a>:</p>
<blockquote>
<p>Not all operations are supported by
all target processors. If a particular
operation cannot be implemented on the
target processor, a warn... | 15,879 |
<p>What are the pros and cons of using table aliases in SQL? I personally try to avoid them, as I think they make the code less readable (especially when reading through large where/and statements), but I'd be interested in hearing any counter-points to this. When is it generally a good idea to use table aliases, and... | <p>Table aliases are a necessary evil when dealing with highly normalized schemas. For example, and I'm not the architect on this DB so bear with me, it can take 7 joins in order to get a clean and complete record back which includes a person's name, address, phone number and company affiliation. </p>
<p>Rather than t... | <p>Aliases are required when joining tables with columns that have identical names.</p>
| 3,222 |
<p>(I asked <a href="https://stackoverflow.com/questions/282830/looking-for-small-open-source-vbnet-project-with-extensive-unit-testing">this</a> question but did not receive much response. It was recommended that I ask the same question with regards to C#. )</p>
<p>I am a VB.NET developer with little C# experience (y... | <p>My <a href="http://pobox.com/~skeet/csharp/miscutil" rel="nofollow noreferrer">MiscUtil</a> library has variable test coverage - some parts are very thoroughly tested, and others were written before I knew about unit testing.</p>
<p>If you wanted to learn by writing some tests for the uncovered stuff, you'd be very... | <p>this link is related to Silverlight but the concepts are probably very similar (from a TDD'ish point of view): <a href="http://www.jeff.wilcox.name/2008/11/04/test-framework-source/" rel="nofollow noreferrer">http://www.jeff.wilcox.name/2008/11/04/test-framework-source/</a></p>
| 36,601 |
<p>I have several xml files, the names of which are stored in another xml file. </p>
<p>I want to use xsl to produce a summary of the combination of the xml files. I remember there was a way to do this with the msxml extensions (I'm using msxml).</p>
<p>I know I can get the content of each file using <code>select="do... | <p>Here is just a small example of what you <strong>could</strong> do:</p>
<p><em>file1.xml:</em></p>
<pre><code><foo>
<bar>Text from file1</bar>
</foo>
</code></pre>
<p><em>file2.xml:</em></p>
<pre><code><foo>
<bar>Text from file2</bar>
</foo>
</code></pre>
<p><em>i... | <p>Have a look at the <a href="http://msdn.microsoft.com/en-us/library/ms256465(VS.85).aspx" rel="nofollow noreferrer"><code>document()</code> function documentation</a>.</p>
<p>You can use <code>document()</code> to load further XML documents during the transformation process. They are loaded as node sets. That means... | 26,740 |
<p>How can I read an Open Office 3.0 spreadsheet (.ods) from Groovy? I'd like to select specific columns from a named worksheet. Ideally, it would be useful to add a 'where' clause, or other criteria clause.</p>
| <p>I've never used it, but <a href="http://api.openoffice.org/" rel="nofollow noreferrer">Open Office has a Java API</a>, which of course you could use from Groovy as well. It looks like the best places to start reading are the <a href="http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OpenOffice.org_Dev... | <p><em>Since the title does not mention Groovy (only question specifics does), I didn't want to make this a new question.</em></p>
<p>How to generally read an Open Office spreadsheet document? There are tools for creating one (ooo-python) but not for reading one. They are XML but just bluntly diving into that and try... | 28,155 |
<p>What's the cleanest, most effective way to validate decimal numbers in JavaScript?</p>
<p>Bonus points for:</p>
<ol>
<li>Clarity. Solution should be clean and simple.</li>
<li>Cross-platform.</li>
</ol>
<p>Test cases:</p>
<pre><code>01. IsNumeric('-1') => true
02. IsNumeric('-1.5') => true
03. IsNu... | <p><a href="https://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric/174921#174921">@Joel's answer</a> is pretty close, but it will fail in the following cases:</p>
<pre><code>// Whitespace strings:
IsNumeric(' ') == true;
IsNumeric('\t\t') == true;
IsNumeric('\n\r') == true;
// Number li... | <p>The following may work as well.</p>
<pre><code>function isNumeric(v) {
return v.length > 0 && !isNaN(v) && v.search(/[A-Z]|[#]/ig) == -1;
};
</code></pre>
| 3,870 |
<p>In the <code>IDisposable.Dispose</code> method is there a way to figure out if an exception is being thrown?</p>
<pre><code>using (MyWrapper wrapper = new MyWrapper())
{
throw new Exception("Bad error.");
}
</code></pre>
<p>If an exception is thrown in the <code>using</code> statement I want to know about it w... | <p><strong>No</strong>, there is no way to do this in the .Net framework, you cannot figure out the current-exception-which-is-being-thrown in a finally clause. </p>
<p>See this <a href="http://samsaffron.com/blog/archive/2007/08/06/16.aspx" rel="noreferrer">post on my blog</a>, for a comparison with a similar pattern... | <p>This will catch exceptions thrown either directly or inside the dispose method:</p>
<pre><code>try
{
using (MyWrapper wrapper = new MyWrapper())
{
throw new MyException("Bad error.");
}
}
catch ( MyException myex ) {
//deal with your exception
}
catch ( Exception ex ) {
//any other excep... | 27,117 |
<p>In MS SQL Server, I create my scripts to use customizable variables:</p>
<pre><code>DECLARE @somevariable int
SELECT @somevariable = -1
INSERT INTO foo VALUES ( @somevariable )
</code></pre>
<p>I'll then change the value of <code>@somevariable</code> at runtime, depending on the value that I want in the particu... | <p>Postgres variables are created through the \set command, for example ...</p>
<pre><code>\set myvariable value
</code></pre>
<p>... and can then be substituted, for example, as ...</p>
<pre><code>SELECT * FROM :myvariable.table1;
</code></pre>
<p>... or ...</p>
<pre><code>SELECT * FROM table1 WHERE :myvariable I... | <p>I've posted a new solution for this <a href="https://stackoverflow.com/questions/13316773/is-there-a-way-to-define-a-named-constant-in-a-postgresql-query/54322738#54322738">on another thread</a>.</p>
<p>It uses a table to store variables, and can be updated at any time. A static immutable getter function is dynamic... | 5,758 |
<p>I want to bring up a file dialog in Java that defaults to the application installation directory.</p>
<p>What's the best way to get that information programmatically?</p>
| <pre><code>System.getProperty("user.dir")
</code></pre>
<p>gets the directory the Java VM was started from.</p>
| <pre><code>System.getProperty("user.dir");
</code></pre>
<p>The above method gets the user's working directory when the application was launched. This is fine if the application is launched by a script or shortcut that ensures that this is the case.</p>
<p>However, if the app is launched from somewhere else (entirely... | 4,807 |
<p>Code below is not working as expected to detect if it is in design mode (VS.Net 2003 - Control Library):</p>
<p>if (this.Site != null && this.Site.DesignMode == true) <br>
{<br>
// Design Mode<br>
}<br>
else<br>
{<br>
// Run-time<br>
}<br></p>
<p>It is used in a complex user control, deriving from anot... | <p><code>DesignMode</code> won't work from inside a constructor. Some alternatives (not sure if they work in 1.1) are</p>
<p><code>if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime)</code></p>
<p>or</p>
<p>call <code>GetService(typeof(IDesignerHost))</code> and s... | <p>I guess you could use HttpContext.Current == null as described at <a href="http://west-wind.com/weblog/posts/189.aspx" rel="nofollow noreferrer">http://west-wind.com/weblog/posts/189.aspx</a></p>
<p>In .Net 2.0 there's Control.DesignMode (<a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.design... | 17,474 |
<p>I have a Tevo Tarantula 3D printer.</p>
<p>I'm trying to print a calibration cube. </p>
<p>The slicer is Cura and is set for a 1.75 mm filament extruded by a nozzle of 0.4 mm, with a heat bed temperature of 60°C and extruder 200°C. </p>
<p>As seen in the image I stopped the printer after a minute, when ... | <p>I don't have this specific printer but this used to happen to me as well on my D-Bot. The reason being bed not being leveled properly. Ensure that your bed is leveled such that the distance between the nozzle and bed is about 0.2mm after homing. Also coat your bed with something sticky like glue or hairspray. You wo... | <p>I've cleaned the heated bed as suggested using ethanol,
then I've tested the Z distance of the nozzle from the bed with a paper sheet and it was ok. Lastly, I tried to raise the temperature of the extruder for the first layer to 215°C. I think that this did the trick.</p>
| 591 |
<p>I'm using StructureMap in my project and when the application finishes running I need to call the Dispose() method on all of the Singleton instances inside the ObjectFactory that implement IDisposable.</p>
<p>I cannot find anyway to do it via the StructureMap API.</p>
<p>Another thought I had was to get a referenc... | <p>I don't know how to directly change the offset, but I managed to fix this by:</p>
<ol>
<li>Changing the increment amount by X (1 million in my case).</li>
<li>Inserting a dummy record.</li>
<li>Reducing the increment amount back down to 1.</li>
<li>Deleting the dummy record.</li>
</ol>
<p>I used this SQL statement... | <p>I don't know how to directly change the offset, but I managed to fix this by:</p>
<ol>
<li>Changing the increment amount by X (1 million in my case).</li>
<li>Inserting a dummy record.</li>
<li>Reducing the increment amount back down to 1.</li>
<li>Deleting the dummy record.</li>
</ol>
<p>I used this SQL statement... | 46,162 |
<p>I'm trying to embed an xsl into a XML file. The reason for doing this is to create a single file that could be moved to different computers, this would prevent the need to move the xsl file. </p>
<p>The xsl file is creating a table and grabbing a test step from the xml and whether it passed or failed, pretty simp... | <p><a href="http://www.w3.org/TR/xslt#section-Embedding-Stylesheets" rel="nofollow noreferrer"><strong>Although the W3C XSLT Spec supports embedding an XSLT stylesheet</strong></a> into an XML document, it seems that IE and Firefox do not support this.</p>
<p><strong>UPDATE</strong>: As per the comment by Robert Niest... | <p>Stylesheet embedding is possible for most browsers but IE.
Find the reference to a description and example in the posting below.</p>
<p>IE6/7/8 do not support embedded stylesheets by default.</p>
<p>You may want to use the workaround enabling IE to process embedded stylesheets from here:</p>
<p><a href="http://ww... | 47,065 |
<p>I have an EXE loaded into a byte array, and I am trying to load it into an assembly object using Assembly.Load. I am getting errors trying to load.</p>
<p>Here is the code that is causing the exception:</p>
<pre><code>Assembly a = Assembly.Load(bin);
</code></pre>
<p>bin is my byte array, loaded from the EXE.</p... | <p>Make sure the file you're trying to load is a .NET Managed exe/dll.</p>
| <p>I am not sure, but because it is an EXE, it might be failing because of the unmanaged headers in the EXE?</p>
<p>Why not just do a LoadFrom( filename )?</p>
| 43,887 |
<p>I am looking for template/generator libraries for C++ that are similar to eg. Ruby's Erb, Haml, PHP's Smarty, etc.</p>
<p>It would be great if I it would sport some basic features like loops, if/else, int conversion to strings, etc.</p>
<p>Parameter passing to template rendering engine is also important if I could... | <p>A quick review of the mentioned project.</p>
<p><a href="http://rgrz.tumblr.com/post/13808947359/review-of-html-template-engines-in-c-language" rel="nofollow noreferrer">http://rgrz.tumblr.com/post/13808947359/review-of-html-template-engines-in-c-language</a></p>
<h2>ClearSilver</h2>
<ul>
<li>Site: <a href="http:... | <p>I have tried using template engine and Dynamic C++ Pages provided by the ffead-cpp framework, an example implementation is shown on the <a href="http://code.google.com/p/ffead-cpp/wiki/ExampledcpFile" rel="nofollow">wiki</a> </p>
| 46,358 |
<p>I would like to know if there is software that, given a regex and of course some other constraints like length, produces random text that always matches the given regex.
Thanks</p>
| <p><a href="http://code.google.com/p/xeger" rel="noreferrer">Xeger</a> is capable of doing it: </p>
<pre><code>String regex = "[ab]{4,6}c";
Xeger generator = new Xeger(regex);
String result = generator.generate();
assert result.matches(regex);
</code></pre>
| <p>Instead of starting from a regexp, you should be looking into writing a small context free grammer, this will allow you to easily generate such random text. Unfortunately, I know of no tool which will do it directly for you, so you would need to do a bit of code yourself to actually generate the text. If you have no... | 34,524 |
<p>I've tested in Chrome, do I need to test in Safari?</p>
| <p>I've noticed Safari handles Asian characters better than Chrome.
Also Chrome and Safari rely on the same Webkit for rendering pages, but their Javascript engines are totally different, so if you use Javascript in your pages you need to check both.</p>
| <p>In a word, No. You can't assume that because it works in one it will definitely work in all cases in the other. Sure, 99% of the time, it might be the same - but 99% isn't 100% - at least, it wasn't last time I checked. Call me a pedantic git if you like.</p>
| 48,866 |
<p>I have a table in a ORACLE 10g database with a column "<code>kzCode NUMBER(1)</code>".</p>
<p>If I try to map this with Hibernate annotations in JBOSS Server WebApp like this:</p>
<pre><code>@Column(nullable=false)
private Integer kzCode;
</code></pre>
<p>I got an error: </p>
<pre><code>org.hibernate.HibernateEx... | <p>ok, got it!</p>
<p>I had a wrong dialect property in persistence.xml file.
Now all works fine..</p>
| <pre><code>@Column(nullable=false)
private Boolean kzCode;
</code></pre>
<p>or if you really want it to be a number, change the Oracle type to NUMBER(36, 0) and use long or Long in your Java.</p>
| 44,726 |
<p>How can I create an Excel spreadsheet with C# without requiring Excel to be installed on the machine that's running the code?</p>
| <p>You can use a library called ExcelLibrary. It's a free, open source library posted on Google Code:</p>
<p><a href="https://code.google.com/archive/p/excellibrary/" rel="noreferrer">ExcelLibrary</a></p>
<p>This looks to be a port of the PHP ExcelWriter that you mentioned above. It will not write to the new .xlsx fo... | <p>I am using following code for create excel 2007 file which create the file and write in that file but when i open the file but it give me error that
exel cannot open the file bcz file might be coruupted or extension of the file is not compatible.
but if i used .xls for file it work fines</p>
<pre><code>for (int i =... | 18,205 |
<p>So you know a lot of Mac apps use "bundles": It looks like a single file to your application, but it's actually a folder with many files inside.</p>
<p>For a version control system to handle this, it needs to:</p>
<ul>
<li>check out all the files in a directory, so the app can modify them as necessary</li>
<li>at... | <p>Mercurial in particular versions based on file, not directory structure. Therefore, your working tree, which is a fully-fledged repository, doesn't spit out .svn folders at each level.</p>
<p>It also means that a directory that is replaced, like an Application or other Bundle, will still find it's contents with pa... | <p>An update from the future:</p>
<p>If I recall, the problem with managing bundles in SVN was all the .svn folders getting cleared each time you made a bundle. This shouldn't be a problem any more, now that SVN stores everything in a single .svn folder at the root.</p>
| 4,666 |
<p>Whilst investigating a memory leak I discovered that it was caused by calling NewRow() on a Table inside a loop many times. However the DataRow created was never added to the Table Rows collection and the Table Rows Count never got above zero.</p>
<p>My question is why does this use up more memory every time NewRow... | <p>DataRow inherits schema from the DataTable, so there are references from DataRow to the table schema that generated the row. The new row is in Detached state in the table.<br>
this is why GC left the new unused rows alone. </p>
| <p>If you create newRow = table.NewRow() and then in the code below decide than this newRow you more not need.
1) Add if row in the table.
2) Remove, it will prevent memory leak.</p>
<pre><code> var table = new DataTable();
while (true)
{
var newRow = table.NewRow();
table.Rows.Add(newRow);... | 30,042 |
<p>I'm looking for something containing similar functions to Matlab’s financial and financial derivatives toolbox but don’t have the cash to spend on matlab. I would appreciate any info on free or open source libraries or programs that will let me easily calculate interest rates, risk etc.</p>
| <p>How about <a href="http://www.jquantlib.org/index.php/Main_Page" rel="noreferrer">JQuantLib</a> or <a href="http://quantlib.org/index.shtml" rel="noreferrer">QuantLib</a>?</p>
| <p>How about the <a href="http://www.gnu.org/software/octave/" rel="nofollow noreferrer">Octave</a> financial functions?</p>
<p><a href="http://www.gnu.org/software/octave/doc/interpreter/Financial-Functions.html#Financial-Functions" rel="nofollow noreferrer">http://www.gnu.org/software/octave/doc/interpreter/Financia... | 43,164 |
<p>How can I validate date strings in Perl? I'd like to account for leap years and also time zones. Someone may enter dates in the following formats:</p>
<pre>
11/17/2008
11/17/2008 3pm
11/17/2008 12:01am
11/17/2008 12:01am EST
11/17/2008 12:01am CST
</pre>
| <p>I use <a href="http://search.cpan.org/dist/DateTime-Format-DateManip/lib/DateTime/Format/DateManip.pm" rel="nofollow noreferrer">DateTime::Format::DateManip</a> for things like this. Using your dates....</p>
<pre><code>use DateTime::Format::DateManip;
my @dates = (
'11/17/2008',
'11/17/2008 3pm',
'1... | <p>I'll post my answers here as I come across them.</p>
<p>use Time::Local<br>
<a href="http://www.perlmonks.org/?node_id=642627" rel="nofollow noreferrer">http://www.perlmonks.org/?node_id=642627</a></p>
| 38,050 |
<p>Should I be able to hand turn the stepper motor for the extruder of an Ender 3?</p>
<p>Trying to figure out why the motor isn’t turning on a new to me, never used, but out-of-warranty Ender 3.</p>
<p>Swapping controller cables I discovered the extruder port on the motherboard is dead, but even if I put it on the X a... | <p>Yes - you should be able to turn the extruder by hand when it is unplugged and therefore not powered.</p>
<p>The V2 comes with a blue plastic knob for this purpose, it may be too small to turn the shaft by hand.</p>
<p>When powered and "steppers enabled" the motors need a lot more force to overcome, but ev... | <p>Criggie's answer is basically correct, but I disagree with the conclusion that it:</p>
<blockquote>
<p>Could be expensive - you might want to compare cost of parts with cost of a new printer, remembering there may be other non-functional components still undiscovered.</p>
</blockquote>
<p>If you want to turn the End... | 2,145 |
<p>I just don't get it.
I use cocos2d for development of a small game on the iPhone/Pod. The framework is just great, but I fail at touch detection. I read that you just need to overwrite the proper functions (e.g. "touchesBegan" ) in the implementation of a class which subclasses CocosNode. But it doesn't wo... | <p>Layer is the only cocos2d class which gets touches.</p>
<p>The trick is that ALL instances of Layer get passed the touch events, one after the other, so your code has to handle this.</p>
<p>I did it like this:</p>
<pre><code>-(BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [tou... | <p>-Make your scene conforms to protocol <code>CCTargetedTouchDelegate</code>
-Add This line to <code>init</code> of your scene:</p>
<pre><code>[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
</code></pre>
<p>-Implement these functions:</p>
<pre><code>- (BOOL)c... | 49,476 |
<p>When I try to add a HTTP header key/value pair on a <code>WebRequest</code> object, I get the following exception:</p>
<blockquote>
<p>This header must be modified using the appropriate property</p>
</blockquote>
<p>I've tried adding new values to the <code>Headers</code> collection by using the Add() method but... | <p>If you need the short and technical answer go right to the last section of the answer.</p>
<p>If you want to know better, read it all, and i hope you'll enjoy...</p>
<hr>
<p>I countered this problem too today, and what i discovered today is that:</p>
<ol>
<li><p>the above answers are true, as:</p>
<p>1.1 it's t... | <p>I'm using just: </p>
<pre><code>request.ContentType = "application/json; charset=utf-8"
</code></pre>
| 29,668 |
<p>Sometimes I break long conditions in <code>if</code>s onto several lines. The most obvious way to do this is:</p>
<pre><code> if (cond1 == 'val1' and cond2 == 'val2' and
cond3 == 'val3' and cond4 == 'val4'):
do_something
</code></pre>
<p>Isn't very very appealing visually, because the action blends wi... | <p>You don't need to use 4 spaces on your second conditional line. Maybe use:</p>
<pre><code>if (cond1 == 'val1' and cond2 == 'val2' and
cond3 == 'val3' and cond4 == 'val4'):
do_something
</code></pre>
<p>Also, don't forget the whitespace is more flexible than you might think:</p>
<pre><code>if (
... | <p>Pack your conditions into a list, then do smth. like:</p>
<pre><code>if False not in Conditions:
do_something
</code></pre>
| 21,908 |
<p>Question number three in my quest to properly understand MVC <em>before</em> I implement it:</p>
<p>I have two cases in mind:</p>
<ol>
<li>The primary application
window needs to launch the
preferences window. (One View
invoking another View.)</li>
<li>The primary Model for an application
needs to access a propert... | <p>You may want to consider looking up the Front Controller design pattern.</p>
<blockquote>
<p>The Front Controller pattern defines a single component that is responsible for processing application requests. A front controller centralizes functions such as view selection, security, and templating, and applies them ... | <p>Model does not mean a single model object. The model is the subset of the entirety of your domain model which is directly related to the controller actions and the views in question.</p>
| 28,205 |
<p>Is there any lib that convert very long numbers to string just copying the data?</p>
<p>These one-liners are too slow:</p>
<pre><code>def xlong(s):
return sum([ord(c) << e*8 for e,c in enumerate(s)])
def xstr(x):
return chr(x&255) + xstr(x >> 8) if x else ''
print xlong('abcd'*1024) % 666... | <p>You want the struct module.</p>
<pre><code>packed = struct.pack('l', 123456)
assert struct.unpack('l', packed)[0] == 123456
</code></pre>
| <p>Performance of <code>cPickle</code> vs. <code>marshal</code> (Python 2.5.2, Windows):</p>
<pre><code>python -mtimeit -s"from cPickle import loads,dumps;d=13**666" "loads(dumps(d))"
1000 loops, best of 3: 600 usec per loop
python -mtimeit -s"from marshal import loads,dumps;d=13**666" "loads(dumps(d))"
100000 loops,... | 42,627 |
<p>I'm using the <code>cacheCounter</code> in <code>CakePHP</code>, which increments a counter for related fields.</p>
<p>Example, I have a Person table a Source table. Person.source_id maps to a row in the Source table. Each person has one Source, and each Source has none or many Person rows.</p>
<p><code>cacheCount... | <p>To monitor changes in a field, you can use this logic in your model with no changes elsewhere required:</p>
<pre><code>function beforeSave() {
$this->recursive = -1;
$this->old = $this->find(array($this->primaryKey => $this->id));
if ($this->old){
$changed_fields = array();
... | <p>See if the "save" uses some sort of DBAL call that returns "affected rows", usually this is how you can judge if the last query changed data, or if it didn't. Because if it didn't, the affected rows after an UPDATE-statement are 0.</p>
| 14,098 |
<p>I have an application that uses <code>window.open()</code> to generate dynamic popups. Unfortunately, I've had trouble creating the content of the new windows using the standard DOM functions (<code>createElement</code>, <code>appendChild</code>), and I've gone to using <code>document.write()</code> to generate the ... | <p>Why not use a library function such as <a href="http://plugins.jquery.com/project/modaldialog" rel="nofollow noreferrer">http://plugins.jquery.com/project/modaldialog</a> instead of reinventing the wheel?</p>
<p>[EDIT] OR</p>
<pre><code>function writePopup(){
var popup = window.open("", "_blank", "height=400... | <p>Would it be possible to have another page that generates the dynamic content, and pop it open, passing arguments that identify the content you want generated, instead of trying to write to a new window?</p>
| 33,266 |
<p>Does anyone know how I can check to see if a directory is writeable in PHP? </p>
<p>The function <a href="http://php.net/manual/en/function.is-writable.php" rel="nofollow noreferrer"><code>is_writable</code></a> doesn't work for folders.</p>
<blockquote>
<p>Edit: It does work. See the accepted answer.</p>
</blo... | <p>Yes, it does work for folders....</p>
<blockquote>
<p>Returns TRUE if the filename exists and is writable. The filename argument may be a directory name allowing you to check if a directory is writable. </p>
</blockquote>
| <p>this is how I do it:</p>
<p>create a file with <code>file_put_contents()</code> and check the return value, if it is positive (number of written in Bytes) then you can go ahead and do what you have to do, if it is FALSE then it is not writable </p>
<pre><code>$is_writable = file_put_contents('directory/dummy.txt',... | 13,446 |
<p>I need to find out the file/directory name that a .lnk is pointing to using c#.</p>
<p>What is the simplest way to do this?</p>
<p>Thanks.</p>
| <p>I wrote this for video browser, it works really well </p>
<pre><code>#region Signitures imported from http://pinvoke.net
[DllImport("shfolder.dll", CharSet = CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath);
[Flags()]
enum... | <p>Or simply test <code>mydir</code> and if it does not exists, <code>mydir.lnk</code> with <code>File.Exixts()</code>.</p>
<p>Works for a file.</p>
| 16,825 |
<p>In an UML component diagram, how does one tag or identify a component as a database, so that it's easily recognizable? In the old days there was the cylinder symbol for showing database but that's not part of the UML. Same goes for an application server for instance, how would that be shown?</p>
<p>Are stereotypes ... | <p>Just use the <code><<database>></code> for the component diagram.</p>
<p>For a more detailed information check out this article: <a href="http://www.sparxsystems.com.au/resources/uml_datamodel.html" rel="noreferrer">http://www.sparxsystems.com.au/resources/uml_datamodel.html</a></p>
| <p>You tag databases <code><<database>></code> and servers as (it appears) <code><<infrastructure>></code> <a href="http://www.agilemodeling.com/artifacts/componentDiagram.htm" rel="nofollow noreferrer">according to Scott Ambler</a>. I pulled this information from Figure 1, but I would recommend... | 30,631 |
<p>Is it good practice to have more than one <code>try{} catch{}</code> statement per method?</p>
| <p>In my point of view it is good practice to have each method handle only a single task. As such you'll rarely need to have multiple try/catch blocks within a single method. However, I don't see any problems with it. </p>
<p>As Lisa pointed out you should catch specific exceptions and <em>only</em> catch the exceptio... | <p>I would say that depends. To me, it looks a little sloppy having all these try-catches everywhere. I try to consolidate to a try block with many catches. Sometimes this doesn't work, you may need to have them separate, but to keep things readable, that's how I prefer it at least.</p>
<p>Also if your method is to... | 48,662 |
<p>Is it possible to write connect and open a SQL Compact 3.5 database from within MS Access 2003? I want to be able to use MS Access 2003 to manipulate data in a SQL Compact 3.5 database. If it is possible, then what statements would be used to open the database?</p>
| <p>This is just an idea and I can't confirm that it will work, but given that SQL Compact lacks an ODBC driver and you can't have linked tables, perhaps you can use an OLEDB connect string for SQL Compact as the Source Connect String of a saved QueryDef in Access. If you can get that to work you may be able to create a... | <p>Though I did not try it specifically with SQL Compact, connecting to the server should be standard:</p>
<ol>
<li>Check that the ADODB file (msado21.tlb) is correctly refernced in your available tools</li>
<li><p>Write down your connection string somewhere like this one: </p>
<p>MyConnectionString = "Provider=SQLOL... | 42,517 |
<p>Going back to my previous question on OCSP, does anybody know of "reliable" OCSP libraries for Python, Java and C?</p>
<p>I need "client" OCSP functionality, as I'll be checking the status of Certs against an OCSP responder, so responder functionality is not that important.</p>
<p>Thanks</p>
| <p>Have you check pyOpenSSL.. am sure openssl supports ocsp and python binding may support it</p>
| <p><a href="http://www.openssl.org/" rel="nofollow noreferrer">OpenSSL</a> is the most widely used product for OCSP in C. It's quite reliable, although incredibly obtuse. I'd recommend looking at apps/ocsp.c for a pretty good example of how to make OCSP requests and validate responses.</p>
<p>Vista and Server 2008 hav... | 17,325 |
<p>I'm building a static ASP.NET site (using Masterpages and a few forms) and I'm about to release it onto my production server.</p>
<p>I know about changing <code><compilation debug="true"></code> to false, but I'm wondering what other things I can do to obtain the highest speed possible. There is no data acces... | <p>If you're writing any log or output files, make sure the proper folder permissions are setup in the production environment. Typically debug/test environments are much more lax on file read/write permissions than production.</p>
| <p>You should read this:<br>
<a href="https://stackoverflow.com/questions/72394/what-should-a-developer-know-before-building-a-public-web-site">https://stackoverflow.com/questions/72394/what-should-a-developer-know-before-building-a-public-web-site</a></p>
<p>It's currently the 9th highest voted question on SO and in ... | 41,245 |
<p>I have an ASP.NET web page with a Login control on it. When I hit Enter, the Login button doesn't fire; instead the page submits, doing nothing.</p>
<p>The standard solution to this that I've found online is to enclose the Login control in a Panel, then set the Panel default button. But apparently that doesn't wo... | <p>This should be helpful: <a href="http://weblogs.asp.net/jgalloway/archive/2007/10/03/asp-net-setting-the-defaultbutton-for-a-login-control.aspx" rel="noreferrer">http://weblogs.asp.net/jgalloway/archive/2007/10/03/asp-net-setting-the-defaultbutton-for-a-login-control.aspx</a></p>
<p>You can use the following to ref... | <p>Based on your good answers, made a custom control that<br/>
enables a Page to have several default buttons based on which panel which is in focus.<br/>
It overrides Panel's OnLoad method and DefaultButton property.</p>
<pre><code>public class DefaultButtonPanel:Panel
{
protected override void OnLoad(EventArgs ... | 24,645 |
<p>I need to write a browser interface for an application running embedded on a single board computer (<a href="http://www.gumstix.com/store/catalog/product_info.php?products_id=178" rel="nofollow noreferrer">Gumstix Verdex</a> for anyone who's interested), so I won't be able to use any web frameworks due to space and ... | <p>One of the biggest resources for CGI programming is the <a href="https://web.archive.org/web/20090413024447/http://hoohoo.ncsa.uiuc.edu/cgi/" rel="nofollow noreferrer">CGI homepage</a>. Once you're done with that, familiarizing yourself with the <a href="https://docs.python.org/library/cgi.html" rel="nofollow norefe... | <ul>
<li><a href="http://www.cs.virginia.edu/~lab2q/" rel="nofollow noreferrer">http://www.cs.virginia.edu/~lab2q/</a></li>
<li><a href="http://www.devshed.com/c/a/Python/Writing-CGI-Programs-in-Python/" rel="nofollow noreferrer">http://www.devshed.com/c/a/Python/Writing-CGI-Programs-in-Python/</a></li>
<li><a href="ht... | 28,128 |
<p>I have a bunch of legacy documents that are HTML-like. As in, they look like HTML, but have additional made up tags that aren't a part of HTML</p>
<pre><code><strong>This is an example of a <pseud-template>fake tag</pseud-template></strong>
</code></pre>
<p>I need to parse these files. PHP... | <p>You can suppress warnings with <a href="http://www.php.net/manual/en/function.libxml-use-internal-errors.php" rel="noreferrer"><code>libxml_use_internal_errors</code></a>, while loading the document. Eg.:</p>
<pre><code>libxml_use_internal_errors(true);
$doc = new DomDocument();
$doc->loadHTML("<strong>Thi... | <p>My quick and dirty solution to this problem was to run a loop that matches my list of custom tags with a regular expression. The regexp doesn't catch tags that have another inner custom tag inside them. </p>
<p>When there is a match, a function to process that tag is called and returns the "processed HTML". If that... | 9,223 |
<p>What'd also interest me is which have more or less dependencies.</p>
| <p>I'm using <a href="http://coderay.rubychan.de/" rel="nofollow noreferrer">Coderay</a> (<a href="http://blog.logeek.fr/2008/3/31/data-visualization-with-ruby-and-rmagick-where-are-those-bikes" rel="nofollow noreferrer">see it in action at the bottom of this article</a>)</p>
<p>Not sure how many (if any) dependencies... | <p><a href="http://www.google.hu/search?q=ruby+syntax+highlighting+library&btnG=Keres%C3%A9s&hl=hu&sa=2" rel="nofollow noreferrer">Google is our friend</a>...</p>
<p>First hit: <a href="http://syntax.rubyforge.org/chapter-1.html#s1" rel="nofollow noreferrer">http://syntax.rubyforge.org/chapter-1.html#s1</a... | 27,268 |
<p>I am writing a C# program which captures signals from a external device, and sends keystrokes to another application. I am using SendKeys and it works fine.</p>
<p>SendKeys does "press" a key by holding and releasing it immediately. I would like to make it push key and release it at will.</p>
<p>My question is : "... | <p>I don't think it's possible from .NET directly
You could try using keybd_event native call by p/invoking the function as described here: <a href="http://pinvoke.net/default.aspx/user32.keybd_event" rel="nofollow noreferrer">http://pinvoke.net/default.aspx/user32.keybd_event</a></p>
<p>The MSDN for keybd_event is he... | <p>I once was looking to do the same thing on powerpoint, to hide the cursor, and later to stop the slideshow. But it's hard and tricky as there's many top level windows appeared in powerpoint, also it's hard to figure out which part of the emulation failed if it doesn't work. After looking into the message queue using... | 20,771 |
<p>I am overriding a lot of SAP's Portal functionality in my current project. I have to create a custom fixed width framework, custom iView trays, custom KM API functionality, and more.</p>
<p>With all of these custom parts, I will not be using a lot of the style functionality implemented by SAP's Theme editor. What... | <p>I'd consider it dirty hack, but as a non-Portal developer I'd consider using JavaScript to insert a new link element in the head pointing to your new CSS file. Of course you'd have a flash of un-styled content because the script probably won't run until after part of the page has been downloaded and rendered, but ... | <p>I hate that I'm answering my own question, but I did find a potential solution that's not documented well and in typical SAP fashion uses deprecated methods. So it might be a slightly less dirty hack than what Eric suggested. I found it through an unrelated SDN forum post.</p>
<p>Basically, you dive into the requ... | 8,781 |
<p>I am currently using Telerik's carousel control, but it is lacking many features and is buggy. Is there a good control out there that looks the the coverflow control in itunes?</p>
| <p>ElementFlow control is inside the codeplex project called <a href="http://www.codeplex.com/fluidkit" rel="nofollow noreferrer">FluidKit</a> - can be downloaded from <a href="http://www.codeplex.com/fluidkit" rel="nofollow noreferrer">here</a> </p>
| <p><a href="http://www.telerik.com/products/wpf/carousel.aspx" rel="nofollow noreferrer">http://www.telerik.com/products/wpf/carousel.aspx</a>
<a href="http://www.devexpress.com/Products/NET/Controls/WPF/Carousel/dependency_properties.xml" rel="nofollow noreferrer">http://www.devexpress.com/Products/NET/Controls/WPF/Ca... | 19,800 |
<p>I generally try and keep all related entities in the same repository. The following are entities that have a relationship between the two (marked with indentation):</p>
<ul>
<li>User
<ul>
<li>UserPreference</li>
</ul></li>
</ul>
<p>So they make sense to go into a user repository. However users are often linked to... | <p>In the Eric Evan's Domain Driven Design ( <a href="http://domaindrivendesign.org/index.htm" rel="nofollow noreferrer">http://domaindrivendesign.org/index.htm</a> ) sense of things you should first think about what about your Aggregates. You then build you repositories around those.</p>
<p>There are many techniques ... | <p>If SQL Server is your database, and by repository you mean a database, then I would just stick the information in whatever database makes sense and have a view in dependent databases that selects out of the other database via three-dot notation.</p>
| 48,171 |
<p>I get the concept of creating a business object or entity to represent something like a Person. I can then serialize the Person using a DTO and send it down to the client. If the client changes the object, it can have an IsDirty flag on there so when it gets sent back to the server I know to update it.</p>
<p>But w... | <p>Firstly, you can use an existing framework that addresses these issues, like CSLA.NET. The author of this framework has tackled these very issues. Go to <a href="http://www.rockfordlhotka.net/cslanet/" rel="nofollow noreferrer">http://www.rockfordlhotka.net/cslanet/</a> for this. Even if you don't use the full fra... | <p>The data objects don't track changes. The change tracking occurs on the DataContext and objects that you've retrieved through the DataContext. So in order to track changes you need to do the following:</p>
<pre><code>public class FooDataContext : DataContext
{
public Table<Order> Orders;
}
public class... | 10,560 |
<p>We have an application where people can type in multiple langugaes. Though we only have one database to store all the data. We have text columns as nvarchar ( assuming we only want text data to be in multiple languages and not all dates etc.)</p>
<p>Do you think this is a feasbile solution and are there any other p... | <p>I think it depends on the type of data. For names + addresses it's probably ok... a name is a name no matter what language it's in.</p>
<p>For descriptive text (eg a notes field) it might be confusing... at the very least you might want to record the language that the text is in so that you can filter against it l... | <p>--some thoughts</p>
<pre><code> USE [db]
GO
/****** Object: Table [dbo].[CultureInfo] Script Date: 06/23/2009 21:07:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[CultureInfo](
[CultureInfoId] [int] IDENTI... | 21,937 |
<p>A number of business areas I work with use a folder structure to organise their Sharepoint housed documents (not ideal I know, but we're stuck with it). </p>
<p>I would like to use a web part page to present a number of views of their document libraries based on the subfolders that the documents appear in, but thi... | <p>With Sharepoint Designer you can edit the CAML of your XSLT List View. </p>
<p>If you set the Scope attribute of the View element to <em>Recursive</em> or <em>RecursiveAll</em>, which returns all Files and Folders, you can filter the documents by <em>FileDirRef</em>:</p>
<pre><code><Where>
<Contains>... | <p>What kind of document library information do you want in the view?
How do you want the user to filter the view?</p>
<p>In general the most powerful way of creating views in sharepoint is with the data view web part.
<a href="http://office.microsoft.com/en-us/sharepointdesigner/HA100948041033.aspx" rel="nofollow no... | 37,759 |
<p>Has anyone managed to do this? I tried making a managed wrapper class for IPropertyStore but am getting AccessViolationExceptions on the methods (i.e. IPropertyStore::GetValue) that take a pointer to PROPVARIANT (rendered as a MarshalAs(UnmanagedType.Struct) out parameter in my managed version) Probably my underst... | <p>Speaking of nullable types - I think they can be used to solve the problem of forcing/not forcing the initialization of an enum. Say we have</p>
<pre><code>enum Color { Red, Blue }
</code></pre>
<p>And let's say you have a function:</p>
<pre><code>void Draw(Color c);
</code></pre>
<p>That function says that it <... | <p>Depends how the type is used. It's often easier for users of the type not to have an "undefined" value, because you don't have to special-case one value. But if you need one (because values sometimes need to be in a state which is otherwise not any of the enumerated values) then you need one. You usually don't save ... | 44,988 |
<p>I am wondering what is your experience with AxoSoft OnTime issues tracking and project management solution in case you have ever used it (pros and cons)...</p>
<p>Cheers,
B.</p>
| <p>The. Client. Is. Bloody. Slow!</p>
<p>But yes, we use it. And it is powerful. And configurable.</p>
<p>But hell is the client slow!</p>
<p>Use the http(s) if at all possible.</p>
| <p>We use it and its got a lot of nice features - def some quirks, but since we have implemented it - it has kept us all on the same page. It has some nice integration plugins to visual studio as well.</p>
<p>I would say its worth a go.</p>
<p>Sorry, just wanted to add: we use it for issue tracking only</p>
| 26,203 |
<p>I am attempting to construct model tank tracks with accompanying wheels and sprockets. All parts will be printed in PLA. The tracks will be driven by electric motors.</p>
<p>What would be a suitable grease for this project to minimize friction without damaging the plastics.</p>
| <p>I use cosmetic vaseline - <a href="https://en.wikipedia.org/wiki/Petroleum_jelly" rel="noreferrer">petroleum jelly</a>. Usually it is white to transparent and odorless. It's cheap and available in all drugstores and cosmetics stores.</p>
<p>As suggested by Tom van der Zanden I'm adding additional info about interac... | <p>I have been using <em>sewing machine oil</em> for my 3D printed extruder gear for a couple of years, without any noticeable wear so far.</p>
<p>In general, I believe any kind of low viscosity oil would do, but then again, it also depends on the environment in which you plan to use the model. If you plan on using it... | 298 |
<p>Let's say I have a class that has a member called data which is a list. </p>
<p>I want to be able to initialize the class with, for example, a filename (which contains data to initialize the list) or with an actual list.</p>
<p>What's your technique for doing this?</p>
<p>Do you just check the type by looking at... | <p>A much neater way to get 'alternate constructors' is to use classmethods. For instance:</p>
<pre><code>>>> class MyData:
... def __init__(self, data):
... "Initialize MyData from a sequence"
... self.data = data
...
... @classmethod
... def fromfilename(cls, filename):
... ... | <p>OK, great. I just tossed together this example with a tuple, not a filename, but that's easy. Thanks all.</p>
<pre><code>class MyData:
def __init__(self, data):
self.myList = []
if isinstance(data, tuple):
for i in data:
self.myList.append(i)
else:
... | 17,106 |
<p>I have a 4 side convex Polygon defined by 4 points in 2D, and I want to be able to generate random points inside it.</p>
<p>If it really simplifies the problem, I can limit the polygon to a parallelogram, but a more general answer is preferred.</p>
<p>Generating random points until one is inside the polygon wouldn... | <p>A. If you can restrict your input to parallelogram, this is really simple:</p>
<ol>
<li>Take two random numbers between 0 and 1. We'll call then <code>u</code> and <code>v</code>.</li>
<li><p>If your parallelogram is defined by the points ABCD such that AB, BC, CD and DA are the sides, then take your point as being... | <p>For PostGIS, this is what I am using (you might want a ward for possible infinite loops). You might export the algorithm to your programming language:</p>
<pre><code>CREATE or replace FUNCTION random_point(geometry)
RETURNS geometry
AS $$
DECLARE
env geometry;
corner1 geometry;
corner2 geometry;
mi... | 29,803 |
<p>Is there a way to conveniently define a C-like structure in Python? I'm tired of writing stuff like:</p>
<pre><code>class MyStruct():
def __init__(self, field1, field2, field3):
self.field1 = field1
self.field2 = field2
self.field3 = field3
</code></pre>
| <p>Use a <a href="https://docs.python.org/2/library/collections.html#collections.namedtuple" rel="noreferrer">named tuple</a>, which was added to the <a href="http://docs.python.org/library/collections.html" rel="noreferrer">collections module</a> in the standard library in Python 2.6. It's also possible to use Raymond... | <p>I think Python structure dictionary is suitable for this requirement.</p>
<pre class="lang-py prettyprint-override"><code>d = dict{}
d[field1] = field1
d[field2] = field2
d[field2] = field3
</code></pre>
| 5,660 |
<p>I'm looking for someone reasonably cheap but better than the majority of budget hosts out there. I'm currently with brinkster.net and I've become increasingly annoyed at the their immense unreliability and low available resources.</p>
<p>Fasthosts business plan is close, but has no mysql, only has ASP.NET 2.0 and i... | <p>I have had several sites hosted on <a href="http://discountasp.net" rel="nofollow noreferrer">http://discountasp.net</a> and have had very good results. They are on year 4 of being voted best ASP.NET host in the asp.netPRO reader's choice survey.</p>
| <p>I've been with these guys for quite a bit,
<a href="http://www.webhost4life.com/" rel="nofollow noreferrer">http://www.webhost4life.com/</a>
<br>
Cheap and cheerful.</p>
| 11,624 |
<p>I have a string containing a date, and another string containing the date format of the first string. Is there a function that I can call to convert that date into something like a SYSTEMTIME structure? Basically, I'd like the opposite of <a href="http://msdn.microsoft.com/en-us/library/ms776293(VS.85).aspx" rel="no... | <p>No, but you can write a function that will convert the date format string into a <code>sscanf</code> format string and series of variables. Then copy the data from the variables to the <code>SYSTEMTIME</code> structure and you're all set.</p>
<p>It's not trivial, but it is probably the most flexible arrangement if... | <p>In the source file <a href="http://code.google.com/p/kgui/source/browse/trunk/kgui.cpp" rel="nofollow noreferrer">Here</a>.</p>
<p>I have a function that reads dates in a bunch of different formats, the function is called </p>
<pre><code>bool kGUIDate::Setz(const char *datestring)
</code></pre>
<p>It's a class th... | 28,981 |
<p>We're setting up an OpenSolaris server on Amazon's EC2 service. However, vi/vim doesn't work properly, and pkg doesn't have nano/pico.</p>
<p>Is there any other text-editor maybe?</p>
| <p>Sounds like you may just need to set an appropriate termtype to get vi working. Look into the "TERM" environment variable options, perhaps one of those will help you.</p>
| <p>SUN is working on the SUNWgnu-nano package to include this in the next release. In the meantime, you can compile the nano sources yourself. It worked for me. To compile, follow these steps:</p>
<ol>
<li>Make sure you install SUNWgcc package so that gcc is installed.</li>
<li><p>Download the source package from the ... | 42,879 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.