qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
365,868 | <p>I have a fairly standard rails app and would like to be able to access the basic CRUD (Create, Update, Delete) operations as well as queries I have added, from an iPhone app. Rails provides the REST API for these operations more or less out of the box. </p>
<p>What is the best approach to deal with the REST/XML part on the iphone, and are there any good objective-C libraries that do this kind of thing already? The operations will also need to be associated with a particular user (i.e. authenticated).</p>
| [
{
"answer_id": 365928,
"author": "Lily Ballard",
"author_id": 582,
"author_profile": "https://Stackoverflow.com/users/582",
"pm_score": 2,
"selected": false,
"text": "initWithMethod:delegate:params:"
},
{
"answer_id": 367974,
"author": "diclophis",
"author_id": 32678,
... | 2008/12/13 | [
"https://Stackoverflow.com/questions/365868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42404/"
] |
365,887 | <p>I know how they are different syntactically, and that C++ uses new, and C uses malloc. But how do they work, in a high-level explanation?</p>
<p>See <a href="https://stackoverflow.com/questions/240212/what-is-the-difference-between-newdelete-and-mallocfree#240308">What is the difference between new/delete and malloc/free?</a></p>
| [
{
"answer_id": 365891,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": true,
"text": "new (a, b, c) TypeId;\n\n// the function called by the compiler has to have the following signature:\noperat... | 2008/12/13 | [
"https://Stackoverflow.com/questions/365887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25632/"
] |
365,888 | <p>Now, I realise the initial response to this is likely to be "you can't" or "use analytics", but I'll continue in the hope that someone has more insight than that.</p>
<p>Google adwords with "autotagging" appends a "gclid" (presumably "google click id") to link that sends you to the advertised site. It appears in the web log since it's a query parameter, and it's used by analytics to tie that visit to the ad/campaign.</p>
<p>What I would like to do is to extract any useful information from the gclid in order to do our own analysis on our traffic. The reasons for this are:</p>
<ul>
<li>Stats are imperfect, but if we are collating them, we know exactly what assumptions we have made, and how they were calculated.</li>
<li>We can tie the data to the rest of our data and produce far more accurate stats wrt conversion rate.</li>
<li>We don't have to rely on javascript for conversions.</li>
</ul>
<p>Now it is clear that the gclid is base64 encoded (or some close variant), and some parts of it vary more than others. Beyond that, I haven't been able to determine what any of it relates to.</p>
<p>Does anybody have any insight into how I might approach decoding this, or has anybody already related gclids back to compaigns or even accounts?</p>
<p>I have spoken to a couple of people at google, and despite their "don't be evil" motto, they were completely unwilling to discuss the possibility of divulging this information, even under an NDA. It seems they like the monopoly they have over <em>our</em> web stats.</p>
| [
{
"answer_id": 5887955,
"author": "Jeff Wu",
"author_id": 538336,
"author_profile": "https://Stackoverflow.com/users/538336",
"pm_score": 2,
"selected": false,
"text": ".*[?&]gclid=([^$&]*)\n"
},
{
"answer_id": 20616153,
"author": "andre",
"author_id": 3108126,
"autho... | 2008/12/13 | [
"https://Stackoverflow.com/questions/365888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26334/"
] |
365,892 | <p>Duplicate Of : <a href="https://stackoverflow.com/questions/2527/c-treeview-context-menus">Find node clicked under context menu</a></p>
<p>I've got a context menu on a Treeview, when the user right clicks it supposed to change based on the currently right clicked node's tag object.</p>
<p>Currently I'm updating the context menu in after_select event, however this doesn't work when user right clicks to another node without selecting it.</p>
<p>How can I detect which node right clicked and change the context menu? Or am I doing it wrong?</p>
| [
{
"answer_id": 5887955,
"author": "Jeff Wu",
"author_id": 538336,
"author_profile": "https://Stackoverflow.com/users/538336",
"pm_score": 2,
"selected": false,
"text": ".*[?&]gclid=([^$&]*)\n"
},
{
"answer_id": 20616153,
"author": "andre",
"author_id": 3108126,
"autho... | 2008/12/13 | [
"https://Stackoverflow.com/questions/365892",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40322/"
] |
365,898 | <p>I'm familiar with .NET and with SQL. Now I'm looking at the new LINQ and it looks to me just like a cursor. I understand the ease of use, etc., but if I do a LINQ-to-SQL query with a foreach loop, am I just using a DB cursor? Or is there some sort of magic behind the scenes where LINQ collects all the data at once and feeds it to my program one row at a time?</p>
| [
{
"answer_id": 365916,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "IDataReader"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/365898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12897/"
] |
365,935 | <p>All of my methods are failing me in various ways.
different lighting can mess it all up too.</p>
<p>has anyone every trying to return a name given a rgb value? "red" "green" "blue" would be enough to satisfy my needs for today.</p>
<p>i have unsafe byte processing of images from my web cam.</p>
<p><a href="https://i.stack.imgur.com/ptjtc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ptjtc.png" alt="webcam"></a>
</p>
<p><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Color_star-en.svg/646px-Color_star-en.svg.png" alt="colors"></p>
| [
{
"answer_id": 365942,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "IsNamedColor"
},
{
"answer_id": 365949,
"author": "Brian",
"author_id": 19299,
"author_profile": ... | 2008/12/13 | [
"https://Stackoverflow.com/questions/365935",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146637/"
] |
365,968 | <p>I am looking to add the capability for users to write plugins to the program I have developed in Delphi. The program is a single executable with no DLLs used. </p>
<p>This would allow the user community to write extensions to my program to access the internal data and add capabilities that they may find useful. </p>
<p>I've seen the post at: <a href="https://stackoverflow.com/questions/8140/adding-plugin-capability">Suggestions for Adding Plugin Capability?</a> but its answers don't seem transferrable to a Delphi program.</p>
<p>I would like, if possible, to add this capability and keep my application as a single executable without any DLLs or additional modules required.</p>
<p>Do you know of any resources, components or articles that would suggest how to best do this in Delphi, or do you have your own recommendation?</p>
| [
{
"answer_id": 366007,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 3,
"selected": false,
"text": "LoadLibrary"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/365968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30176/"
] |
365,975 | <p>Namely, how does the following code:</p>
<pre><code>var sup = new Array(5);
sup[0] = 'z3ero';
sup[1] = 'o3ne';
sup[4] = 'f3our';
document.write(sup.length + "<br />");
</code></pre>
<p>output '5' for the length, when all you've done is set various elements?</p>
<p>My 'problem' with this code is that I don't understand how <code>length</code> changes without calling a <code>getLength()</code> or a <code>setLength()</code> method. When I do any of the following:</p>
<pre><code>a.length
a['length']
a.length = 4
a['length'] = 5
</code></pre>
<p>on a non-array object, it behaves like a dict / associative array. When I do this on the array object, it has special meaning. What mechanism in JavaScript allows this to happen? Does JavaScript have some type of property system which translates</p>
<pre><code>a.length
a['length']
</code></pre>
<p>into "get" methods and</p>
<pre><code>a.length = 4
a['length'] = 5
</code></pre>
<p>into "set" methods?</p>
| [
{
"answer_id": 365992,
"author": "finpingvin",
"author_id": 46054,
"author_profile": "https://Stackoverflow.com/users/46054",
"pm_score": 2,
"selected": false,
"text": "sup['look'] = 4;"
},
{
"answer_id": 365995,
"author": "tvanfosson",
"author_id": 12950,
"author_pro... | 2008/12/14 | [
"https://Stackoverflow.com/questions/365975",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] |
366,017 | <p>I'm creating a set of enum values, but I need each enum value to be 64 bits wide. If I recall correctly, an enum is generally the same size as an int; but I thought I read somewhere that (at least in GCC) the compiler can make the enum any width they need to be to hold their values. So, is it possible to have an enum that is 64 bits wide?</p>
| [
{
"answer_id": 366026,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 8,
"selected": true,
"text": "enum"
},
{
"answer_id": 24067364,
"author": "Kevin Cox",
"author_id": 1166181,
"author_profile": ... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28804/"
] |
366,031 | <p>Is there any way to create an array-like object in JavaScript, without using the built-in array? I'm specifically concerned with behavior like this:</p>
<pre><code>var sup = new Array(5);
//sup.length here is 0
sup[0] = 'z3ero';
//sup.length here is 1
sup[1] = 'o3ne';
//sup.length here is 2
sup[4] = 'f3our';
//sup.length here is 5
</code></pre>
<p><strong>The particular behavior I'm looking at here is that sup.length changes without any methods being called.</strong> I understand from <a href="https://stackoverflow.com/questions/365975/how-are-javascript-arrays-implemented">this question</a> that the [] operator is overloaded in the case of arrays, and this accounts for this behavior. Is there a pure-javascript way to duplicate this behavior, or is the language not flexible enough for that?</p>
<p>According to the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array" rel="noreferrer">Mozilla docs</a>, values returned by regex also do funky things with this index. Is this possible with plain javascript?</p>
| [
{
"answer_id": 366044,
"author": "finpingvin",
"author_id": 46054,
"author_profile": "https://Stackoverflow.com/users/46054",
"pm_score": 1,
"selected": false,
"text": "var sup = []; //Shorthand for an empty array\n//sup.length is 0\nsup.push(1); //Adds an item to the array (You don't ne... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] |
366,047 | <p>Looking at the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array" rel="noreferrer">mozilla documentation</a>, looking at the regular expression example (headed "Creating an array using the result of a match"), we have statements like:</p>
<blockquote>
<p>input: A read-only property that reflects the original string against which the regular expression was matched.</p>
<p>index: A read-only property that is the zero-based index of the match in the string.</p>
</blockquote>
<p>etc... is it possible to create your own object in JavaScript which will have read-only properties, or is this a privilege reserved to built-in types implemented by particular browsers?</p>
| [
{
"answer_id": 366082,
"author": "Ryan Doherty",
"author_id": 956,
"author_profile": "https://Stackoverflow.com/users/956",
"pm_score": 3,
"selected": false,
"text": "YAHOO.myProject.myModule = function () {\n\n//\"private\" variables:\nvar myPrivateVar = \"I can be accessed only from wi... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366047",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] |
366,054 | <p>i have a string that looks like</p>
<pre><code>"<input id=a/>"<input id=b/>"<input id=c/>etc.
</code></pre>
<p>I need to change it to</p>
<pre><code>"<input id='a'/>"<input id='b'/>"<input id='c'/>etc,
</code></pre>
<p>any ideas how? </p>
| [
{
"answer_id": 366090,
"author": "foxdonut",
"author_id": 26353,
"author_profile": "https://Stackoverflow.com/users/26353",
"pm_score": 1,
"selected": false,
"text": "%s/\"<input id=\\(.\\)\\/>/\"<input id='\\1'\\/>/g\n"
},
{
"answer_id": 366099,
"author": "Renaud Bompuis",
... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,088 | <p>If you create a pure ActionScript project in Flex Builder 3 and want to do unit testing using flexunit, what is the best option?</p>
<p>The built-in Flex builder will refuse to build the mxml file containing the TestRunnerBase component as it is a pure ActionScript project (no Flex allowed). It is impossible to add the mxml file to the "ActionScript Applications" list in the project settings.</p>
<p>Right now I can see two options, both undesirable.</p>
<ol>
<li>Add the unit testing mxml file to the project and create an external tool setup to build and run it. This is the approach I'm taking now, and it works fine, except that interactive debugging is impossible.</li>
<li>Create a new Flex project just for the test mxml file and add the main project's src directory as an additional source directory in the build options. I don't like this approach because it requires that I keep the mxml file in a separate directory tree from all the other source files in addition to the ugliness of maintaining two projects.</li>
</ol>
| [
{
"answer_id": 367871,
"author": "Richard Szalay",
"author_id": 3603,
"author_profile": "https://Stackoverflow.com/users/3603",
"pm_score": 1,
"selected": false,
"text": "// import mx.core.Application;\n// import flexunit.framework.*;\n\n// class AutomatedTestHarness extends Application ... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45084/"
] |
366,093 | <p>If I check out a tagged version of my source code without creating a branch, Git indicates that I'm not associated with any branch at all. It's happy to let me make changes and check them in though. Where do those changes go? If I switch back to 'master' they disappear (overwritten by what was in master) and I can't seem to find them again. What gives? If Git lets me commit changes against what's essentially an anonymous branch, surely I can get them back?</p>
| [
{
"answer_id": 366103,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 3,
"selected": false,
"text": "git checkout -b my-branch-name\n"
},
{
"answer_id": 366147,
"author": "Paul",
"author_id": 23356,
"auth... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/826/"
] |
366,104 | <p>Make a <strong>new AS3 Document</strong> in Flash, <strong>paste</strong> in the following code and <strong>run it:</strong></p>
<pre><code>var a:Number=0;
trace(a) // 0
a+=0.3;
trace(a) // 0.3
a+=0.3;
trace(a) // 0.6
a+=0.3;
trace(a) // 0.8999999999999999
a+=0.3;
trace(a) // 1.2
a+=0.3;
trace(a) // 1.5
a+=0.3;
trace(a) // 1.8
a+=0.3;
trace(a) // 2.1
a+=0.3;
// ^ This is the output. Notice the inaccuracy starting from 0.9 / 0.89
</code></pre>
<p><strong>Why the error?</strong> I'm just doing an ordinary hi resolution addition.</p>
<p>Any <strong>workarounds?</strong></p>
| [
{
"answer_id": 366108,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 4,
"selected": true,
"text": "trace (round (a, 1))\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366104",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41021/"
] |
366,109 | <p>I have a VB6 legacy program which I need to change. I am unable to run the program from the IDE. When I activate one of the forms in the IDE I get an error which refers me to an error log file. The log file has the following in it</p>
<p>"Cannot load control SSPanel; license not found"</p>
<p>The SSPanel is part the Sheridan 3D controls (THREED32.ocx) and the component is selected.</p>
<p>How can I fix the error?</p>
| [
{
"answer_id": 22933989,
"author": "Bob Tway",
"author_id": 271907,
"author_profile": "https://Stackoverflow.com/users/271907",
"pm_score": 2,
"selected": false,
"text": "regtlibv12.exe"
},
{
"answer_id": 38057467,
"author": "Julian",
"author_id": 5202466,
"author_pro... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2755/"
] |
366,115 | <p>I found the following code to create a tinyurl.com url:</p>
<pre><code>http://tinyurl.com/api-create.php?url=http://myurl.com
</code></pre>
<p>This will automatically create a tinyurl url. Is there a way to do this using code, specifically C# in ASP.NET?</p>
| [
{
"answer_id": 366135,
"author": "mattruma",
"author_id": 1768,
"author_profile": "https://Stackoverflow.com/users/1768",
"pm_score": 4,
"selected": false,
"text": " public static string MakeTinyUrl(string url)\n {\n try\n {\n if (url.Length <= 30)\n ... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1768/"
] |
366,124 | <p>I'm building an application where I should capture several values and build a text with them: <code>Name</code>, <code>Age</code>, etc.</p>
<p>The output will be a plain text into a <code>TextBox</code>.</p>
<p>I am trying to make those information appear in kind of <code>columns</code>, therefore I am trying to separate them with <code>tab</code> to make it clearer.</p>
<p>For example, instead of having:</p>
<pre><code>Ann 26
Sarah 29
Paul 45
</code></pre>
<p>I would like it to show as:</p>
<pre><code>Ann 26
Sarah 29
Paul 45
</code></pre>
<p>Any tip on how to <code>insert</code> the tabs into my text?</p>
| [
{
"answer_id": 366126,
"author": "DShook",
"author_id": 370,
"author_profile": "https://Stackoverflow.com/users/370",
"pm_score": 10,
"selected": true,
"text": "\\t"
},
{
"answer_id": 366131,
"author": "Dan R",
"author_id": 24222,
"author_profile": "https://Stackoverf... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366124",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19159/"
] |
366,137 | <pre><code><?php
function data_info($data)
{
if ($data) {
while (!feof($data)) {
$buffer = fgets($data);
if (file_exists($buffer)) {
$bufferArray[$buffer]['Exists'] = (file_exists($buffer));
$bufferArray[$buffer]['Readable'] = (is_readable($buffer));
$bufferArray[$buffer]['Writable'] = (is_writable($buffer));
$bufferArray[$buffer]['Size'] = (filesize($buffer));
} else {
$bufferArray[$buffer]['Exists'] = "No";
}
}
print_r($bufferArray);
} else {
echo "The file could not be opened";
}
}
$data = fopen("D:/xampp/htdocs/Practice/ficheros.txt", "r");
data_info($data);
?>
</code></pre>
<p>If I have this:
ficheros.txt:
ExistingFile.txt
ExistingFile2.txt
ExistingFile3.txt...
...
It works, but If I have at least 1 NON EXISTING FILE then It will take every file as a non existing one too.</p>
<p>What's wrong? I believe someting in the inner if condition.</p>
<hr>
<p>I mean, what is wrong with the entire code.</p>
<p>I just need to make an array with arrays in it, a good result would be:</p>
<pre><code> array
(
'text.txt' => array
(
'exists' => true,
'readable' => true,
'writable' => true,
'Size' => 64
),
'document.doc' => array
(
'exists' => false
),
'photo.jpg' => array
(
'exists' => true,
'readable' => true,
'writable' => false,
'size' => 354915
)
)
</code></pre>
| [
{
"answer_id": 366150,
"author": "Athena",
"author_id": 17846,
"author_profile": "https://Stackoverflow.com/users/17846",
"pm_score": 3,
"selected": true,
"text": "$buffer"
},
{
"answer_id": 366157,
"author": "matta",
"author_id": 46071,
"author_profile": "https://Sta... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46071/"
] |
366,145 | <p>I'm trying to write a greasemonkey script, and it would be preferable for it to be able to work with images (specifically, find the darkest pixel in an image). Is there a way to do this or must I embed flash?</p>
| [
{
"answer_id": 366165,
"author": "Matthew Crumley",
"author_id": 2214,
"author_profile": "https://Stackoverflow.com/users/2214",
"pm_score": 4,
"selected": true,
"text": "// Create the canvas element\nvar canvas = document.createElement(\"canvas\");\ncanvas.width = image.width;\ncanvas.h... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29595/"
] |
366,160 | <p>First, let me explain what I am doing. I need to take an order, which is split up into different databases, and print out this very large order. What I need from the orders is about 100 or so columns from different databases. The way I was doing in was querying with a join and assigning all of the column values to a variable in my one large Order class. This has started to become troublesome. I am wondering of instead of having one class that is comprised of 100 or so members that make up the order. Should I have just one class for every database I use, and then work with that?</p>
<p>Let me add to this. Basically, is it better to map you objects to the original database tables, or the result set. Because I have my object mapped to the result set and not the individual tables.</p>
| [
{
"answer_id": 366177,
"author": "Stephen Wrighton",
"author_id": 7516,
"author_profile": "https://Stackoverflow.com/users/7516",
"pm_score": 1,
"selected": false,
"text": "Method New Order(orderId) {\n Get Database 1 Details\n Load Details into appropriate Variables\n Get Database... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45429/"
] |
366,183 | <p>I've got a website (currently in development for a third party, I'm sorry I can't show) that requires users to confirm their contact information by, clicking on a link sent to their email address, upon registration for the website.</p>
<p>It's a pretty standard practice, not very technical or unique, which is why I was surprised to find that Hotmail and Yahoo (and maybe others, I'm not sure) are blocking any email messages that are generated dynamically via the PHP code that runs the website.</p>
<p>I'm using the PHP framework CodeIgniter, and making use of their email library. I've checked my code and everything looks great, and I've also looked over the email class and it looks tip-top as well. </p>
<p>Not to mention, the message sent are delivered to every other mail service I've tried, including gmail, and several POP accounts. This leads me to believe that the problem is on the Hotmail/Yahoo end. </p>
<p>I suspect they are purposefully rejecting/bouncing the message due to formatting, subject content, or some other arbitrary issue. </p>
<p>The HTML email design is minimal, only really utilizing HTML for header tags a link. The subject of the message simply states "Welcome to ____", and is addressed from "support@______.com".</p>
<p>My question is, are there any articles relating to what could be causing this that I could read to better understand why the messages are being rejected, so I can fix the issue? </p>
<p>Preferably the article or document would be from Hotmail and Yahoo (with inside info), or from somebody who has experienced the same issue, and has come to a solution. </p>
<p>Also, are there any available utilities to test what is actually happening with the message once it hits their servers (i.e. Is it being bounced, or something else?)</p>
<p>Thank you very much! :)</p>
| [
{
"answer_id": 368380,
"author": "Riho",
"author_id": 44715,
"author_profile": "https://Stackoverflow.com/users/44715",
"pm_score": 0,
"selected": false,
"text": " $headers = \"MIME-Version: 1.0\\r\\n\";\n $headers .= \"Content-type: text/plain; charset=iso-8859-1\\r\\n\";\n $headers .=... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366183",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1198507/"
] |
366,186 | <p>I've got a column in a table (eg. UserName) which I want to make sure is unique. So I create a unique key for that column and call it IX_Users_UserName.</p>
<p>Now, if I do lots of searching for users based on their username I want to make sure there is an index for that field.</p>
<p>Do I need to create a separate index, or is the unique key also considered an index, just like the primary key is a clustered unique key?</p>
| [
{
"answer_id": 366200,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 6,
"selected": true,
"text": "IX_"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30674/"
] |
366,187 | <p>I'm looking for help getting started working programmatically with audio.</p>
<p>Specifically, the platform I'm working with exposes APIs to extract audio data from a resource (like an MP3), or to play back arbitrary data as audio. In both cases the actual data is byte arrays of 32bit floats representing 44.1 KHz stereo. What I'm looking for is help understanding what those floats represent, and what kinds of things can be done with them to dynamically analyze or modify the sound they represent.</p>
<p>What sort of concepts do I need to learn about to work with audio this way?</p>
| [
{
"answer_id": 366246,
"author": "coobird",
"author_id": 17172,
"author_profile": "https://Stackoverflow.com/users/17172",
"pm_score": 8,
"selected": true,
"text": "float"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10651/"
] |
366,189 | <p>i've got a commenting system in our database. Just like stackoverflow -> each post has a list of comments. kewl.</p>
<p>Anonymous people can add a comment or registered users also.</p>
<p>In my table, i'm thinking of having the following:</p>
<ul>
<li>Userid int NULLABLE</li>
<li>AnonymousNickname varchar(100) NULLABLE</li>
<li>AnonymousEmail varchar(200) NULLABLE</li>
</ul>
<p>now it can only be one or the other. You're either registered or your not. </p>
<p>So should i enforce some type of constraint that says <em>one or the other</em> .. and if so, how?</p>
<p>NOTE: Database is Microsoft Sql Server 2008.</p>
<p>cheers!</p>
| [
{
"answer_id": 366199,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": true,
"text": "(Userid is not null and AnonymousNickname is null and AnonymousEmail is null)\nor (Userid is null and AnonymousNickname ... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366189",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30674/"
] |
366,202 | <p>I'm new to regular expressions and would appreciate your help. I'm trying to put together an expression that will split the example string using all spaces that are not surrounded by single or double quotes. My last attempt looks like this: <code>(?!")</code> and isn't quite working. It's splitting on the space before the quote.</p>
<p>Example input: </p>
<pre><code>This is a string that "will be" highlighted when your 'regular expression' matches something.
</code></pre>
<p>Desired output:</p>
<pre><code>This
is
a
string
that
will be
highlighted
when
your
regular expression
matches
something.
</code></pre>
<p>Note that <code>"will be"</code> and <code>'regular expression'</code> retain the space between the words.</p>
| [
{
"answer_id": 366216,
"author": "Jonathan Lonowski",
"author_id": 15031,
"author_profile": "https://Stackoverflow.com/users/15031",
"pm_score": 1,
"selected": false,
"text": "\"will be\""
},
{
"answer_id": 366222,
"author": "Zach Scrivena",
"author_id": 20029,
"autho... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46077/"
] |
366,211 | <p><strong>Problem:</strong> EmacsW32 is a version of Emacs that allows the user to make Emacs treat the "Windows" key as the "Meta" key (instead of treating the Alt key as the "Meta" key). Although this works as advertised, the question is what happens when you want to create an Emacs keybinding for the "Alt" key?</p>
<p><strong>Question:</strong> Is there a way in this case to allow Emacs to capture and create keybindings to the "Alt" key also, even though it now considers "Windows" key to be the new Meta?</p>
| [
{
"answer_id": 366394,
"author": "Svante",
"author_id": 31615,
"author_profile": "https://Stackoverflow.com/users/31615",
"pm_score": 1,
"selected": false,
"text": "Meta"
},
{
"answer_id": 366636,
"author": "ShreevatsaR",
"author_id": 4958,
"author_profile": "https://... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42223/"
] |
366,228 | <p>I am not understanding the point of using .def files with DLLs.</p>
<p>It seems that it replaces the need to use explicit exports within your DLL code (ie. explicit __declspec(dllexport)) however I am unable to generate a lib file when not using these which then creates linker issues later when using the DLL. </p>
<p>So how do you use .defs when linking with the client application, do they replace the need to use a header or .lib file?</p>
| [
{
"answer_id": 376784,
"author": "cweston",
"author_id": 37966,
"author_profile": "https://Stackoverflow.com/users/37966",
"pm_score": 4,
"selected": false,
"text": "lib /machine:i386 /def:sqlite3.def\n"
},
{
"answer_id": 597573,
"author": "Community",
"author_id": -1,
... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37966/"
] |
366,232 | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/517915/when-to-use-strictfp-keyword-in-java">When to use “strictfp” keyword in java?</a> </p>
</blockquote>
<p>What is the use of Strictfp method in java?</p>
| [
{
"answer_id": 366269,
"author": "SCdF",
"author_id": 1666,
"author_profile": "https://Stackoverflow.com/users/1666",
"pm_score": 4,
"selected": true,
"text": "strictfp"
},
{
"answer_id": 366270,
"author": "Max Stewart",
"author_id": 18338,
"author_profile": "https://... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40945/"
] |
366,237 | <p>Here's an example:</p>
<pre><code>Double d = (1/3);
System.out.println(d);
</code></pre>
<p>This returns 0, not 0.33333... as it should.</p>
<p>Does anyone know?</p>
| [
{
"answer_id": 366240,
"author": "Firas Assaad",
"author_id": 23153,
"author_profile": "https://Stackoverflow.com/users/23153",
"pm_score": 6,
"selected": true,
"text": "1"
},
{
"answer_id": 366253,
"author": "coobird",
"author_id": 17172,
"author_profile": "https://S... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46084/"
] |
366,245 | <p>I'd like to make a simple html form where a person can upvote or downvote an item. However I don't like the default look of a <code><input type="submit"></code> . What other options do I have to send a POST request than a bulky, default button?</p>
| [
{
"answer_id": 366252,
"author": "Maxime Rouiller",
"author_id": 24975,
"author_profile": "https://Stackoverflow.com/users/24975",
"pm_score": 3,
"selected": false,
"text": "document.myform.submit();\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25680/"
] |
366,251 | <p>I'm trying to use prototype and scriptaculous to hide and display a div element but the function (below) to take advantage of the prototype setStyle property isn't working and I'm not sure what the problem is.</p>
<pre><code><script type="text/javascript" language="javascript">
function bodyOnload() {
$('content1').setStyle({ display: 'none' });
$('content2').setStyle({ display: 'none' });
}
</script>
<script type="text/javascript" language="javascript">
var currentId = null;
Effect.Accordion = function (contentId) {
var slideDown = 0.5;
var slideUp = 0.5;
contentId = $(contentId);
if (currentId != contentId) {
if (currentId == null) {
new Effect.SlideDown(contentId, {duration: slideDown});
} else {
new Effect.SlideUp(currentId, {duration: slideUp});
new Effect.SlideDown(contentId, {duration: slideDown});
}
currentId = contentId;
} else {
new Effect.SlideUp(currentId, {duration: slideUp});
currentId = null;
}
};
</script>
</code></pre>
<p>The preceding function is called as such:</p>
<pre><code><div id="accordion">
<div id="part1">
<div id="nav1" onclick="new Effect.Accordion('content1');">
Post a comment 1
</div>
<div id="content1">
<form id="form" name="form" action="post.php" method="post">
<textarea name="commentbody" cols="20" rows="10"></textarea>
<button type="submit">Post Comment</button>
<input type="hidden" name="blogID" value="1" />
<input type="hidden" name="userID" value="3" />
<input type="hidden" name="parentID" value="7" />
<div class="spacer"></div></form>
</div>
</div>
<div id="part2">
<div id="nav2" onclick="new Effect.Accordion('content2');">
Post a comment 2
</div>
<div id="content2">
<form id="form" name="form" action="post.php" method="post">
<textarea name="commentbody" cols="20" rows="10"></textarea>
<button type="submit">Post Comment</button>
<input type="hidden" name="blogID" value="1" />
<input type="hidden" name="userID" value="3" />
<input type="hidden" name="parentID" value="7" />
<div class="spacer"></div></form>
</div>
</div>
</div>
</code></pre>
<p>Here's what happens with the code.</p>
<ul>
<li>In both ie and firefox it does nothing but when you click on the link that calls the effect.accordion method the method works as expected. The problem is with the prototype function which doesn't hide the elements. Any help with be greatly appreciated. </li>
</ul>
| [
{
"answer_id": 366297,
"author": "maxnk",
"author_id": 45862,
"author_profile": "https://Stackoverflow.com/users/45862",
"pm_score": 1,
"selected": false,
"text": "window.onload = bodyOnload;\n"
},
{
"answer_id": 366304,
"author": "Jonathan Lonowski",
"author_id": 15031,
... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40376/"
] |
366,255 | <p>MSIE v7 does not (in my hands) open a Modeless Dialog or trigger an onLoad event if there is a Javascript alert in the target page. The following fails in MSIE v7 but is OK in v6 (zip file of full source available if required). </p>
<p>Would appreciate others confirming this and discussing why this should be so.</p>
<p>index.htm (only javascript function shown here)</p>
<pre><code>function openDialog(n) {
if (typeof(window.showModalDialog) == 'object') { /* Ensure of browser support */
var sURL = 'modeless.htm'; /* Set the URL */
var oWin = window.showModelessDialog(sURL); /* Create new modeless window */
}
else {
alert('"showModlessDialog" not supported!');
}
}
</code></pre>
<p>modeless.htm</p>
<pre><code><html>
<head>
<title>Modeless dialog</title>
</head>
<body bgcolor="#ff0000" text="#ffffff" onLoad="alert('Modeless is now loaded')">
<center>
<h1>Modeless</h1>
</center>
<script type="text/javascript" language="JavaScript">
/* If the next line is included, it prevents the onLoad event occurring in MSIE v7 */
alert('This alert stops the onLoad event in MSIE v7!');
</script>
</body>
</html>
</code></pre>
| [
{
"answer_id": 372300,
"author": "w4g3n3r",
"author_id": 36745,
"author_profile": "https://Stackoverflow.com/users/36745",
"pm_score": 0,
"selected": false,
"text": "<html>\n <head>\n <title>Index</title>\n <script type=\"text/javascript\" language=\"JavaScript\">\n\n function openDi... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46085/"
] |
366,262 | <p>I need to know how I can search an array for some literal text and have it used as a condition whether to continue.</p>
<p>Here's why:
Each time I execute a function I am pushing the ID of the property it acts upon into an array. I need my function to check if that ID is in the array already and if it is, remove it and execute my other function (the opposite).</p>
<p>Here's an example array:</p>
<pre><code>var myArray = new Array();
myArray.push([1.000,1.000,"test1"]);
myArray.push([2.000,2.000,"test2"]);
myArray.push([3.000,3.000,"test3"]);
</code></pre>
<p>I know the Grep function can search but I can't get it to evaluate true or false if it finds something.</p>
<p>Heres my ideal use of the search evaluation.</p>
<pre><code>function searcher(id){
if(myArray.grep(id);){
oppositeFunction(id);
}else{
function(id);
}
}
</code></pre>
| [
{
"answer_id": 366271,
"author": "Supernovah",
"author_id": 36076,
"author_profile": "https://Stackoverflow.com/users/36076",
"pm_score": 1,
"selected": false,
"text": "function arraytest(){\n var myArray = new Array(); \n myArray.push([\"test1\"]); \n myArray.push([\"test2\"]... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366262",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36076/"
] |
366,273 | <p>Can anyone send me a c code to divide 2 64bit numbers. My compiler only supports 32/32 division.</p>
<p>Thanx & Regards</p>
<p>Mani</p>
| [
{
"answer_id": 366300,
"author": "Tom",
"author_id": 40620,
"author_profile": "https://Stackoverflow.com/users/40620",
"pm_score": 4,
"selected": false,
"text": "#include <stdint.h>\n#include <stdio.h>\nint main(void)\n{\n int64_t numerator = 123;\n int64_t denominator = 10;\n i... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,311 | <p>I'm pretty happy with <a href="http://whatcodecraves.com/posts/2008/12/13/rails-flash-with-ajax.html" rel="noreferrer">the solution</a> that I came up with. Basically, I have a helper method that reloads the flash inline, and then I have an after_filter that clear out the flash if the request is xhr. Does anyone have a simpler solution than that?</p>
<p><strong>Update:</strong> The solution above was written back in Rails 1.x and is no longer supported.</p>
| [
{
"answer_id": 405290,
"author": "nakajima",
"author_id": 39589,
"author_profile": "https://Stackoverflow.com/users/39589",
"pm_score": 3,
"selected": false,
"text": "flash.now[:notice]"
},
{
"answer_id": 423957,
"author": "Silviu Postavaru",
"author_id": 3718,
"autho... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25024/"
] |
366,324 | <p>Just for the sake of experimentation, I've been trying to determine different ways to non-destructively chain <code>window.onload</code> functions in a web browser. This is the idea of what I have so far:</p>
<pre><code>var load = window.onload;
var newFunction = function(){
alert("ha!");
}
window.onload = function(){
load();
newFunction();
}
</code></pre>
<p>The problem I see with this is that every time you chain a function, it adds another level of function calls to the stack. Is there a better way to go about this that doesn't add unnecessary depth to the call stack?</p>
| [
{
"answer_id": 366335,
"author": "Kit Sunde",
"author_id": 29347,
"author_profile": "https://Stackoverflow.com/users/29347",
"pm_score": 0,
"selected": false,
"text": "var addEvent = function( obj, type, fn ) {\n if (obj.addEventListener)\n obj.addEventListener(type... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1370/"
] |
366,326 | <p>We all know and love Process.WaitForExit().</p>
<p>Given a pid of a process on a remote machine (created by WMI/psexec), how do I wait for it to end?</p>
| [
{
"answer_id": 366385,
"author": "Kent Boogaart",
"author_id": 5380,
"author_profile": "https://Stackoverflow.com/users/5380",
"pm_score": 1,
"selected": true,
"text": "Process.GetProcessById(processId, machineName).WaitForExit();\n"
},
{
"answer_id": 366472,
"author": "rippe... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11236/"
] |
366,329 | <p>Why can't Delphi variants hold objects? More importantly, what's the reason behind this limitation? </p>
| [
{
"answer_id": 366363,
"author": "gabr",
"author_id": 4997,
"author_profile": "https://Stackoverflow.com/users/4997",
"pm_score": 5,
"selected": false,
"text": "obj := TObject.Create;\nv := NativeUInt(obj);\nobj := TSomeObject(NativeUInt(v));\n"
},
{
"answer_id": 366615,
"aut... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366329",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14716/"
] |
366,332 | <pre><code>public class Address
{
public string ZipCode {get; set;}
}
public class Customer
{
public Address Address {get; set;}
}
</code></pre>
<p>how can I access eitther "ZipCode" or "Address.ZipCode" with reflection? For example: </p>
<pre><code>Typeof(Customer).GetProperty("ZipCode")?
</code></pre>
| [
{
"answer_id": 366337,
"author": "maxnk",
"author_id": 45862,
"author_profile": "https://Stackoverflow.com/users/45862",
"pm_score": 2,
"selected": false,
"text": "typeof (Customer).GetProperty(\"Address\").PropertyType.GetProperty(\"ZipCode\")\n"
},
{
"answer_id": 366339,
"a... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31624/"
] |
366,345 | <p>I have an external DLL whose source code is C#. From the documentation for the DLL, I determined that it writes its debug messages to the console using <code>Console.WriteLine</code>.</p>
<p>I'd like to use this DLL within a WinForms application. However, what I have discovered is that I cannot see the debug messages emitted by the DLL since a WinForms application does not have a console.</p>
<p>is there a way to capture those debug messages, perhaps even to a simple log file? Of course, using <code>ProcessInfo.RedirectStandartOutput</code> will not work as I do not use the DLL as a process.</p>
| [
{
"answer_id": 366434,
"author": "user46119",
"author_id": 46119,
"author_profile": "https://Stackoverflow.com/users/46119",
"pm_score": 2,
"selected": false,
"text": " Debug.Listeners.Add(new ConsoleTraceListener())\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33030/"
] |
366,364 | <p>I just got a weird idea about how to configure environment-dependent parameters. Sort of like parameters you can find in Rails' config/database.yml</p>
<p>In my current project I use PHP and Litespeed Web Server (though the same technique applies to PHP + Apache), and I thought... 'why not use mod_rewrite for this?'. I have separate virtual hosts configs for each env (development/production at the moment)</p>
<p>What I have now is:</p>
<pre>
<code>
RewriteRule (.*) $1 [env=development:1]
</pre>
<p></code></p>
<p>for the development environment vhost. But what if it will be something like this?</p>
<pre>
<code>
RewriteRule (.*) $1 [env=development:1,env=mysql_host:localhost,env=mysql_port:3306,env=mysql_user:root,env=mysql_pass:,env=mysql_db:mydbname]
</pre>
<p></code></p>
<p>Would it make sense or will cause some problems? What do you think?</p>
| [
{
"answer_id": 384187,
"author": "ejunker",
"author_id": 796,
"author_profile": "https://Stackoverflow.com/users/796",
"pm_score": 0,
"selected": false,
"text": "php_value ENV \"development\"\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366364",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45652/"
] |
366,375 | <p>Can someone explain to or link to an article that explains how the parameters passed into the action of a controller are populated? I understand the basic mapping when you have the Controller/Action/ID and the ID is passed in as a variable, if it doesn't convert to the type that you are asking for then it won't be passed in to that action.</p>
<p>However I have been looking at the MVCContrib sub controller code and there was the following example:</p>
<pre><code>public ActionResult Index(FirstLevelSubController firstLevel)
</code></pre>
<p>I want to know how this parameter is being populated because as far as I know nothing is being passed in to populate this?</p>
<p>Let's say I created the following action which is the only action in the controller:</p>
<pre><code>[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index(Task task, ToDoList list)
</code></pre>
<p>What would I be passed back and why? (I know I could do a quick test to find out if they did come back but that would make me non the wiser as to why.</p>
<p>Thanks</p>
| [
{
"answer_id": 366695,
"author": "Todd Smith",
"author_id": 31624,
"author_profile": "https://Stackoverflow.com/users/31624",
"pm_score": 2,
"selected": false,
"text": "http://localhost/Task/Index/?task=mytask&todolist=a,b,c,d\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366375",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26081/"
] |
366,379 | <p>I want to show first element that is hidden by jquery. my html code is:</p>
<pre><code><ol>
<li>1</li>
<li style="display:none">2</li>
<li style="display:none">3</li>
<li style="display:none">4</li>
<li style="display:none">5</li>
<li><a class="add">Add More ...</a></li>
</ol>
</code></pre>
<p>I want to show first hidden LI, each time that "a" element was clicked.
My solution is below. but I think better way exists.</p>
<pre><code>$("a.add").click(function(){
var hiddens=$(":hidden",$(this).parent().parent());
if (hiddens.length>0)
{
hiddens.each(function(index,el){
if(index==0)
{
$(this).slideToggle("fast");
}
});
}
if (hiddens.length==1)
{
$(this).parent().hide();
}
</code></pre>
<p>Tanx</p>
| [
{
"answer_id": 366395,
"author": "user38526",
"author_id": 38526,
"author_profile": "https://Stackoverflow.com/users/38526",
"pm_score": 2,
"selected": false,
"text": "$(\"a.add\").click(function(){\n $(\":hidden:first\").show();\n});\n"
},
{
"answer_id": 366400,
"author":... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46110/"
] |
366,380 | <p>I write this tiny C++ example in Eclipse 3.4.1 (CDT 5.0.1):</p>
<pre><code>#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
int foo()
{
std::vector<int> numbers;
BOOST_FOREACH(int n, numbers)
{
std::cout << n << std::endl;
}
std::cout << numbers.size << std::endl;
}
</code></pre>
<p>Then I hit Shift+Ctrl+F to format my code, and it becomes:</p>
<pre><code>#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
int foo()
{
std::vector<int> numbers;
BOOST_FOREACH(int n, numbers)
{ std::cout << n << std::endl;
}
std::cout << numbers.size << std::endl;
}
</code></pre>
<p>This is with the BSD/Allman Code Style. Other styles obviously vary the look of the formatted code, but none give correct indentation.</p>
<p>When I use the format feature on a larger piece of code, subsequent functions or methods are also affected by too little indentation, making the formatting help pretty unhelpful.</p>
<p>Is there something I can do to make the indentation work properly with BOOST_FOREACH?</p>
| [
{
"answer_id": 9135228,
"author": "Pescuma",
"author_id": 802685,
"author_profile": "https://Stackoverflow.com/users/802685",
"pm_score": 2,
"selected": false,
"text": "#ifdef __CDT_PARSER__\n #undef BOOST_FOREACH\n #define BOOST_FOREACH(a, b) for(a; ; )\n#endif\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20444/"
] |
366,422 | <p>Sometimes it seems natural to have a default parameter which is an empty list. Yet <a href="https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument">Python produces unexpected behavior in these situations</a>.</p>
<p>If for example, I have a function:</p>
<pre><code>def my_func(working_list=[]):
working_list.append("a")
print(working_list)
</code></pre>
<p>The first time it is called, the default will work, but calls after that will update the existing list (with one <code>"a"</code> each call) and print the updated version.</p>
<p>So, what is the Pythonic way to get the behavior I desire (a fresh list on each call)?</p>
| [
{
"answer_id": 366430,
"author": "HenryR",
"author_id": 2827,
"author_profile": "https://Stackoverflow.com/users/2827",
"pm_score": 9,
"selected": true,
"text": "def my_func(working_list=None):\n if working_list is None: \n working_list = []\n\n # alternative:\n # working... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2242/"
] |
366,432 | <p>I need to use lists for my program and needed to decide if I use std::vector or std::list.
The problem with vector is that there is no remove method and with list that there is no operator []. So I decided to write my own class extending std::list and overloading the [] operator.</p>
<p>My code looks like this:</p>
<pre><code>#include <list>
template <class T >
class myList : public std::list<T>
{
public:
T operator[](int index);
T operator[](int & index);
myList(void);
~myList(void);
};
#include "myList.h"
template<class T>
myList<T>::myList(void): std::list<T>() {}
template<class T>
myList<T>::~myList(void)
{
std::list<T>::~list();
}
template<class T>
T myList<T>::operator[](int index) {
int count = 0;
std::list<T>::iterator itr = this->begin();
while(count != index)itr++;
return *itr;
}
template<class T>
T myList<T>::operator[](int & index) {
int count = 0;
std::list<T>::iterator itr = this->begin();
while(count != index)itr++;
return *itr;
}
</code></pre>
<p>I can compile it but I get a linker error if I try to use it. Any ideas?</p>
| [
{
"answer_id": 366465,
"author": "ChrisN",
"author_id": 3853,
"author_profile": "https://Stackoverflow.com/users/3853",
"pm_score": 4,
"selected": false,
"text": "std::list"
},
{
"answer_id": 366605,
"author": "Nemanja Trifunovic",
"author_id": 8899,
"author_profile":... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366432",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2450/"
] |
366,485 | <p>I am very interested in streaming data for web-applications. I have tried out some javascript libraries, but the hacks and browser-incompatibilities drive me crazy ! HTML5 will hopefully standardize streaming data, but until then, hopefully I can resort to Flash to make this work in all browsers. Unfortunately, I'm not very familiar with all the functionality that Flash offers.</p>
<p>I have tried loadVariables.onData in Flash 8, but it doesn't support streaming data. The data is only available after the request has been finished. Is there any way to call a function every time new data is returned ?</p>
| [
{
"answer_id": 373690,
"author": "aaaidan",
"author_id": 26331,
"author_profile": "https://Stackoverflow.com/users/26331",
"pm_score": 0,
"selected": false,
"text": "URLStream"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366485",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6388/"
] |
366,507 | <p>A lot of times in code on the internet or code from my co-workers I see them creating an Object with just one method which only gets used once in the whole application. Like this:</p>
<pre><code> class iOnlyHaveOneMethod{
public function theOneMethod(){
//loads and loads of code, say 100's of lines
// but it only gets used once in the whole application
}
}
if($foo){
$bar = new iOnlyHaveOneMEthod;
$bar->theOneMethod();
}
</code></pre>
<p>Is that really better then:</p>
<pre><code>if($foo){
//loads and loads of code which only gets used here and nowhere else
}
</code></pre>
<p>?<br>
For readability it makes sense to move the loads and loads of code away, but shouldn't it just be in a function?</p>
<pre><code>function loadsAndLoadsOfCode(){
//Loads and loads of code
}
if($foo){ loadsAndLoadsOfCode(); }
</code></pre>
<p>Is moving the code to a new object really better then just creating a function or putting the code in there directly?<br>
To me the function part makes more sense and seems more readible then creating an object which hardly is of any use since it just holds one method.</p>
| [
{
"answer_id": 366546,
"author": "Dan Vinton",
"author_id": 21849,
"author_profile": "https://Stackoverflow.com/users/21849",
"pm_score": 2,
"selected": false,
"text": "// let's instead assume that $bar was set earlier using a setter\nif($foo){ \n $bar = getMyBar();\n $bar->theOneM... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366507",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35197/"
] |
366,533 | <p>How to run the first process from a list of processes stored in a file and immediately delete the first line as if the file was a queue and I called "pop"?</p>
<p>I'd like to call the first command listed in a simple text file with \n as the separator in a pop-like fashion:</p>
<p><em>Figure 1:</em></p>
<pre><code>cmdqueue.lst :
proc_C1
proc_C2
proc_C3
.
.
</code></pre>
<p><em>Figure 2:</em></p>
<p>Pop the first command via <code>popcmd</code>:</p>
<pre><code>proc_A | proc_B | popcmd cmdqueue.lst | proc_D
</code></pre>
<p><em>Figure 3:</em></p>
<pre><code>cmdqueue.lst :
proc_C2
proc_C3
proc_C4
.
.
</code></pre>
| [
{
"answer_id": 366553,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 3,
"selected": true,
"text": "#!/usr/bin/env python\nimport os, shlex, sys\nfrom subprocess import call\nfilename = sys.argv[1]\nlines = open(filename).readlin... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4085/"
] |
366,541 | <p>I want to serialize a Dictionary that has a custom <code>IEqualityComparer</code>.</p>
<p>I've tried using <code>DataContractSerializer</code> but I can't get the <code>Comparer</code> to be serialized.</p>
<p>I can't use <code>BinaryFormatter</code> because of <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=303278&wa=wsignin1.0" rel="nofollow noreferrer">this</a>.</p>
<p>I can always do something like:</p>
<pre><code>var myDictionary = new MyDictionary(deserializedDictionary, myComparer);
</code></pre>
<p>But that means I'd need twice the memory the dictionary uses.</p>
| [
{
"answer_id": 366553,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 3,
"selected": true,
"text": "#!/usr/bin/env python\nimport os, shlex, sys\nfrom subprocess import call\nfilename = sys.argv[1]\nlines = open(filename).readlin... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19956/"
] |
366,550 | <p>I am currently reading "Beginning CakePHP:From Novice to Professional" by David Golding. At one point I have to use the CLI-command "cake bake", I get the welcome-screen but when I try to bake e.g. a Controller I get the following error messages:</p>
<pre><code>Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 117
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 122
Warning: mysql_get_server_info(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 130
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 154
Error: Your database does not have any tables.
</code></pre>
<p>I suspect that the error-messages has to do with php trying to access the wrong mysql-socket, namely the default osx mysql-socket - instead of the one that MAMP uses. Hence I change my database configurations to connect to the UNIX mysql-socket (:/Applications/MAMP/tmp/mysql/mysql.sock):</p>
<pre><code>class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'connect' => 'mysql_connect',
'persistent' => false,
'host' =>':/Applications/MAMP/tmp/mysql/mysql.sock', // UNIX MySQL-socket
'login' => 'my_user',
'password' => 'my_pass',
'database' => 'blog',
'prefix' => '',
);
}
</code></pre>
<p>But I get the same error-messages with the new socket:</p>
<pre><code>Warning: mysql_connect(): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock:3306' (2) in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 117
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 122
Warning: mysql_get_server_info(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 130
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/blog/cake/libs/model/datasources/dbo/dbo_mysql.php on line 154
Error: Your database does not have any tables.
</code></pre>
<p>Also, even though I use the UNIX-socket that MAMP show on it's welcome-screen, CakePHP loses the database-connection, when using this socket instead of localhost.</p>
<p>Any ideas on how I can get bake to work?</p>
<p><strong>-- Edit 1 --</strong></p>
<p>Thank you guys for helping me out! :)</p>
<p>I have a problem figuring out where in my.cnf to edit to get MySQL to listen to TCP/IP request. The only paragraph I can find where TCP/IP is mentioned is the following: </p>
<pre><code># Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
</code></pre>
<p>That allows me to turn off TCP/IP completely, which is the opposite of my intention. I don't know how to go about what you suggest, if you could be more elaborate it would be great. I am a total n00b on these matters :S</p>
<p>Reg. connecting to a local socket: I removed the leading colon in the host-parameter, same result.</p>
| [
{
"answer_id": 373504,
"author": "user42801",
"author_id": 42801,
"author_profile": "https://Stackoverflow.com/users/42801",
"pm_score": 1,
"selected": false,
"text": "my-macbook:~ chris$ php -i | grep mysql.default_socket\nmysql.default_socket => no value => no value\nmy-macbook:~ chris... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366550",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24218/"
] |
366,586 | <p>I use codeigniter as my main install on the main domain. I have created a subdomain and a folder called live e.g. live.domain.com maps to public/live . However in public I use codeigniter.</p>
<p>I now have the dynamic codeigniter url: </p>
<pre>http://domain.com/api/</pre>
<p>which I want to map to my subdomain: </p>
<pre>https://live.domain.com</pre>
<p>So going to:</p>
<pre>https://live.domain.com/api/functioname</pre>
<p>would be using the script: </p>
<pre>http://domain.com/api/apifunctioname</pre>
<p>and possibly:</p>
<pre>http://domain.com/api/apifunctioname/parameter1/parameter</pre>
<p>Everything is on the same server so no redirects are needed.</p>
<p>Anyone have any ideas on which rewrite rules to use?</p>
<pre><code>Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.domain\.com [NC]
RewriteRule (.+)$ "http://domain.com/api/$1" [L]
</code></pre>
<p>The above works great as a rewrite but redirects to <a href="http://domain.com/api/functionname" rel="noreferrer">http://domain.com/api/functionname</a> instead I want it to route; so that when going to:</p>
<pre>https://live.domain.com/api/functioname</pre>
<p>It stays at that url but uses the script of </p>
<pre>http://domain.com/api/functionname</pre>
<p>Thank you very much,</p>
<p>Ice</p>
| [
{
"answer_id": 5423470,
"author": "Muhammad Hamizi Jaminan",
"author_id": 1045240,
"author_profile": "https://Stackoverflow.com/users/1045240",
"pm_score": 2,
"selected": false,
"text": "RewriteEngine On\nRewriteCond %{HTTP_HOST} ^live\\.domain\\.com$ [NC]\nRewriteRule (.+)$ \"https://do... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,588 | <p>I am a hobbyist programmer (started with VBA to make excel quicker) and have been working with VB.NET / C#.NET and am trying to learn ADO.NET.</p>
<p>A facet of programming that has always frustrated me is what does 'good' look like? I am not a professional so have little to compare against. What makes a better programmer?
Is it:</p>
<ul>
<li>They have a better understanding of
all the objects / classes / methods
in a given language?</li>
<li>Their programs are more efficient?</li>
<li>The design of their programs are much
better in terms of better
documentation, good choice of names
for functions etc.?</li>
</ul>
<p>Put another way, if I were to look at the code of a professional programmer, what is the first thing that I would notice about their code relative to mine? For example, I read books like 'Professional ASP.NET' by Wrox press. Are the code examples in that book 'world class'? Is that the pinnacle? Would any top-gun programmer look at that code and think it was good code?</p>
| [
{
"answer_id": 367150,
"author": "Filip Ekberg",
"author_id": 39106,
"author_profile": "https://Stackoverflow.com/users/39106",
"pm_score": 1,
"selected": false,
"text": "Communication issues when adapting outsourcing"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366588",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/235442/"
] |
366,595 | <p>I'm trying to use <a href="http://www.appelsiini.net/projects/jeditable" rel="nofollow noreferrer">Jeditable</a> as an inline editing solution.</p>
<p>The default behavior (click on the element to edit it) works quite well, but I would like to activate an element by clicking on another element.</p>
<p>For example clicking on a.activateEdit will activate the next div.edit (obviously should be done using jQuery selectors).</p>
<p>I've looked into Jeditable docs for this, but couldn't find the right syntax</p>
<p>FYI, the default Jeditable syntax is something along the lines of:</p>
<pre><code> $(document).ready(function() {
$('.edit').editable('http://www.example.com/save.php');
});
</code></pre>
<p><strong>*Edit: found <a href="http://groups.google.com/group/jquery-en/browse_thread/thread/33c18dcf32276c89/7711363c7496fcb3?hide_quotes=no" rel="nofollow noreferrer">a better solution</a> *</strong></p>
| [
{
"answer_id": 366704,
"author": "Ata",
"author_id": 46110,
"author_profile": "https://Stackoverflow.com/users/46110",
"pm_score": 2,
"selected": false,
"text": "<a class=\"clickme\">Click me to edit</a>\n<div class=\"edit\">Edit Me!</div>\n"
},
{
"answer_id": 367054,
"author... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1011/"
] |
366,601 | <p>I'm having issues getting Firefox to update a webpage when its class is changed dynamically.</p>
<p>I'm using an HTML <code>table</code> element. When the user clicks a cell in the table header, my script toggles the class back and forth between <code>sorted_asc</code> and <code>sorted_des</code>. I have pseudo element which adds an arrow glyph (pointing up or down) depending on which class the cell currently is.</p>
<pre><code>.thead .tr .sorted_asc .cell:after {
content: ' \25B2';
}
</code></pre>
<p>The problem is, that when you click the cell header a second time, the page doesn't update the arrow... until the user mouses away from the element. I think it's a bug as it works fine in Safari, and as I don't see any <code>:hover</code> tags in my CSS or other entries that might interfere.</p>
<p>Anyone seen this before, or know how to work around the issue?</p>
| [
{
"answer_id": 366646,
"author": "I.devries",
"author_id": 6388,
"author_profile": "https://Stackoverflow.com/users/6388",
"pm_score": 3,
"selected": true,
"text": "document.body.style.display = 'none';\ndocument.body.style.display = 'block';\n"
},
{
"answer_id": 366954,
"aut... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4939/"
] |
366,602 | <p>In my C++ program (on Windows), I'm allocating a block of memory and can make sure it stays locked (unswapped and contiguous) in physical memory (i.e. using VirtualAllocEx(), MapUserPhysicalPages() etc). </p>
<p>In the context of my process, I can get the VIRTUAL memory address of that block,
<b> but I need to find out the PHYSICAL memory address of it </b> in order to pass it to some external device. </p>
<p><br>
<b>1.</b> Is there any way I can translate the virtual address to the physical one within my program, in USER mode? <br>
<br><b>2.</b> If not, I can find out this virtual to physical mapping only in KERNEL mode. I guess it means I have to write a driver to do it...? Do you know of any readily available driver/DLL/API which I can use, that my application (program) will interface with to do the translation?
<br><br> <b>3.</b> In case I'll have to write the driver myself, how do I do this translation? which functions do I use? Is it <b>mmGetPhysicalAddress()</b>? How do I use it?
<br><br><b>4.</b> Also, if I understand correctly, mmGetPhysicalAddress() returns the physical address of a virtual base address that is in the context of the calling process. But if the calling process is the driver, and I'm using my application to call the driver for that function, I'm changing contexts and I am no longer in the context of the app when the mmGetPhysicalAddress routine is called... so how do I translate the virtual address in the application (user-mode) memory space, not the driver?</p>
<p>Any answers, tips and code excerpts will be much appreciated!!</p>
<p>Thanks</p>
| [
{
"answer_id": 366725,
"author": "Christopher",
"author_id": 3186,
"author_profile": "https://Stackoverflow.com/users/3186",
"pm_score": 3,
"selected": false,
"text": "MmGetPhysicalAddress"
},
{
"answer_id": 366858,
"author": "bk1e",
"author_id": 8090,
"author_profile... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,603 | <p>Having a table with a column like: <code>mydate DATETIME</code> ...</p>
<p>I have a query such as:</p>
<pre><code>SELECT SUM(foo), mydate FROM a_table GROUP BY a_table.mydate;
</code></pre>
<p>This will group by the full <code>datetime</code>, including hours and minutes. I wish to make the group by, only by the date <code>YYYY/MM/DD</code> not by the <code>YYYY/MM/DD/HH/mm</code>.</p>
<p>How to do this?</p>
| [
{
"answer_id": 366610,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 9,
"selected": true,
"text": "SELECT SUM(foo), DATE(mydate) FROM a_table GROUP BY DATE(a_table.mydate);\n"
},
{
"answer_id": 366645,
"author"... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26004/"
] |
366,629 | <p>This is the code I wrote:</p>
<pre><code> MailMessage mail = new MailMessage("test@gmail.com", "me@myurl.com");
mail.Subject = "This is a test!!";
mail.Body = "testing...";
SmtpPermission connectAccess = new SmtpPermission(SmtpAccess.Connect);
System.Console.WriteLine("Access? " + connectAccess.Access);
SmtpClient client = new SmtpClient("mail.myurl.com", 2525);
client.Send(mail);
</code></pre>
<p>It's not working. I get an exception at the line "client.Send(mail)" that says "Mailbox unavailable. The server response was (MYLOCALCOMPUTERNAME) [MY LOCAL IP]:3045 is currently not permitted to relay through."</p>
<p>connectAccess.Access does return "Connect" (I'm not sure if this was necessary... I added it in to start the troubleshooting process.)</p>
<p>Does this mean that my local machine has to be configured in some way? What about when I deploy my app to other peoples machines? Will there need to be local configuration there? I'm just looking to create a "Send Feedback" type of link from my application.</p>
<p>(Note: in my real application I am using my real email addresses in both the "to" and "from" and my smtp is really my smtp address at the place that hosts my url/website)</p>
<p>thanks!</p>
<p>-Adeena</p>
| [
{
"answer_id": 366690,
"author": "adeena",
"author_id": 44004,
"author_profile": "https://Stackoverflow.com/users/44004",
"pm_score": 3,
"selected": false,
"text": " client.Credentials = new System.Net.NetworkCredential(\"myloginat+myurl.com\", \"mypassword\");\n"
},
{
"answer_id... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366629",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44004/"
] |
366,631 | <p>I am working on a ASP.NET app and i have a need to post back to the server after a file is chosen in a FileUpload control without having to have the user explicitly click a 'submit' button. Is this possible? and if so, how?</p>
| [
{
"answer_id": 366644,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 6,
"selected": true,
"text": "change"
},
{
"answer_id": 367138,
"author": "Abram Simon",
"author_id": 46204,
"author_profile": "https... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366631",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18811/"
] |
366,658 | <p>Does Java 6 consume more memory than you expect for largish applications?</p>
<p>I have an application I have been developing for years, which has, until now taken about 30-40 MB in my particular test configuration; now with Java 6u10 and 11 it is taking several hundred while active. It bounces around a lot, anywhere between 50M and 200M, and when it idles, it <em>does</em> GC and drop the memory right down. In addition it generates millions of page faults. All of this is observed via Windows Task Manager.</p>
<p>So, I ran it up under my profiler (jProfiler) and using jVisualVM, and both of them indicate the usual moderate heap and perm-gen usages of around 30M combined, even when fully active doing my load-test cycle.</p>
<p>So I am mystified! And it not just requesting more memory from the Windows Virtual Memory pool - this is showing up as 200M "Mem Usage".</p>
<p>CLARIFICATION: I want to be perfectly clear on this - observed over an 18 hour period with Java VisualVM the class heap and perm gen heap have been perfectly stable. The allocated volatile heap (eden and tenured) sits unmoved at 16MB (which it reaches in the first few minutes), and the use of this memory fluctuates in a perfect pattern of growing evenly from 8MB to 16MB, at which point GC kicks in an drops it back to 8MB. Over this 18 hour period, the system was under constant maximum load since I was running a stress test. This behavior is <em>perfectly</em> and <em>consistently</em> reproducible, seen over numerous runs. The only anomaly is that while this is going on the memory taken from Windows, observed via Task Manager, fluctuates all over the place from 64MB up to 900+MB.</p>
<p>UPDATE 2008-12-18: I have run the program with -Xms16M -Xmx16M without any apparent adverse affect - performance is fine, total run time is about the same. But memory use in a short run still peaked at about 180M.</p>
<p>Update 2009-01-21: It seems the answer may be in the number of threads - see my answer below.</p>
<hr>
<p>EDIT: And I mean millions of page faults literally - in the region of 30M+.</p>
<p>EDIT: I have a 4G machine, so the 200M is not significant in that regard.</p>
| [
{
"answer_id": 367933,
"author": "Michael Borgwardt",
"author_id": 16883,
"author_profile": "https://Stackoverflow.com/users/16883",
"pm_score": 4,
"selected": false,
"text": "public class FreeTest\n{\n public static void main(String[] args) throws Exception\n {\n byte[][] b... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8946/"
] |
366,682 | <p>There is a socket related function call in my code, that function is from another module thus out of my control, the problem is that it blocks for hours occasionally, which is totally unacceptable, How can I limit the function execution time from my code? I guess the solution must utilize another thread.</p>
| [
{
"answer_id": 366763,
"author": "rik.the.vik",
"author_id": 45570,
"author_profile": "https://Stackoverflow.com/users/45570",
"pm_score": 7,
"selected": true,
"text": "import signal\n\ndef signal_handler(signum, frame):\n raise Exception(\"Timed out!\")\n\nsignal.signal(signal.SIGALR... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1925263/"
] |
366,696 | <p>Im trying to do a dialog box with jquery. In this dialog box Im going to have terms and conditions. The problem is that the dialog box is only displayed for the FIRST TIME.</p>
<p>This is the code.</p>
<p>JavaScript:</p>
<pre><code>function showTOC()
{
$("#TOC").dialog({
modal: true,
overlay: {
opacity: 0.7,
background: "black"
}
})
}
</code></pre>
<p>HTML (a href):</p>
<pre><code><a class="TOClink" href="javascript:showTOC();">View Terms & Conditions</a>
<div id="example" title="Terms & Conditions">1..2..</div>
</code></pre>
<p>The problem I think is that when you close the dialog box the DIV is destroyed from the html code therfore it can never be displayed again on screen.</p>
<p>Can you please help!</p>
<p>Thanks</p>
| [
{
"answer_id": 366730,
"author": "carlsz",
"author_id": 46077,
"author_profile": "https://Stackoverflow.com/users/46077",
"pm_score": 6,
"selected": true,
"text": "$(document).ready({\n $('a.TOClink').click(function(){\n showTOC();\n });\n});\n\nfunction showTOC() {\n $('... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44973/"
] |
366,697 | <p>I have the following code which adapts linq entities to my Domain objects:</p>
<pre><code>return from g in DBContext.Gigs
select new DO.Gig
{
ID = g.ID,
Name = g.Name,
Description = g.Description,
StartDate = g.Date,
EndDate = g.EndDate,
IsDeleted = g.IsDeleted,
Created = g.Created,
TicketPrice = g.TicketPrice
};
</code></pre>
<p>This works very nicely.</p>
<p>However I now want to populate a domain object Venue object and add it to the gig in the same statement. Heres my attempt....</p>
<pre><code>return from g in DBContext.Gigs
join venue in DBContext.Venues on g.VenueID equals venue.ID
select new DO.Gig
{
ID = g.ID,
Name = g.Name,
Description = g.Description,
StartDate = g.Date,
EndDate = g.EndDate,
IsDeleted = g.IsDeleted,
Created = g.Created,
TicketPrice = g.TicketPrice,
Venue = from v in DBContext.Venues
where v.ID == g.VenueID
select new DO.Venue
{
ID = v.ID,
Name = v.Name,
Address = v.Address,
Telephone = v.Telephone,
URL = v.Website
}
};
</code></pre>
<p>However this doesnt compile!!!</p>
<p>Is it possible to adapt children objects using the "select new" approach?</p>
<p>What am I doing so very very wrong?</p>
| [
{
"answer_id": 366721,
"author": "Mike Two",
"author_id": 23659,
"author_profile": "https://Stackoverflow.com/users/23659",
"pm_score": 1,
"selected": false,
"text": "return from g in DBContext.Gigs \n join venue in DBContext.Venues on g.VenueID equals venue.ID \n select new DO.Gig... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,706 | <p>This is a follow-up to <a href="https://stackoverflow.com/questions/365522/what-is-the-best-way-to-add-two-numbers-without-using-the-operator">my question yesterday</a>:</p>
<p>CMS kindly provided this example of using bitwise operators to add two numbers in C:</p>
<pre><code>#include<stdio.h>
int add(int x, int y) {
int a, b;
do {
a = x & y;
b = x ^ y;
x = a << 1;
y = b;
} while (a);
return b;
}
int main( void ){
printf( "6 + 3 = %d", add(6,3));
printf( "6 - 3 = %d", add(6,-3));
return 0;
}
</code></pre>
<p>It works great and I then ported it to Python as follows:</p>
<pre><code>def add(x, y):
while True:
a = x & y
b = x ^ y
x = a << 1
y = b
if a == 0:
break
return b
print "6 + 3 = %d" % add(6,3)
print "6 - 3 = %d" % add(6,-3)
</code></pre>
<p>They both work for addition and the C program works for subtraction as well. However, the Python program enters an infinite loop for subtraction. I am trying to get to the bottom of this and have posted the program here for further experimentation: <a href="http://codepad.org/pb8IuLnY" rel="nofollow noreferrer">http://codepad.org/pb8IuLnY</a></p>
<p>Can anyone advise why there would be a difference between the way C handles this and the way CPython handles this?</p>
| [
{
"answer_id": 366735,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 3,
"selected": false,
"text": ">>> 1 << 100\n1267650600228229401496703205376L\n"
},
{
"answer_id": 3487601,
"author": "nithin",
"au... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366706",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23126/"
] |
366,718 | <p>So I am sold on the concept of attempting to collect data automatically from a program - i.e., popping up a dialog box that asks the user to send the report when something goes wrong.</p>
<p>I'm working in MS Visual Studio C#.</p>
<p>From an implementation point of view, does it make sense to put a try/catch loop in my main program.cs file, around where the application is run? Like this:</p>
<pre><code> try
{
Application.Run(new myMainForm());
}
catch (Exception ex)
{
//the code to build the report I want to send and to
//pop up the Problem Report form and ask the user to send
}
</code></pre>
<p>or does it make sense to put try/catch loops throughout pieces of the code to catch more specific exception types? (I'm thinking not because this is a new application, and putting in more specific exception catches means I have an idea of what's going to go wrong... I don't, which is why the above seems to make sense to me.)</p>
<p>-Adeena</p>
| [
{
"answer_id": 366731,
"author": "chakrit",
"author_id": 3055,
"author_profile": "https://Stackoverflow.com/users/3055",
"pm_score": 3,
"selected": false,
"text": "[STAThread]\nstatic void Main() \n{\n System.Windows.Forms.Application.ThreadException += new ThreadExceptionEventHandler(... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366718",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44004/"
] |
366,719 | <h1>Premise</h1>
<p>I believe that there is a way to objectively define "Good" and "Bad" Object-Oriented design techniques and that, as a community we can determine what these are. This is an academic exercise. If done with seriousness and resolve, I believe it can be of great benefit to the community as a whole. The community will benefit by having a place we can all point to to say, "This technique is 'Good' or 'Bad' and we should or should not use it unless there are special circumstances."</p>
<h1>Plan</h1>
<p>For this effort, we should focus on Object-Oriented principles (as opposed to Functional, Set-based, or other type of languages).</p>
<p>I'm not planning on accepting one answer, instead I'd like the answers to contribute to the final collection or be a rational debate of the issues.</p>
<p>I realize that this may controversial, but I believe we can iron something out. There are exceptions to most every rule and I believe this is where the disagreement will fall. We should make declarations and then note relevant exceptions and objections from dissenters.</p>
<h1>Basis</h1>
<p>I'd like to take a stab at defining "Good" and "Bad":</p>
<ul>
<li><p>"Good" - This technique will work the first time and be a lasting solution. It will be easy to change later and will pay the time investment of its implementation quickly. It can be consistently applied and easily recognized by maintenance programmers in the future. Overall, it contributes to the good function and lowers cost of maintenance over the life of the product.</p>
</li>
<li><p>"Bad" - This technique may work in the short term, but soon becomes a liability. It is immediately difficult to change or becomes more difficult over time. The initial investment may be small or large, but it quickly becomes a growing cost, eventually becoming a sunk cost and must be removed or worked around constantly. It is subjectively applied and inconsistent and may be a surprise or not easily recognizable by maintenance programmers in the future. Overall, it contributes to the ultimate increasing cost of maintaining and/or operating the product and inhibits or prevents changes to the product. By inhibiting or preventing change, it becomes not just a direct cost, but an opportunity cost and a significant liability.</p>
</li>
</ul>
<h1>Starter</h1>
<p>As an example of what I think a good contribution would look like, I'd like to propose a "Good" principle:</p>
<h2>Separation of Concerns</h2>
<p>[Short description]</p>
<h3>Example</h3>
<p>[Code or some other type of example]</p>
<h3>Goals</h3>
<p>[Explanation of what problems this principle prevents]</p>
<h3>Applicability</h3>
<p>[Why, where, and when would I use this principle?]</p>
<h3>Exceptions</h3>
<p>[When wouldn't I use this principle, or where might it actually be harmful?]</p>
<h3>Objections</h3>
<p>[Note any dissenting opinions or objections from the community here]</p>
| [
{
"answer_id": 366791,
"author": "Tom",
"author_id": 40620,
"author_profile": "https://Stackoverflow.com/users/40620",
"pm_score": 2,
"selected": true,
"text": "class Foo : private boost::noncopyable { ... };\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10862/"
] |
366,720 | <p>Currently my code is organized in the following tree structure:</p>
<pre><code>src/
module1.py
module2.py
test_module1.py
test_module2.py
subpackage1/
__init__.py
moduleA.py
moduleB.py
test_moduleA.py
test_moduleB.py
</code></pre>
<p>Where the <code>module*.py</code> files contains the source code and the <code>test_module*.py</code> contains the <code>TestCase</code>s for the relevant module.</p>
<p>With the following comands I can run the tests contained in a single file, for example:</p>
<pre><code>$ cd src
$ nosetests test_filesystem.py
..................
----------------------------------------------------------------------
Ran 18 tests in 0.390s
OK
</code></pre>
<p>How can I run all tests? I tried with <code>nosetests -m 'test_.*'</code> but it doesn't work.</p>
<pre><code>$cd src
$ nosetests -m 'test_.*'
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
</code></pre>
<p>Thanks</p>
| [
{
"answer_id": 366770,
"author": "Tom",
"author_id": 40620,
"author_profile": "https://Stackoverflow.com/users/40620",
"pm_score": 2,
"selected": false,
"text": "setup.py"
},
{
"answer_id": 366819,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stack... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36131/"
] |
366,758 | <p>I would like to access the contacts field on an email message (Email options) in outlook. Normally this field ties an email to a contact. Since it is a freeform text field available from the options dialog box, I am trying to use it to store a "next action" for my email message. I would like to set the next action based on the subject but I can't figure out how to access thas field from the outlook.mailitem object</p>
<p>Thanks
Jim</p>
| [
{
"answer_id": 380413,
"author": "Oliver Giesen",
"author_id": 9784,
"author_profile": "https://Stackoverflow.com/users/9784",
"pm_score": 0,
"selected": false,
"text": "UserProperties"
},
{
"answer_id": 453860,
"author": "Geoff",
"author_id": 55487,
"author_profile":... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366758",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,768 | <p>Can I convert a bitmap to PNG in memory (i.e. without writing to a file) using only the Platform SDK? (i.e. no libpng, etc.).</p>
<p>I also want to be able to define a transparent color (not alpha channel) for this image.</p>
<p><strong>The GdiPlus solution seems to be limited to images of width divisible by 4</strong>. Anything else fails during the call to Save(). Does anyone know the reason for this limitation and how/whether I can work around it?</p>
<p><strong>Update: Bounty</strong></p>
<p>I'm starting a bounty (I really want this to work). I implemented the GDI+ solution, but as I said, it's limited to images with quad width. The bounty will go to anyone who can solve this width issue (without changing the image dimensions), or can offer an alternative non-GDI+ solution that works.</p>
| [
{
"answer_id": 366785,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": false,
"text": "Save"
},
{
"answer_id": 538497,
"author": "Aardvark",
"author_id": 3655,
"author_profil... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11208/"
] |
366,772 | <p>I'm using windbg to examine some crash dumps sent in by an app. There seems to be some correlation between a crash I'm seeing and having a certain 3rd party DLL loaded into the process (a flaky Winsock LSP, I suspect). To make this sort of analysis easier in the future, is there a windbg script that would just show me a list of modules that are non-Microsoft? This would make patterns between crashes more obvious to me. I'm using "lm D sm", but going through the list manually right now is a pain.</p>
<p>Thanks!</p>
| [
{
"answer_id": 573827,
"author": "AaronBa",
"author_id": 69370,
"author_profile": "https://Stackoverflow.com/users/69370",
"pm_score": 0,
"selected": false,
"text": ".load clr10\\sos\n!sam c:\\temp\\modules\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23524/"
] |
366,775 | <p>Im trying to add a connection to a database in SQL Server 2008 using Visual Studio 2008. When testing the connection, it says that it is successful. However, once I said okay, it complains and say: "Cannot add data connection. Object reference not set to an instance of an object."</p>
<p>How do I go about adding a data connection to a SQL Server 2008 using Visual Studio 2008?</p>
| [
{
"answer_id": 366811,
"author": "JamesSugrue",
"author_id": 1075,
"author_profile": "https://Stackoverflow.com/users/1075",
"pm_score": 1,
"selected": false,
"text": "var conn = new SqlConnection([connectionString]);\nconn.Open();\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366775",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,794 | <pre><code><?php
$string = 'The quick brown fox jumped over the lazy dog.';
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements[0] = 'slow';
$replacements[1] = 'black';
$replacements[2] = 'bear';
echo preg_replace($patterns, $replacements, $string);
?>
</code></pre>
<p>Ok guys,
Now I have the above code. It just works well.
Now for example I'd like to also replace "lazy" and "dog" with "slow" What I have to do now is would look like this, right?</p>
<pre><code><?php
$string = 'The quick brown fox jumped over the lazy dog.';
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$patterns[3] = '/lazy/';
$patterns[4] = '/dog/';
$replacements[0] = 'slow';
$replacements[1] = 'black';
$replacements[2] = 'bear';
$replacements[3] = 'slow';
$replacements[4] = 'slow';
echo preg_replace($patterns, $replacements, $string);
?>
</code></pre>
<p>Ok.</p>
<p>So my question is, is there any way I can do like this</p>
<pre><code>$patterns[0] = '/quick/', '/lazy/', '/dog/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements[0] = 'slow';
$replacements[1] = 'black';
$replacements[2] = 'bear';
</code></pre>
<p>Thanks</p>
| [
{
"answer_id": 366797,
"author": "Jonathan Lonowski",
"author_id": 15031,
"author_profile": "https://Stackoverflow.com/users/15031",
"pm_score": 3,
"selected": true,
"text": "$patterns[0] = '/quick|lazy|dog/';\n"
},
{
"answer_id": 366884,
"author": "TravisO",
"author_id":... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366794",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,805 | <p>How can I change <code>CSS</code> from <code>javascript</code>. </p>
<p>I'm using <code>jQuery-ui Dialog</code> and I want to change the style of a <code>DIV</code> from javascript.</p>
<p>Thanks</p>
| [
{
"answer_id": 366809,
"author": "Paolo Bergantino",
"author_id": 16417,
"author_profile": "https://Stackoverflow.com/users/16417",
"pm_score": 4,
"selected": true,
"text": "css"
},
{
"answer_id": 366818,
"author": "Tuminoid",
"author_id": 40657,
"author_profile": "ht... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366805",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44973/"
] |
366,822 | <p>I have always written regexes like this</p>
<pre><code><A HREF="([^"]*)" TARGET="_blank">([^<]*)</A>
</code></pre>
<p>but I just learned about this <a href="http://www.regular-expressions.info/examples.html" rel="nofollow noreferrer">lazy thing</a> and that I can write it like this</p>
<pre><code><A HREF="(.*?)" TARGET="_blank">(.*?)</A>
</code></pre>
<p>is there any disadvantage to using this second approach? The regex is definitely more compact (even SO parses it better).</p>
<p><strong>Edit</strong>: There are two best answers here, which point out two important differences between the expressions. ysth's answer points to a weakness in the non-greedy/lazy one, in which the hyperlink itself could possibly include other attributes of the A tag (definitely not good). Rob Kennedy points out a weakness in the greedy example, in that anchor texts cannot include other tags (definitely not okay, because it wouldn't grab all the anchor text either)... so the answer is that, regular expressions being what they are, lazy and non-lazy solutions that seem the same are probably not semantically equivalent.</p>
<p><strong>Edit</strong>: Third best answer is by Alan M about relative speed of the expressions. For the time being, I'll mark his as best answer so people give him more points :) </p>
| [
{
"answer_id": 366868,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 3,
"selected": false,
"text": "img"
},
{
"answer_id": 366907,
"author": "ysth",
"author_id": 17389,
"author_profile": "https://St... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8047/"
] |
366,834 | <p>Does anyone have any suggestions as to how I can clean the body of incoming emails? I want to strip out disclaimers, images and maybe any previous email text that may be also be present so that I am left with just the body text content. My guess is it isn't going to be possible in any reliable way, but has anyone tried it? Are there any libraries geared towards this sort of thing?</p>
| [
{
"answer_id": 59001867,
"author": "Paul Mendoza",
"author_id": 29277,
"author_profile": "https://Stackoverflow.com/users/29277",
"pm_score": 0,
"selected": false,
"text": "var parser = new SigParser.EmailParsing.EmailParser();\nvar result = await parser.GetCleanedBodyAsync(new SigParser... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27805/"
] |
366,838 | <p>Hey, i am currently working on a django app for my studies, and came to the point of l18n. Localizing the site itself was very easy, but now i have to allow users, to translate the dynamic content of the application.
Users can save "products" in the database and give them names and descriptions, but since the whole site should be localized, i must provide a way of translating theses names and descriptions to the users.</p>
<p>Is there a natural way in django to do this? Or do i have to realize it as part of the application (by representing the translations in the datamodel)</p>
<p>Thanks, Janosch</p>
| [
{
"answer_id": 12482331,
"author": "Kostyantyn",
"author_id": 1176671,
"author_profile": "https://Stackoverflow.com/users/1176671",
"pm_score": 1,
"selected": false,
"text": "class Product(models.Model):\n name=models.CharField(max_length=100)\n name_ar=models.CharField(max_length=... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46172/"
] |
366,849 | <p>Lets say my alphabet contains X letters and my language supports only Y letter words (Y < X ofcourse). I need to generate all the words possible in random order.</p>
<p>E.g.
Alphabet=a,b,c,d,e,f,g
Y=3</p>
<p>So the words would be:
aaa
aab
aac
aba
..
bbb
ccc
..
(the above should be generated in random order)</p>
<p>The trivial way to do it would be to generate the words and then randomize the list. I DONT want to do that. I want to generate the words in random order.</p>
<p>rondom(n)=letter[x].random(n-1) will not work because then you'll have a list of words starting with letter[x].. which will make the list not so random.</p>
<p>Any code/pseudocode appreciated.</p>
| [
{
"answer_id": 366870,
"author": "Jennifer",
"author_id": 22360,
"author_profile": "https://Stackoverflow.com/users/22360",
"pm_score": 0,
"selected": false,
"text": " char[] alphabet = {'a', 'b', 'c', 'd'};\n int wordLength = 3;\n\n Random rand = new Random();\n\n ... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13820/"
] |
366,852 | <p>I'm writing a financial application in C# where performance (i.e. speed) is critical. Because it's a financial app I have to use the Decimal datatype intensively. </p>
<p>I've optimized the code as much as I could with the help of a profiler. Before using Decimal, everything was done with the Double datatype and the speed was several times faster. However, Double is not an option because of its binary nature, causing a lot of precision errors over the course of multiple operations.</p>
<p>Is there any decimal library that I can interface with C# that could give me a performance improvement over the native Decimal datatype in .NET?</p>
<p>Based on the answers I already got, I noticed I was not clear enough, so here are some additional details:</p>
<ul>
<li>The app has to be as fast as it can possibly go (i.e. as fast as it was when using Double instead of Decimal would be a dream). Double was about 15x faster than Decimal, as the operations are hardware based.</li>
<li>The hardware is already top-notch (I'm running on a Dual Xenon Quad-Core) and the application uses threads, so CPU utilization is always 100% on the machine. Additionally, the app is running in 64bit mode, which gives it a mensurable performance advantage over 32bit.</li>
<li>I've optimized past the point of sanity (more than one month and a half optimizing; believe it or not, it now takes approx. 1/5000 of what it took to do the same calculations I used as a reference initially); this optimization involved everything: string processing, I/O, database access and indexes, memory, loops, changing the way some things were made, and even using "switch" over "if" everywhere it made a difference. The profiler is now clearly showing that the remaining performance culprit is on the Decimal datatype operators. Nothing else is adding up a considerable amount of time.</li>
<li>You have to believe me here: I've gone as far as I could possibly go in the realm of C#.NET to optimize the application, and I'm really amazed at its current performance. I'm now looking for a good idea in order to improve Decimal performance to something close to Double. I know it's only a dream, but just wanted to check I thought of everything possible. :)</li>
</ul>
<p>Thanks!</p>
| [
{
"answer_id": 1221409,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "#include <emmintrin.h>\n#include <tmmintrin.h>\n\nextern \"C\" DllExport __int32* sse2_add(__int32* arr1, __int32* arr2);\n\n... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46178/"
] |
366,854 | <p>I have a problem with the <a href="https://jqueryui.com/dialog/" rel="nofollow noreferrer"><code>jquery-ui dialog box</code></a>. </p>
<p><strong>The problem is that when I close the dialog box and then I click on the link that triggers it, it does not pop-up again unless I refresh the page.</strong> </p>
<p>How can I call the dialog box back without refreshing the actual page. </p>
<p>Below is my code:</p>
<pre><code>$(document).ready(function() {
$('#showTerms').click(function()
{
$('#terms').css('display','inline');
$('#terms').dialog({
resizable: false,
modal: true,
width: 400,
height: 450,
overlay: { backgroundColor: "#000", opacity: 0.5 },
buttons:{ "Close": function() { $(this).dialog("close"); } },
close: function(ev, ui) { $(this).remove(); },
});
});
</code></pre>
<p>Thanks</p>
| [
{
"answer_id": 366893,
"author": "Darko",
"author_id": 32943,
"author_profile": "https://Stackoverflow.com/users/32943",
"pm_score": 4,
"selected": false,
"text": "$(this).remove()"
},
{
"answer_id": 366898,
"author": "David Bonnici",
"author_id": 44973,
"author_profi... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44973/"
] |
366,856 | <p>I'm about to put my head thru this sliding glass door. I can't figure out how to execute the following code in VB.NET to save my life. </p>
<pre><code>private static void InitStructureMap()
{
ObjectFactory.Initialize(x =>
{
x.AddRegistry(new DataAccessRegistry());
x.AddRegistry(new CoreRegistry());
x.AddRegistry(new WebUIRegistry());
x.Scan(scanner =>
{
scanner.Assembly("RPMWare.Core");
scanner.Assembly("RPMWare.Core.DataAccess");
scanner.WithDefaultConventions();
});
});
}
</code></pre>
| [
{
"answer_id": 366894,
"author": "Kyle West",
"author_id": 34133,
"author_profile": "https://Stackoverflow.com/users/34133",
"pm_score": 0,
"selected": false,
"text": "Private Shared Sub InitStructureMap()\nObjectFactory.Initialize(Function (ByVal x As IInitializationExpression) \n x.... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34133/"
] |
366,857 | <p>Remember the little div that shows up at the top of the page to notify us of things (like new badges)?</p>
<p>I would like to implement something like that as well and am looking for some best practices or patterns.</p>
<p>My site is an ASP.NET MVC app as well. Ideally the answers would include specifics like "put <em>this</em> in the master page" and "do <em>this</em> in the controllers".</p>
<p>Just to save you from having to look yourself, this is the code I see from the welcome message you get when not logged in at stackoverflow.</p>
<pre><code><div class="notify" style="">
<span>
First time at Stack Overflow? Check out the
<a href="/messages/mark-as-read?returnurl=%2ffaq">FAQ</a>!
</span>
<a class="close-notify" onclick="notify.close(true)" title="dismiss this notification">×</a>
</div>
<script type="text/javascript">
$().ready(function() {
notify.show();
});
</script>
</code></pre>
<p>I'd like to add that I understand this perfectly and also understand the jquery involvement. I'm just interested in who puts the code into the markup and when ("who" as in which entities within an ASP.NET MVC app).</p>
<p>Thanks!</p>
| [
{
"answer_id": 366864,
"author": "Tom",
"author_id": 20,
"author_profile": "https://Stackoverflow.com/users/20",
"pm_score": 2,
"selected": false,
"text": "onclick"
},
{
"answer_id": 878056,
"author": "itsadok",
"author_id": 7581,
"author_profile": "https://Stackoverf... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2595/"
] |
366,860 | <p>From the man page on git-merge, there are a number of merge strategies you can use. </p>
<ul>
<li><p><em>resolve</em> -
This can only resolve two heads (i.e. the current branch and another branch you pulled from) using 3-way merge algorithm. It tries to carefully detect criss-cross merge ambiguities and is considered generally safe and fast.</p></li>
<li><p><em>recursive</em> -
This can only resolve two heads using 3-way merge algorithm. When there are more than one common ancestors that can be used for 3-way merge, it creates a merged tree of the common ancestors and uses that as the reference tree for the 3-way merge. This has been reported to result in fewer merge conflicts without causing mis-merges by tests done on actual merge commits taken from Linux 2.6 kernel development history. Additionally this can detect and handle merges involving renames. This is the default merge strategy when pulling or merging one branch.</p></li>
<li><p><em>octopus</em> -
This resolves more than two-head case, but refuses to do complex merge that needs manual resolution. It is primarily meant to be used for bundling topic branch heads together. This is the default merge strategy when pulling or merging more than one branches.</p></li>
<li><p><em>ours</em> -
This resolves any number of heads, but the result of the merge is always the current branch head. It is meant to be used to supersede old development history of side branches.</p></li>
<li><p><em>subtree</em> -
This is a modified recursive strategy. When merging trees A and B, if B corresponds to a subtree of A, B is first adjusted to match the tree structure of A, instead of reading the trees at the same level. This adjustment is also done to the common ancestor tree.</p></li>
</ul>
<p>When should I specify something different than the default? What scenarios are each best for?</p>
| [
{
"answer_id": 366940,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 9,
"selected": true,
"text": "commit ae632e99ba0ccd0e9e06d09e8647659220d043b9\nMerge: f51262e... c9ce629... aa0f25d...\n"
},
{
"answer_id": 106364... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9594/"
] |
366,861 | <p>Pretty straightforward stuff, here -- I'm just not good enough with mysql to understand what it wants from me.</p>
<p>I've got a short java test-case that opens a connection on mysql on my dev system but, when I try to put it to my server, it fails.</p>
<p>Any help in tracking this down would be most appreciated.</p>
<p>Thanks!</p>
<p><strong>Test Code</strong></p>
<pre><code>import java.util.*;
import java.sql.*;
public class mysqltest {
static public void getDBConnection() {
System.out.println ("Start of getDBConnection.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "magnets_development";
String driver = "com.mysql.jdbc.Driver";
String userName = "*****"; // blanked for publication
String password = "*****";
try {
Class.forName (driver).newInstance();
System.out.println ("driver.newInstance gotten.");
conn = DriverManager.getConnection (url+dbName, userName, password);
System.out.println ("Connection gotten: " + conn + ".");
Statement sql = conn.createStatement ();
ResultSet results = sql.executeQuery ("use " + dbName + ";");
}
catch (Exception ex) {
System.out.println ("*** Got exception.");
ex.printStackTrace();
}
}
public static void main(String args[]) {
System.out.println ("Main started.");
mysqltest.getDBConnection();
}
}
</code></pre>
<p><strong>Dev System Output</strong> <em>(Expected/correct response)</em></p>
<pre><code>olie$ java mysqltest
Main started.
Start of getDBConnection.
Properties set.
driver.newInstance gotten.
Connection gotten: com.mysql.jdbc.Connection@c980c9.
olie$
</code></pre>
<p><strong>Server Output</strong> <em>(Error I'm trying to track-down)</em> (Some blank lines removed.)</p>
<pre><code>mini$ java mysqltest
Main started.
Start of getDBConnection.
Properties set.
driver.newInstance gotten.
*** Got exception.
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection refused
STACKTRACE:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at java.net.Socket.<init>(Socket.java:367)
at java.net.Socket.<init>(Socket.java:209)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at mysqltest.getDBConnection(mysqltest.java:34)
at mysqltest.main(mysqltest.java:49)
** END NESTED EXCEPTION **
Last packet sent to the server was 3 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at mysqltest.getDBConnection(mysqltest.java:34)
at mysqltest.main(mysqltest.java:49)
mini$
</code></pre>
| [
{
"answer_id": 366869,
"author": "Milhous",
"author_id": 17712,
"author_profile": "https://Stackoverflow.com/users/17712",
"pm_score": 0,
"selected": false,
"text": "properties.setProperty(\"socket\", \"/Applications/MAMP/tmp/mysql/mysql.sock\");\n"
},
{
"answer_id": 367455,
... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366861",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34820/"
] |
366,883 | <p>Is there a way to avoid row deletion on an specific table using constrains?</p>
<p>I'd like to (for example) deny row deletion if the id is 0,1 or 2</p>
<p>This is in order to avoid users deleting master accounts for an application, and I'd like to avoid it even if someone tries it (by mistake) using sql directly.</p>
<p>Thanks!</p>
<p><strong>EDIT:</strong></p>
<p>The whole idea of this question is not to touch the application. It's not a matter of security, I just need to know if It's possible to do what I asked with constrains or any other thing that SQL Server has (It does not need to be an standard db solution).</p>
<p><strong>EDIT 2:</strong></p>
<p>Code samples are very, very appreciated :D</p>
| [
{
"answer_id": 366918,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 5,
"selected": true,
"text": "CREATE TABLE NoKillI (\n id INT NOT NULL, FOREIGN KEY (id) REFERENCES Accounts(id) ON DELETE RESTRICT\n);\nINSERT INTO... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7595/"
] |
366,887 | <p>On Stackers' recommendation, I have been reading Crockford's excellent <em>Javascript: The Good Parts</em>.</p>
<p>It's a great book, but since so much of it is devoted to describing the best way to use Javascript's basic functionality, I'm not sure how I can put his advice into practice without duplicating the efforts of many other Javascript programmers.</p>
<p>Take this passage, for example:</p>
<blockquote>
<p>When you make a new object, you can select the object that should be its prototype. The mechanism that Javascript provides to do this is messy and complex, but it can be significantly simplified. We will add a <code>create</code> method to the <code>Object</code> function. The <code>create</code> method creates a new object that uses an old object as its prototype.</p>
<pre><code>if (typeof Object.create !== 'function') {
Object.create = function(o) {
var F = function () {};
F.prototype = o;
return new F();
}
</code></pre>
</blockquote>
<p>I could manually add this code to all my Javascript projects, but keeping track of everything would be a huge pain.</p>
<p><strong>Are there any libraries that implement <em>The Good Part</em>'s recommendations and thereby save me the trouble of having to keep track of them (/ physically type them all out)?</strong></p>
| [
{
"answer_id": 367112,
"author": "pottedmeat",
"author_id": 2120,
"author_profile": "https://Stackoverflow.com/users/2120",
"pm_score": 1,
"selected": false,
"text": "dojo.delegate"
},
{
"answer_id": 11798237,
"author": "feklee",
"author_id": 282729,
"author_profile":... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25068/"
] |
366,889 | <p>Does the SDK provide any way to change the brightness of the backlight, or turn it off temporarily? </p>
| [
{
"answer_id": 467029,
"author": "Rhubarb",
"author_id": 20479,
"author_profile": "https://Stackoverflow.com/users/20479",
"pm_score": 3,
"selected": false,
"text": "GSEventSetBacklightLevel();\n"
},
{
"answer_id": 6938088,
"author": "Raj",
"author_id": 596503,
"autho... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366889",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13009/"
] |
366,896 | <p>I've got a custom TObjectList descendant in Delphi 2009, and I'd like to play with its enumerator a bit and add some filtering functionality to the MoveNext method, to cause it to skip certain objects. MoveNext is called by DoMoveNext, which is a virtual method, so this shouldn't be difficult to override... except for one thing. The TEnumerator for TObjectList isn't its own class; it's declared as a nested type within the TObjectList declaration.</p>
<p>Is there any simple way to override TEnumerator.DoMoveNext in my descendant class, or do I have to reimplement the whole TEnumerator? It's not a very big class, but I'd prefer to keep redundancies to a minimum if I can...</p>
| [
{
"answer_id": 366935,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 3,
"selected": false,
"text": "type\n TMasonEnumerator = class(TObjectList.TEnumerator)\n protected\n function DoMoveNext: Boolean; override;\n ... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366896",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32914/"
] |
366,897 | <p>I've got a big file on which I'm opening a FileInputStream. This file contains some files each having an offset from the beginning and a size. Furthermore, I've got a parser that should evaluate such a contained file.</p>
<pre><code>File file = ...; // the big file
long offset = 1734; // a contained file's offset
long size = 256; // a contained file's size
FileInputStream fis = new FileInputStream(file );
fis.skip(offset);
parse(fis, size);
public void parse(InputStream is, long size) {
// parse stream data and insure we don't read more than size bytes
is.close();
}
</code></pre>
<p>I feel like this is no good practice. Is there a better way to do this, maybe using buffering?</p>
<p>Furthermore, I feel like the skip() method slows the reading process a lot.</p>
| [
{
"answer_id": 366903,
"author": "krosenvold",
"author_id": 23691,
"author_profile": "https://Stackoverflow.com/users/23691",
"pm_score": 2,
"selected": false,
"text": "List<InputStream> getStreams(File inputFile)\n"
},
{
"answer_id": 366914,
"author": "Esko",
"author_id"... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366897",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12463/"
] |
366,913 | <p>I'm learning Rails and it's going well so far. My biggest question at the moment is: how do I go about manually inserting a row into my database? I've got the scaffolding in place for creating rows of DataTypeOne, but I want a row for DataTypeTwo to be created when the form for DataTypeOne is submitted (and have it reference the id of DataTypeOne...but I think I can work this out on my own).</p>
<p>Thanks in advance.</p>
| [
{
"answer_id": 366921,
"author": "TonyLa",
"author_id": 1295,
"author_profile": "https://Stackoverflow.com/users/1295",
"pm_score": 4,
"selected": true,
"text": "new_record = DataTypeTwo.new\nnew_record.save!\n"
},
{
"answer_id": 366930,
"author": "Yaser Sulaiman",
"autho... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34795/"
] |
366,915 | <p>I have an articles table and a categories table. I want to fetch 7 articles for each category. Currently I have this but it's terrible slow on large tables so it's not really a solution:</p>
<pre><code>SELECT id,
title,
categories_id,
body,
DATE_FORMAT(pubdate, "%d/%m/%y %H:%i") as pubdate
FROM articles AS t
WHERE (
SELECT COUNT(*)
FROM articles
WHERE t.categories_id = categories_id
AND id< t.id AND publish = 1
AND expires > '2008-12-14 18:38:02'
AND pubdate <= '2008-12-14 18:38:02'
) < 7
ORDER BY categories_id DESC
</code></pre>
<p>Using explain, it shows me it's doing a join type ALL & REF. The select types are PRIMARY and DEPENDENT SUBQUERY .</p>
<p>Is there a better solution?</p>
| [
{
"answer_id": 366939,
"author": "Jennifer",
"author_id": 22360,
"author_profile": "https://Stackoverflow.com/users/22360",
"pm_score": 0,
"selected": false,
"text": "SELECT categories_id FROM Categories\n"
},
{
"answer_id": 366950,
"author": "Turnkey",
"author_id": 13144... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46183/"
] |
366,928 | <p>I'm heavily using Cygwin (with <a href="http://en.wikipedia.org/wiki/PuTTY" rel="noreferrer">PuTTY </a> shell). But, it's quite tricky to invoke <code>cl.exe</code> (that is, the Visual C++ compiler toolchain) in the Cygwin Bash shell. Running <code>vcvars*.bat</code> in the Bash shell doesn't work obviously. I tried to migrate VC++'s environment variables to Cygwin, but it's not that easy.</p>
<p>How do I run the VC++ compiler in Cygwin's Bash shell?</p>
| [
{
"answer_id": 366934,
"author": "Diomidis Spinellis",
"author_id": 20520,
"author_profile": "https://Stackoverflow.com/users/20520",
"pm_score": 4,
"selected": false,
"text": "sh-3.2$ cl\nMicrosoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86\nCopyright (C) Micr... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46185/"
] |
366,938 | <p>I have an NSView subclass which has property which I want to be bindable. I've implemented the following in the subclass:</p>
<p>myView.h:</p>
<pre><code>@property (readwrite, retain) NSArray *representedObjects;
</code></pre>
<p>myView.m:</p>
<pre><code>@synthesize representedObjects;
+(void)initialize
{
[self exposeBinding: @"representedObjects"];
}
-(void)bind:(NSString *)binding toObject:(id)observableController withKeyPath:(NSString *)keyPath options:(NSDictionary *)options
{
if ([binding isEqualToString:@"representedObjects"]) {
[observableController addObserver: self forKeyPath:@"arrangedObjects" options:NSKeyValueChangeNewKey context:nil];
} else {
[super bind: binding toObject:observableController withKeyPath:keyPath options: options];
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"arrangedObjects"]) {
[self setRepresentedObjects: [object arrangedObjects]];
}
}
</code></pre>
<p>I then create the binding to an arrayController in <code>-[AppController awakeFromNib]</code>:</p>
<pre><code>[myView bind:@"representedObjects" toObject:arrayController withKeyPath:@"arrangedObjects" options: nil];
</code></pre>
<p>Is this the correct way of implementing binding? It involves a lot of boiler plate code which makes me think that I'm doing something wrong.</p>
<p>I thought that NSObject would automagically implement what I have done manually in <code>-bind:toObject:withKeyPath:options:</code> but this doesn't seem to be the case. If I comment out my <code>-bind:toObject:withKeyPath:options:</code> the setRepresentedObjects method is never called.</p>
<p>Additional info:
I've done some more investigating and have reached the conclusion that my original approach is correct and you do have to over ride <code>-bind:toObject:withKeyPath:options:</code>. Here's a quote from <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/HowDoBindingsWork.html#//apple_ref/doc/uid/20002373" rel="nofollow noreferrer">Cocoa Bindings Programming Topics: How Do Bindings Work?</a>:</p>
<blockquote>
<p>In its bind:toObject:withKeyPath:options: method an object must as a minimum do the following:</p>
<ul>
<li>Determine which binding is being set</li>
<li>Record what object it is being bound to using what keypath and with what options</li>
<li>Register as an observer of the keypath of the object to which it is bound so that it receives notification of changes</li>
</ul>
<p>The code sample in Listing 2 shows a partial implementation of Joystick’s bind:toObject:withKeyPath:options: method dealing with just the angle binding.</p>
<p>Listing 2 Partial implementation of the bind:toObject:withKeyPath:options method for the Joystick class:</p>
<blockquote>
<pre><code>static void *AngleBindingContext = (void *)@"JoystickAngle";
- (void)bind:(NSString *)binding
toObject:(id)observableObject
withKeyPath:(NSString *)keyPath
options:(NSDictionary *)options
{
// Observe the observableObject for changes -- note, pass binding identifier
// as the context, so you get that back in observeValueForKeyPath:...
// This way you can easily determine what needs to be updated.
if ([binding isEqualToString:@"angle"])
{
[observableObject addObserver:self
forKeyPath:keyPath
options:0
context:AngleBindingContext];
// Register what object and what keypath are
// associated with this binding
observedObjectForAngle = [observableObject retain];
observedKeyPathForAngle = [keyPath copy];
// Record the value transformer, if there is one
angleValueTransformer = nil;
NSString *vtName = [options objectForKey:@"NSValueTransformerName"];
if (vtName != nil)
{
angleValueTransformer = [NSValueTransformer
valueTransformerForName:vtName];
}
}
// Implementation continues...
</code></pre>
</blockquote>
</blockquote>
<p>This clearly shows that the Joystick class (which is an NSView subclass) needs to override <code>-bind:toObject:withKeyPath:options:</code>.</p>
<p>I find this surprising. I was skeptical of this conclusion as I have found no other code samples that do this. However, as the offical Apple documentation says I should over ride <code>-bind:toObject:withKeyPath:options:</code> I conclude that it is the correct approach.</p>
<p>I would be very happy if someone could prove me wrong!</p>
| [
{
"answer_id": 423175,
"author": "Rob Keniger",
"author_id": 50122,
"author_profile": "https://Stackoverflow.com/users/50122",
"pm_score": 0,
"selected": false,
"text": "-bind:toObject:withKeyPath:options:"
},
{
"answer_id": 7394273,
"author": "paulmelnikow",
"author_id":... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,955 | <p>how do I bind a <code>std::ostream</code> to either <code>std::cout</code> or to an <code>std::ofstream</code> object, depending on a certain program condition? Although this invalid for many reasons, I would like to achieve something that is semantically equivalent to the following:</p>
<pre><code>std::ostream out = condition ? &std::cout : std::ofstream(filename);
</code></pre>
<p>I've seen some examples that are not exception-safe, such as one from <a href="http://www2.roguewave.com/support/docs/sourcepro/edition9/html/stdlibug/34-2.html" rel="noreferrer">http://www2.roguewave.com/support/docs/sourcepro/edition9/html/stdlibug/34-2.html</a>:</p>
<pre><code>int main(int argc, char *argv[])
{
std::ostream* fp; //1
if (argc > 1)
fp = new std::ofstream(argv[1]); //2
else
fp = &std::cout //3
*fp << "Hello world!" << std::endl; //4
if (fp!=&std::cout)
delete fp;
}
</code></pre>
<p>Does anyone know a better, exception-safe solution?</p>
| [
{
"answer_id": 366967,
"author": "Tom",
"author_id": 40620,
"author_profile": "https://Stackoverflow.com/users/40620",
"pm_score": 5,
"selected": false,
"text": "void process(std::ostream &os);\n\nint main(int argc, char *argv[]) {\n std::ostream* fp = &cout;\n std::ofstream fout;\... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1170277/"
] |
366,968 | <p>I have been searching for a way to insert linebreaks in my code for when I view my source. I am not looking for <code><br /></code></p>
<p>Something like the PHP equiv to <code>\n</code></p>
<p>Any ideas on how to do this in ASP? I will be placing this inside a string.</p>
| [
{
"answer_id": 366979,
"author": "John Sheehan",
"author_id": 1786,
"author_profile": "https://Stackoverflow.com/users/1786",
"pm_score": 6,
"selected": true,
"text": "Response.Write \"hello\" & vbCrLf & \"world\"\n"
},
{
"answer_id": 367023,
"author": "Taptronic",
"autho... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
366,980 | <p>What are the main differences among them? And in which typical scenarios is it better to use each language?</p>
| [
{
"answer_id": 367014,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 10,
"selected": true,
"text": "sed"
},
{
"answer_id": 367082,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "htt... | 2008/12/14 | [
"https://Stackoverflow.com/questions/366980",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44100/"
] |
366,998 | <p><em>Javascript: The Good Parts</em> is a great book. Often I find myself reading passages like the following from the perspective of a language designer:</p>
<blockquote>
<p><code>undefined</code> and <code>NaN</code> are not constants. They are global variables, and you can change their values. This should not be possible, and yet it is. Don't do it.</p>
</blockquote>
<p>Takeaways:</p>
<ol>
<li>Don't change the value of <code>undefined</code> in my Javascript code.</li>
<li>When designing a language, make its equivalent of <code>undefined</code> immutable.</li>
</ol>
<p>A different more subtle example would be "<code>for in</code> shouldn't enumerate over prototype properties".</p>
<p>I want a book at talks about these issues of language design outside of the context of a particular language.</p>
<p><strong>If you were trying to design the "perfect" OO language, what books would you read for guidance?</strong></p>
| [
{
"answer_id": 367472,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 1,
"selected": false,
"text": "Perl6"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/366998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25068/"
] |
367,007 | <p>On the page <a href="http://tesselaar.com/gallery/" rel="nofollow noreferrer">http://tesselaar.com/gallery/</a> I have a heading (level 1) at the top of the page "Photo Gallery" that doesn't display in IE7 and I can't work out why.</p>
<p>It follows the same CSS and page-structure as the rest of the site, the only difference being there is an element being floated to the right immediately after.</p>
<p>Any insight would be appreciated.</p>
| [
{
"answer_id": 367790,
"author": "annakata",
"author_id": 13018,
"author_profile": "https://Stackoverflow.com/users/13018",
"pm_score": 2,
"selected": true,
"text": "text-align: right;"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/367007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14979/"
] |
367,020 | <p>What's the best way to animate a background image sliding to the left, and looping it? Say I've got a progress bar with a background I want to animate when it's active (like in Gnome or OS X).</p>
<p>I've been playing with the <code>$(...).animate()</code> function and trying to modify the relevant CSS property, but I keep hitting a brick wall when trying to figure out how to modify the <code>background-position</code> property. I can't just increment its value, and I'm not sure if this is even the best approach.</p>
<p>Any help appreciated!</p>
| [
{
"answer_id": 367028,
"author": "Wilco",
"author_id": 5291,
"author_profile": "https://Stackoverflow.com/users/5291",
"pm_score": 5,
"selected": true,
"text": "function animateBar(self) {\n // Setup\n var bar = self.element.find('.ui-progress-bar');\n\n bar.css('background-posi... | 2008/12/14 | [
"https://Stackoverflow.com/questions/367020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5291/"
] |
367,029 | <p>Most of the time, the errors you get from your model properties will happen when you're saving data. For instance, if you try saving a string as an IntegerProperty, that will result in an error.</p>
<p>The one exception (no pun intended) is ReferenceProperty. If you have lots of references and you're not completely careful about leaving in bad references, it's common to be greeted with an error like "TemplateSyntaxError: Caught an exception while rendering: ReferenceProperty failed to be resolved".</p>
<p>And this is if there's only one bad reference in the view. D'oh. </p>
<p>I could write a try/except block to try to access all the reference properties and delete them if an exception is raised, but this functionality could surely be useful to many other developers if there was a more generic method than the one I'd be capable of writing. I imagine it would take a list of model types and try to access each reference property of each entity in each model, setting the property to None if an exception is raised.</p>
<p>I'll see if I can do this myself, but it would definitely help to have some suggestions/snippets to get me started.</p>
| [
{
"answer_id": 2152183,
"author": "Mehmet",
"author_id": 565109,
"author_profile": "https://Stackoverflow.com/users/565109",
"pm_score": 0,
"selected": false,
"text": "obj1 = db.get(obj2.reference)\n\nif not obj1:\n # Referenced entity was deleted.\n"
}
] | 2008/12/14 | [
"https://Stackoverflow.com/questions/367029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9106/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.