qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
395,433 | <p>Erlang with mnesia/dets is famous for it slow startup times after a crash. Basically the same issue as with fsck on older filesystems.</p>
<p>But I also experience slow startup times after regular shutdowns: about 8 Minutes for 250 MB on-disk data on a beefy machine.</p>
<p>So I have to do something special on shutdown besides typing "q()."? Is there a way to speed up startup times?</p>
| [
{
"answer_id": 395450,
"author": "Tautologistics",
"author_id": 44481,
"author_profile": "https://Stackoverflow.com/users/44481",
"pm_score": 1,
"selected": false,
"text": "application:stop(mnesia)\n"
},
{
"answer_id": 463413,
"author": "max",
"author_id": 49407,
"aut... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49407/"
] |
395,436 | <p>I am using statfs() which gives me the free blocks available to a non-superuser.</p>
<p>I am unsure how to convert this into KB/MB/GB.</p>
<p>The values that are returned are:</p>
<pre><code>fundamental file system block size: 4096
total data blocks in file system: 3805452
free blocks in fs: 63425
free blocks avail to non-superuser: 63425
total file nodes in file system: 3805450
free file nodes in fs: 63425
</code></pre>
<p>The value I am interested is saying 63425, but I am not sure what that means KB/MB/GB wise.</p>
<p>I am running this on the iPhone and an application is supposed to have access to 2GB I believe, if that much is open on the device, which in my case I do.</p>
<p>So I should be getting a value somewhere around 2G, I would think.</p>
<p>I ran 63425 against an online blocks to MB converter but that gives me a result of 30MB which shouldn't be the case.</p>
<p>Can anyone help me in figuring out how to get KB/MB/GB from this info?</p>
<p>Thanks.</p>
| [
{
"answer_id": 395514,
"author": "kdbdallas",
"author_id": 26728,
"author_profile": "https://Stackoverflow.com/users/26728",
"pm_score": 2,
"selected": false,
"text": "NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);\n\nstruct statfs tStat... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395436",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26728/"
] |
395,451 | <p>I have a script that I'd like to continue using, but it looks like I either have to find some workaround for a bug in Python 3, or downgrade back to 2.6, and thus having to downgrade other scripts as well...</p>
<p>Hopefully someone here have already managed to find a workaround.</p>
<p>The problem is that due to the new changes in Python 3.0 regarding bytes and strings, not all the library code is apparently tested.</p>
<p>I have a script that downloades a page from a web server. This script passed a username and password as part of the url in python 2.6, but in Python 3.0, this doesn't work any more.</p>
<p>For instance, this:</p>
<pre><code>import urllib.request;
url = "http://username:password@server/file";
urllib.request.urlretrieve(url, "temp.dat");
</code></pre>
<p>fails with this exception:</p>
<pre><code>Traceback (most recent call last):
File "C:\Temp\test.py", line 5, in <module>
urllib.request.urlretrieve(url, "test.html");
File "C:\Python30\lib\urllib\request.py", line 134, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "C:\Python30\lib\urllib\request.py", line 1476, in retrieve
fp = self.open(url, data)
File "C:\Python30\lib\urllib\request.py", line 1444, in open
return getattr(self, name)(url)
File "C:\Python30\lib\urllib\request.py", line 1618, in open_http
return self._open_generic_http(http.client.HTTPConnection, url, data)
File "C:\Python30\lib\urllib\request.py", line 1576, in _open_generic_http
auth = base64.b64encode(user_passwd).strip()
File "C:\Python30\lib\base64.py", line 56, in b64encode
raise TypeError("expected bytes, not %s" % s.__class__.__name__)
TypeError: expected bytes, not str
</code></pre>
<p>Apparently, base64-encoding now needs bytes in and outputs a string, and thus urlretrieve (or some code therein) which builds up a string of username:password, and tries to base64-encode this for simple authorization, fails.</p>
<p>If I instead try to use urlopen, like this:</p>
<pre><code>import urllib.request;
url = "http://username:password@server/file";
f = urllib.request.urlopen(url);
contents = f.read();
</code></pre>
<p>Then it fails with this exception:</p>
<pre><code>Traceback (most recent call last):
File "C:\Temp\test.py", line 5, in <module>
f = urllib.request.urlopen(url);
File "C:\Python30\lib\urllib\request.py", line 122, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python30\lib\urllib\request.py", line 359, in open
response = self._open(req, data)
File "C:\Python30\lib\urllib\request.py", line 377, in _open
'_open', req)
File "C:\Python30\lib\urllib\request.py", line 337, in _call_chain
result = func(*args)
File "C:\Python30\lib\urllib\request.py", line 1082, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:\Python30\lib\urllib\request.py", line 1051, in do_open
h = http_class(host, timeout=req.timeout) # will parse host:port
File "C:\Python30\lib\http\client.py", line 620, in __init__
self._set_hostport(host, port)
File "C:\Python30\lib\http\client.py", line 632, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
http.client.InvalidURL: nonnumeric port: 'password@server'
</code></pre>
<p>Apparently the url parsing in this "next gen url retrieval library" doesn't know what to do with username and passwords in the url.</p>
<p>What other choices do I have?</p>
| [
{
"answer_id": 395481,
"author": "jb.",
"author_id": 37522,
"author_profile": "https://Stackoverflow.com/users/37522",
"pm_score": 6,
"selected": true,
"text": "import urllib.request\n# Create an OpenerDirector with support for Basic HTTP Authentication...\nauth_handler = urllib.request.... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395451",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/267/"
] |
395,454 | <p>I'm trying to loop through items of a checkbox list. If it's checked, I want to set a value. If not, I want to set another value. I was using the below, but it only gives me checked items:</p>
<pre><code>foreach (DataRowView myRow in clbIncludes.CheckedItems)
{
MarkVehicle(myRow);
}
</code></pre>
| [
{
"answer_id": 395473,
"author": "JasonS",
"author_id": 1865,
"author_profile": "https://Stackoverflow.com/users/1865",
"pm_score": 5,
"selected": false,
"text": "foreach (ListItem listItem in clbIncludes.Items)\n{\n if (listItem.Selected) { \n //do some work \n }\n else ... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46064/"
] |
395,484 | <p>Let's say you have the following chunk of code:</p>
<pre><code><div id="container">
<someelement>This is any element.</someelement>
</div>
</code></pre>
<p>What's the best CSS I could use to horizontally center "someelement" within its containing div?</p>
| [
{
"answer_id": 395493,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 2,
"selected": false,
"text": "<someelement style=\"margin-left:auto;margin-right:auto\">This is any element</someelement>\n"
},
{
"answer_id": ... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1615/"
] |
395,486 | <p>Like many of you, I have to deal with a large amount of files: source code, binary downloads, spreadsheets, pdf's, word docs, images, note files, quick scripts, and more.</p>
<p>These files can fall into many categories:</p>
<ul>
<li>Temporary files that should eventually be deleted</li>
<li>Important or useful references files that should be archived</li>
<li>Files tied to specific projects at a specific employer</li>
<li>General employer documents such as holiday schedules, healthcare plans, travel request forms, etc</li>
<li>Professional documents not tied to any specific employer</li>
<li>Side projects</li>
<li>Personal documents (taxes, important receipts, notes, etc)</li>
</ul>
<p>I'd like to avoid huge folder hierarchies, especially for the files I access via commandline on a frequent basis</p>
<p>For archived files, an indexed, tag-based categorization system would seem to be a better fit than the folder approach.</p>
<p>Are there any recommended tools or systems for managing files effectively? I'm considering turning my Downloads folder into a sort of "Inbox" and taking a GTD approach. Also, programs like Hazel might be able to help.</p>
<p>My focus is on Mac software, but I'm interested in hearing all approaches.</p>
<p>What folder structures, systems, and tools do you use to manage your files?</p>
| [
{
"answer_id": 395567,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 3,
"selected": true,
"text": "C:\\Filing Cabinet\\"
}
] | 2008/12/27 | [
"https://Stackoverflow.com/questions/395486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36041/"
] |
395,504 | <p>I'm wanting to decrement a variable in a MySQL table by one everytime an UPDATE query is ran.</p>
<p>What I have is this, which isn't working:</p>
<p><code>UPDATE forum SET replys = reply-- WHERE fid = '$id'</code></p>
<p>Is this possible in any way, or am I going to have to run a SELECT and get the value first, decrement it, and then insert the new value into the UPDATE query?</p>
| [
{
"answer_id": 395521,
"author": "stu",
"author_id": 12386,
"author_profile": "https://Stackoverflow.com/users/12386",
"pm_score": 5,
"selected": true,
"text": "UPDATE forum SET replys = reply - 1 WHERE fid = '$id'\n"
},
{
"answer_id": 395524,
"author": "duffymo",
"author... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395504",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36545/"
] |
395,505 | <p>What would be the best compression algorithm to use to compress packets before sending them over the wire? The packets are encoded using JSON. Would LZW be a good one for this or is there something better?</p>
| [
{
"answer_id": 395668,
"author": "afeldspar",
"author_id": 33904,
"author_profile": "https://Stackoverflow.com/users/33904",
"pm_score": 5,
"selected": true,
"text": "{\n \"vector\": {\n \"latitude\": 16,\n \"longitude\": 18,\n \"altitude\": 20\n },\n \"vect... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49018/"
] |
395,506 | <p>I'm trying to implement a comet style, long polling connection using an XMLHttpResponse object.
The idea is to maintain an open connection to a server which sends data when it is available (faking push). As soon as the XHR object completes, I need to spawn a new one to wait for any fresh data.</p>
<p>Below is a snippet of code which outlines a solution that works but, as the comment says, only because of a timeout which I need to get rid of.</p>
<pre><code>window.onload = function(){
XHR.init();
}
XHR = {
init: function() {
this.xhr = new XMLHttpRequest();
this.xhr.open( "GET", "proxy.php?salt="+Math.round( Math.random()*10000 ), true );
this.xhr.onreadystatechange = this.process.bind( this );
this.xhr.send( null );
},
process: function() {
if( this.xhr.readyState == 4 ) {
// firebug console
console.log( this.xhr.responseText );
// ** Attempting to create new XMLHttpRequest object to
// replace the one that's just completed
// doesn't work without the timeout
setTimeout( function() { this.init() }.bind( this ), 1000 );
}
}
}
Function.prototype.bind = function( obj ) {
var method = this;
return function() {
return method.apply( obj, arguments );
}
}
// proxy.php - a dummy that keeps the XHR object waiting for a response
<?php
$rand = mt_rand( 1, 10 );
sleep( $rand );
echo date( 'H:i:s' ).' - '.$rand;
</code></pre>
<p>I think the problem might be that you can't delete an object (xhr) from it's own event handler (process) as is the case here. especially because the 'this' within the handler is bound to an object (XHR) which contains the object (xhr) I'm trying to delete.
Kinda circular!</p>
<p>Can anyone help? The above example is the closest I can get.</p>
| [
{
"answer_id": 395610,
"author": "some",
"author_id": 36866,
"author_profile": "https://Stackoverflow.com/users/36866",
"pm_score": 0,
"selected": false,
"text": "<script type=\"text/javascript\">myupdate(\"mydata\");</script> \n"
},
{
"answer_id": 395672,
"author": "Jonathan... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395506",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12161/"
] |
395,509 | <p>I'm new to the Mac OS X, and I'm just about ready to throw my brand new <a href="http://en.wikipedia.org/wiki/MacBook_Pro" rel="nofollow noreferrer">MacBook Pro</a> out the window. Every tutorial on setting up a Django development environment on <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow noreferrer">Mac OS X Leopard</a> is insidiously wrong. They are all skipping over one step, or assuming you have setup something one way, or are just assuming that I know one thing that I must not.</p>
<p>I'm very familiar with how to setup the environment on Ubuntu/Linux, and the only part I'm getting stuck on with <a href="https://en.wikipedia.org/wiki/OS_X" rel="nofollow noreferrer">OS X</a> is how to install MySQL, autostart it, and install the Python MySQL bindings. I think my mistake was using a hodgepodge of tools I don't fully understand; I used fink to install MySQL and its development libraries and then tried to build the Python-MySQL bindings from source (but they won't build.)</p>
<p>UPDATE:
I installed the binary MySQL package from <a href="http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg" rel="nofollow noreferrer">http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg</a>, and I got MySQL server running (can access with admin.)
The MySQL version I got from port was rubbish, I could not get it to run at all.</p>
<p>I modified the source for the Python-MySQL package as per the answer I chose, but I still got compilation errors that I listed in the comments. I was able to fix these by adding /usr/local/mysql/bin/ to my path in my "~/.profile" file.
"
PATH=/usr/local/mysql/bin:$PATH
"</p>
<p>Thanks for the help, I was very wary about editing the source code since this operation had been so easy on Ubuntu, but I'll be more willing to try that in the future. I'm really missing Ubuntu's "apt-get" command; it makes life very easy and simple sometimes. I already have an Ubuntu <a href="http://en.wikipedia.org/wiki/VMware" rel="nofollow noreferrer">VMware</a> image running on my Mac, so I can always use that as a fallback (plus it more closely matches my production machines so should be a good test environment for debugging production problems.)</p>
| [
{
"answer_id": 395546,
"author": "James Cape",
"author_id": 41044,
"author_profile": "https://Stackoverflow.com/users/41044",
"pm_score": 2,
"selected": false,
"text": "# port install <pkgname>"
},
{
"answer_id": 395568,
"author": "James Brady",
"author_id": 29903,
"a... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36680/"
] |
395,525 | <p>I have a funciton that I am currently using to show a hidden div.a_type</p>
<p>How can I modify this code so that instead of fading in the hidden div,
I can add the new div to the DOM</p>
<pre>
jQuery(function(){ // Add Answer
jQuery(".add_answer").click(function(){
if(count >= "4"){
alert('Only 4 Answers Allowed');
}else{
var count = $(this).attr("alt");
count++;
$(this).parents('div:first').find('.a_type_'+count+'').fadeIn();
$(this).attr("alt", count);
}
});
});
</pre>
<hr>
<p>Ok, now that i have this sorted out, i have one more question,</p>
<p>I have another function that removes the inserted div's if a button is clicked.
It's not working now that the additional divs are not loaded into the dom on pageload.
How can i trigger the function to remove these now?</p>
<p>jQuery(function(){ // Hide Answer</p>
<pre><code>jQuery(".destroy_answer").click(function(){
$(this).parents("div:first").fadeOut(function (){ $(this).remove() });
var count = $(this).parents('div:first').parents('div:first').find('.add_answer').attr("alt");
count--;
$(this).parents('div:first').parents('div:first').find('.add_answer').attr("alt", count);
});
</code></pre>
<p>});</p>
| [
{
"answer_id": 395531,
"author": "Pim Jager",
"author_id": 35197,
"author_profile": "https://Stackoverflow.com/users/35197",
"pm_score": 4,
"selected": true,
"text": "$('.a_type:last').insertAfter('<div class=\"a_type\">content</div>');\n $.get('path/to/somefile.php', function(data){\n $... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48973/"
] |
395,526 | <p>I am building a CMS and the naming convention for classes has been debated between the other developer involved and myself. The problem arises specifically with "Page", as it is a public class available in a typical library.</p>
<p>A natural response would be to call it MVCMSPage (where MVCMS is the to-be name of the cms) or to rely on referencing the class through the dll (can't think of the term atm..) but both seem to have a hint of codesmell to them.</p>
<p>What would you advise? </p>
<p>Thanks</p>
| [
{
"answer_id": 395545,
"author": "Dan Herbert",
"author_id": 392,
"author_profile": "https://Stackoverflow.com/users/392",
"pm_score": 3,
"selected": true,
"text": "Page Page ApplicationName + \"Page\"\n MVCMS MvcmsPage MVCmsPage MvCmsPage\n Page"
},
{
"answer_id": 395558,
"a... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395526",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48266/"
] |
395,527 | <p>Which would be the correct format for this XML data, are they equivalent or are there trade offs between the two?</p>
<p>1.</p>
<pre><code><sitemap>
<category name="Animals">
<section title="Dogs">
<page url="/pics/greatdane.jpg" title="Great Dane"/>
</section>
</category>
</sitemap>
</code></pre>
<p>2.</p>
<pre><code><sitemap>
<page>
<category>Animals</category>
<section>Dogs</section>
<title>Great Dane</title>
<url>/pics/greatdane.jpg</url>
</page>
</sitemap>
</code></pre>
<p>I've implemented the first example with my style sheet and it seems to work fine, but I'm unsure what the correct form should be.</p>
| [
{
"answer_id": 395550,
"author": "cletus",
"author_id": 18393,
"author_profile": "https://Stackoverflow.com/users/18393",
"pm_score": 5,
"selected": true,
"text": "<page>\n <name>Sitemap</name>\n</page>\n <page>"
},
{
"answer_id": 395678,
"author": "Steve Steiner",
"auth... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46108/"
] |
395,549 | <p>Given this:</p>
<pre><code>Interface IBase {string X {get;set;}}
Interface ISuper {string Y {get;set;}}
class Base : IBase {etc...}
class Super : Base, ISuper {etc...}
void Questionable (Base b) {
Console.WriteLine ("The class supports the following interfaces... ")
// The Magic Happens Here
}
</code></pre>
<p>What can I replace "The Magic" with to display the supported interfaces on object b?</p>
<p>Yes, I know by being of class Base it supports "IBase", the real hierarchy is more complex that this. :)</p>
<p>Thanks!
-DF5</p>
<p>EDIT: Now that I've seen the answer I feel stupid for not tripping over that via Intellisense. :)</p>
<p>Thanks All! -DF5</p>
| [
{
"answer_id": 395560,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 2,
"selected": false,
"text": "foreach (var t in b.GetType().GetInterfaces())\n{\n Console.WriteLine(t.ToString());\n}\n"
},
{
"answer_id": ... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1736623/"
] |
395,555 | <p>I have a string (of undertermined length) that I want to copy a lot of times replacing one character at a time from an array (of undertermined length) of characters.</p>
<p>So say I have this string: 'aa'<br>
And this array: ['a', 'b', 'c', 'd'] </p>
<p>after some magic for-looping stuff there would be an array like: ['aa', 'ab', 'ac', 'ad', 'ba', 'bb' ... 'dc', 'dd'] </p>
<p>How would you do this? I tried something using three for loops but I just can't seem to get it.</p>
<p><b>Edit</b><br>
The dependency on the string is the following:</p>
<p>Say the string is: 'ba'<br>
then the output should be: ['ba', 'bb', 'bc', 'bd', 'ca' ... 'dd']</p>
| [
{
"answer_id": 395612,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 0,
"selected": false,
"text": "a = \"abcd\" \nb = \"ba\"\nres = []\nfor i in a: # i is \"a\", \"b\", ...\n for j in b: # j i... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35197/"
] |
395,569 | <p>How can I determine how much memory each device driver is consuming? I'm assuming this can be done with some Win32 or .NET API, but I just haven't been able to determine which. </p>
| [
{
"answer_id": 423541,
"author": "bk1e",
"author_id": 8090,
"author_profile": "https://Stackoverflow.com/users/8090",
"pm_score": 4,
"selected": false,
"text": "ExAllocatePoolWithTag poolmon IoAllocateMdl nt!poolhittag ExAllocatePoolWithTag"
}
] | 2008/12/27 | [
"https://Stackoverflow.com/questions/395569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4593/"
] |
395,586 | <p>Can someone tell me why this Grails domain class will not compile (at runtime)?</p>
<pre><code>class Person {
String name
String getSomething(int i) {
}
}
</code></pre>
<p>I get this error when I run with <code>grails run-app</code>:</p>
<pre><code>2008-12-27 15:26:33.955::WARN: Failed startup of context org.mortbay.jetty.webapp.WebAppContext@187e184{/asrs2,C:\Steve\asrs2/web-app}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at java.security.AccessController.doPrivileged(Native Method)
at RunApp_groovy$_run_closure2_closure7.doCall(RunApp_groovy:67)
at RunApp_groovy$_run_closure2_closure7.doCall(RunApp_groovy)
at Init_groovy$_run_closure6.doCall(Init_groovy:131)
at RunApp_groovy$_run_closure2.doCall(RunApp_groovy:66)
at RunApp_groovy$_run_closure2.doCall(RunApp_groovy)
at RunApp_groovy$_run_closure1.doCall(RunApp_groovy:57)
at RunApp_groovy$_run_closure1.doCall(RunApp_groovy)
at gant.Gant.dispatch(Gant.groovy:271)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:436)
at gant.Gant.processArgs(Gant.groovy:372)
Caused by: java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
... 13 more
</code></pre>
<p>If I change the method <code>getSomething</code> to <code>doSomething</code> then it works. Is <code>getSomething(int i)</code> somehow being treated as a bean method?</p>
<p><strong>Follow up</strong>: This is a <a href="http://jira.codehaus.org/browse/GRAILS-3760" rel="nofollow noreferrer">Grails bug</a> which will be fixed in 1.2.</p>
| [
{
"answer_id": 467370,
"author": "Rob Hruska",
"author_id": 29995,
"author_profile": "https://Stackoverflow.com/users/29995",
"pm_score": 2,
"selected": false,
"text": "def class Person {\n String name\n\n def getSomething(int i) {\n // foo\n }\n}\n something class Person... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24396/"
] |
395,592 | <p>While researching the issue of <a href="http://www.subbu.org/blog/2006/08/json-vs-xml" rel="noreferrer">JSON vs XML</a>, I came across <a href="https://stackoverflow.com/questions/325085/when-to-prefer-json-over-xml">this question</a>. Now one of the reasons to prefer JSON was listed as the ease of conversion in Javascript, namely with the <code>eval()</code>. Now this immediately struck me as potentially problematic from a security perspective.</p>
<p>So I started doing some research into the security aspects of JSON and across this blog post about how <a href="http://incompleteness.me/blog/2007/03/05/json-is-not-as-safe-as-people-think-it-is/" rel="noreferrer">JSON is not as safe as people think it is</a>. This part stuck out:</p>
<blockquote>
<p><strong>Update:</strong> If you are doing JSON 100%
properly, then you will only have
objects at the top level. Arrays,
Strings, Numbers, etc will all be
wrapped. A JSON object will then fail
to eval() because the JavaScript
interpreter will think it's looking at
a block rather than an object. This
goes a long way to protecting against
these attacks, however it's still best
to protect your secure data with
un-predictable URLs.</p>
</blockquote>
<p>Ok, so that's a good rule to start with: JSON objects at the top level should always be objects and never arrays, numbers or strings. Sounds like a good rule to me.</p>
<p>Is there anything else to do or avoid when it comes to JSON and AJAX related security?</p>
<p>The last part of the above quote mentions unpredictable URLs. Does anyone have more information on this, especially how you do it in PHP? I'm far more experienced in Java than PHP and in Java it's easy (in that you can map a whole range of URLs to a single servlet) whereas all the PHP I've done have mapped a single URL to the PHP script.</p>
<p>Also, how exactly do you use unpredictable URLs to increase security?</p>
| [
{
"answer_id": 395606,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 2,
"selected": false,
"text": "http://yourbank.com/json-api/your-name/statement http://yourbank.com/json-api/your-name/big-long-key-unique-to-you/statement"
... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395592",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18393/"
] |
395,593 | <p>I'm having trouble computing reflection angles for a ball hitting an oblique wall. I'm using an algorithm lifted from this <a href="http://www.johanvanmol.org/content/view/45/37/1/6/" rel="nofollow noreferrer">tutorial</a>. It looks like this (in Actionscript 3), with p1 being the current velocity vector and p2 the normal of the wall:</p>
<pre><code>private function getReflect2(p1 : Point, p2 : Point) : Point
{
var wallvec : Point = getNorm(p2);
var wallnorm : Point = p2;
var t : Number = dotProduct(wallvec, p1);
var n : Number = dotProduct(wallnorm, p1);
var vt : Point = new Point(wallvec.x * t, wallvec.y * t);
var vn : Point = new Point(wallnorm.x * -n, wallnorm.y * -n);
var vx : Number = dotProduct(new Point(1,0), vn) + dotProduct(new Point(1,0), vt);
var vy : Number = dotProduct(new Point(0,1), vn) + dotProduct(new Point(0,1), vt);
return new Point(vx, vy);
}
</code></pre>
<p>The function returns the new velocity vector, and does so correctly for collisions with perpendicular walls but not for oblique ones. The ball may hit the wall from both "sides" (ie. the normal may be jutting in the other direction).</p>
<p>Can anyone spot my error? Or suggest a better algorithm?</p>
| [
{
"answer_id": 395603,
"author": "Eugene Yokota",
"author_id": 3827,
"author_profile": "https://Stackoverflow.com/users/3827",
"pm_score": 0,
"selected": false,
"text": "wallvec wallvec P1 (1, 0) P2 (0, 1)"
},
{
"answer_id": 395632,
"author": "Raymond Martineau",
"author_... | 2008/12/27 | [
"https://Stackoverflow.com/questions/395593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2942/"
] |
395,618 | <p>What is the benefit/downside to using a <code>switch</code> statement vs. an <code>if/else</code> in C#. I can't imagine there being that big of a difference, other than maybe the look of your code.</p>
<p>Is there any reason why the resulting IL or associated runtime performance would be radically different?</p>
<h3>Related: <a href="https://stackoverflow.com/questions/94305/what-is-quicker-switch-on-string-or-elseif-on-type">What is quicker, switch on string or elseif on type?</a></h3>
| [
{
"answer_id": 395620,
"author": "kemiller2002",
"author_id": 1942,
"author_profile": "https://Stackoverflow.com/users/1942",
"pm_score": 4,
"selected": false,
"text": "switch(variable)\n{\n case someVariable:\n break;\n default:\n break;\n}\n switch(variable)\n{\n case CONSTANT... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395618",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5235/"
] |
395,628 | <p>I can easily define a datatype for a node of a directed graph.</p>
<pre><code>data Node = Node String [Node] derving (Show, Read)
</code></pre>
<p>I can save the graph to a file using show function, then restore it using read. However, show will not cope with a cycle. Is there a trivial way to save and restore a graph?</p>
| [
{
"answer_id": 395943,
"author": "Paul Johnson",
"author_id": 49220,
"author_profile": "https://Stackoverflow.com/users/49220",
"pm_score": 4,
"selected": true,
"text": "import qualified Data.Map as M\n\ndata Node = Node String [Node]\n\ninstance Show Node where\n show (Node name other... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5978/"
] |
395,650 | <p>I come from a Java background and with any servlets-based technology, it's trivial to map a range of URLs (eg /reports/<em>, /secure/</em>.do) to a specified servlet. Now I'm less familiar with PHP but I haven't yet seen anything that does quite the same thing with PHP (or mod_php). It's entirely possible that I'm missing something simple.</p>
<p>How do you do this in PHP?</p>
<p>One of the reasons I want to do this is "one use" URLs. Now this can sorta be done with GET parameters (like an MD5 hash token) but I'm interested in URL mapping as a general solution to many problems.</p>
<p>Another big reason to use something like this is to have RESTful URLs.</p>
| [
{
"answer_id": 395700,
"author": "Eineki",
"author_id": 29125,
"author_profile": "https://Stackoverflow.com/users/29125",
"pm_score": 4,
"selected": false,
"text": "<FilesMatch \"^servlet$\"> \n ForceType application/x-httpd-php\n</FilesMatch> \n <?php\n $data = explode('/',$HTTP_SERVE... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18393/"
] |
395,652 | <p>One of the things I like about Java servlets is the use of unobtrusive filters and interceptors. Basically you could use these things to enforce security, put extra information on the <code>HttpRequest</code>, do monitoring or whatever.</p>
<p>Is there some equivalent in PHP?</p>
<p>From what I've seen so far it seems that you tend to include a certain file in all your pages that will do things like start the session, enforce security, etc. Not as elegant. Is that the only solution?</p>
| [
{
"answer_id": 395722,
"author": "Eineki",
"author_id": 29125,
"author_profile": "https://Stackoverflow.com/users/29125",
"pm_score": 2,
"selected": false,
"text": "auto_prepend_file string \n"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/395652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18393/"
] |
395,663 | <p>I have a WPF App that implements a ListView. I would like to show an image (a small icon) in one of the columns depending on the type of the data that row represents. Sort of like the display you see in Windows Explorer. </p>
<p>I am using DataTriggers elsewhere in my XAML, it seems like a similar method could be used to swap out entire cell contents, but I can't find an example of anyone doing that.</p>
<p>Any thoughts?</p>
| [
{
"answer_id": 837119,
"author": "Josh G",
"author_id": 64329,
"author_profile": "https://Stackoverflow.com/users/64329",
"pm_score": 3,
"selected": true,
"text": "<DataTemplate x:Key=\"ImageColumn\">\n <Grid>\n <Image x:Name=\"img\" Source=\"MyImage.png\"/>\n <Rectangle... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6054/"
] |
395,667 | <p>How can I create a method in the @implementation of a class without defining it in the @interface?</p>
<p>For example, I have a constructor that does some initialisation and then reads data from a file. I want to factor out the file-reading code into a separate method that I then call from within the constructor. I don't want to define this method in the header because it's private only to this @implementation context.</p>
<p>Is this possible?</p>
<p>Here's my example. I have a little program that read's a Todo task-list from a file.</p>
<p>Here is the @interface:</p>
<pre><code>@interface TDTaskList : NSObject {
NSString* name; // The name of this list.
NSMutableArray* tasks; // The set of tasks in this list.
}
-(id)initListOfName:(NSString*)aName;
-(NSArray*)loadListWithName:(NSString*)aName;
@end
</code></pre>
<p>And here is part of the @implementation:</p>
<pre><code>-(id)initListOfName:(NSString*)aName {
if (self = [super init]) {
name = aName;
NSArray* aTasks = [self loadListWithName:aName];
tasks = [NSMutableArray arrayWithArray:aTasks];
}
return self;
}
-(NSArray*)loadListWithName:(NSString*)aName {
// TODO This is a STUB till i figure out how to read/write from a file ...
TDTask* task1 = [[TDTask alloc] initWithLabel:@"Get the Milk."];
TDTask* task2 = [[TDTask alloc] initWithLabel:@"Do some homework."];
return [NSArray arrayWithObjects:task1, task2, nil];
}
</code></pre>
<p>What I want to do is to <strong>not</strong> have to define the following in the interface:</p>
<pre><code>-(NSArray*)loadListWithName:(NSString*)aName;
</code></pre>
| [
{
"answer_id": 395670,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 2,
"selected": false,
"text": "// In TDTaskList.m\n@interface TDTaskList(TDTaskListPrivate)\n-(id)initListOfName:(NSString*)aName;\n-(NSArray*)load... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41493/"
] |
395,675 | <p>How can I reference a Groovy domain class from Java class using Eclipse?</p>
<p>I've put my domain class in package:</p>
<pre><code>package com.me.myproject
public class Person {
String name
int age
}
</code></pre>
<p>Then in my Java class I attempt to reference <code>com.me.myproject.Person</code>. This works for <code>grails run-app</code> (command line) but not Eclipse. Eclipse can't resolve the Groovy domain class.</p>
<p>I'm running Eclipse 3.4.1 with the latest Groovy and Grails Eclipse plugins:</p>
<ul>
<li>Grails Eclipse Feature 0.1.0 20081120_2330</li>
<li>GroovyFeature 1.5.7.20081120_2330</li>
</ul>
<p>I've tried setting the Eclipse default output folder to the same as Groovy compiler output location. I've also tried both enabling and disabling the “Disable Groovy Compiler Generating Class Files” setting. I've also tried not putting any of my classes in a package. None of these work.</p>
| [
{
"answer_id": 1147672,
"author": "Tom Clift",
"author_id": 31440,
"author_profile": "https://Stackoverflow.com/users/31440",
"pm_score": 0,
"selected": false,
"text": "web-app/WEB-INF/groovy-classes"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/395675",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24396/"
] |
395,682 | <p>I'm having a hell of a time understanding pointers in Objective C. They don't behave like I would assume based on various C tutorials.</p>
<p>Example:</p>
<pre><code>// Define Name and ID
NSString *processName = [[NSProcessInfo processInfo] processName];
NSNumber *processID = [NSNumber numberWithInt:[[NSProcessInfo processInfo] processIdentifier]];
// Print Name and ID
NSLog(@"Process Name: %@ Process Identifier: %@", processName, processID);
</code></pre>
<p>As I understand it, processName is a pointer to an object of type NSString. processID is a pointer to an object of type NSNumber. When both are called in NSLog(), they do not have an asterisk preceding their name and therefore should be returning pointer values. Why is there no 'address of' character in Obj C? Why does this code work?</p>
<p>Thank you for your time.</p>
| [
{
"answer_id": 395699,
"author": "Ashley Clark",
"author_id": 4556,
"author_profile": "https://Stackoverflow.com/users/4556",
"pm_score": 3,
"selected": false,
"text": "%@ NSLog -description %x %qx"
},
{
"answer_id": 395706,
"author": "dvenema",
"author_id": 6219,
"au... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29297/"
] |
395,685 | <p>I'd use a singleton like this:</p>
<pre><code>Singleton* single = Singleton::instance();
single->do_it();
</code></pre>
<p>I'd use an unnamed class like this:</p>
<pre><code>single.do_it();
</code></pre>
<p>I feel as if the Singleton pattern has no advantage over the unnamed class other than having readable error messages. Using singletons is clumsier than using an unnamed class object: First, clients must first get a handle of the instance; second, the implementer of <code>Singleton::instance()</code> might need to consider concurrency.</p>
<p>So why and how would you choose a singleton over an unnamed class?</p>
<p>As an addendum, although the obvious definition of an unnamed class might be</p>
<pre><code>class {
// ...
}single;
</code></pre>
<p>I could as well define it like so:</p>
<pre><code>#ifndef NDEBUG
class Singleton__ { // readable error messages,
#else
class { // unnamed, clients can't instantiate
#endif
// ...
}single;
</code></pre>
<p>with the latter approach having the advantage of readable compiler error messages but not being a singleton in debug mode.</p>
| [
{
"answer_id": 395738,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": true,
"text": "class { } single;\nint main() { }\n single single single"
},
{
"answer_id": 396033,
"author": "R... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456/"
] |
395,704 | <p>General tutorial or good resource on how to use threads in Python?</p>
<p>When to use threads, how they are effective, and some general background on threads [specific to Python]?</p>
| [
{
"answer_id": 396055,
"author": "James Brady",
"author_id": 29903,
"author_profile": "https://Stackoverflow.com/users/29903",
"pm_score": 3,
"selected": false,
"text": "multiprocessing threading"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/395704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51518/"
] |
395,735 | <p>I was wondering how to check whether a variable is a class (not an instance!) or not.</p>
<p>I've tried to use the function <code>isinstance(object, class_or_type_or_tuple)</code> to do this, but I don't know what type would a class will have.</p>
<p>For example, in the following code</p>
<pre><code>class Foo: pass
isinstance(Foo, **???**) # i want to make this return True.
</code></pre>
<p>I tried to substitute "<code>class</code>" with <strong>???</strong>, but I realized that <code>class</code> is a keyword in python.</p>
| [
{
"answer_id": 395741,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 6,
"selected": false,
"text": ">>> class X(object):\n... pass\n... \n>>> type(X)\n<type 'type'>\n>>> isinstance(X,type)\nTrue\n"
},
{
"answer_... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395735",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32267/"
] |
395,739 | <p>When I'm naming array-type variables, I often am confronted with a dilemma:
Do I name my array using plural or singular?</p>
<p>For example, let's say I have an array of names: In PHP I would say: <code>$names=array("Alice","Bobby","Charles");</code> </p>
<p>However, then lets say I want to reference a name in this array. For Bobby, I'd say: <code>$names[1]</code>. However, this seams counter-intuitive. I'd rather call Bobby <code>$name[1]</code>, because Bobby is only one name.</p>
<p>So, you can see a slight discrepancy. Are there conventions for naming arrays?</p>
| [
{
"answer_id": 395742,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 7,
"selected": true,
"text": "$name = $names[1];\n"
},
{
"answer_id": 395787,
"author": "James Van Boxtel",
"author_id": 43994,
"a... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1615/"
] |
395,759 | <p>I'm trying to make an ajax call to grab session data to insert into my page after it's loaded like this</p>
<pre><code>jQuery(function(){ // Add Answer
jQuery(".add_answer").livequery('click',function(){
var count = $(this).attr("alt");
count++;
var count1 = count-1;
$.get('quiz/select', function(p_type){ // Ajax Call for Select Data
$(this).parents('div:first').find('.a_type_'+count1+'').after('' + p_type + '');
$(this).attr("alt", count);
});
});
});
</code></pre>
<p>The file i'm calling is found but its contents are not printed out by 'p_type'
and the <code>$(this).attr("alt", count);</code> part of the function is not executing</p>
<p>Note: I'm using CodeIgniter for my framework and jquery for js</p>
| [
{
"answer_id": 396016,
"author": "Soviut",
"author_id": 46914,
"author_profile": "https://Stackoverflow.com/users/46914",
"pm_score": 3,
"selected": true,
"text": "jQuery(\".add_answer\").livequery('click',function()\n{\n var add_answer = $(this);\n\n $.get(...)\n {\n add... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395759",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48973/"
] |
395,779 | <p>I am building an MVC application in which I am reading a list of files from the file system and I want to pass the relative URL to that file to the view, preferably prefixed with "~/" so that whatever view is selected cab render the URL appropriately. </p>
<p>To do this, I need to enumerate the files in the file system and convert their physical paths back to relative URLs. There are a few algorithms I've experimented with, but I am concerned about efficiency and minimal string operations. Also, I believe there's nothing in the .Net Framework that can perform this operation, but is there something in the latest MVC release that can?</p>
| [
{
"answer_id": 395798,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 6,
"selected": true,
"text": "~ public string ReverseMapPath(string path)\n{\n string appPath = HttpContext.Current.Server.MapPath(\"~\");\... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1875/"
] |
395,783 | <p>I have a Rails site, where the content is written in markdown. I wish to display a snippet of each, with a "Read more.." link.</p>
<p>How do I go about this? Simple truncating the raw text will not work, for example..</p>
<pre><code>>> "This is an [example](http://example.com)"[0..25]
=> "This is an [example](http:"
</code></pre>
<p>Ideally I want to allow the author to (optionally) insert a marker to specify what to use as the "snippet", if not it would take 250 words, and append "..." - for example..</p>
<pre><code>This article is an example of something or other.
This segment will be used as the snippet on the index page.
^^^^^^^^^^^^^^^
This text will be visible once clicking the "Read more.." link
</code></pre>
<p>The marker could be thought of like an EOF marker (which can be ignored when displaying the full document)</p>
<p>I am using <a href="http://maruku.rubyforge.org/" rel="noreferrer">maruku</a> for the Markdown processing (RedCloth is very biased towards Textile, BlueCloth is extremely buggy, and I wanted a native-Ruby parser which ruled out peg-markdown and RDiscount)</p>
<p>Alternatively (since the Markdown is translated to HTML anyway) truncating the HTML correctly would be an option - although it would be preferable to not <code>markdown()</code> the entire document, just to get the first few lines.</p>
<p>So, the options I can think of are (in order of preference)..</p>
<ul>
<li>Add a "truncate" option to the maruku parser, which will only parse the first x words, or till the "excerpt" marker.</li>
<li>Write/find a parser-agnostic Markdown truncate'r</li>
<li>Write/find an intelligent HTML truncating function</li>
</ul>
| [
{
"answer_id": 395807,
"author": "csexton",
"author_id": 19839,
"author_profile": "https://Stackoverflow.com/users/19839",
"pm_score": 1,
"selected": false,
"text": "markdown_string = <<-eos\nThis article is an example of something or other.\n\nThis segment will be used as the snippet on... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/745/"
] |
395,799 | <p>Should HtmlEncode() be abandoned and Replace() used instead of I want to parse links in posts/comments (with regular expressions)? HtmlEncode() replaces & with &amp; which I assume can cause problems with links, should I just use Replace() to replace < with &lt;?</p>
<p>For example if a user posts something like:<br />
See this site <a href="http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3" rel="nofollow noreferrer">http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3</a></p>
<p>I want it to be:<br />
See this site <a href="http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3"><a href="http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3</a&gt" rel="nofollow noreferrer">http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3</a&gt</a>;</p>
<p>But With HtmlEncode() the URL will become (notice the ampersand):<br />
See this site <a href="http://www.somesite.com/somepage.aspx?qs1=1&amp;qs2=2&amp;qs3=3" rel="nofollow noreferrer">http://www.somesite.com/somepage.aspx?qs1=1&amp;qs2=2&amp;qs3=3</a></p>
<p>Should I avoid the problem by using Replace() instead?</p>
<p>Thanks</p>
| [
{
"answer_id": 395864,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 2,
"selected": false,
"text": "HtmlEncode()"
},
{
"answer_id": 395865,
"author": "Yuliy",
"author_id": 47527,
"author_profile": "https://St... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395799",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/676066/"
] |
395,810 | <p>I'm making a search function for my website, which finds relevant results from a database. I'm looking for a way to count occurrences of a word, but I need to ensure that there are word boundaries on both sides of the word ( so I don't end up with "triple" when I want "rip").</p>
<p>Does anyone have any ideas?</p>
<hr>
<p>People have misunderstood my question:</p>
<p>How can I count the number of such occurences <strong><em>within a single row?</em></strong></p>
| [
{
"answer_id": 396266,
"author": "ʞɔıu",
"author_id": 41613,
"author_profile": "https://Stackoverflow.com/users/41613",
"pm_score": 0,
"selected": false,
"text": "select count(*) from yourtable where match(title, body) against ('some_word');\n"
},
{
"answer_id": 398480,
"auth... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1615/"
] |
395,816 | <p>For my Java game server I send the Action ID of the packet which basically tells the server what the packet is for. I want to map each Action ID (an integer) to a function. Is there a way of doing this without using a switch?</p>
| [
{
"answer_id": 395822,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 2,
"selected": false,
"text": "public interface PacketProcessor\n{\n public void processPacket(Packet packet);\n}\n\n...\n\nPacketProcessor doTh... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49018/"
] |
395,832 | <p>I want to get the UCS-2 code points for a given UTF-8 string. For example the word "hello" should become something like "0068 0065 006C 006C 006F". Please note that the characters could be from any language including complex scripts like the east asian languages.</p>
<p>So, the problem comes down to "convert a given character to its UCS-2 code point"</p>
<p>But how? Please, any kind of help will be very very much appreciated since I am in a great hurry.</p>
<hr>
<p><em>Transcription of questioner's response posted as an answer</em></p>
<p>Thanks for your reply, but it needs to be done in PHP v 4 or 5 but not 6.</p>
<p>The string will be a user input, from a form field.</p>
<p>I want to implement a PHP version of utf8to16 or utf8decode like</p>
<pre><code>function get_ucs2_codepoint($char)
{
// calculation of ucs2 codepoint value and assign it to $hex_codepoint
return $hex_codepoint;
}
</code></pre>
<p>Can you help me with PHP or can it be done with PHP with version mentioned above?</p>
| [
{
"answer_id": 395854,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 4,
"selected": false,
"text": "wchar_t utf8_char_to_ucs2(const unsigned char *utf8)\n{\n if(!(utf8[0] & 0x80)) // 0xxxxxxx\n return (wchar... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395832",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47468/"
] |
395,846 | <p>Is there any way to send ARP packet on Windows without the use of another library such as winpcap?</p>
<p>I have heard that Windows XP SP2 blocks raw ethernet sockets, but I have also heard that raw sockets are only blocked for administrators. Any clarification here?</p>
| [
{
"answer_id": 395921,
"author": "Mihai Limbășan",
"author_id": 14444,
"author_profile": "https://Stackoverflow.com/users/14444",
"pm_score": 2,
"selected": false,
"text": "arp -d tar.get.ip.address"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/395846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
395,849 | <p>Take the following code for example;</p>
<pre><code> if (Convert.ToString(frm.WindowState) == "Minimized")
Layout.WindowState = "Maximized";
else
Layout.WindowState = Convert.ToString(frm.WindowState);
</code></pre>
<p>We are analysing the string definition of the window state, i.e. "Minimized".</p>
<p>Would this string description change between cultures?</p>
<p>Lastly, whilst on this code, is there an Enum which we could use in order to check against the window state? </p>
<p>Can we refactor this code segment?</p>
| [
{
"answer_id": 395855,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 4,
"selected": true,
"text": "WindowState System.Windows.Forms.FormWindowState ToString()"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/395849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48499/"
] |
395,857 | <p>I don't think this can be done "cleanly", but I'll ask anyway.</p>
<p>I have a system which needs to get a JSON resource via a REST GET call in order to initialize. At the moment the system waits until the onLoad event and fires an ajax request to retrieve the resource, which I don't think is the best way to do it, as the resource is needed a run time.</p>
<p>What I would love to do is somehow load the resource at runtime inside an HTML tag then eval the contents. But what I'm working on is an API to be used by others, so I would like to achieve this in a logical and standards based way.</p>
<p>So is there any tag which fits the bill? A tag which can be placed in the doc head, that I will be able to read and eval the contents of at runtime?</p>
<p>Regards,</p>
<p>Chris</p>
| [
{
"answer_id": 395861,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<script> var foo ="
},
{
"answer_id": 395924,
"author": "Community",
"author_id": -1,
"author_profile": "h... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37196/"
] |
395,867 | <p>How would I go about sending an email to a user, say, 48 hours after they sign up, in Ruby on Rails? Thanks!</p>
| [
{
"answer_id": 396264,
"author": "Pete",
"author_id": 13472,
"author_profile": "https://Stackoverflow.com/users/13472",
"pm_score": 2,
"selected": false,
"text": "MiddleMan(:email_worker).enq_send_email_task(:message => @message, \n :job_key => \"notify1\",\n :scheduled_at => Time.now ... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
395,874 | <p>I've encountered the need to remove comments of the form:</p>
<pre><code><!-- Foo
Bar -->
</code></pre>
<p>I'd like to use a regular expression that matches anything (including line breaks) between the beginning and end 'delimiters.'</p>
<p>What would a good regex be for this task?</p>
| [
{
"answer_id": 395879,
"author": "Diadistis",
"author_id": 47401,
"author_profile": "https://Stackoverflow.com/users/47401",
"pm_score": 4,
"selected": true,
"text": "Regex xmlCommentsRegex = new Regex(\"<!--.*?-->\", RegexOptions.Singleline | RegexOptions.Compiled);\n Regex xmlCommentsR... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395874",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37971/"
] |
395,886 | <p>I'm still a newbie to Adobe Air/Flex, and still fairly new with SQL.</p>
<p>I've downloaded <a href="http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-air%E2%80%A6-part-1/" rel="nofollow noreferrer">this</a> (<a href="http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-air" rel="nofollow noreferrer">http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-air</a>…-part-1/) code and have been looking over it and I'm trying to implement the same idea. </p>
<p>I think it's just something stupid. I'm using Flex Builder. I made a new desktop application project, didn't import anything.</p>
<p>I added a DataGrid object and bound it to an ArrayCollection:</p>
<p>I'm trying to make it so when the program initializes it will load data from a database if it exists, otherwise it'll create a new one.</p>
<p>The problem is, when the application runs, the datagrid is empty. No column headers, no data, nothing. I've tried changing a whole bunch of stuff, I've used the debugger to make sure all the functions are being called like they're supposed to. I don't know what I'm doing wrong. I've compared my code to the before mentioned code, I've looked for tutorials on Google. Anyone know what I'm doing wrong?</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="672" height="446"
applicationComplete="onFormLoaded()"
title="iRecipes">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var sqlConnection:SQLConnection;
[Bindable] private var recipeList:ArrayCollection;
private function onFormLoaded():void
{
sqlConnection = new SQLConnection();
openDataBase();
}
private function openDataBase():void
{
var file:File = File.userDirectory.resolvePath("recipes.db");
sqlConnection.open(file, SQLMode.CREATE);
if(!file.exists)
{
createDatabase();
}
populateRecipeList()
}
private function createDatabase():void
{
var statement:SQLStatement = new SQLStatement();
statement.sqlConnection = sqlConnection;
statement.text = "CREATE TABLE Recipes (recipeId INTEGER PRIMARY KEY AUTOINCREMENT, recipeName TEXT, authorName TEXT)";
statement.execute();
statement.text = "INSERT INTO Recipes (recipeName, authorName) VALUES (:recipeName, :authorName)";
statement.parameters[":recipeName"] = "Soup";
statement.parameters[":authorName"] = "Joel Johnson";
statement.execute();
statement.parameters[":recipeName"] = "Garbage";
statement.parameters[":authorName"] = "Bob Vila";
statement.execute();
}
private function populateRecipeList():void
{
var statement:SQLStatement = new SQLStatement();
statement.sqlConnection = sqlConnection;
statement.text = "SELECT * FROM Recipes";
statement.execute();
recipeList = new ArrayCollection(statement.getResult().data);
}
]]>
</mx:Script>
<mx:DataGrid dataProvider="{recipeList}">
</mx:DataGrid>
</mx:WindowedApplication>
</code></pre>
| [
{
"answer_id": 395879,
"author": "Diadistis",
"author_id": 47401,
"author_profile": "https://Stackoverflow.com/users/47401",
"pm_score": 4,
"selected": true,
"text": "Regex xmlCommentsRegex = new Regex(\"<!--.*?-->\", RegexOptions.Singleline | RegexOptions.Compiled);\n Regex xmlCommentsR... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13713/"
] |
395,892 | <p>What is the best approach to implementing authorisation/authentication for a Windows Forms app talking to an IIS-hosted RESTful WCF Service?</p>
<p>The reason I ask is I am very confused, after sifting through different articles and posts expressing a different method and eventually hitting a ~650 page document on WCF Security Best Practices" (<a href="http://www.codeplex.com/WCFSecurityGuide" rel="nofollow noreferrer">http://www.codeplex.com/WCFSecurityGuide</a>) I am just uncertain which approach is the BEST to take and how to get started on implementation, given my scenario.</p>
<p>I started with this article "A Guide to Designing and Building RESTful Web Services with WCF 3.5" (<a href="http://msdn.microsoft.com/en-us/library/dd203052.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/dd203052.aspx</a>) and a PDC video on RESTful WCF services, which was great and helped me implement my first REST-friendly WCF service,</p>
<p>After I had the service working, I returned to implement security, see. "Security Considerations" (quarter down the page) and attempted to implement a HTTP Authorization header as per the instructions, however I found the code to be incomplete (see how 'UserKeys' variable was never declared). This is the point at which I tried to research more on how to do this (using a HMAC hash with the "Authorization" HTTP header, but could not find much on google?) it led me to other articles regarding message-level security, forms auth and custom validators and frankly I am not sure which is the best and most appropriate approach to take now.</p>
<p>So with all that said (and thanks for listening up till now!), I guess my main questions are,<br /></p>
<p><strong>- Which security implementation should I use?<br /><br />
- Is there any way to avoid sending the username/password with every WCF call? I would prefer not to send these extra bytes if a connection has been established at the beginning, which it will be before subsequent calls are allowed to be made after login.<br /><br />
- Should I even really be concerned about anything other than plain text if I am using SSL?</strong></p>
<p>As said, .NET 3.5 win forms app, IIS-hosted WCF service, however what is important is I wish any and all WCF services to require this authorization procedure (however it should be, session, http header or otherwise) as I do not want anybody to be able to hit these services from the web.</p>
<p>I know the above post is large but I had to express the route I have already been down and what I need to accomplish, any and all help is greatly appreciated.</p>
<p>PS: I am also aware of this post <a href="https://stackoverflow.com/questions/141484/how-to-configure-secure-restful-services-with-wcf-using-usernamepassword-ssl">How to configure secure RESTful services with WCF using username/password + SSL</a> and if the community suggests I move away from REST for WCF services, I can do this, however I started with this to keep consistency for any public APIs to come.</p>
<p>I think it's important I state how I am accessing my WCF Service (contacting the service is working, but what is the best way to validate credentials - and then return the Member object?):</p>
<pre><code>WebChannelFactory<IMemberService> cf = new WebChannelFactory<IMemberService>(
new Uri(Properties.Settings.Default.MemberServiceEndpoint));
IMemberService channel = cf.CreateChannel();
Member m = channel.GetMember("user", "pass");
</code></pre>
<p>Code that was half implemented from MS article (and some of my own for testing):</p>
<pre><code> public Member GetMember(string username, string password)
{
if (string.IsNullOrEmpty(username))
throw new WebProtocolException(HttpStatusCode.BadRequest, "Username must be provided.", null);
if (string.IsNullOrEmpty(password))
throw new WebProtocolException(HttpStatusCode.BadRequest, "Password must be provided.", null);
if (!AuthenticateMember(username))
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Unauthorized;
return null;
}
return new Member() { Username = "goneale" };
}
</code></pre>
| [
{
"answer_id": 396815,
"author": "Nicholas Piasecki",
"author_id": 32187,
"author_profile": "https://Stackoverflow.com/users/32187",
"pm_score": 5,
"selected": true,
"text": "Login()"
},
{
"answer_id": 2555379,
"author": "Tawani",
"author_id": 61525,
"author_profile":... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395892",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41211/"
] |
395,922 | <p>Is there a way to read value for the WiX variable from a text file?</p>
<p>What I am trying to do is to include a version-specific information into instlal package.</p>
<p>This version information extracted into the text file on the pre-build step,
the question is how to propages this text file content into a build process.</p>
<p>One of the possible solution is to update whole .wxs file on the pre-build step
too, but it feel a bit sloppy.</p>
<p>Is there any other, less-intrusive way?</p>
<p>Thank you.</p>
| [
{
"answer_id": 396292,
"author": "Stefan",
"author_id": 48003,
"author_profile": "https://Stackoverflow.com/users/48003",
"pm_score": 4,
"selected": true,
"text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Include Id=\"VersionNumberInclude\">\n <?define MajorVersion=\"1\" ?>\n <... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48829/"
] |
395,928 | <p>I'm try to develop a regex that will be used in a C# program..</p>
<p>My initial regex was:</p>
<pre><code>(?<=\()\w+(?=\))
</code></pre>
<p>Which successfully matches "(foo)" - matching but excluding from output the open and close parens, to produce simply "foo".</p>
<p>However, if I modify the regex to:</p>
<pre><code>\[(?<=\()\w+(?=\))\]
</code></pre>
<p>and I try to match against "[(foo)]" it fails to match. This is surprising. I'm simply prepending and appending the literal open and close brace around my previous expression. I'm stumped. I use Expresso to develop and test my expressions.</p>
<p>Thanks in advance for your kind help.</p>
<p>Rob Cecil</p>
| [
{
"answer_id": 395934,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 3,
"selected": false,
"text": "(?<=\\[\\()\\w+(?=\\)\\])\n"
},
{
"answer_id": 395994,
"author": "PhiLho",
"author_id": 15459,
"author... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49465/"
] |
395,960 | <p>For those of you who have had the opportunity of writing web applications in PHP and then as an application server (eg. Python-based solutions like CherryPy or Pylons), in what context are application servers a better alternative to PHP?</p>
<p>I tend to favor PHP simply because it's available on just about any web server (especially shared host), but I'm looking for other good reasons to make an informed choice. Thank you.</p>
| [
{
"answer_id": 397730,
"author": "Adam Byrtek",
"author_id": 36656,
"author_profile": "https://Stackoverflow.com/users/36656",
"pm_score": 3,
"selected": false,
"text": "mod_php"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/395960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
395,968 | <p>What are the similarities and differences between GridView, DetailView, FormView? </p>
<p>What are use case scenarios for when you would use each of these controls and why?</p>
| [
{
"answer_id": 13764419,
"author": "rajeev",
"author_id": 1885638,
"author_profile": "https://Stackoverflow.com/users/1885638",
"pm_score": 0,
"selected": false,
"text": "edit update delete ButtonField ImageButton Hyperlink autogenerate deletebutton autogenerate editbutton GridView"
}
... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22162/"
] |
395,973 | <p>Hey, I stumbled upon this site looking for solutions for event overlaps in mySQL tables. I was SO impressed with the solution (which is helping already) I thought I'd see if I could get some more help...</p>
<p>Okay, so Joe want's to swap shifts with someone at work. He has a court date. He goes to the shift swap form and it pull up this week's schedule (or what's left of it). This is done with a DB query. No sweat. He picks a shift. From this point, it gets prickly.</p>
<p>So, first, the form passes the shift start and shift end to the script. It runs a query for anyone who has a shift that overlaps this shift. They can't work two shifts at once, so all user IDs from this query are put on a black list. This query looks like:</p>
<pre><code>SELECT DISTINCT user_id FROM shifts
WHERE
FROM_UNIXTIME('$swap_shift_start') < shiftend
AND FROM_UNIXTIME('$swap_shift_end') > shiftstart
</code></pre>
<p>Next, we run a query for all shifts that are a) the same length (company policy), and b) don't overlap with any other shifts Joe is working.</p>
<p>What I currently have is something like this:</p>
<pre><code>SELECT *
FROM shifts
AND shiftstart BETWEEN FROM_UNIXTIME('$startday') AND FROM_UNIXTIME('$endday')
AND user_id NOT IN ($busy_users)
AND (TIME_TO_SEC(TIMEDIFF(shiftend,shiftstart)) = '$swap_shift_length')
$conflict_dates
ORDER BY shiftstart, lastname
</code></pre>
<p>Now, you are probably wondering "what is $conflict_dates???"</p>
<p>Well, when Joe submits the swap shift, it reloads his shifts for the week in case he decides to check out another shift's potential. So when it does that first query, while the script is looping through and outputting his choices, it is also building a string that looks kind of like:</p>
<pre><code>AND NOT(
'joe_shift1_start' < shiftend
AND 'joe_shift1_end' > shiftstart)
AND NOT(
'joe_shift2_start' < shiftend
AND 'joe_shift2_end' > shiftstart)
...etc
</code></pre>
<p>So that the database is getting a pretty long query along the lines of:</p>
<pre><code>SELECT *
FROM shifts
AND shiftstart BETWEEN FROM_UNIXTIME('$startday') AND FROM_UNIXTIME('$endday')
AND user_id NOT IN ('blacklisteduser1', 'blacklisteduser2',...etc)
AND (TIME_TO_SEC(TIMEDIFF(shiftend,shiftstart)) = '$swap_shift_length')
AND NOT(
'joe_shift1_start' < shiftend
AND 'joe_shift1_end' > shiftstart)
AND NOT(
'joe_shift2_start' < shiftend
AND 'joe_shift2_end' > shiftstart)
AND NOT(
'joe_shift3_start' < shiftend
AND 'joe_shift3_end' > shiftstart)
AND NOT(
'joe_shift4_start' < shiftend
AND 'joe_shift4_end' > shiftstart)
...etc
ORDER BY shiftstart, lastname
</code></pre>
<p>So, my hope is that either SQL has some genius way of dealing with this in a simpler way, or that someone can point out a fantastic logical principal that accounts for the potential conflicts in a much smarter way. (Notice the use of the 'start > end, end < start', before I found that I was using betweens and had to subtract a minute off both ends.)</p>
<p>Thanks!</p>
<p>A</p>
| [
{
"answer_id": 395985,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 1,
"selected": false,
"text": "joe_shift{1,2,3} CREATE TEMPORARY TABLE joes_shifts (\n shiftstart DATETIME\n shiftend DATETIME\n);\nINSERT INTO joe... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49478/"
] |
395,981 | <p>I have a problem involving a collection of continuous probability distribution functions, most of which are determined empirically (e.g. departure times, transit times). What I need is some way of taking two of these PDFs and doing arithmetic on them. E.g. if I have two values x taken from PDF X, and y taken from PDF Y, I need to get the PDF for (x+y), or any other operation f(x,y).</p>
<p>An analytical solution is not possible, so what I'm looking for is some representation of PDFs that allows such things. An obvious (but computationally expensive) solution is monte-carlo: generate lots of values of x and y, and then just measure f(x, y). But that takes too much CPU time.</p>
<p>I did think about representing the PDF as a list of ranges where each range has a roughly equal probability, effectively representing the PDF as the union of a list of uniform distributions. But I can't see how to combine them.</p>
<p>Does anyone have any good solutions to this problem?</p>
<p><strong>Edit:</strong> The goal is to create a mini-language (aka Domain Specific Language) for manipulating PDFs. But first I need to sort out the underlying representation and algorithms.</p>
<p><strong>Edit 2:</strong> dmckee suggests a histogram implementation. That is what I was getting at with my list of uniform distributions. But I don't see how to combine them to create new distributions. Ultimately I need to find things like P(x < y) in cases where this may be quite small.</p>
<p><strong>Edit 3:</strong> I have a bunch of histograms. They are not evenly distributed because I'm generating them from occurance data, so basically if I have 100 samples and I want ten points in the histogram then I allocate 10 samples to each bar, and make the bars variable width but constant area.</p>
<p>I've figured out that to add PDFs you convolve them, and I've boned up on the maths for that. When you convolve two uniform distributions you get a new distribution with three sections: the wider uniform distribution is still there, but with a triangle stuck on each side the width of the narrower one. So if I convolve each element of X and Y I'll get a bunch of these, all overlapping. Now I'm trying to figure out how to sum them all and then get a histogram that is the best approximation to it.</p>
<p>I'm beginning to wonder if Monte-Carlo wasn't such a bad idea after all.</p>
<p><strong>Edit 4:</strong> <a href="http://www.heldermann-verlag.de/eqc/eqc01_16/eqc16002.pdf" rel="noreferrer">This paper</a> discusses convolutions of uniform distributions in some detail. In general you get a "trapezoid" distribution. Since each "column" in the histograms is a uniform distribution, I had hoped that the problem could be solved by convolving these columns and summing the results. </p>
<p>However the result is considerably more complex than the inputs, and also includes triangles. <strong>Edit 5:</strong> [Wrong stuff removed]. But if these trapezoids are approximated to rectangles with the same area then you get the Right Answer, and reducing the number of rectangles in the result looks pretty straightforward too. This might be the solution I've been trying to find.</p>
<p><strong>Edit 6:</strong> Solved! Here is the final Haskell code for this problem:</p>
<pre><code>-- | Continuous distributions of scalars are represented as a
-- | histogram where each bar has approximately constant area but
-- | variable width and height. A histogram with N bars is stored as
-- | a list of N+1 values.
data Continuous = C {
cN :: Int,
-- ^ Number of bars in the histogram.
cAreas :: [Double],
-- ^ Areas of the bars. @length cAreas == cN@
cBars :: [Double]
-- ^ Boundaries of the bars. @length cBars == cN + 1@
} deriving (Show, Read)
{- | Add distributions. If two random variables @vX@ and @vY@ are
taken from distributions @x@ and @y@ respectively then the
distribution of @(vX + vY)@ will be @(x .+. y).
This is implemented as the convolution of distributions x and y.
Each is a histogram, which is to say the sum of a collection of
uniform distributions (the "bars"). Therefore the convolution can be
computed as the sum of the convolutions of the cross product of the
components of x and y.
When you convolve two uniform distributions of unequal size you get a
trapezoidal distribution. Let p = p2-p1, q - q2-q1. Then we get:
> | |
> | ______ |
> | | | with | _____________
> | | | | | |
> +-----+----+------- +--+-----------+-
> p1 p2 q1 q2
>
> gives h|....... _______________
> | /: :\
> | / : : \ 1
> | / : : \ where h = -
> | / : : \ q
> | / : : \
> +--+-----+-------------+-----+-----
> p1+q1 p2+q1 p1+q2 p2+q2
However we cannot keep the trapezoid in the final result because our
representation is restricted to uniform distributions. So instead we
store a uniform approximation to the trapezoid with the same area:
> h|......___________________
> | | / \ |
> | |/ \|
> | | |
> | /| |\
> | / | | \
> +-----+-------------------+--------
> p1+q1+p/2 p2+q2-p/2
-}
(.+.) :: Continuous -> Continuous -> Continuous
c .+. d = C {cN = length bars - 1,
cBars = map fst bars,
cAreas = zipWith barArea bars (tail bars)}
where
-- The convolve function returns a list of two (x, deltaY) pairs.
-- These can be sorted by x and then sequentially summed to get
-- the new histogram. The "b" parameter is the product of the
-- height of the input bars, which was omitted from the diagrams
-- above.
convolve b c1 c2 d1 d2 =
if (c2-c1) < (d2-d1) then convolve1 b c1 c2 d1 d2 else convolve1 b d1
d2 c1 c2
convolve1 b p1 p2 q1 q2 =
[(p1+q1+halfP, h), (p2+q2-halfP, (-h))]
where
halfP = (p2-p1)/2
h = b / (q2-q1)
outline = map sumGroup $ groupBy ((==) `on` fst) $ sortBy (comparing fst)
$ concat
[convolve (areaC*areaD) c1 c2 d1 d2 |
(c1, c2, areaC) <- zip3 (cBars c) (tail $ cBars c) (cAreas c),
(d1, d2, areaD) <- zip3 (cBars d) (tail $ cBars d) (cAreas d)
]
sumGroup pairs = (fst $ head pairs, sum $ map snd pairs)
bars = tail $ scanl (\(_,y) (x2,dy) -> (x2, y+dy)) (0, 0) outline
barArea (x1, h) (x2, _) = (x2 - x1) * h
</code></pre>
<p>Other operators are left as an exercise for the reader.</p>
| [
{
"answer_id": 395989,
"author": "dmckee --- ex-moderator kitten",
"author_id": 2509,
"author_profile": "https://Stackoverflow.com/users/2509",
"pm_score": 2,
"selected": false,
"text": "f = x + y f g = x * z h = y(x) struct histogram_struct {\n int bins; /* Assumed to be uniform */\n ... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49220/"
] |
395,982 | <p>I have read posts like these:</p>
<ol>
<li><a href="https://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python">What is a metaclass in Python?</a> </li>
<li><a href="https://stackoverflow.com/questions/392160/what-are-your-concrete-use-cases-for-metaclasses-in-python">What are your (concrete) use-cases for metaclasses in Python?</a></li>
<li><a href="http://fuhm.net/super-harmful/" rel="noreferrer">Python's Super is nifty, but you can't use it</a></li>
</ol>
<p>But somehow I got confused. Many confusions like:</p>
<p>When and why would I have to do something like the following?</p>
<pre><code># Refer link1
return super(MyType, cls).__new__(cls, name, bases, newattrs)
</code></pre>
<p>or</p>
<pre><code># Refer link2
return super(MetaSingleton, cls).__call__(*args, **kw)
</code></pre>
<p>or</p>
<pre><code># Refer link2
return type(self.__name__ + other.__name__, (self, other), {})
</code></pre>
<p>How does super work exactly?</p>
<p>What is class registry and unregistry in link1 and how exactly does it work? (I thought it has something to do with <a href="http://en.wikipedia.org/wiki/Singleton_pattern" rel="noreferrer">singleton</a>. I may be wrong, being from C background. My coding style is still a mix of functional and OO).</p>
<p>What is the flow of class instantiation (subclass, metaclass, super, type) and method invocation (</p>
<pre><code>metaclass->__new__, metaclass->__init__, super->__new__, subclass->__init__ inherited from metaclass
</code></pre>
<p>) with well-commented working code (though the first link is quite close, but it does not talk about cls keyword and super(..) and registry). Preferably an example with multiple inheritance.</p>
<p>P.S.: I made the last part as code because Stack Overflow formatting was converting the text <code>metaclass->__new__</code>
to metaclass-><strong>new</strong></p>
| [
{
"answer_id": 396109,
"author": "James Brady",
"author_id": 29903,
"author_profile": "https://Stackoverflow.com/users/29903",
"pm_score": 6,
"selected": true,
"text": "super super super() mro() __new__ super(MyType, cls) type type.__new__ __call__ cls.instance __new__ __new__ print('>>>... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33612/"
] |
395,995 | <p>From what I'm reading, <code>$</code> is described as "applies a function to its arguments." However, it doesn't seem to work quite like <code>(apply ...)</code> in Lisp, because it's a binary operator, so really the only thing it looks like it does is help to avoid parentheses sometimes, like <code>foo $ bar quux</code> instead of <code>foo (bar quux)</code>. Am I understanding it right? Is the latter form considered "bad style"?</p>
| [
{
"answer_id": 396061,
"author": "Apocalisp",
"author_id": 3434,
"author_profile": "https://Stackoverflow.com/users/3434",
"pm_score": 5,
"selected": true,
"text": "$ i (h (g (f x)))\n i $ h $ g $ f x\n i h g f x\n (((i h) g) f) x\n ($) zipWith ($) fs xs\n fs xs sequence fs x fs x fs <*>... | 2008/12/28 | [
"https://Stackoverflow.com/questions/395995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38803/"
] |
396,005 | <p>Given a set of words, we need to find the anagram words and display each category alone using the best algorithm.</p>
<p>input:</p>
<pre><code>man car kile arc none like
</code></pre>
<p>output:</p>
<pre><code>man
car arc
kile like
none
</code></pre>
<p>The best solution I am developing now is based on an hashtable, but I am thinking about equation to convert anagram word into integer value.</p>
<p>Example: man => 'm'+'a'+'n' but this will not give unique values.</p>
<p>Any suggestion?</p>
<hr>
<p>See following code in C#:</p>
<pre><code>string line = Console.ReadLine();
string []words=line.Split(' ');
int[] numbers = GetUniqueInts(words);
for (int i = 0; i < words.Length; i++)
{
if (table.ContainsKey(numbers[i]))
{
table[numbers[i]] = table[numbers[i]].Append(words[i]);
}
else
{
table.Add(numbers[i],new StringBuilder(words[i]));
}
}
</code></pre>
<p>The problem is how to develop <code>GetUniqueInts(string [])</code> method.</p>
| [
{
"answer_id": 396026,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 6,
"selected": true,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nclass FindAnagrams\n{\n static void Main(strin... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42749/"
] |
396,053 | <p>I have been unable to trigger an <strong>onselect</strong> event handler attached to a <strong><div></strong> element. Is it possible to force a <strong><div></strong> to emit <strong>select</strong> events?</p>
| [
{
"answer_id": 396075,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 2,
"selected": false,
"text": "OnClick :select"
},
{
"answer_id": 9295851,
"author": "Fahim Parkar",
"author_id": 1066828,
"author_profil... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27122/"
] |
396,064 | <p>When using auto implemnted properies like</p>
<p>public string MyProperty { get; set; }</p>
<p>This is great until you come to naming conventions.</p>
<p>I use underscore for class level fields ie</p>
<p>string _MyProperty;</p>
<p>so with auto implemented means that it is not obvious what the variable is and it scope.</p>
<p>If you get my meaning, any thoughts??</p>
<p>Malcolm</p>
<p>Edit: As the property is public you dont want to use a underscore either.</p>
| [
{
"answer_id": 396079,
"author": "karlis",
"author_id": 49034,
"author_profile": "https://Stackoverflow.com/users/49034",
"pm_score": 0,
"selected": false,
"text": " public string SomeString { private set; get; }\n\n private string some2string;\n\n public string Some3string { se... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40568/"
] |
396,069 | <p>I need some help with .NET (C#) and MS Outlook. I'm building a simple desktop application and want to send an e-mail using Outlook.</p>
<ol>
<li><p>If my desktop app generates a message, it should be able to send it as an email via outlook (we can assume outlook is running on the same PC) - a very simple operation.</p></li>
<li><p>If I can do 1, that's great. If possible, I would like to be able to insert items to the outlook calendar.</p></li>
</ol>
<p>I'm using VS 2008 professional and C#, the target will be .NET 3.5</p>
<p>Any help, sample code is very appreciated.</p>
| [
{
"answer_id": 396097,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 1,
"selected": false,
"text": "/// <summary>\n/// The MAPISendMail function sends a message.\n///\n/// This function differs from the MAPISendDocuments funct... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
396,084 | <p>I'm a C++ newbie, but I wasn't able to find the answer to this (most likely trivial) question online. I am having some trouble compiling some code where two classes include each other. To begin, should my #include statements go inside or outside of my macros? In practice, this hasn't seemed to matter. However, in this particular case, I am having trouble. Putting the #include statements outside of the macros causes the compiler to recurse and gives me "#include nested too deeply" errors. This seems to makes sense to me since neither class has been fully defined before #include has been invoked. However, strangely, when I try to put them inside, I am unable to declare a type of one of the classes, for it is not recognized. Here is, in essence, what I'm trying to compile:</p>
<p>A.h</p>
<pre><code>#ifndef A_H_
#define A_H_
#include "B.h"
class A
{
private:
B b;
public:
A() : b(*this) {}
};
#endif /*A_H_*/
</code></pre>
<p>B.h</p>
<pre><code>#ifndef B_H_
#define B_H_
#include "A.h"
class B
{
private:
A& a;
public:
B(A& a) : a(a) {}
};
#endif /*B_H_*/
</code></pre>
<p>main.cpp</p>
<pre><code>#include "A.h"
int main()
{
A a;
}
</code></pre>
<p>If it makes a difference, I am using g++ 4.3.2.</p>
<p>And just to be clear, in general, where should #include statements go? I have always seen them go outside of the macros, but the scenario I described clearly seems to break this principle. Thanks to any helpers in advance! Please allow me to clarify my intent if I have made any silly mistakes!</p>
| [
{
"answer_id": 396089,
"author": "Nathan Fellman",
"author_id": 1084,
"author_profile": "https://Stackoverflow.com/users/1084",
"pm_score": 0,
"selected": false,
"text": "A B"
},
{
"answer_id": 396090,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48096/"
] |
396,099 | <p>I mean to open the built-in Windows GUI from command line- not to launch by Schtasks</p>
| [
{
"answer_id": 396119,
"author": "Mahendra",
"author_id": 36816,
"author_profile": "https://Stackoverflow.com/users/36816",
"pm_score": 3,
"selected": false,
"text": "C:\\Documents and Settings\\mahendra.patil>at/?\n AT [\\\\computername] [ [id] [/DELETE] | /DELETE [/YES]]\nAT [\\\\compu... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
396,100 | <p>I'm implementing a sparse matrix with linked lists and it's not fun to manually check for leaks, any thoughts? </p>
| [
{
"answer_id": 396105,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 5,
"selected": true,
"text": "valgrind std::list"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/396100",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49500/"
] |
396,101 | <p>I'm trying to Remote Debugging a Windows Forms Application (C#), but i'm always getting this error: </p>
<blockquote>
<p><em>Unable to connect to the Microsoft Visual Studio Remote Debugging Monitor
named 'XXX. The Visual Studio Remote
Debugger on the target computer cannot
connect back to this computer.
Authentication failed. Please see Help
for assistance.</em></p>
</blockquote>
<p>I tried to config according to the MSDN guides but i was not able to make it work.</p>
<h2>My setup:</h2>
<ul>
<li><strong>Development Computer</strong> - XP (x86) that
is connected to a domain. </li>
<li><strong>Test Computer</strong> - Vista (x86) that is <strong>NOT</strong>
connected to a domain.</li>
<li>I have network connection between
the machines. </li>
<li>I created a local user in the <strong>Test
computer</strong> (user1) with the name of my domain
user that I run the Visual Studio (mydomain\user1). setup the same password.</li>
<li><p>On The Test Computer i'm running <strong>"msvsmon.exe"</strong> as application (not as services), i'm running it using <strong>"runas"</strong> command with the user that i have created. (user1):</p>
<p>runas /u:user1 msvsmon.exe</p></li>
</ul>
<p>Can Someone help me please?</p>
<p>Thanks.</p>
| [
{
"answer_id": 396129,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 1,
"selected": false,
"text": "TESTCOMPUTER\\user1 mydomain\\user1 msvsmon.exe msvsmon,exe msvsmon.exe"
},
{
"answer_id": 404686,
"autho... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34369/"
] |
396,117 | <p>I wonder, whether it is possible to create class-methods in VBA. By class-method I mean methods that can be called without having an object of the class. The 'static'-keyword does that trick in C++ and Java.</p>
<p>In the example below, I try to create a static factory method.</p>
<p>Example:</p>
<pre><code>'Classmodule Person'
Option Explicit
Private m_name As String
Public Property Let name(name As String)
m_name = name
End Property
Public Function sayHello() As String
Debug.Print "Hi, I am " & m_name & "!"
End Function
'---How to make the following method static?---'
Public Function Create(name As String) As Person
Dim p As New Person
p.m_name = name
Set Create = p
End Function
'Using Person'
Dim p As New Person
p.name = "Bob"
p.sayHello 'Works as expected'
Set p2 = Person.Create("Bob") 'Yields an error'
</code></pre>
| [
{
"answer_id": 396358,
"author": "Mike Woodhouse",
"author_id": 1060,
"author_profile": "https://Stackoverflow.com/users/1060",
"pm_score": 2,
"selected": false,
"text": "With New NotReallyStaticClass\n .PerformNotReallyStatic Method, OnSome, Values\nEnd With\n"
},
{
"answer_i... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396117",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34039/"
] |
396,128 | <p>Is there a way that I can get the most used applications via VB.NET? I'm developing a sort of hobby project as a quick launcher kind of thing and thought this would sit perfectly on the main form.</p>
<p>If possible, would somebody be able to explain to me how add/remove applications manages to get the frequency of used applications? It would be good if I could get it in a list like the XP/Vista start menu as well.</p>
<p>Any guidance would be greatly appreciated. :)</p>
| [
{
"answer_id": 419927,
"author": "Dirk Vollmar",
"author_id": 40347,
"author_profile": "https://Stackoverflow.com/users/40347",
"pm_score": 0,
"selected": false,
"text": "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Management\\ARPCache\n Structure SlowInfoCache\... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20900/"
] |
396,137 | <p>I have some questions about multi-threaded programming and multi-core usage.</p>
<p>In particular I'm wondering how the operating system and/or framework (this is .NET) deals with cores that are heavily used.</p>
<p>Here's my questions regarding threads:</p>
<ul>
<li>When a new thread is spawned, what is the algorithm for assigning the thread to a particular core?
<ol>
<li>Round-robin type of algorithm</li>
<li>Random</li>
<li>The currently least used core</li>
</ol></li>
<li>If not the currently least used core, would this type of code that determined this dwarf the typical use of a thread and thus just make matters worse?</li>
<li>Are threads moved from one core to another during their lifetime? If so, is this to handle cores that for some reason gets "overused" and thus the operating system try to shuffle threads over to less used cores to help the system? If not, again, why not?</li>
</ul>
<p>My final question, which is basically a reuse of the above, is about the .NET ThreadPool class, which handles things like .BeginInvoke and such. Does this class do any of this stuff? If not, why not, or should it?</p>
<p>Is there any way to tweak this handling, sort of hint at the operating system that this particular thread, please pay a bit more attention to it when you assign it a core, since I know it will use a lot of cpu. Would that make sense? Or would "a lot of cpu" just be relative and thus not really good enough?</p>
| [
{
"answer_id": 396161,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 3,
"selected": false,
"text": "Parallel.For"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/396137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/267/"
] |
396,139 | <p>I'm in a ASP.NET project where I need to give several parameters to the administrator that is going to install the website, like:</p>
<pre><code>AllowUserToChangePanelLayout
AllowUserToDeleteCompany
</code></pre>
<p>etc...</p>
<p>My question is, will be a good thing to add this into the web.config file, using my own configSession or add as a profile varibles? or should I create a XML file for this?</p>
<p>What do you do and what are the cons and favs?</p>
<p>I originally thought about web.config but I then realized that I should mess up with Website configurations and my own web app configuration and that I should create a different file, them I read <a href="http://www.aspcode.net/Your-own-configuration-setting-section-in-webconfig.aspx" rel="nofollow noreferrer">this post</a> and now I'm on this place... should I do this or that?</p>
| [
{
"answer_id": 396144,
"author": "configurator",
"author_id": 9536,
"author_profile": "https://Stackoverflow.com/users/9536",
"pm_score": 5,
"selected": true,
"text": "<appSettings>\n <add key=\"ConnString\" value=\"my conn string\" />\n <add key=\"MaxUsers\" value=\"50\" />\n</app... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28004/"
] |
396,142 | <p>I am using VSTS Unitesting platform. I am trying to test a method which got references to assemblies which in turn contain DllImport to C++ DLLs.</p>
<p>In order for it to work I need to copy C++ DLLs to reside on the same directory the EXE and DLLs are running.</p>
<p>Of course when I use the same code with Unittest I also need to supply those DLLs.
I found out that the Unittest framework us using the $(Solution)\TestResults[WorkSpace] [DateTime]\Out as a working directory.</p>
<p>If I manually copy the C++ DLLs to this directory the unit test is is working like a charm.</p>
<p>The problem is that every time the Unitest is running it creates a new directory.</p>
<p>Has anybody encountered it? do you have a solution?</p>
<p>Thanks,
Ariel</p>
| [
{
"answer_id": 396144,
"author": "configurator",
"author_id": 9536,
"author_profile": "https://Stackoverflow.com/users/9536",
"pm_score": 5,
"selected": true,
"text": "<appSettings>\n <add key=\"ConnString\" value=\"my conn string\" />\n <add key=\"MaxUsers\" value=\"50\" />\n</app... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396142",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11659/"
] |
396,145 | <p>I want to center a <code>div</code> vertically with CSS. I don't want tables or JavaScript, but only pure CSS. I found some solutions, but all of them are missing Internet Explorer 6 support.</p>
<pre><code><body>
<div>Div to be aligned vertically</div>
</body>
</code></pre>
<p>How can I center a <code>div</code> vertically in all major browsers, including Internet Explorer 6?</p>
| [
{
"answer_id": 396255,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 7,
"selected": false,
"text": "#container {\n position: absolute;\n top: 50%;\n margin-top: -200px;\n /* Half of #content height */\n left: 0;\n width:... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49380/"
] |
396,156 | <p>I have a <code>JPanel</code> subclass on which I add buttons, labels, tables, etc. To show on screen it I use <code>JFrame</code>:</p>
<pre><code>MainPanel mainPanel = new MainPanel(); //JPanel subclass
JFrame mainFrame = new JFrame();
mainFrame.setTitle("main window title");
mainFrame.getContentPane().add(mainPanel);
mainFrame.setLocation(100, 100);
mainFrame.pack();
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
</code></pre>
<p>But when I size the window, size of panel don't change. How to make size of panel to be the same as the size of window even if it was resized?</p>
| [
{
"answer_id": 396201,
"author": "Richard Walton",
"author_id": 15075,
"author_profile": "https://Stackoverflow.com/users/15075",
"pm_score": 2,
"selected": false,
"text": "mainFrame.setLayout(new BorderLayout());\n"
},
{
"answer_id": 396253,
"author": "Ole",
"author_id":... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/174644/"
] |
396,166 | <p>I need to check to see if a variable contains anything OTHER than a-z A-Z 0-9 and the "." character (full stop). Any help would be appreciated.</p>
| [
{
"answer_id": 396172,
"author": "maxnk",
"author_id": 45862,
"author_profile": "https://Stackoverflow.com/users/45862",
"pm_score": 3,
"selected": false,
"text": "if (preg_match(\"/[^A-Za-z0-9.]/\", $myVar)) {\n // make something\n}\n"
},
{
"answer_id": 396190,
"author": "... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396166",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26823/"
] |
396,168 | <p>Let's say we have two classes, Foo and Foo Sub, each in a different file, foo.rb and foo_sub.rb respectively.</p>
<p>foo.rb:</p>
<pre><code>require "foo_sub"
class Foo
def foo
FooSub.SOME_CONSTANT
end
end
</code></pre>
<p>foo_sub.rb:</p>
<pre><code>require "foo"
class FooSub < Foo
SOME_CONSTANT = 1
end
</code></pre>
<p>This isn't going to work due to the circular dependency - we can't define either class without the other. There are various solutions that I've seen. Two of them I want to avoid - namely, putting them in the same file and removing the circular dependency. So, the only other solution I've found is a forward declaration:</p>
<p>foo.rb:</p>
<pre><code>class Foo
end
require "foo_sub"
class Foo
def foo
FooSub.SOME_CONSTANT
end
end
</code></pre>
<p>foo_sub.rb</p>
<pre><code>require "foo"
class FooSub < Foo
SOME_CONSTANT = 1
end
</code></pre>
<p>Unfortunately, I can't get the same thing to work if I have three files:</p>
<p>foo.rb:</p>
<pre><code>class Foo
end
require "foo_sub_sub"
class Foo
def foo
FooSubSub.SOME_CONSTANT
end
end
</code></pre>
<p>foo_sub.rb:</p>
<pre><code>require "foo"
class FooSub < Foo
end
</code></pre>
<p>foo_sub_sub.rb:</p>
<pre><code>require "foo_sub"
class FooSubSub < FooSub
SOME_CONSTANT = 1
end
</code></pre>
<p>If I require foo_sub.rb, then FooSub is an uninitialized constant in foo_sub_sub.rb. Any ideas how to get around this without putting them in the same file nor removing the circular dependency?</p>
| [
{
"answer_id": 396184,
"author": "Jules",
"author_id": 40078,
"author_profile": "https://Stackoverflow.com/users/40078",
"pm_score": 5,
"selected": true,
"text": "require \"foo.rb\"\nrequire \"foo_sub.rb\"\n"
},
{
"answer_id": 1546863,
"author": "PETER BROWN",
"author_id"... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49381/"
] |
396,169 | <p>In my WinForms app, data can be printed on many locations. Everytime the user wants to print, I create a new PrintDocument instance, which is used for the current print job and then disposed. Everything is working, but the Print dialog is always set back to the default printer and its default parameters. If another printer is selected, the user must choose it every time again and again.</p>
<p>Is it a common approach to create one global PrintDocument instance and share it for all printing jobs accross the application? Like this the last selected printer would be always used. Or are there any other ways?</p>
<p>Thank you,
Petr</p>
| [
{
"answer_id": 396186,
"author": "lc.",
"author_id": 44853,
"author_profile": "https://Stackoverflow.com/users/44853",
"pm_score": 4,
"selected": true,
"text": "PrinterSettings PrintDocument"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/396169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20353/"
] |
396,176 | <p>I use an external diff tool with Subversion (Beyond Compare rules!), and one of the great features is being able to use the diff program to make some minor edits to the file as I'm reviewing the changes I've made.</p>
<p>But <code>svn diff</code> works differently on different projects of mine. In all, the left-hand file is a temp file containing the latest revision stored in Subversion (the head). But in some, the right-hand file is the actual working file, while in others it's a temp file copy of the working file. In the first case, I can make changes in the diff program and they affect the working copy. In the second case, I'm editing a temp file, so changes are lost.</p>
<p>Why does Subversion sometimes diff against the working file but sometimes against a temp copy of the working file? How can I make it always use the working file?</p>
| [
{
"answer_id": 62343836,
"author": "QtY",
"author_id": 13733780,
"author_profile": "https://Stackoverflow.com/users/13733780",
"pm_score": -1,
"selected": false,
"text": "$svn diff --diff-cmd=svn-diff-meld -r 12345 ./dirToCompare\n\n$ cat /usr/local/bin/svn-diff-meld\n#!/bin/sh\n# SVN D... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396176",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14343/"
] |
396,181 | <p>I'm trying to list the files in a directory and do something to them in the Mac OS X prompt.</p>
<p>It should go like this: for f in $(ls -1); do echo $f; done</p>
<p>If I have files without spaces in their names (fileA.txt, fileB.txt), the echo works fine.
If the files include spaces in their names ("file A.txt", "file B.txt"), I get 4 strings (file, A.txt, file, B.txt).</p>
<p>I've tried quoting the listing command, but it only changed the problem.</p>
<p>If I do this: for f in $(ls -1); do echo $f; done
I get: file A.txt\nfile B.txt</p>
<p>(It displays correctly, but it is a single string and I need the 2 lines separated.</p>
| [
{
"answer_id": 396188,
"author": "derobert",
"author_id": 27727,
"author_profile": "https://Stackoverflow.com/users/27727",
"pm_score": 3,
"selected": false,
"text": "for f in *; do echo \"$f\"; done\n ls * $IFS"
},
{
"answer_id": 396198,
"author": "Mihai Limbășan",
"auth... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
396,183 | <p>I'm trying to use SDL in C++ with Visual Studio 2008 Express. The following program compiles but does not link:</p>
<pre><code>#include <SDL.h>
int main(int argc, char *argv[])
{
return 0;
}
</code></pre>
<p>The link error is:</p>
<pre><code>LINK : fatal error LNK1561: entry point must be defined
</code></pre>
<p>I get this regardless of how or if I link with SDL.lib and SDLmain.lib. Defining <code>main</code> as <code>main()</code> or <code>SDL_main()</code> gives the same error, with or without <code>extern "C"</code>.</p>
<p>Edit: I solved this by not including SDL.h in main.cpp - a refactoring I did independent of the problem. A similar solution would be to <code>#undef main</code> right before defining the function.</p>
| [
{
"answer_id": 396308,
"author": "Judge Maygarden",
"author_id": 1491,
"author_profile": "https://Stackoverflow.com/users/1491",
"pm_score": 4,
"selected": true,
"text": "int main(int argc, char *argv[])\n"
},
{
"answer_id": 667115,
"author": "Degvik",
"author_id": 26276,... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396183",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3102/"
] |
396,191 | <p>Is it cool?</p>
<p>IMO one-liners reduces the readability and makes debugging/understanding more difficult.</p>
| [
{
"answer_id": 396199,
"author": "Bob",
"author_id": 45,
"author_profile": "https://Stackoverflow.com/users/45",
"pm_score": 2,
"selected": false,
"text": "int value = bool ? 1 : 0;\n"
},
{
"answer_id": 396202,
"author": "Jon Skeet",
"author_id": 22656,
"author_profil... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
396,222 | <ol>
<li>Is the .NET class System.Net.CookieContainer thread safe? --<strong>Update:</strong> Turnkey answered--</li>
<li>Is there any way to ensure thread safeness to variables which are modified during asynchronous requests (ie. HttpWebRequest.CookieContainer)?</li>
<li>Is there any attribute to highlight thread safe classes? --<strong>Update:</strong> If thread-safeness is described on MSDN then probably they don't have an attribute for this --</li>
<li>Are all .NET classes thread safe? --<strong>Update:</strong> Marc answered--</li>
</ol>
<p>I ask these questions because I use the CookieContainer in asynchronous requests in a multithreaded code. And I can't put an asynchrounous request inside a lock. Maybe I'll have to use readonly "variables" (or immutable types) like in F#, right?</p>
| [
{
"answer_id": 396248,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "Monitor lock(syncLock) {\n // prepare request from (synchronized) state\n req.Begin{...}\n}\n lock(syncLock) {\n... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48465/"
] |
396,229 | <p>What is the recommended location to save user preference files? Is there a recommended method for dealing with user preferences?</p>
<p>Currently I use the path returned from <code>typeof(MyLibrary).Assembly.Location</code> as a default location to store files generated or required by the application.</p>
<p>EDIT:
I found two related/interesting questions:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/147533/best-place-to-save-user-information-xp-and-vista">Best place to save user information for Windows XP and Vista applications</a></li>
<li><a href="https://stackoverflow.com/questions/348022/whats-the-way-to-implement-save-load-functionality">What's the way to implement Save / Load functionality?</a></li>
</ul>
<p>EDIT #2:
This is just a note for people like me who had never used settings before.
Settings are pretty useful, but I had to do a whole bunch of digging to figure out what was going on (coming from the Python world, not something I am used too). Things got complicated as I wanted to save dictionaries and apparently they can't be serialized. Settings also seem to get stored in 3 different files depending on what you do. There is an <code>app.config</code>, <code>user.config</code> and a <code>settings.setting</code> file. So here are two more links that I found useful:</p>
<ul>
<li><a href="http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ddeaca86-a093-4997-82c9-01bc0c630138" rel="noreferrer">http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ddeaca86-a093-4997-82c9-01bc0c630138</a> </li>
<li><a href="http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/efe370dc-f933-4e55-adf7-3cd8063949b0/" rel="noreferrer">http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/efe370dc-f933-4e55-adf7-3cd8063949b0/</a></li>
</ul>
| [
{
"answer_id": 396243,
"author": "Sailing Judo",
"author_id": 42620,
"author_profile": "https://Stackoverflow.com/users/42620",
"pm_score": 7,
"selected": true,
"text": "forms.Width = Application1.Properties.Settings.Default.Width;\n Application1.Properties.Settings.Default.Width = forms... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47660/"
] |
396,245 | <p>How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.</p>
| [
{
"answer_id": 396770,
"author": "Jack Leow",
"author_id": 31506,
"author_profile": "https://Stackoverflow.com/users/31506",
"pm_score": 8,
"selected": true,
"text": "mvn install:install-file -DgroupId=com.stackoverflow... -DartifactId=yourartifactid... -Dversion=1.0 -Dpackaging=jar -Dfi... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17712/"
] |
396,260 | <p>Here's the scenario: I have a set of buttons that I want to bind to corresponding functions when clicked. The ids of these buttons are the same as the names of their corresponding functions. I could do this:</p>
<pre><code>$("#kick").click(kick);
$("#push").click(push);
$("#shove").click(shove);
</code></pre>
<p>But I'm lazy and would like to do this more lazily (as is my nature). As the buttons are all contained in a block element, I'd like to do something like this:</p>
<pre><code>$("#button_holder > span").each(function () {
var doThis = this.id;
$(this).click(doThis);
});
</code></pre>
<p>Except that doesn't work. Any suggestions?</p>
| [
{
"answer_id": 396262,
"author": "Moran Helman",
"author_id": 1409636,
"author_profile": "https://Stackoverflow.com/users/1409636",
"pm_score": 0,
"selected": false,
"text": "$(\"#button_holder > span\").each(function () {\n var doThis = this.id;\n $(this).click(function(doThis){\n... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11782/"
] |
396,272 | <p>I have a Windows Forms application. When the user imports a license for my application I'd like to "phone home" (hit an aspx page on the web) and register the license information.</p>
<p>The problem is that the user may not have an internet connection working at that moment. I'd like to test this first. What's the best way to detect if the user has an internet connection available?</p>
| [
{
"answer_id": 396323,
"author": "Leon Tayson",
"author_id": 18413,
"author_profile": "https://Stackoverflow.com/users/18413",
"pm_score": 3,
"selected": false,
"text": "// Create a new WebRequest Object to the mentioned URL.\nWebRequest myWebRequest=WebRequest.Create(\"http://www.contos... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
396,280 | <p>Starting to build web applications for mobile devices (any phone). <br/>
What would be the best approach using ASP.NET 3.5/ASP.NET 4.0 and C#?
<br/></p>
<p>UPDATE (feb2010) <br/>
Any news using windows mobile 7?<br/></p>
| [
{
"answer_id": 396366,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 5,
"selected": true,
"text": "<?xml version=\"1.0\"?>\n<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"\n \"http://www.wapforum.org/DTD/wml_1.1.xml... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396280",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49544/"
] |
396,281 | <p>I'm fairly new to C# programming.</p>
<p>I am making a program for fun that adds two numbers together, than displays the sum in a message box. I have two numericUpDowns and a button on my form. When the button is pushed I want it to display a message box with the answer. </p>
<p>The problem is, I am unsure how to add the twp values from the numericUpDowns together.</p>
<p>So far, I have this in my button event handler:</p>
<pre><code>private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(this.numericUpDown1.Value + this.numericUpDown2.Value);
}
</code></pre>
<p>But obviously, it does not work. It gives me 2 compiler errors:
1. The best overloaded method match for 'System.Windows.Forms.MessageBox.Show(string) has some invalid arguments
2. Argument '1': cannot convert decimal to 'string'</p>
<p>Thanks!</p>
| [
{
"answer_id": 396290,
"author": "lc.",
"author_id": 44853,
"author_profile": "https://Stackoverflow.com/users/44853",
"pm_score": 4,
"selected": true,
"text": "this.numericUpDown1.Value + this.numericUpDown2.Value MessageBox.Show() .ToString() private void button1_Click(object sender, E... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396281",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49549/"
] |
396,296 | <p>I need to find a path or paths down a complicated graph structure. The graph is built using something similar to this:</p>
<pre><code>class Node
{
public string Value { get; set;}
public List<Node> Nodes { get; set;}
public Node()
{
Nodes = new List<Node>();
}
}
</code></pre>
<p>What makes this complicated is that the nodes can reference back to an earlier node. For example,</p>
<blockquote>
<p>A -> C -> E -> A</p>
</blockquote>
<p>What I need to do is get a list of stacks which represent paths through the Nodes until I get to a Node with a specific value. Since its possible there can be some very large paths available we can have a maximum Nodes to try.</p>
<pre><code>List<Stack<Node>> paths = FindPaths(string ValueToFind, int MaxNumberNodes);
</code></pre>
<p>Does anyone have a way to build this (or something similar)? I've done recursion in the past but I'm having a total brain fart thinking about this for some reason. My question specified a lambda expression but using a lambda is not necessarily required. I'd be grateful for any solution.</p>
<p>Side note: I lifted the class from aku's excellent answer for <a href="https://stackoverflow.com/questions/61143/recursive-lambda-expression-to-traverse-a-tree-in-c">this recursion question</a>. While his elegant solution shown below traverses the tree structure it doesn't seem to allow enough flexibility to do what I need (for example, dismiss paths that are circular and track paths that are successful).</p>
<pre><code>Action<Node> traverse = null;
traverse = (n) => { Console.WriteLine(n.Value); n.Nodes.ForEach(traverse);};
traverse(root); // where root is the tree structure
</code></pre>
<p><strong>Edit</strong>:</p>
<p>Based on input from the comments and answers below I found an excellent solution over in CodeProject. It uses the A* path finding algorithm. <a href="http://www.codeproject.com/KB/recipes/graphs_astar.aspx" rel="nofollow noreferrer">Here is the link.</a></p>
| [
{
"answer_id": 396409,
"author": "Brann",
"author_id": 47341,
"author_profile": "https://Stackoverflow.com/users/47341",
"pm_score": 0,
"selected": false,
"text": " public void ExploreGraph(TreeNode tn, Dictionary<TreeNode, bool> visitednodes)\n {\n\n foreach (Treenode... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42620/"
] |
396,319 | <p>You have a forum (vbulletin) that has a bunch of images - how easy would it be to have a page that visits a thread, steps through each page and forwards to the user (via ajax or whatever) the images. i'm not asking about filtering (that's easy of course).</p>
<p>doable in a day? :)</p>
<p>I have a site that uses codeigniter as well - would it be even simpler using it?</p>
| [
{
"answer_id": 396343,
"author": "Ole",
"author_id": 49540,
"author_profile": "https://Stackoverflow.com/users/49540",
"pm_score": 0,
"selected": false,
"text": "<img .../>"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/396319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
396,324 | <p>I am tying to make comments in a blog engine XSS-safe. Tried a lot of different approaches but find it very difficult.</p>
<p>When I am displaying the comments I am first using <a href="http://www.codeplex.com/AntiXSS" rel="nofollow noreferrer">Microsoft AntiXss 3.0</a> to html encode the whole thing. Then I am trying to html decode the safe tags using a whitelist approach.</p>
<p>Been looking at <a href="http://refactormycode.com/codes/333-sanitize-html#refactor_44440" rel="nofollow noreferrer">Steve Downing's example</a> in Atwood's "Sanitize HTML" thread at refactormycode.</p>
<p>My problem is that the AntiXss library encodes the values to &#DECIMAL; notation and I don't know how to rewrite Steve's example, since my regex knowledge is limited.</p>
<p>I tried the following code where I simply replaced entities to decimal form but it does not work properly. </p>
<pre><code>&lt; with &#60;
&gt; with &#62;
</code></pre>
<p>My rewrite:</p>
<pre><code>class HtmlSanitizer
{
/// <summary>
/// A regex that matches things that look like a HTML tag after HtmlEncoding. Splits the input so we can get discrete
/// chunks that start with &lt; and ends with either end of line or &gt;
/// </summary>
private static Regex _tags = new Regex("&#60;(?!&#62;).+?(&#62;|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
/// <summary>
/// A regex that will match tags on the whitelist, so we can run them through
/// HttpUtility.HtmlDecode
/// FIXME - Could be improved, since this might decode &gt; etc in the middle of
/// an a/link tag (i.e. in the text in between the opening and closing tag)
/// </summary>
private static Regex _whitelist = new Regex(@"
^&#60;/?(a|b(lockquote)?|code|em|h(1|2|3)|i|li|ol|p(re)?|s(ub|up|trong|trike)?|ul)&#62;$
|^&#60;(b|h)r\s?/?&#62;$
|^&#60;a(?!&#62;).+?&#62;$
|^&#60;img(?!&#62;).+?/?&#62;$",
RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace |
RegexOptions.ExplicitCapture | RegexOptions.Compiled);
/// <summary>
/// HtmlDecode any potentially safe HTML tags from the provided HtmlEncoded HTML input using
/// a whitelist based approach, leaving the dangerous tags Encoded HTML tags
/// </summary>
public static string Sanitize(string html)
{
string tagname = "";
Match tag;
MatchCollection tags = _tags.Matches(html);
string safeHtml = "";
// iterate through all HTML tags in the input
for (int i = tags.Count - 1; i > -1; i--)
{
tag = tags[i];
tagname = tag.Value.ToLowerInvariant();
if (_whitelist.IsMatch(tagname))
{
// If we find a tag on the whitelist, run it through
// HtmlDecode, and re-insert it into the text
safeHtml = HttpUtility.HtmlDecode(tag.Value);
html = html.Remove(tag.Index, tag.Length);
html = html.Insert(tag.Index, safeHtml);
}
}
return html;
}
}
</code></pre>
<p>My input testing html is:</p>
<pre><code><p><script language="javascript">alert('XSS')</script><b>bold should work</b></p>
</code></pre>
<p>After AntiXss it turns into:</p>
<pre><code>&#60;p&#62;&#60;script language&#61;&#34;javascript&#34;&#62;alert&#40;&#39;XSS&#39;&#41;&#60;&#47;script&#62;&#60;b&#62;bold should work&#60;&#47;b&#62;&#60;&#47;p&#62;
</code></pre>
<p>When I run the version of Sanitize(string html) above it gives me:</p>
<pre><code><p><script language="javascript">alert&#40;&#39;XSS&#39;&#41;</script><b>bold should work</b></p>
</code></pre>
<p>The regex is matching script from the whitelist which I don't want. Any help with this would be highly appreciated.</p>
| [
{
"answer_id": 396400,
"author": "some",
"author_id": 36866,
"author_profile": "https://Stackoverflow.com/users/36866",
"pm_score": 2,
"selected": true,
"text": "private static Regex _whitelist = new Regex(@\"\n ^&\\#60;(&\\#47;)? (a|b(lockquote)?|code|em|h(1|2|3)|i|li|ol|p(re)?|s(ub|... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33349/"
] |
396,327 | <p>The following code prints 20, i.e. sizeof(z) is 20.</p>
<pre><code>#include <iostream.h>
class Base
{
public:
int a;
};
class X:virtual public Base
{
public:
int x;
};
class Y:virtual public Base
{
public:
int y;
};
class Z:public X,public Y
{
};
int main()
{
Z z;
cout << sizeof(z) <<endl;
}
</code></pre>
<p>Whereas if I don't use virtual base classes here, i.e. for the following code :
sizeof(z) is 16.</p>
<pre><code>#include <iostream.h>
class Base
{
public:
int a;
};
class X:public Base
{
public:
int x;
};
class Y:public Base
{
public:
int y;
};
class Z:public X,public Y
{
};
int main()
{
Z z;
cout << sizeof(z) <<endl;
}
</code></pre>
<p>Why is sizeof(z) more(20) in the first case?
Shouldn't it be 12, since Base will be included
only once in Z?</p>
| [
{
"answer_id": 396353,
"author": "markets",
"author_id": 4662,
"author_profile": "https://Stackoverflow.com/users/4662",
"pm_score": 5,
"selected": true,
"text": "Offset Size Type Scope Name\n 0 4 int Base a\n 4 4 int X x\n 8 4 int Base ... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49560/"
] |
396,337 | <p>Is there a framework that supports generating some standard unit tests from annotations? An example of what I have in mind would be:</p>
<pre><code>@HasPublicDefaultConstructor
public class Foo {
}
</code></pre>
<p>This would obviously be used to automatically generate a unit test that checks whether Foo has a default constructor. Am I the only person who thought of something like that yet? ;) While I'm most interested in Java, solutions in other languages would certainly be interesting, too.</p>
<p>EDIT: In response to S.Lott's answer, let me clarify:</p>
<p>I'm trying to test whether the class has a default constructor. (Of course that is just an example.) I could just do so by writing a test, but I find that quite tedious. So I'm looking for a tool that would process the annotations at compile time (via APT) and generate the test for me.
Does something like that exist? If not, do you think it is a good idea?</p>
| [
{
"answer_id": 398160,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 1,
"selected": false,
"text": "@StandardTestForClassHierarchy1\n@StandardTestForClassHierarchy2\n@StandardTestForClassHierarchy3\n@StandardTestForSomeOthe... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396337",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46450/"
] |
396,369 | <p>When an application crashes on Windows and a debugger such as Visual Studio is installed the following modal dialog appears:</p>
<blockquote>
<p>[Title: Microsoft Windows]</p>
<p>X has stopped working</p>
<p>A problem caused the program to stop
working correctly. Windows will close
the program and notify you if a
solution is available.</p>
<p>[Debug][Close Application]</p>
</blockquote>
<p>Is there a way to disable this dialog? That is, have the program just crash and burn silently? </p>
<p>My scenario is that I would like to run several automated tests, some of which will crash due to bugs in the application under test. I don't want these dialogs stalling the automation run.</p>
<p>Searching around I think I've located the solution for disabling this on Windows XP, which is nuking this reg key:</p>
<blockquote>
<p>HKLM\Software\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger</p>
</blockquote>
<p>However, that did not work on Windows Vista.</p>
| [
{
"answer_id": 396510,
"author": "NicJ",
"author_id": 43815,
"author_profile": "https://Stackoverflow.com/users/43815",
"pm_score": 7,
"selected": true,
"text": "Windows Registry Editor Version 5.00\n\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting]\n\"ForceQu... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/322/"
] |
396,385 | <p>I have a reference-type variable that is <code>readonly</code>, because the reference never change, only its properties. When I tried to add the <code>volatile</code> modifier to it the compiled warned me that it wouldn't let both modifiers apply to the same variable. But I think I need it to be volatile because I don't want to have caching problems when reading its properties. Am I missing anything? Or is the compiler wrong?</p>
<p><strong>Update</strong> As Martin stated in one of the comments below: Both readonly and volatile modifiers apply only to the reference, and not to the object's properties, in the case of reference-type objects. That is what I was missing, so the compiler is right.</p>
<pre><code>class C
{
readonly volatile string s; // error CS0678: 'C.s': a field cannot be both volatile and readonly
}
</code></pre>
| [
{
"answer_id": 396413,
"author": "P Daddy",
"author_id": 36388,
"author_profile": "https://Stackoverflow.com/users/36388",
"pm_score": 5,
"selected": true,
"text": "readonly volatile readonly volatile"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/396385",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48465/"
] |
396,391 | <p>It's quite some time that I'm trying to figure out this problem and from googling around many people have similar problems.</p>
<p>I'm trying to model a User in a Social Network, using Hibernate, and what is more basic to a social network than to map a friendship relation?
Every user in the system should have a list of it's friends and I thought that this might be an incredibly easy task (just use a ManyToMany relation, right?). So I went on to try the following:</p>
<pre><code>@Entity
@Table(name="users")
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="userid")
protected Long id = null;
@ManyToMany
protected List<User> friends = null
}
</code></pre>
<p>The problem now is that it tells me I use ManyToMany wrongly by having no clear distinction between friend and befriended. So far so good, I get the error, but how can I do what I want?</p>
<p>Any idea? I've reached the end of my wisdom.</p>
| [
{
"answer_id": 396401,
"author": "Ole",
"author_id": 49540,
"author_profile": "https://Stackoverflow.com/users/49540",
"pm_score": 1,
"selected": false,
"text": "ManyToMany @ManyToMany(mappedBy = \"friends\")\n @Entity\n@Table(name=\"users\")\npublic class User {\n @Id\n @GeneratedVa... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49561/"
] |
396,394 | <p>When I reading source code of Beast, I found a lot of code like this:</p>
<pre><code><%= 'Password'[:password_title] %>
</code></pre>
<p>It seems like a call to [] method with Symbol as input parameter to a String to me, but I didn't find such type of parameter of String [] method in the ruby API. What is this means?
thanks in advance.</p>
| [
{
"answer_id": 396419,
"author": "eric2323223",
"author_id": 44512,
"author_profile": "https://Stackoverflow.com/users/44512",
"pm_score": 1,
"selected": false,
"text": "str[fixnum] => fixnum or nil\nstr[fixnum, fixnum] => new_str or nil\nstr[range] => new_str or nil\nstr[regexp] => new_... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44512/"
] |
396,421 | <p>I'm checking if two strings <code>a</code> and <code>b</code> are permutations of each other, and I'm wondering what the ideal way to do this is in Python. From the Zen of Python, "There should be one -- and preferably only one -- obvious way to do it," but I see there are at least two ways:</p>
<pre><code>sorted(a) == sorted(b)
</code></pre>
<p>and</p>
<pre><code>all(a.count(char) == b.count(char) for char in a)
</code></pre>
<p>but the first one is slower when (for example) the first char of <code>a</code> is nowhere in <code>b</code>, and the second is slower when they are actually permutations.</p>
<p>Is there any better (either in the sense of more Pythonic, or in the sense of faster on average) way to do it? Or should I just choose from these two depending on which situation I expect to be most common?</p>
| [
{
"answer_id": 396436,
"author": "ʞɔıu",
"author_id": 41613,
"author_profile": "https://Stackoverflow.com/users/41613",
"pm_score": 3,
"selected": false,
"text": "all(a.count(char) == b.count(char) for char in a)\n set(a) == set(b)\n all(str1.count(char) == str2.count(char) for char in s... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396421",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49559/"
] |
396,425 | <p>I have a service that returns a collection of MyClass objects.
If all of the MyClass instances have null in MyClass2Reference then everything works fine.
Otherwise, I get a "Connection reset" error on the client side.
What am I doing wrong?</p>
<pre><code>[DataContract]
public MyClass
{
[DataMember]
int ID;
[DataMember]
MyClass2 MyClass2Reference;
}
[DataContract]
public MyClass2
{
[DataMember]
int ID;
[DataMember]
string Name;
}
</code></pre>
| [
{
"answer_id": 396436,
"author": "ʞɔıu",
"author_id": 41613,
"author_profile": "https://Stackoverflow.com/users/41613",
"pm_score": 3,
"selected": false,
"text": "all(a.count(char) == b.count(char) for char in a)\n set(a) == set(b)\n all(str1.count(char) == str2.count(char) for char in s... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396425",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19956/"
] |
396,429 | <p>Here's one I have always wondered about...</p>
<p>Please excuse my naivety, but - How do you decide what version number to name your software?</p>
<p>I assume, when somebody creates a "final" version of an application/program it is version 1.0? - Then, what happens when you update it, how do you decide to call it 1.1 or 1.03 etc etc. </p>
<p>Is this mostly for the developer?</p>
| [
{
"answer_id": 396435,
"author": "cdecker",
"author_id": 49561,
"author_profile": "https://Stackoverflow.com/users/49561",
"pm_score": 3,
"selected": false,
"text": "* The A number denotes the kernel version. It is rarely changed, and\n * The B number denotes the major revision of the ke... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37418/"
] |
396,439 | <p>What is the cleanest way to align properly radio buttons / checkboxes with text? The only reliable solution which I have been using so far is table based:</p>
<pre><code><table>
<tr>
<td><input type="radio" name="opt"></td>
<td>Option 1</td>
</tr>
<tr>
<td><input type="radio" name="opt"></td>
<td>Option 2</td>
</tr>
</table>
</code></pre>
<p>This may be frown upon by some. I’ve just spent some time (again) investigating a tableless solution but failed. I’ve tried various combinations of floats, absolute/relative positioning and similar approaches. Not only that they mostly relied silently on an estimated height of the radio buttons / checkboxes, but they also behaved differently in different browsers. Ideally, I would like to find a solution which does not assume anything about sizes or special browser quirks. I’m fine with using tables, but I wonder where there is another solution.</p>
| [
{
"answer_id": 396476,
"author": "Keith Donegan",
"author_id": 37418,
"author_profile": "https://Stackoverflow.com/users/37418",
"pm_score": 3,
"selected": false,
"text": " <p class=\"clearfix\">\n <input id=\"option1\" type=\"radio\" name=\"opt\" />\n <label for=\"option1\">... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396439",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15716/"
] |
396,442 | <p>I am curious what strategies folks have found for unit testing a data access class that does not involve loading (and presumably unloading) a real database for each test method? Are you using mock objects to represent the database connection? If so, are you required to pass the mock object into every method-under-test, and thus forcing the API to require a real db connection as a parameter to every method? Or, are you passing a mock object into the constructor at setup()?</p>
<p>I have a class that is implementing what I believe is a Data Mapper (or maybe gateway) pattern. It is the class responsible for encapsulating SQL and returning (or saving) "business objects". The rest of the code can interact with this mapper layer and the business objects, with total disregard for the persistence model. This code needs to have/maintain, or just know about, a live db connection in the real system. Emulating this under test is tricky.</p>
<p>The problem is how to unit test one of these mapper classes. The practice for creating a unit test under xUnit that I have seen most often is using the setup() method of the test to instantiate the SUT (system under test), usually your object that you're testing, and store it in a local variable in the test class. Then each of your test methods, interact with a unique instance of that SUT.</p>
<p>The assumption though is that whatever you're doing in the setup() method will presumably be replicated somewhere in your real code. So, you have to think about the setup process as "is this something I will want to repeatedly reproduce every time I need to use this object in the real world." If I am passing a db connection into the mapper's constructor in the setup that's fine, but doesn't that mean I'll have to pass a live db connection into the mapper object's constructor every time I want to really use one? Imagine that you'll have all kinds of places where you need to retrieve or store a business object and that to use a data mapper object, you need to pass in the db connection every time?</p>
<p>In my case, I am trying to establish tests for these data mapper objects that achieve the following:</p>
<ol>
<li>Do not require the database connection object to be instantiated and passed into every method of the mapper class.</li>
<li>Do not require that the test case either connect to a real db or create a real, but "test", db on the fly for each test method.</li>
</ol>
<p>I have basically seen two suggestions, pass the connection object as a parameter (which I have already addressed) or extend the SUT class just for the test and override whatever db connection setup process you have in the real world to use a mock system instead.</p>
<p>I am curious if anyone else is facing these issues, with any language, and what you have done to solve them? Maybe there is something obvious that I am missing?</p>
| [
{
"answer_id": 407786,
"author": "Limbic System",
"author_id": 1274957,
"author_profile": "https://Stackoverflow.com/users/1274957",
"pm_score": 0,
"selected": false,
"text": "setConnection() java.sql.Connection"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/396442",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/577/"
] |
396,449 | <p>I found the "always stop on error (dbstop if error)" to be very useful when I debug MATLAB code. <br>
However, closing matlab also resets it to "Never stop if error"</p>
<p>How can I make this setting persist?</p>
| [
{
"answer_id": 396483,
"author": "Dani",
"author_id": 28772,
"author_profile": "https://Stackoverflow.com/users/28772",
"pm_score": 5,
"selected": true,
"text": "edit startup.m\n dbstop if error\n"
}
] | 2008/12/28 | [
"https://Stackoverflow.com/questions/396449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28772/"
] |
396,455 | <p>I am currently analyzing a wikipedia dump file; I am extracting a bunch of data from it using python and persisting it into a PostgreSQL db. I am always trying to make things go faster for this file is huge (18GB). In order to interface with PostgreSQL, I am using psycopg2, but this module seems to mimic many other such DBAPIs.</p>
<p>Anyway, I have a question concerning cursor.executemany(command, values); it seems to me like executing an executemany once every 1000 values or so is better than calling cursor.execute(command % value) for each of these 5 million values (please confirm or correct me!).</p>
<p>But, you see, I am using an executemany to INSERT 1000 rows into a table which has a UNIQUE integrity constraint; this constraint is not verified in python beforehand, for this would either require me to SELECT all the time (this seems counter productive) or require me to get more than 3 GB of RAM. All this to say that I count on Postgres to warn me when my script tried to INSERT an already existing row via catching the psycopg2.DatabaseError. </p>
<p>When my script detects such a non-UNIQUE INSERT, it connection.rollback() (which makes ups to 1000 rows everytime, and kind of makes the executemany worthless) and then INSERTs all values one by one.</p>
<p>Since psycopg2 is so poorly documented (as are so many great modules...), I cannot find an efficient and effective workaround. I have reduced the number of values INSERTed per executemany from 1000 to 100 in order to reduce the likeliness of a non-UNIQUE INSERT per executemany, but I am pretty certain their is a way to just tell psycopg2 to ignore these execeptions or to tell the cursor to continue the executemany. </p>
<p>Basically, this seems like the kind of problem which has a solution so easy and popular, that all I can do is ask in order to learn about it.</p>
<p>Thanks again!</p>
| [
{
"answer_id": 550849,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "insert into mytable\nselect * from (\n select distinct * \n from scratch\n) uniq\nwhere not exists (\n select 1 \n ... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
396,463 | <p>I have a site with URLs like this:</p>
<pre><code>http://domain.co.uk/subdir/page.php
</code></pre>
<p>I have redesigned the site so URLs are now like this:</p>
<pre><code>http://domain.co.uk/page.php
</code></pre>
<p>How can I 301 redirect all the pages to their new locations using Apache's mod_rewrite?</p>
| [
{
"answer_id": 396477,
"author": "ceejayoz",
"author_id": 1902010,
"author_profile": "https://Stackoverflow.com/users/1902010",
"pm_score": 2,
"selected": false,
"text": "RewriteRule ^subdir/(.*)$ http://domain.co.uk/$1 [R=301,QSA,L]\n"
},
{
"answer_id": 396487,
"author": "Co... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16511/"
] |
396,480 | <p>I'm wondering if there is an existing class or library code in Cocoa Touch that shows the user a list of real-time suggestions while they are entering text input, with the suggestions based on similarities between what they have already entered and previous entries.</p>
<p>For instance, see how Safari on the iPod Touch shows realtime suggestions when you start to type in a URL, based on previously visited sites.</p>
<p>If there is a standard way of doing this, I'd love to know! If not, suggestions for a reasonable way to implement this -- subclass UITextField and go from there? -- would be welcome. </p>
| [
{
"answer_id": 396477,
"author": "ceejayoz",
"author_id": 1902010,
"author_profile": "https://Stackoverflow.com/users/1902010",
"pm_score": 2,
"selected": false,
"text": "RewriteRule ^subdir/(.*)$ http://domain.co.uk/$1 [R=301,QSA,L]\n"
},
{
"answer_id": 396487,
"author": "Co... | 2008/12/28 | [
"https://Stackoverflow.com/questions/396480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.