qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
346,169 | <p>How do you decide between passing arguments to a method versus simply declaring them as object instance variables that are visible to all of the object's methods?</p>
<p>I prefer keeping instance variables in a list at the end of the Class, but this list gets longer as my program grows. I figure if a variable is passed often enough it should just be visible to all methods that need it, but then I wonder, "if everything is public there will be no need for passing anything at all!"</p>
| [
{
"answer_id": 346184,
"author": "ng.mangine",
"author_id": 37784,
"author_profile": "https://Stackoverflow.com/users/37784",
"pm_score": 5,
"selected": false,
"text": "myCircle = myDrawing.drawCircle(center, radius);\n"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29182/"
] |
346,175 | <p>In 64 bit versions of windows, 32 bit software is installed in "c:\program files (x86)". This means you cannot use $(programfiles) to get the path to (32 bit) software. So I need a $(ProgramFiles32) to overcome this in my MSBuild project. I don't want to change the project depending on the os it is running on.</p>
<p>I have a solution that I will post, but maybe there is a easier/better way.</p>
| [
{
"answer_id": 346176,
"author": "wimh",
"author_id": 33499,
"author_profile": "https://Stackoverflow.com/users/33499",
"pm_score": 4,
"selected": false,
"text": "<PropertyGroup>\n <ProgramFiles32 Condition=\"Exists('$(PROGRAMFILES) (x86)')\">$(PROGRAMFILES) (x86)</ProgramFiles32>\n <P... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33499/"
] |
346,189 | <p>I want to use the built-in preference system for my xulrunner (Firefox) application. But I can't figure out how to easily drive the user interface based on preferences.</p>
<p>The user can specify a list of home pages, and each home page will show up in a different tab. Because the tabs are in the presentation layer, I'd like to create them using a template in the xul code. Is this possible?</p>
<p>I haven't seen a way to do this with xul templates. Is there an alternative templating system that would allow me to change the UI based on user preferences?</p>
| [
{
"answer_id": 931647,
"author": "vava",
"author_id": 6258,
"author_profile": "https://Stackoverflow.com/users/6258",
"pm_score": 0,
"selected": false,
"text": "\nXML.prototype.function::domNode = function domNode() {\n function addPrefix(prefix, name) {\n if (typeof(prefix) ==... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346189",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37784/"
] |
346,226 | <p>I am totally new to XSLT and can't work out where I am going wrong with the following code.</p>
<pre><code><xsl:variable name="var" select="boolean('false')"/>
<xsl:if test="$var'">variable is true</xsl:if>
</code></pre>
<p>It is always returning true when it is meant to be false. Why?</p>
| [
{
"answer_id": 346227,
"author": "Yuval Adam",
"author_id": 24545,
"author_profile": "https://Stackoverflow.com/users/24545",
"pm_score": 4,
"selected": false,
"text": "<xsl:variable name=\"var_false\" select=\"false()\"/>\n<xsl:variable name=\"var_true\" select=\"true()\"/>\n"
},
{
... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5838/"
] |
346,230 | <p>I'm using <code>urllib2</code> to read in a page. I need to do a quick regex on the source and pull out a few variables but <code>urllib2</code> presents as a file object rather than a string.</p>
<p>I'm new to python so I'm struggling to see how I use a file object to do this. Is there a quick way to convert this into a string?</p>
| [
{
"answer_id": 346237,
"author": "stesch",
"author_id": 41860,
"author_profile": "https://Stackoverflow.com/users/41860",
"pm_score": 7,
"selected": true,
"text": "f"
},
{
"answer_id": 346260,
"author": "t3rse",
"author_id": 64,
"author_profile": "https://Stackoverflo... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12870/"
] |
346,243 | <p>If i have the following directory structure:</p>
<p>Project1/bin/debug<br>
Project2/xml/file.xml</p>
<p>I am trying to refer to file.xml from Project1/bin/debug directory</p>
<p>I am essentially trying to do the following:</p>
<pre><code>string path = Environment.CurrentDirectory + @"..\..\Project2\xml\File.xml":
</code></pre>
<p>what is the correct syntax for this?</p>
| [
{
"answer_id": 346248,
"author": "lubos hasko",
"author_id": 275,
"author_profile": "https://Stackoverflow.com/users/275",
"pm_score": 2,
"selected": false,
"text": "System.IO.Path.GetFullPath(@\"..\\..\\Project2\\xml\\File.xml\")\n"
},
{
"answer_id": 346249,
"author": "Blair... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
346,267 | <p>I have a string like this that I need to parse into a 2D array:</p>
<pre><code> str = "'813702104[813702106]','813702141[813702143]','813702172[813702174]'"
</code></pre>
<p>the array equiv would be:</p>
<pre><code>arr[0][0] = 813702104
arr[0][1] = 813702106
arr[1][0] = 813702141
arr[1][1] = 813702143
#... etc ...
</code></pre>
<p>I'm trying to do this by REGEX. The string above is buried in an HTML page but I can be certain it's the only string in that pattern on the page. I'm not sure if this is the best way, but it's all I've got right now.</p>
<pre><code>imgRegex = re.compile(r"(?:'(?P<main>\d+)\[(?P<thumb>\d+)\]',?)+")
</code></pre>
<p>If I run <code>imgRegex.match(str).groups()</code> I only get one result (the first couplet). How do I either get multiple matches back or a 2d match object (if such a thing exists!)?</p>
<p><em>Note: Contrary to how it might look, this is <strong>not</strong> homework</em></p>
<h1>Note <em>part deux</em>: The real string is embedded in a <em>large</em> HTML file and therefore splitting does not appear to be an option.</h1>
<p>I'm still getting answers for this, so I thought I better edit it to show why I'm not changing the accepted answer. Splitting, though more efficient on this test string, isn't going to extract the parts from a whole HTML file. I <em>could</em> combine a regex and splitting but that seems silly.</p>
<p>If you do have a better way to find the parts from a load of HTML (the pattern <code>\d+\[\d+\]</code> is unique to this string in the source), I'll happily change accepted answers. Anything else is academic.</p>
| [
{
"answer_id": 346276,
"author": "stesch",
"author_id": 41860,
"author_profile": "https://Stackoverflow.com/users/41860",
"pm_score": 4,
"selected": true,
"text": "findall"
},
{
"answer_id": 346281,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stac... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12870/"
] |
346,268 | <p>I have data that needs to be executed on a certain background thread. I have code coming from all other threads that need to call into this. does anyone have a good tutorial or best practice on having a queue for synchronization to support this threading requirement</p>
| [
{
"answer_id": 346312,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 1,
"selected": false,
"text": "producer/consumer"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
346,297 | <p>Hi all I've just started a new project using Visual Web Developer 2008 Express and all my code behinds are not in any namespace. How can I set the default namespace for the project?</p>
<p>In VisualStudioPro it used to be in project properties, the website properties in Visual Web Developer 2008 Express seem very ... express.</p>
<p>Thanks,</p>
<p>David.</p>
| [
{
"answer_id": 346493,
"author": "mmx",
"author_id": 33708,
"author_profile": "https://Stackoverflow.com/users/33708",
"pm_score": 3,
"selected": true,
"text": "namespace MyDefaultNamespace {\n // original code\n}\n"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346297",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12148/"
] |
346,306 | <p>I have used a static global variable and a static volatile variable in file scope,
<p> both are updated by an ISR and a main loop and main loop checks the value of the variable. <p>here during optimization neither the global variable nor the volatile variable are optimized. So instead of using a volatile variable a global variable solves the problem.
<p>So is it good to use global variable instead of volatile?
<p>Any specific reason to use static volatile??
<p>Any example program would be appreciable.
<p>Thanks in advance..</p>
| [
{
"answer_id": 346318,
"author": "friol",
"author_id": 23034,
"author_profile": "https://Stackoverflow.com/users/23034",
"pm_score": 4,
"selected": false,
"text": "#define MYPORT 0xDEADB33F\n\nvolatile char *portptr = (char*)MYPORT;\n*portptr = 'A';\n*portptr = 'B';\n"
},
{
"answ... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346306",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31116/"
] |
346,313 | <p>I'm trying to do a JOIN in Linq using lambda expressions ... and running into some problems. </p>
<p>I have two entities, Comments and CommentSources. CommentSources are associated to Comments. I have the following code, which does work:</p>
<pre><code>01 IQueryable<Data.Comment> query = ctx.DataContext.Comments;
02
03
04 if (criteria.IsDeleted == DeletedFilter.Deleted)
05 query = query.Where(row => row.DeletedBy != Guid.Empty);
06 else if (criteria.IsDeleted == DeletedFilter.NotDeleted)
07 query = query.Where(row => row.DeletedBy == Guid.Empty);
08
09 var data = query.Select(row => CommentInfo.FetchCommentInfo(row));
</code></pre>
<p>I need to join CommentSources on Comments on the field, and I would like to use, if possible, something like:</p>
<pre><code>01 query = query.Join(join code goes here)
</code></pre>
<p>How can I do this using lambdas in the expression tree?</p>
<p><strong>One more thing ... how do I add a Where to the Join statement?</strong></p>
<p>Instead of asking another question ... how would I do a Where clause on that Join? For example, I have a field called SourceId on the CommentSource that I would like to filter by.</p>
| [
{
"answer_id": 346346,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 5,
"selected": true,
"text": "query = query.Join(ctx.DataContext.CommentSource,\n comment => comment.CommentSourceId,\n ... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1768/"
] |
346,323 | <p>I'm starting to code up my own window manager, and was wondering how to use the xorg api to get from raw image data ( such as the data given by libpng ), into an Xorg Pixmap or something drawable by Xorg?</p>
| [
{
"answer_id": 6772012,
"author": "Dave",
"author_id": 852548,
"author_profile": "https://Stackoverflow.com/users/852548",
"pm_score": 0,
"selected": false,
"text": "struct Image img = get_pixels_and_geometry_from_libpng(\"filename.png\");\nXImage *img = XCreateImage(/*5000 paremeters*/)... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25893/"
] |
346,345 | <p>I have been hearing that with unit testing we can catch most of the bugs in the code and I really believe that this is true. But my question is in large projects where each class is dependent on many other classes how do you go about unit testing the class ? Stubbing out every other class doesn't make much sense because of both complexity and the time required to write the stubs. What is your opinion about it?</p>
| [
{
"answer_id": 346483,
"author": "Jeffrey Fredrick",
"author_id": 35894,
"author_profile": "https://Stackoverflow.com/users/35894",
"pm_score": 0,
"selected": false,
"text": "public int foo(A a, B b) {\n C c = a.getC();\n D d = b.getD();\n\n Bar bar = calculateBar(c, d);\n\n return c... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39742/"
] |
346,349 | <p>I want to create a program that requests from the user 10 grades and then filters them to pass and fail, then prints the number of passes and fails. I did the program but the output is wrong.</p>
<pre><code>int pass,fail,grade,studentcounter;
pass=0;
fail=0;
grade=0;
studentcounter=10;
while (studentcounter!=0)
{
printf("enter the next grade\n");
scanf("%d",grade);
student--;
}
switch (grade)
{
case 1:
if (grade >= 50)
pass++;
break;
case 2:
if (grade <= 49)
fail++;
break;
}
}
printf("the number of fail is %d",fail);
printf("the number of pass is %d",pass);
}
</code></pre>
<p>The problem is that the program request the ten grades but at the end it will print the number of fail and the number of pass as zero. Why?</p>
| [
{
"answer_id": 346357,
"author": "John T",
"author_id": 36457,
"author_profile": "https://Stackoverflow.com/users/36457",
"pm_score": 3,
"selected": true,
"text": "studentcounter=0;\n\nwhile (studentcounter!=0) {\n\nprintf(\"enter the next grade\\n\");\n\nscanf(\"%d\",grade);\n\nstudent-... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346349",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
346,352 | <p>Can somebody give some clear explanation of the meaning of the SIZE and RSS values we get from prstat in Solaris?</p>
<p>I wrote a testing C++ application that allocates memory with <code>new[]</code>, fills it and frees it with <code>delete[]</code>.</p>
<p>As I understood, the SIZE value should be related to how much virtual memory has been "reserved" by the process, that is memory "malloced" or "newed".</p>
<p>That memory doesn't sum up in the RSS value unless I really use it (filling with some values). But then even if I free the memory, the RSS doesn't drop.</p>
<p>I don't understand what semantic I can correctly assign to those 2 values.</p>
| [
{
"answer_id": 2023651,
"author": "jlliagre",
"author_id": 211665,
"author_profile": "https://Stackoverflow.com/users/211665",
"pm_score": 4,
"selected": true,
"text": "export LD_PRELOAD=libumem.so\nexport UMEM_OPTIONS=backend=mmap\n"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41789/"
] |
346,361 | <p>I'm developing a experimental <strong>Linux Kernel module</strong>, so...</p>
<p>How to <strong>UDP Broadcast</strong> from Linux Kernel?</p>
| [
{
"answer_id": 346727,
"author": "Evan Anderson",
"author_id": 40764,
"author_profile": "https://Stackoverflow.com/users/40764",
"pm_score": 2,
"selected": false,
"text": "lock_sock(sock->sk);\nsock->sk->broadcast = 1;\nrelease_sock(sock->sk);\n"
},
{
"answer_id": 346731,
"au... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1100/"
] |
346,362 | <p>I have several templates that match various nodes in an xml document. If I do just an<br>
<xsl:apply-templates/>
it somehow recursively outputs the text of all the nodes beneath. I just want it to recursively match any template I have defined. How do I do that ? </p>
| [
{
"answer_id": 346396,
"author": "Dirk Vollmar",
"author_id": 40347,
"author_profile": "https://Stackoverflow.com/users/40347",
"pm_score": 2,
"selected": false,
"text": "<xsl:template match=\"* | /\" >\n <xsl:apply-templates mode=\"myMode\" />\n</xsl:template>\n\n<xsl:template match=... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43940/"
] |
346,365 | <p>The following is okay:</p>
<pre><code>try
{
Console.WriteLine("Before");
yield return 1;
Console.WriteLine("After");
}
finally
{
Console.WriteLine("Done");
}
</code></pre>
<p>The <code>finally</code> block runs when the whole thing has finished executing (<code>IEnumerator<T></code> supports <code>IDisposable</code> to provide a way to ensure this even when the enumeration is abandoned before it finishes).</p>
<p>But this is not okay:</p>
<pre><code>try
{
Console.WriteLine("Before");
yield return 1; // error CS1626: Cannot yield a value in the body of a try block with a catch clause
Console.WriteLine("After");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
</code></pre>
<p>Suppose (for the sake of argument) that an exception is thrown by one or other of the <code>WriteLine</code> calls inside the try block. What's the problem with continuing the execution in <code>catch</code> block?</p>
<p>Of course, the yield return part is (currently) unable to throw anything, but why should that stop us from having an enclosing <code>try</code>/<code>catch</code> to deal with exceptions thrown before or after a <code>yield return</code>?</p>
<p><strong>Update:</strong> There's an <a href="https://web.archive.org/web/20080818052536/http://blogs.msdn.com/oldnewthing/archive/2008/08/14/8862242.aspx" rel="noreferrer">interesting comment from Eric Lippert here</a> - seems that they already have enough problems implementing the try/finally behaviour correctly!</p>
<p>EDIT: The MSDN page on this error is: <a href="http://msdn.microsoft.com/en-us/library/cs1x15az.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/cs1x15az.aspx</a>. It doesn't explain why, though.</p>
| [
{
"answer_id": 346434,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 3,
"selected": false,
"text": "yield"
},
{
"answer_id": 346772,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346365",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27423/"
] |
346,372 | <p>I know how I use these terms, but I'm wondering if there are accepted definitions for <strong>faking</strong>, <strong>mocking</strong>, and <strong>stubbing</strong> for unit tests? How do you define these for your tests? Describe situations where you might use each.</p>
<p>Here is how I use them:</p>
<p><strong>Fake</strong>: a class that implements an interface but contains fixed data and no logic. Simply returns "good" or "bad" data depending on the implementation.</p>
<p><strong>Mock</strong>: a class that implements an interface and allows the ability to dynamically set the values to return/exceptions to throw from particular methods and provides the ability to check if particular methods have been called/not called.</p>
<p><strong>Stub</strong>: Like a mock class, except that it doesn't provide the ability to verify that methods have been called/not called.</p>
<p>Mocks and stubs can be hand generated or generated by a mocking framework. Fake classes are generated by hand. I use mocks primarily to verify interactions between my class and dependent classes. I use stubs once I have verified the interactions and am testing alternate paths through my code. I use fake classes primarily to abstract out data dependencies or when mocks/stubs are too tedious to set up each time.</p>
| [
{
"answer_id": 33333064,
"author": "Marjan Venema",
"author_id": 11225,
"author_profile": "https://Stackoverflow.com/users/11225",
"pm_score": 7,
"selected": false,
"text": "const pleaseReturn5 = 5;\nvar fake = new FakeX(pleaseReturn5);\nvar cut = new ClassUnderTest(fake);\n\ncut.SquareI... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12950/"
] |
346,380 | <p>In Ruby you can reference variables inside strings and they are interpolated at runtime. </p>
<p>For example if you declare a variable <code>foo</code> equals <code>"Ted"</code> and you declare a string <code>"Hello, #{foo}"</code> it interpolates to <code>"Hello, Ted"</code>. </p>
<p>I've not been able to figure out how to perform the magic <code>"#{}"</code> interpolation on data read from a file. </p>
<p>In pseudo code it might look something like this:</p>
<pre><code>interpolated_string = File.new('myfile.txt').read.interpolate
</code></pre>
<p>But that last <code>interpolate</code> method doesn't exist.</p>
| [
{
"answer_id": 346413,
"author": "stesch",
"author_id": 41860,
"author_profile": "https://Stackoverflow.com/users/41860",
"pm_score": 5,
"selected": true,
"text": "erb"
},
{
"answer_id": 346432,
"author": "Daniel Lucraft",
"author_id": 11951,
"author_profile": "https:... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4061/"
] |
346,426 | <p>I am having problems using <a href="http://code.google.com/p/django-tagging/" rel="nofollow noreferrer">django-tagging</a>. I try to follow the <a href="http://code.google.com/p/django-tagging/source/browse/trunk/docs/overview.txt" rel="nofollow noreferrer">documentation</a> but it fails at the second step</p>
<blockquote>
<p>Once you've installed Django Tagging and want to use it in your Django applications, do the following:</p>
<ol>
<li>Put <code>'tagging'</code> in your <code>INSTALLED_APPS</code> setting.</li>
<li>Run the command <code>manage.py syncdb</code>.</li>
</ol>
<p>The <code>syncdb</code> command creates the necessary database tables and creates permission objects for all installed apps that need them.</p>
</blockquote>
<p>I get a python Traceback with the following error:</p>
<pre><code>ImportError: cannot import name parse_lookup
</code></pre>
<p>The following works, so I think it is correctly installed:</p>
<pre><code>>> import tagging
>> tagging.VERSION
(0, 2.1000000000000001, None)
</code></pre>
<p>What am I missing?</p>
| [
{
"answer_id": 346441,
"author": "ayaz",
"author_id": 23191,
"author_profile": "https://Stackoverflow.com/users/23191",
"pm_score": 0,
"selected": false,
"text": "In [1]: import tagging; tagging.VERSION\nOut[1]: (0, 3, 'pre')\n"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24946/"
] |
346,445 | <p>I've been banging my head against for wall for a while with this one.</p>
<p>I want to SSH into a set of machines and check whether they are available (accepting connections and not being used). I have created a small script, tssh, which does just that:</p>
<pre><code>#!/bin/bash
host=$1
timeout=${2:-1}
ssh -qo "ConnectTimeout $timeout" $host "[ \`who | cut -f1 | wc -l \` -eq 0 ] && exit 0 || exit 1"
</code></pre>
<p>This script works correctly. Returning 255 if there was a connection problem, 1 if the machine is busy and 0 if everything is good. If anyone knows a better way to do this please let me know.</p>
<p>So next I try and call tssh on my set of machines using a while read loop, and this is where it all goes wrong. The loop exits as soon as tssh returns 0 and never completes the full set. </p>
<pre><code>while read nu ; do tssh "MYBOXES$nu" ; done < <(ruby -e '(0..20).each { |i| puts i }')
</code></pre>
<p>At first I thought this was a subshell problem but apparently not.
Any help, along with comments on style/content, would be much appreciated!
I know I'm going to kick myself when I find out why...</p>
| [
{
"answer_id": 346455,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 3,
"selected": true,
"text": "for nu in `ruby -e '(0..20).each { |i| puts i}'`; do\n tssh \"MYBOXES$nu\" \ndone\n"
},
{
"answer_id": 346473,
... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
346,446 | <p>I've inherited a database that has a structure with a table of products, a table consisting of some product attributes and another table to build the relationship between these attributes and a given product.</p>
<p>A user can filter the products by a combination of these attributes, meaning that if more than one attribute is selected only products with all those attributes are returned. Unfortunately, there is now an exception to this rule, whereby a user selecting one of two specific attributes needs results containing either (or both).</p>
<p>The query currently looks like this (not my code):</p>
<pre><code>SELECT DISTINCT p.* FROM products AS p
INNER JOIN attributes a ON p.product_id=a.property_id
WHERE a.attribute_id IN (1,3,7)
GROUP BY p.property_id
HAVING COUNT(DISTINCT a.attribute_id) = 3
</code></pre>
<p>I doubt the above is a particularly efficient way of retrieving the required products, but I'm unsure how to proceed in light of the new requirement.</p>
<p>I've now created some php code to construct a special query when the two "special" attributes (3 and 7) are selected:</p>
<pre><code>SELECT DISTINCT p.* FROM products AS p
INNER JOIN attributes a ON p.product_id=a.property_id
WHERE a.attribute_id IN (1,3) OR a.attribute_id IN (1,7)
GROUP BY p.property_id
HAVING COUNT(DISTINCT a.attribute_id) = 2
</code></pre>
<p>However, this still does not work as required - any products that share both these attributes are not returned in the result (this is obviously due to the HAVING COUNT clause, but I don't know how I go about fixing it. For clarity, the issue is if 10 products have only attribute 3 but a further five have attributes 3 and 7, the above query will only return the 10 records. </p>
<p>Might it be possible to use some kind of subquery or what alternatives are there?</p>
| [
{
"answer_id": 346527,
"author": "ʞɔıu",
"author_id": 41613,
"author_profile": "https://Stackoverflow.com/users/41613",
"pm_score": 1,
"selected": false,
"text": "SELECT ... FROM products AS p \nINNER JOIN attributes a1 ON p.product_id=a1.property_id AND a1.attribute_id=1\nINNER JOIN att... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29538/"
] |
346,449 | <p>I'm looking for a free templating engine to generate simple reports. I want some basic features such as :</p>
<ul>
<li>Ability to Write Loops (with any IEnumerable)</li>
<li>Passing Variables</li>
<li>Passing Templates Files (main template, footer, header)</li>
</ul>
<p>I'll use this to generate reports in HTML and XML. I'm not looking for a ASP.NET Template Engine.</p>
<p>This is for a WinForms applications.</p>
<p>I've seen this question <a href="https://stackoverflow.com/questions/340095/can-you-recommend-a-net-template-engine">Can you recommend a .net template engine?</a>, however all of those template engines are total overkill for me and focused for ASP.NET.</p>
<p>Please only recommend free libraries.</p>
<p>// I'm still looking an NVelocity but it doesn't look any promising for .NET, overly complicated, when you download it's bunch of files not clear what to do, no tutorial, startup document etc.</p>
| [
{
"answer_id": 346520,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 3,
"selected": true,
"text": "<html>\n <head>\n <title>My Report</title>\n </head>\n <body>\n <% foreach (ReportRow r in ReportData... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40322/"
] |
346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm happy adding a formatted field in my model.</p>
| [
{
"answer_id": 346476,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 2,
"selected": false,
"text": "def format_price(self):\n import locale\n locale.setlocale(locale.LC_ALL, '')\n return locale.format('%d', self.price... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12870/"
] |
346,499 | <p>I want to store a string in memory and read it later:</p>
<pre><code>$$->desc.constant->base.id = (char*)malloc(200);
sprintf($$->desc.constant->base.id, "%f", $1);
printf("->%s\n", $$->desc.constant->base.id); //LINE A
printf("->%i\n", $$->desc.constant); //LINE B
//SOME OTHER CODE
//Then, later on in a function call:
printf("%i", expr->desc.constant); // LINE D
printf("%s", expr->desc.constant->base.id); // LINE C
</code></pre>
<p>Although Line B and Line D show the same address, the printf in Line C fails with a Segmentation fault. What am I missing?</p>
<p>Any help would really be appreciated!</p>
| [
{
"answer_id": 346507,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": true,
"text": "printf(\"->%i\\n\", $$->desc.constant); //LINE B\n"
},
{
"answer_id": 346560,
"author": "1800 IN... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43960/"
] |
346,506 | <p>We use a modified version of the IE engine (the COM version in a C# wrapper) to display a lot of the formatted content in our application. The problem, however, is you don't have a lot of control of any printout of such documents. For example, you can't force a color printout without accessing the registry or directing the user to their Internet Explorer options. So, we've been investigating the new WPF WebBrowser control, which might better suit our purposes.</p>
<p>The problem is (other than Microsoft called it the same name as the Windows Forms version of the control making Google searches less useful than I like) I can't seem to find any good guidelines on how to print the contents of the control. The Document returned from the object isn't paginated, making it hard to use with the PrintDialog. Similar, sending the Visual to PrintDialog doesn't seem like a good idea. Sizing the control properly in this context seems dubious, particularly when you consider paging. </p>
<p>There has to be some good documentation on this somewhere. Can someone direct me to it or provide a good suggestion on how to do this?</p>
| [
{
"answer_id": 346521,
"author": "mackenir",
"author_id": 25457,
"author_profile": "https://Stackoverflow.com/users/25457",
"pm_score": 1,
"selected": false,
"text": "ActiveXHost"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346506",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7357/"
] |
346,512 | <p>On AS400 in interactive SQL in a 5250 session,</p>
<pre><code>select * from myfile
</code></pre>
<p>returns rows from one member only when myfile has more than one member.</p>
<p>How can I get rows from a specific member?</p>
<p>Important: in the end I'd like to do this over JDBC with jt400 so really I want a solution that'll work there.</p>
<p>Thanks.</p>
| [
{
"answer_id": 435704,
"author": "Ryan Guill",
"author_id": 7186,
"author_profile": "https://Stackoverflow.com/users/7186",
"pm_score": 5,
"selected": false,
"text": "CREATE ALIAS myLibrary/myAlias FOR memberLibrary/memberFile(memberName)\n"
},
{
"answer_id": 17396146,
"autho... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29574/"
] |
346,516 | <p>I am trying to add a link into the pop-up text bubble of a marker in Google Maps through the API. I have successfully run the below code:</p>
<pre><code>echo '<marker lat="43.91892" lng="-78.89231" html="Albertus Magnus College&lt;br&gt;Link to Admissions" label="Albertus Magnus College" />';
</code></pre>
<p>But once I actually try to add the link it fails. Like this:</p>
<pre><code>echo '<marker lat="43.91892" lng="-78.89231" html="Albertus Magnus College&lt;br&gt;&lt;a href='http://www.albertus.edu/admission/index.shtml'&gt;Admissions&lt;\/a&gt;" label="Albertus Magnus College" />';
</code></pre>
<p>Does anyone know how to successfully write this code? I am writing it into PHP because I have some other functionality that won't let me just write it in XML.</p>
<p>Update: I got it to work like this for some reason...</p>
<pre><code>$window2a_url = '&lt;a href=&apos;http://www.albertus.edu/admission/index.shtml&apos;&gt;Admissions';
echo '<marker lat="41.331304" lng="-72.921438" html=" Albertus Magnus College&lt;br&gt;';
echo $window2a_url;
echo '" label="Albertus Magnus College" />';
</code></pre>
<p>I had to escape the apostrophes... If anyone has a more elegant solution, I am all ears!</p>
| [
{
"answer_id": 346564,
"author": "benlumley",
"author_id": 39161,
"author_profile": "https://Stackoverflow.com/users/39161",
"pm_score": 0,
"selected": false,
"text": "echo '<marker lat=\"43.91892\" lng=\"-78.89231\" html=\"Albertus Magnus College<br><a href=\\'http://www.albert... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33194/"
] |
346,523 | <p>I have an expression tree I have created by parsing an Xml using the expression class in C#. <a href="https://stackoverflow.com/questions/344741/how-do-i-create-an-expression-tree-by-parsing-xml-in-c">See this question</a>.</p>
<p>I only have Add, Subtract, Divide, Multiply, Parameters, And and Or in my Expression Tree.
Is there a way to convert this ExpressionTree into a callable method?
...or do I have to emit the IL manually?</p>
<p>Kind regards,</p>
| [
{
"answer_id": 346532,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": false,
"text": "var lambda = Expression.Lambda<Func<float,int>>(body, param);\nFunc<float,int> method = lambda.Compile();\nint v = me... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21586/"
] |
346,531 | <p>I'm migrating my WordPress blog and phpBB Forum into a new hosting server. I am using phpMyAdmin to import the SQL script from the database in the previous site. </p>
<p>When I open the .sql script with Kate, it says it uses UTF8 as encoding. When I import the sql in the new server, I have the option in phpMyAdmin to choose the encoding, where utf8 is selected by default.</p>
<p>Still, when I finish importing the database, I read the posts text directly in phpMyAdmin, and see characters such as "é", "ñ", etc. which haven't been "interpreted" and been replaced with weird characters insted.</p>
<p>I can see my WordPress installation is not working also. Apparently there's a problem with this encoding thing, but I think the problem is in the MySQL database or phpMyAdmin and not WordPress.</p>
<p>The versions of MySQL are practically the same, MySQL 5, but a different revision. Also, there was no problem when migrating the forum database, so this is even stranger...</p>
<p>I'm lost as to how to fix this... Any ideas are welcome.</p>
| [
{
"answer_id": 346552,
"author": "markus",
"author_id": 11995,
"author_profile": "https://Stackoverflow.com/users/11995",
"pm_score": 4,
"selected": true,
"text": "SET NAMES 'utf8';\n"
},
{
"answer_id": 346715,
"author": "Fernando Briano",
"author_id": 1492,
"author_p... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1492/"
] |
346,536 | <p>Is there any good example to give the difference between a <code>struct</code> and a <code>union</code>?
Basically I know that <code>struct</code> uses all the memory of its member and <code>union</code> uses the largest members memory space. Is there any other OS level difference? </p>
| [
{
"answer_id": 346541,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 11,
"selected": true,
"text": "union foo {\n int a; // can't use both a and b at once\n char b;\n} foo;\n\nstruct bar {\n int a; // can use both a... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35416/"
] |
346,542 | <p>Thanks for reading this</p>
<p>I thought I could use find(), but couldn't make it work. I know I can add IDs or classnames, but would like to know how with the current markup.</p>
<p>Thanks</p>
<p>Here is the HTML</p>
<pre><code><input name="keywordCheckbox" type="checkbox" value="S" />
<input name="keywordCheckbox" type="checkbox" value="C" />
<input name="keywordCheckbox" type="checkbox" value="A" />
</code></pre>
<p>and the js</p>
<pre><code><script language="Javascript" src="javascript/jquery-1.2.6.min.js"></script>
<script type="text/JavaScript">
$(function(){
$('[name="keywordCheckbox"]').bind("click",
function() {
if($(this).attr("checked") == true) {
switch(this.value) {
case "A":
var $_this = $(this) ;
$('[name="keywordCheckbox"]').each(function() {
if($(this).val() != $($_this).val()) { $(this).attr("checked",false); }
});
break ;
default:
DOESN'T WORK --> $('[name="keywordCheckbox"]').find('[value="A"]').attr("checked", false);}
} // END Switch
} // END If
}); // End BIND
}); // End eventlistener
</script>
</code></pre>
| [
{
"answer_id": 346556,
"author": "Pim Jager",
"author_id": 35197,
"author_profile": "https://Stackoverflow.com/users/35197",
"pm_score": 3,
"selected": false,
"text": "$(\"input[name='keywordCheckbox']\").filter(\"input[value='A']\")\n"
},
{
"answer_id": 346558,
"author": "tv... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2755/"
] |
346,544 | <p>I have a remote JS that must appear in the head of the document. If the server is slow to respond or inaccessible, obviously this slows or prevents the page from loading. I have been searching for a simple way to set a limit of say 3 seconds (probably less) for it to give up and simply not load the functionality.</p>
<p>Does anyone have a simple way to do this with Javascript only?</p>
| [
{
"answer_id": 346561,
"author": "Pim Jager",
"author_id": 35197,
"author_profile": "https://Stackoverflow.com/users/35197",
"pm_score": 2,
"selected": false,
"text": "<script type='text/javascript'>\nwindow.onload = function(){\n document.write(\"<script type='text/javascript' src='http... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43962/"
] |
346,546 | <p>Not sure exactly how to word this question ... so edits are welcomed! Anyway ... here goes.</p>
<p>I am currently use Crystal Reports to generated Pdfs and just stream the output to the user. My code looks like the following:</p>
<pre><code>System.IO.MemoryStream stream = new System.IO.MemoryStream();
stream = (System.IO.MemoryStream)this.Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
this.Response.Clear();
this.Response.Buffer = true;
this.Response.ContentType = "application/pdf";
this.Response.BinaryWrite(stream.ToArray());
this.Response.End();
</code></pre>
<p>After this code runs it streams the Pdf to the browser opening up Acrobat Reader. Works great! </p>
<p>My problem is when the user tries to save the file it defaults to the actual file name ... in this case it defaults to CrystalReportPage.pdf. Is there anyway I can set this? If so, how? </p>
<p>Any help would be appreciated.</p>
| [
{
"answer_id": 346550,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": true,
"text": "Content-Disposition: inline; filename=foo.pdf\n"
},
{
"answer_id": 346554,
"author": "mmx",
"author_id... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1768/"
] |
346,567 | <p>Given a document written with normal quotes, e.g.</p>
<pre><code>Ben said "buttons, dear sir".
I replied "Did you say 'buttons'?" to him.
</code></pre>
<p>What ways can one turn these sort of things into LaTeX quotes, with the appropriate semantics. i.e.</p>
<pre><code>Ben said ``buttons, dear sir''.
I replied ``Did you say `buttons'?'' to him.
</code></pre>
<p>So that LaTeX produces:</p>
<pre><code>Ben said “buttons, dear sir”.
I replied “Did you say ‘buttons’?”
</code></pre>
<p>My first thought is to turn to a regex. However, I'm not getting any hits from Google or the regex libraries for "LaTeX quotes regular expression", and of course "TeX quotes regular expression" seems to return too many.</p>
<p>Thank you.</p>
| [
{
"answer_id": 346606,
"author": "dmckee --- ex-moderator kitten",
"author_id": 2509,
"author_profile": "https://Stackoverflow.com/users/2509",
"pm_score": 4,
"selected": true,
"text": "\"'\""
},
{
"answer_id": 346607,
"author": "John D. Cook",
"author_id": 25188,
"au... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19212/"
] |
346,568 | <p>On my blog, I want to display the all the posts from the last month. But if that is less than 10 posts, I want to show the ten most recent posts (in other words, there should never be less than 10 posts on the front page). I am wondering if there is a way to do this in a single query?</p>
<p>Currently, I first run this query:</p>
<pre><code>select count(*) from posts where timestamp > ($thirty_days_ago)
order by timestamp desc
</code></pre>
<p>If that count is greater than or equal to 10:</p>
<pre><code>select * from posts where timestamp > ($thirty_days_ago)
order by timestamp desc
</code></pre>
<p>Otherwise:</p>
<pre><code>select * from posts order by timestamp desc limit 10
</code></pre>
<p>But this requires me to run two queries. Is there a more efficient way to do this with a single query? (I'm using MySQL.)</p>
| [
{
"answer_id": 346584,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 3,
"selected": false,
"text": "(SELECT * FROM posts\nWHERE `timestamp` >= NOW() - INTERVAL 30 DAY)\nUNION\n(SELECT * FROM posts\nORDER BY `timestamp`... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346568",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18511/"
] |
346,572 | <p>We are developing a port of the GNU Assembler for a client architecture.
Now the problem being faced is that:</p>
<p>If an immediate operand to an instruction is an expression involving more than one relocatable symbols, how is it handled in output file in elf format. What will be the relocation information produced in such a case?</p>
<p>For example:</p>
<pre><code>j label1 + label2
</code></pre>
<p>where label1 and label2 are defined in relocatable sections, they might be the same sections or different relocatable sections.</p>
| [
{
"answer_id": 346652,
"author": "BCS",
"author_id": 1343,
"author_profile": "https://Stackoverflow.com/users/1343",
"pm_score": 0,
"selected": false,
"text": "j"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35416/"
] |
346,581 | <p>How can I create a empty .mdb file? I'm using ADO.NET and C#. Thanks!</p>
| [
{
"answer_id": 346614,
"author": "MatthewMartin",
"author_id": 33264,
"author_profile": "https://Stackoverflow.com/users/33264",
"pm_score": 4,
"selected": true,
"text": "COPY model.mdb newdb.mdb"
},
{
"answer_id": 346640,
"author": "Tomalak",
"author_id": 18771,
"aut... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346581",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12243/"
] |
346,589 | <p>I am writing an application in C# which is going to do extensive calculations. Everything is going around basic struct - Value. It is basically double with some additional parameters (accuracy etc.)
It has to be a struct, because there will be too many of them created to afford heap allocation.
Now, I need to make sure they all are correctly initialized.
I cannot declare default explicit constructor, though I am provided default constructor, which initializes everything with 0, which does not make sense in my domain.</p>
<p>And there is no way to deny creating an instance without calling my constructor with parameters either...?</p>
<p>Basically what I need is this test to pass:</p>
<pre><code>[Test]
public void HowDoesThisStructureInitializeByDefault()
{
Value v = new Value(); - if this did not compile - it would have been ok!
Assert.AreEqual(0, v.Val); - passes
Assert.AreEqual(-1, v.Accuracy); - fails
}
</code></pre>
<p>It would be OK to throw an exception if no constructor has been explicitly called and structure is still accessed, but checking that all the time would take too much time.</p>
<p>I am almost losing hope now, please help!</p>
| [
{
"answer_id": 346608,
"author": "Aaron",
"author_id": 31304,
"author_profile": "https://Stackoverflow.com/users/31304",
"pm_score": 0,
"selected": false,
"text": "new Value()"
},
{
"answer_id": 346618,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "ht... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346589",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38325/"
] |
346,594 | <p>I have a client application that once in while notifies about its progress a service.
The method call to the service is marked with IsOneWay=true, because the notification doesn't need any return value and I don't want to delay.</p>
<p>The client may notify about errors to the service, and afterward it terminates.</p>
<p>The question is: does a oneway method call returns to the caller code after it sent the message? or it queues the message and later on it is sent by another thread?</p>
<p>The two processes (the client and the service) are on the same machine, and I noticed that sometimes (when the machine is overloaded) the service doesn't get the error notification. I suspect that the second option I mentioned happens, but I am not sure.</p>
<p>If I am right, how can I make sure the notification is send and keep the method oneway?</p>
| [
{
"answer_id": 8995014,
"author": "Artur A",
"author_id": 304371,
"author_profile": "https://Stackoverflow.com/users/304371",
"pm_score": 3,
"selected": false,
"text": " [ServiceContract]\n public interface IService1\n {\n [OperationContract]\n void ThrowException(... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
346,613 | <p>How can you prematurely exit from a function without returning a value if it is a void function? I have a void method that needs to not execute its code if a certain condition is true. I really don't want to have to change the method to actually return a value.</p>
| [
{
"answer_id": 346616,
"author": "mmx",
"author_id": 33708,
"author_profile": "https://Stackoverflow.com/users/33708",
"pm_score": 9,
"selected": true,
"text": "return;\n"
},
{
"answer_id": 346619,
"author": "jwfearn",
"author_id": 10559,
"author_profile": "https://St... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346613",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43875/"
] |
346,622 | <p>I'm curious about conventions for type-punning pointers/arrays in C++. Here's the use case I have at the moment:</p>
<blockquote>
Compute a simple 32-bit checksum over a binary blob of data by treating it as an array of 32-bit integers (we know its total length is a multiple of 4), and then summing up all values and ignoring overflow.
</blockquote>
<p>I would expect such an function to look like this:</p>
<pre><code>uint32_t compute_checksum(const char *data, size_t size)
{
const uint32_t *udata = /* ??? */;
uint32_t checksum = 0;
for (size_t i = 0; i != size / 4; ++i)
checksum += udata[i];
return udata;
}
</code></pre>
<p>Now the question I have is, what do you consider the "best" way to convert <code>data</code> to <code>udata</code>?</p>
<p>C-style cast?</p>
<pre><code>udata = (const uint32_t *)data
</code></pre>
<p>C++ cast that assumes all pointers are convertible?</p>
<pre><code>udata = reinterpret_cast<const uint32_t *>(data)
</code></pre>
<p>C++ cast that between arbitrary pointer types using intermediate <code>void*</code>?</p>
<pre><code>udata = static_cast<const uint32_t *>(static_cast<const void *>(data))
</code></pre>
<p>Cast through a union?</p>
<pre><code>union {
const uint32_t *udata;
const char *cdata;
};
cdata = data;
// now use udata
</code></pre>
<p>I fully realize that this will not be a 100% portable solution, but I am only expecting to use it on a small set of platforms where I know it works (namely unaligned memory accesses and compiler assumptions on pointer aliasing). What would you recommend?</p>
| [
{
"answer_id": 346764,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 5,
"selected": true,
"text": "const char *data"
},
{
"answer_id": 347585,
"author": "Steve Jessop",
"author_id": 13005,
"author... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346622",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40620/"
] |
346,644 | <p>The following code will generate a link to the page I want to get to.</p>
<pre><code><%= Html.ActionLink(image.Title, image.Id.ToString(), "Image") %>
</code></pre>
<p>The following code will cause the correct url to be rendered on the page.</p>
<pre><code><%= Url.Action("Index", "Image", new { id = image.Id })%>
</code></pre>
<p>But when I try to use it in javascript it fails. (with some strange error about page inheritance)</p>
<pre><code><div onclick="window.location = '<%= Url.Action("Index", "Image", new { id = image.Id })%>'">
...
</div>
</code></pre>
<p>Should the above code work? What is the correct way to generate the javascript attempted above?</p>
<p><strong>Update</strong> There error I get is </p>
<blockquote>
<p>Views\Home\Index.aspx.cs(9): error
ASPNET: Make sure that the class
defined in this code file matches the
'inherits' attribute, and that it
extends the correct base class (e.g.
Page or UserControl).</p>
</blockquote>
<p>Looks like it indicates a bigger problem.</p>
<p><strong>Fixed</strong> Thanks for your help, the code contained a div with <code>runat="server"</code>. When I removed this it runs OK. This maybe because there is no form with <code>runat="server"</code> but I would expect a different error for that.</p>
<p><strong>As this question doesn't seem meaningful should I delete it?</strong></p>
| [
{
"answer_id": 346771,
"author": "Todd Smith",
"author_id": 31624,
"author_profile": "https://Stackoverflow.com/users/31624",
"pm_score": 0,
"selected": false,
"text": "<%= Url.Action(\"Image\", \"Home\", new { id = image.Id })%>\n"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18107/"
] |
346,649 | <p>I have two constructor :</p>
<pre><code>function clsUsagerEmailUserName($nickName, $email)
{
$this->nickName = $nickName;
$this->email = $email;
}
function clsUsagerEmailUserName($email)
{
$this->email = $email;
}
</code></pre>
<p>But this is not working? What's wrong, isn't supposed to be OO at this version of PHP? (I just migrate from PHP4)</p>
| [
{
"answer_id": 346651,
"author": "Patrick Desjardins",
"author_id": 13913,
"author_profile": "https://Stackoverflow.com/users/13913",
"pm_score": 3,
"selected": true,
"text": "function __construct ($var1, $var2 = null)\n{\n if (isset($var2))\n {\n //Do one thing\n }\n else\n... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21386/"
] |
346,659 | <p>All of us who work with relational databases have learned (or are learning) that SQL is different. Eliciting the desired results, and doing so efficiently, involves a tedious process partly characterized by learning unfamiliar paradigms, and finding out that some of our most familiar programming patterns don't work here. What are the common antipatterns you've seen (or yourself committed)?</p>
| [
{
"answer_id": 346679,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 7,
"selected": false,
"text": "SELECT *\nInsert Into blah SELECT *\n"
},
{
"answer_id": 346687,
"author": "Tony Andrews",
"author_id": 18747,... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31641/"
] |
346,692 | <p>I have written a very simple bash script to help me migrate from dev to staging. What it does is it deletes all files in staging, copies the files over from dev to stage.</p>
<p>However, the config.inc.php file needs to have the first instance of "dev" to be changed to "stage", and no other instance changed.</p>
<p>Second, everytime I run it (I run the script from the dev directory), i'd like it to write a log back in the dev directory which will append the date/time stamp that I ran the staging bash script into this log.</p>
<p>Thanks.</p>
| [
{
"answer_id": 346699,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 0,
"selected": false,
"text": "sed"
},
{
"answer_id": 346704,
"author": "friol",
"author_id": 23034,
"author_profile": "https://... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43980/"
] |
346,702 | <p>I'm using the urlrewriter.net as recommended in several questions in here.
I'm having difficulties with displaying images and with the stylesheet.</p>
<p>I read ScottGu's Blog (again as recommended in here) and in the end he does reffer to this problem and states to use ~/ for server controls etc. ("Handling CSS and Image Reference Correctly" at the end of the article).</p>
<p>I tried his solution and it doesn't seem to work.</p>
<p>The only thing that seems to work for me is to write the full path. For some reason, it doesn't seem to me as the right solution. It would make a serious problem developing and debugging.</p>
<p>Does anyone know what can be the cause of the problem?
Is there something I need to change in the web.config file?</p>
<p>Thanks</p>
| [
{
"answer_id": 348010,
"author": "Jamie",
"author_id": 24559,
"author_profile": "https://Stackoverflow.com/users/24559",
"pm_score": 0,
"selected": false,
"text": "<base href=\"http://www.w3schools.com/images/\" />\n"
},
{
"answer_id": 371786,
"author": "user46702",
"auth... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
346,703 | <p>Is there a compelling reason to not use <a href="http://us2.php.net/debug_backtrace" rel="noreferrer"><code>debug_backtrace</code></a> for the sole purpose of determining the calling method's class, name, and parameter list? Not for debugging purposes. It has the word "debug" in the function name, which makes me feel a little dirty to be using it in this way, but it fit the bill for what I needed to do (a single function that can be called from many places and needs to call the calling method from another system). It works, but is this still a bad idea? If so, why?</p>
| [
{
"answer_id": 2962151,
"author": "Jauzsika",
"author_id": 253377,
"author_profile": "https://Stackoverflow.com/users/253377",
"pm_score": 0,
"selected": false,
"text": "/*Called from /var/www/micimacko.php at line 28*/ SELECT count(*) FROM rofibeka;\n"
},
{
"answer_id": 34075506... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43496/"
] |
346,708 | <p>I'm trying to do project Euler number <a href="http://projecteuler.net/index.php?section=problems&id=219" rel="nofollow noreferrer">219</a> but am failing to get a grasp of it. I'm trying to use Python which according to project Euler should be able to do it within a minute! This leads me to think that they can't possibly want me to compute each individual bitstring since that would be too slow in Python - there has to be a sub O(n) algorithm.</p>
<p>I have looked at a recursive solution which stores the bitstrings possible prefixes so that it can quickly pick a new bitstring and it even considers them in groups. This only works in brute-forcing values up to a bit over 10:</p>
<pre><code>cost(1) = 1
cost(2) = 5
cost(3) = 11
cost(4) = 18
cost(5) = 26
cost(6) = 35
cost(7) = 44
cost(8) = 54
cost(9) = 64
cost(10)= 74
cost(11)= 85
cost(12)= 96
</code></pre>
<p>Past this, I am struggling to comprehend how reduce the problem. It is always possible to make a pattern that goes like:</p>
<pre><code>1
01
001
0001
00001
00000
</code></pre>
<p>But it isn't optimal for more than 7 bitstrings. Can anyone guide me in what I should be considering?</p>
| [
{
"answer_id": 346758,
"author": "mattiast",
"author_id": 8272,
"author_profile": "https://Stackoverflow.com/users/8272",
"pm_score": 0,
"selected": false,
"text": "Cost(n) = min {Cost(k)+Cost(n-k)+k+4*(n-k) | 0 < k < n}"
},
{
"answer_id": 346945,
"author": "Community",
"... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
346,718 | <p>I am trying to make a combined image of all images added to a modell in django with inline editing and a ForeignKey. Ive got these models (simplified):</p>
<pre><code>class Modell(models.Model):
title = models.CharField('beskrivelse', max_length=200)
slug = models.SlugField()
is_public = models.BooleanField('publisert', default=True)
def __unicode__(self):
return self.title
def save(self, **kwargs):
super(Modell, self).save(**kwargs)
on_modell_saved(self)
class Image(models.Model):
modell = models.ForeignKey(Modell, related_name="images")
image = ThumbnailImageField('bilde', upload_to=get_upload_path_image)
class Meta:
verbose_name = 'bilde'
verbose_name_plural = 'bilder'
def __unicode__(self):
return str(self.image)
</code></pre>
<p>Then i add Image to the Modell with AdminInline, so when i save the Modell i save x number of images.</p>
<p>But when I try to do something with Modell.images.all in the on_modell_saved function i cant get hold of the objects. Ive got this function that is executed at Modell.save()</p>
<pre><code>def on_modell_saved(instance):
for img in instance.images.all():
print img
</code></pre>
<p>This only prints something the second time i save the Modell and not the first time. So anybody know how to call a function after all items that you are adding with AdminInline is saved?</p>
| [
{
"answer_id": 346763,
"author": "Daniel Naab",
"author_id": 32638,
"author_profile": "https://Stackoverflow.com/users/32638",
"pm_score": 1,
"selected": false,
"text": "Modell"
},
{
"answer_id": 346862,
"author": "muhuk",
"author_id": 42188,
"author_profile": "https:... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346718",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42546/"
] |
346,721 | <p>Would a LINQ for java be a useful tool? I have been working on a tool that will allow a Java object to map to a row in a database. </p>
<ol>
<li>Would this be useful for Java
programmers? </li>
<li>What features would be
useful?</li>
</ol>
| [
{
"answer_id": 1713619,
"author": "Stephen",
"author_id": 37193,
"author_profile": "https://Stackoverflow.com/users/37193",
"pm_score": 4,
"selected": false,
"text": "List(\"Paris\",\"Berlin\",\"London\",\"Tokyo\")\n .filter(c => c.endsWith(\"n\"))\n .map(c => c.length) \n// result wou... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17712/"
] |
346,723 | <p>Say I only needed to use findall() from the re module, is it more efficient to do:</p>
<pre><code>from re import findall
</code></pre>
<p>or </p>
<pre><code>import re
</code></pre>
<p>Is there actually any difference in speed/memory usage etc?</p>
| [
{
"answer_id": 346753,
"author": "Kozyarchuk",
"author_id": 52490,
"author_profile": "https://Stackoverflow.com/users/52490",
"pm_score": 5,
"selected": true,
"text": "re.findall() \n"
},
{
"answer_id": 346967,
"author": "Noah",
"author_id": 28035,
"author_profile": "... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32933/"
] |
346,730 | <p>I want to change member of structure under double pointer. Do you know how?</p>
<p>Example code</p>
<pre><code>typedef struct {
int member;
} Ttype;
void changeMember(Ttype **foo) {
//I don`t know how to do it
//maybe
*foo->member = 1;
}
</code></pre>
| [
{
"answer_id": 346739,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 6,
"selected": true,
"text": "(*foo)->member = 1;\n"
},
{
"answer_id": 346740,
"author": "Konrad Rudolph",
"author_id": 1968,
"autho... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43975/"
] |
346,750 | <p>I'm creating a plugin to a software that skins the form I created. However, the button are not skin based on them and a standard gray button is shown. Asking on the software forum pointed me that .NET forms control are owner-draw and therefor my button won't redraw with the correct style instead of creating a non ownerdraw button.</p>
<p>All controls in the system.windows.forms namespace seem to be ownerdraw.</p>
<p>So how can I create a standar C++ PUSHBUTTON in .NET?</p>
<p>Currently codding in C# if that helps.</p>
<p>Thx</p>
| [
{
"answer_id": 349596,
"author": "P Daddy",
"author_id": 36388,
"author_profile": "https://Stackoverflow.com/users/36388",
"pm_score": 1,
"selected": false,
"text": "FlatStyle"
},
{
"answer_id": 350155,
"author": "Pondidum",
"author_id": 1500,
"author_profile": "https... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346750",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
346,757 | <p>I need to implement a spell checker in C. Basically, I need all the standard operations... I need to be able to spell check a block of text, make word suggestions and dynamically add new words to the index.</p>
<p>I'd kind of like to write this myself, tho I really don't know where to begin.</p>
| [
{
"answer_id": 346818,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 5,
"selected": false,
"text": "*"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3886/"
] |
346,760 | <p>I want to find (not generate) 2 text strings such that, after removing all non letters and ucasing, one string can be translated to the other by simple substitution.</p>
<p>The motivation for this comes from a project I known of that is testing methods for attacking cyphers via probability distributions. I'd like to find a large, coherent plain text that, once encrypted with a simple substitution cypher, can be decrypted to something else that is also coherent.</p>
<p>This ends up as 2 parts, find the longest such strings in a corpus, and get that corpus.</p>
<hr>
<p>The first part seems to me to be amiable to some sort of attack with a B-tree keyed off the string after a substitution that makes the sequence of first occurrences sequential.</p>
<pre><code>HELLOWORLDTHISISIT
1233454637819a9b98
</code></pre>
<p>A little optimization based on knowing the maximum value and length of the string based on each depth of the tree and the rest is just coding.</p>
<hr>
<p>The Other part would be quite a bit more involved; how to generate a large corpus of text to search? some kind of internet spider would seem to be the ideal approach as it would have access to the largest amount of text but how to strip it to just the text?</p>
<p>The question is; Any ideas on how to do this better?</p>
<hr>
<p>Edit: the cipher that was being used is an insanely basic 26 letter substitution cipher.</p>
<p>p.s. this is more a thought experiment then a probable real project for me. </p>
| [
{
"answer_id": 348462,
"author": "Darius Bacon",
"author_id": 27024,
"author_profile": "https://Stackoverflow.com/users/27024",
"pm_score": 2,
"selected": true,
"text": ">>> math.log(factorial(26), 2)\n88.381953327016262\n"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] |
346,762 | <p>In the constructor of my class, I map the current object (<em>this</em>), along with its key (a string entered as a parameter in the constructor) into a static LinkedHashMap so I can reference the object by the string anywhere I might need it later.</p>
<p>Here's the code (if it helps):</p>
<pre><code>public class DataEntry {
/** Internal global list of DataEntry objects. */
private static LinkedHashMap _INTERNAL_LIST;
/** The data entry's name. */
private String NAME;
/** The value this data entry represents. */
private Object VALUE;
/** Defines a DataEntry object with a name and a value. */
public DataEntry( String name, Object value )
{
if( _INTERNAL_LIST == null )
{
_INTERNAL_LIST = new LinkedHashMap();
}
_INTERNAL_LIST.put( name, this );
NAME = name;
VALUE = value;
}
}
</code></pre>
<p>The problem? Instances of this class won't get garbage collected when I'm done using them.</p>
<p>I'm just curious if there's a way to have instances of this class clean themselves up when I'm done using them without having to manually call a Remove() method or something each time (to remove its reference in the internal LinkedHashMap when I'm no longer using them, I mean).</p>
| [
{
"answer_id": 346872,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 4,
"selected": true,
"text": "public static DataEntry getEntry(String name) {\n return _INTERNAL_LIST.get(name);\n}\n"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19825/"
] |
346,770 | <p>Some issues with timezones in PHP have been in the back of my mind for a while now, and I was wondering if there are better ways to handle it than what I'm currently doing.</p>
<p>All of the issues revolve around reformating database stored dates:</p>
<p>When dealing with a site that has to support multiple timezones (for users), to normalize the timezone offest of stored timestamps I always store it with the server timezone using the <code>CURRENT_TIMESTAMP</code> attribute or the <code>NOW()</code> function. </p>
<p>This way I don't have to consider what timezone was set for PHP when the timestamp was entered (since PHP time functions are timezone aware). For each user, according to his preference I set the timezone somewhere in my bootstrap file using:</p>
<pre><code>date_default_timezone_set($timezone);
</code></pre>
<p>When I'm looking to format dates with the php <code>date()</code> function, some form of conversion has to take place since MySQL currently stores timestamp in the format <code>Y-m-d H:i:s</code>. With no regard to timezone, you could simply run:</p>
<pre><code>$date = date($format,strtotime($dbTimestamp));
</code></pre>
<p>The problem with this is that <code>date()</code> and <code>strtotime()</code> are both timezone aware functions, meaning that if the PHP timezone is set differently from the server timezone, the timezone offset will apply twice (instead of once as we would like).</p>
<p>To deal with this, I usually retrieve MySQL timestamps using the <code>UNIX_TIMESTAMP()</code> function which is not timezone aware, allowing my to apply <code>date()</code> directly on it - thereby applying the timezone offset only once.</p>
<p>I don't really like this 'hack' as I can no longer retrieve those columns as I normally would, or use <code>*</code> to fetch all columns (sometimes it simplifies queries greatly). Also, sometimes it's simply not an option to use <code>UNIX_TIMESTAMP()</code> (especially when using with open-source packages without much abstraction for query composition).</p>
<p>Another issue is when storing the timestamp, when usage of <code>CURRENT_TIMESTAMP</code> or <code>NOW()</code> is not an option - storing a PHP generated timestamp will store it with the timezone offset which I would like to avoid.</p>
<p>I'm probably missing something really basic here, but so far I haven't been able to come up with a generic solution to handle those issues so I'm forced to treat them case-by-case. Your thoughts are very welcome</p>
| [
{
"answer_id": 346791,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "SET time_zone"
},
{
"answer_id": 14595648,
"author": "John Conde",
"author_id": 250259,
"author_profile": ... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10585/"
] |
346,777 | <p>how can I check at runtime home many parameters a method or a function have in PHP.</p>
<p>example</p>
<pre>
class foo {
function bar ( arg1, arg2 ){
.....
}
}
</pre>
<p>I will need to know if there is a way to run something like</p>
<pre>
get_func_arg_number ( "foo", "bar" )
</pre>
<p>and the result to be</p>
<pre>
2
</pre>
| [
{
"answer_id": 346789,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 5,
"selected": false,
"text": "$method = new ReflectionMethod('foo', 'bar');\n$num = $method->getNumberOfParameters();\n"
},
{
"answer_id": 346943,
... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346777",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43991/"
] |
346,793 | <p>The people on this website seem to know everything so I figured I would ask this just in case:</p>
<p>Is there a method/function in prototype that converts a JSON object to a string that you can store in a cookie?</p>
<p>If not,..i'll just use another external library.</p>
<p>Thanks,
Andrww</p>
| [
{
"answer_id": 346821,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 4,
"selected": true,
"text": "var data = {name: 'Violet', occupation: 'character', age: 25 };\nvar myString = Object.toJSON(data);\n// myString = '{\"name\"... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
346,811 | <p>I am making a game in JAVA where I want to come up with a list of files in a certain directory in my jar so I can make sure to have a list of those classes to be used in the game.</p>
<p>For example say in my jar I have a directory </p>
<pre><code>mtd/entity/creep/
</code></pre>
<p>I want to get a list of all the .class files in that directory <strong>using java code from another class in the jar</strong>.</p>
<p>What is the best code to do so?</p>
| [
{
"answer_id": 346853,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 4,
"selected": true,
"text": "private static List getClassesFromJARFile(String jar, String packageName) throws Error\n{\n final List classes = new ArrayLis... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346811",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43994/"
] |
346,823 | <p>I am trying to figure out the following problem.
I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good.</p>
<p>Now I am working on the background and the ticking of X, Y axes (if any axes are shown).</p>
<p>I worked out the following.
I have a fixed width of 250 p
The tick gap should be between 12.5 and 50p.</p>
<p>The ticks should indicate either unit or half unit range, by that i mean the following.</p>
<p>x range (-5, 5): one tick = 1</p>
<p>x range (-1, 1): one tick = 0.5 or 0.1 depending on the gap that each of this option would generate. </p>
<p>x range (0.1, 0.3): 0.05 </p>
<p>Given a Xrange
How would you get the number of ticks between either full or half unit range ?</p>
<p>Or maybe there are other way to approach this type of problems.</p>
| [
{
"answer_id": 347271,
"author": "mweerden",
"author_id": 4285,
"author_profile": "https://Stackoverflow.com/users/4285",
"pm_score": 3,
"selected": true,
"text": "delta = maximum - minimum\nfactor = 10**math.ceil(math.log(delta,10)) # smallest power of 10 greater than delta\nnormalised... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32032/"
] |
346,834 | <p>Does anyone have any best practices, tips & tricks, or recommendations for how to create modal Alert Views with Cocoa Touch?</p>
<p>I like to think there is a way to make this difficult task trivial or at least easier.</p>
| [
{
"answer_id": 347769,
"author": "Geraud.ch",
"author_id": 43954,
"author_profile": "https://Stackoverflow.com/users/43954",
"pm_score": 5,
"selected": true,
"text": "void AlertWithMessage(NSString *message)\n{\n/* open an alert with an OK button */\nUIAlertView *alert = [[UIAlertView al... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23294/"
] |
346,837 | <p>I was curious what the differences are between the debug and release modes of the .NET compiler and came across these questions about <a href="https://stackoverflow.com/questions/90871/debug-vs-release-in-net">debug vs release in .NET</a> and <a href="https://stackoverflow.com/questions/312312/what-are-some-reasons-a-release-build-would-run-differently-than-a-debug-build">reasons that release will behave differently than debug</a>. Up to this point I really haven't paid much attention to these compiler modes. Now I will. </p>
<p>My question is, assuming that I am using a testing framework (NUnit) and TDD, would I run into any issues if I simply always compiled in release mode?</p>
| [
{
"answer_id": 347429,
"author": "Robert Rossney",
"author_id": 19403,
"author_profile": "https://Stackoverflow.com/users/19403",
"pm_score": 1,
"selected": false,
"text": "ConditionalAttribute"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2035722/"
] |
346,842 | <p>Well I have a videos website and a few of its tables are:</p>
<p><strong>tags</strong></p>
<pre><code>id ~ int(11), auto-increment [PRIMARY KEY]
tag_name ~ varchar(255)
</code></pre>
<p><strong>videotags</strong></p>
<pre><code>tag_id ~ int(11) [PRIMARY KEY]
video_id ~ int(11) [PRIMARY KEY]
</code></pre>
<p><strong>videos</strong></p>
<pre><code>id ~ int(11), auto-increment [PRIMARY KEY]
video_name ~ varchar(255)
</code></pre>
<p>Now at this point the tags table has >1000 rows and the videotags table has >32000 rows. So when I run a query to display all tags from most common to least common it takes >15 seconds to execute.</p>
<p>I am using PHP and my code (watered down for simplicity) is as follows:</p>
<pre><code>foreach ($database->query("SELECT tag_name,COUNT(tag_id) AS 'tag_count' FROM tags LEFT OUTER JOIN videotags ON tags.id=videotags.tag_id GROUP BY tags.id ORDER BY tag_count DESC") as $tags)
{
echo $tags["tag_name"] . ', ';
}
</code></pre>
<p>Now keeping in mind that this being 100% accurate isn't as important to me as it being fast. So even if the query was executed once a day and its results were used for the remainder of the day, I wouldn't care.</p>
<p>I know absolutely nothing about MySQL/PHP caching so please help!</p>
| [
{
"answer_id": 346866,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 2,
"selected": false,
"text": "EXPLAIN"
},
{
"answer_id": 346869,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https:... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/428190/"
] |
346,855 | <p>The following loop takes about 700 seconds to run in octave and 22 seconds to run in matlab when the DJI matrix has 21000 rows. How can I increase the efficiency of this?</p>
<pre>
for i=1:length(DJI)
DJI2(i,1)=datenum(char(DJI(i,2)),'yyyy-mm-dd');
end
</pre>
| [
{
"answer_id": 346866,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 2,
"selected": false,
"text": "EXPLAIN"
},
{
"answer_id": 346869,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https:... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14744/"
] |
346,858 | <p>I'm trying to parse a simple string in C++. I know the string contains some text with a colon, followed immediately by a space, then a number. I'd like to extract just the number part of the string. I can't just tokenize on the space (using sstream and <<) because the text in front of the colon may or may not have spaces in it.</p>
<p>Some example strings might be:</p>
<blockquote>
<p>Total disk space: 9852465</p>
<p>Free disk space: 6243863</p>
<p>Sectors: 4095</p>
</blockquote>
<p>I'd like to use the standard library, but if you have another solution you can post that too, since others with the same question might like to see different solutions.</p>
| [
{
"answer_id": 346867,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 5,
"selected": true,
"text": "std::string strInput = \"Total disk space: 9852465\";\nstd::string strNumber = \"0\";\nsize_t iIndex = strInput.rfind(... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346858",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1288/"
] |
346,885 | <p>I would like to keep a list of a certain class of objects in my application. But I still want the object to be garbage collected. Can you create <strong>weak references</strong> in .NET?</p>
<p>For reference:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/346762">Garbage Collecting objects which keep track of their own instances in an internal Map</a></li>
<li><a href="https://stackoverflow.com/questions/258505">Create a weak reference to an object</a></li>
</ul>
<p>Answer From MSDN:</p>
<blockquote>
<p>To establish a weak reference with an
object, you create a WeakReference
using the instance of the object to be
tracked. You then set the Target
property to that object and set the
object to null. For a code example,
see WeakReference in the class
library.</p>
</blockquote>
| [
{
"answer_id": 346893,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 3,
"selected": false,
"text": "WeakReference r = new WeakReference(obj);\n"
},
{
"answer_id": 346895,
"author": "Andrew Rollings",
"... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/338/"
] |
346,913 | <p>I'm currently developing a little hobby project to display health information in a game on my G15 keyboard through VB.NET.</p>
<p>When I use ReadProcessMemory via an API call, it keeps returning zero. The MSDN documentation referred me to use the Marshal.GetLastWin32Error() call to find out what is wrong and it returns 1400: INVALID WINDOW HANDLE.</p>
<p>I am now confused about whether the first argument of the function wants a window handle or a process id. Regardless, I have tried both with FindWindow and hardcoding the process id while the application is running (getting it from task manager).</p>
<p>I have tried three different games, Urban Terror, Grand Theft Auto: SA and 3D pinball for windows, getting the memory addresses from an application called Cheat Engine; they all seem to fail.</p>
<p>Here is the code I'm using to do it:</p>
<p>API Call:</p>
<pre><code>Private Declare Function ReadProcessMemory Lib "kernel32" ( _
ByVal hProcess As Integer, _
ByVal lpBaseAddress As Integer, _
ByRef lpBuffer As Single, _
ByVal nSize As Integer, _
ByRef lpNumberOfBytesWritten As Integer _
) As Integer
</code></pre>
<p>Method:</p>
<pre><code>Dim address As Integer
address = &HA90C62&
Dim valueinmemory As Integer
Dim proc As Process = Process.GetCurrentProcess
For Each proc In Process.GetProcesses
If proc.MainWindowTitle = "3D Pinball for Windows - Space Cadet" Then
If ReadProcessMemory(proc.Handle.ToInt32, address, valueinmemory, 4, 0) = 0 Then
MsgBox("aww")
Else
MsgBox(CStr(valueinmemory))
End If
End If
Next
Dim lastError As Integer
lastError = Marshal.GetLastWin32Error()
MessageBox.Show(CStr(lastError))
</code></pre>
<p>Could somebody please explain to me why it is not working? Thanks in advance.</p>
| [
{
"answer_id": 346935,
"author": "arul",
"author_id": 15409,
"author_profile": "https://Stackoverflow.com/users/15409",
"pm_score": 3,
"selected": true,
"text": "<DllImport(\"kernel32.dll\", SetLastError=true)> _\nPublic Shared Function ReadProcessMemory( _\nByVal hProcess As IntPtr, _\n... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20900/"
] |
346,914 | <p>I'm new to ASP.NET MVC and I'm trying to get the full url to a action when working in a view. I need this to submit to a third party API as a callback. For example what I need is</p>
<blockquote>
<p><a href="http://myserver.com/controller/action" rel="noreferrer">http://myserver.com/controller/action</a></p>
</blockquote>
<p>When I use </p>
<pre><code><%= Url.Action("action", "controller") %>
</code></pre>
<p>I get </p>
<blockquote>
<p>/controller/action</p>
</blockquote>
<p>I know several ways to add the server base-path to this but I'm wondering what is the preferred way to do this in the ASP.NET MVC view?</p>
<p>EDIT: Just to clarify, it's not the URL for the current view/action it's for another action in the same controller.</p>
| [
{
"answer_id": 346921,
"author": "John Sheehan",
"author_id": 1786,
"author_profile": "https://Stackoverflow.com/users/1786",
"pm_score": 2,
"selected": false,
"text": "http://<%=Request.Url.Host %><%=Url.Action(\"action\", \"controller\")%>\n"
},
{
"answer_id": 347566,
"auth... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42278/"
] |
346,926 | <p>I have a website with a form that uses TinyMCE; independently, I use jQuery. When I load the form from staging server on Firefox 3 (MacOS X, Linux), TinyMCE doesn't finish loading. There is an error in Firefox console, saying that <code>t.getBody()</code> returned <code>null</code>. <code>t.getBody()</code>, as far as I understand from TinyMCE docs, is a function that returns document's body element to be inspected for some features. Problem doesn't occur when I use Safari, nor when I use Firefox with the same site running from localhost.</p>
<p>Original, failing JavaScript-related code looked like this:</p>
<pre><code><script type="text/javascript" src="http://static.alfa.foo.pl/json2.js"></script>
<script type="text/javascript" src="http://static.alfa.foo.pl/jquery.js"></script>
<script type="text/javascript" src="http://static.alfa.foo.pl/jquery.ui.js"></script>
<script type="text/javascript" src="http://static.alfa.foo.pl/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({ mode:"specific_textareas", editor_selector:"mce", theme:"simple", language:"pl" });
</script>
<script type="text/javascript" src="http://static.alfa.foo.pl/jquery.jeditable.js"></script>
<script type="text/javascript" src="http://static.alfa.foo.pl/jquery.tinymce.js"></script>
<script type="text/javascript" charset="utf-8" src="http://static.alfa.foo.pl/foo.js"></script>
<script type="text/javascript">
$(document).ready(function(){
/* jQuery initialization */ });
</script>
</code></pre>
<p>I tried changing script loading order, moving <code>tinyMCE.init()<code> call to the <code><script/></code> tag containing <code>$(document).ready()</code> call—before, after, and inside this call. No result. When <code>tinyMCE.init()<code> was called from within <code>$(document).ready()</code> handler, the browser did hang on request—looks like it was too late to call the init function.</p>
<p>Then, after googling a bit about using TinyMCE together with jQuery, I changed <code>tinyMCE.init()</code> call to:</p>
<pre><code>tinyMCE.init({ mode:"none", theme:"simple", language:"pl" });
</code></pre>
<p>and added following jQuery call to the <code>$(document).ready()</code> handler:</p>
<pre><code>$(".mce").each( function(i) { tinyMCE.execCommand("mceAddControl",true,this.id); });
</code></pre>
<p>Still the same error. But, and here's where things start to look like real voodoo, when I added alert(i);</code> before the tinyMCE.execCommand()</code> call, alerts were given, and TinyMCE textareas were initialized correctly. I figured this can be a matter of delay introduced by waiting for user dismissing the alert, so I introduced a second of delay by changing the call, still within the $(document).ready()</code> handler, to following:</p>
<pre>setTimeout('$(".mce").each( function(i) { tinyMCE.execCommand("mceAddControl",true,this.id); });',1000);
</code></pre>
<p>With the timeout, TinyMCE textareas initialize correctly, but it's duct taping around the real problem. The problem looks like an evident race condition (especially when I consider that on the same browser, but when server is on localhost, problem doesn't occur). But isn't JavaScript execution single-threaded? Could anybody please enlighten me as to what's going on here, where is the actual problem, and what can I do to have it actually fixed?</p>
| [
{
"answer_id": 347174,
"author": "Jonathan Lonowski",
"author_id": 15031,
"author_profile": "https://Stackoverflow.com/users/15031",
"pm_score": 3,
"selected": false,
"text": "tinyMCE.init(...)"
},
{
"answer_id": 2297055,
"author": "user146498",
"author_id": 146498,
"... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16390/"
] |
346,929 | <p>I am doing some calculations that require a large array to be initialized. The maximum size of the array determines the maximum size of the problem I can solve. </p>
<p>Is there a way to programmatically determine how much memory is available for say, the biggest array of bytes possible?</p>
<p>Thanks </p>
| [
{
"answer_id": 1637306,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "\nUsing pc As New System.Diagnostics.PerformanceCounter(\"Memory\", \"Available Bytes\")\n FreeBytes = pc.NextValue();\nEnd ... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346929",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21197/"
] |
346,940 | <p>I have two tables on a page that I want to display side by side, and then center them within the page (actually within another div, but this is the simplest I could come up with):</p>
<pre><code><style>
#outer { text-align: center; }
#inner { text-align: left; margin: 0 auto; }
.t { float: left; }
table { border: 1px solid black; }
#clearit { clear: left; }
</style>
<div id="outer">
<p>Two tables, side by side, centered together within the page.</p>
<div id="inner">
<div class="t">
<table>
<tr><th>a</th><th>b</th></tr>
<tr><td>1</td><td>2</td></tr>
<tr><td>4</td><td>9</td></tr>
<tr><td>16</td><td>25</td></tr>
</table>
</div>
<div class="t">
<table>
<tr><th>a</th><th>b</th><th>c</th></tr>
<tr><td>1</td><td>2</td><td>2</td></tr>
<tr><td>3</td><td>5</td><td>15</td></tr>
<tr><td>8</td><td>13</td><td>104</td></tr>
</table>
</div>
</div>
<div id="clearit">all done.</div>
</div>
</code></pre>
<p>I understand that it's something to do with the fact that the tables are floated, but I'm at a loss as to understand what I'm missing. There are many web pages that describe something like the technique I show here, but in any event it doesn't work; the tables cling stubbornly to the left hand margin.</p>
| [
{
"answer_id": 346956,
"author": "Andrew G. Johnson",
"author_id": 428190,
"author_profile": "https://Stackoverflow.com/users/428190",
"pm_score": 2,
"selected": false,
"text": "<style>\n#outer { text-align: center; }\n#inner { text-align: left; margin: 0 auto; }\n.t { float: left; }\nta... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346940",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18625/"
] |
346,954 | <p>I saw a link to find out if AD was running, but am not too sure if the same applies to AD/AM.
One caveat is that I should be able to check about any AD/AM instance (any domain) assuming I have permissions.</p>
| [
{
"answer_id": 513873,
"author": "Dscoduc",
"author_id": 51949,
"author_profile": "https://Stackoverflow.com/users/51949",
"pm_score": 1,
"selected": true,
"text": "LDAP://ADAMServer:50000/DC=domain,DC=local\n"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346954",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43999/"
] |
346,957 | <p>I want to write Html format, but I can not even get a simple MSDN example of it to work.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/tbfb3z56.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/tbfb3z56.aspx</a></p>
<p>Does this console app, a clipboard round tripper, work for anyone?</p>
<pre>
using System;
using System.Windows; //Need to add a PresentationCore or System.Windows.Forms reference
class Program {
[STAThread]
static void Main( string[] args ) {
Console.WriteLine( "Copy a small amount of text from a browser, then press enter." );
Console.ReadLine();
var text = Clipboard.GetText();
Console.WriteLine();
Console.WriteLine( "--->The clipboard as Text:" );
Console.WriteLine( text );
Console.WriteLine();
Console.WriteLine( "--->Rewriting clipboard with the same CF_HTML data." );
//***Here is the problem code***
var html = Clipboard.GetText( TextDataFormat.Html );
Clipboard.Clear();
Clipboard.SetText( html, TextDataFormat.Html );
var text2 = Clipboard.GetText();
Console.WriteLine();
Console.WriteLine( "--->The clipboard as Text:" );
Console.WriteLine( text2 );
var isSameText = ( text == text2 );
Console.WriteLine();
Console.WriteLine( isSameText ? "Success" : "Failure" );
Console.WriteLine();
Console.WriteLine( "Press enter to exit." );
Console.ReadLine();
}
}
</pre>
| [
{
"answer_id": 346969,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "var text2 = Clipboard.GetText();"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346957",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14841/"
] |
346,960 | <p>i am trying to use an ASP conditional here:</p>
<pre><code>if (Request.Cookies("username")) and
(Request.Cookies("password")) <> ""
Then
</code></pre>
<p>And i keep getting this error:</p>
<blockquote>
<p>Type mismatch: '[string: ""]'</p>
</blockquote>
<p>Any ideas what I am getting that?</p>
| [
{
"answer_id": 346965,
"author": "hmcclungiii",
"author_id": 24333,
"author_profile": "https://Stackoverflow.com/users/24333",
"pm_score": 3,
"selected": true,
"text": "if (Request.Cookies(\"username\") <> \"\") and (Request.Cookies(\"password\") <> \"\") Then\n"
},
{
"answer_id"... | 2008/12/06 | [
"https://Stackoverflow.com/questions/346960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
346,973 | <p>Is there a simple way to tell what triggered Click event of a Button apart from setting multiple flags in Mouse/Key Up/Down event handlers? I'm currently only interested in distinguishing mouse from everything else, but it would be nice to handle Stylus and other input types if possible. Do I have to create my own button control to achieve this?</p>
<p>Edit: To clarify why I care: in this particular case I'm trying to implement "next" and "previous" buttons for a sort of picture viewer. Pictures in question may be of different size and buttons' positions will change (so they are always centered below picture). It's quite annoying to follow such buttons with mouse if you need to scroll through several pictures, so I want to keep mouse position constant relative to clicked button, but only if it was clicked by mouse, not keyboard.</p>
<p>Edit2: It does not matter whether the buttons are on top or down at the bottom, since the center can change anyway. "Picture viewer" here is just an abstraction and in this particular case it's important for me that top left corner of the picture retains it's position, but it's out of the scope of the question to go in details. Scaling the picture is not so trivial in this sort of application as well, so I do want to know the answer to the question I asked not going into UI implementation discussion.</p>
| [
{
"answer_id": 353140,
"author": "Nir",
"author_id": 3509,
"author_profile": "https://Stackoverflow.com/users/3509",
"pm_score": 4,
"selected": true,
"text": "if (InputManager.Current.MostRecentInputDevice is KeyboardDevice)\n"
}
] | 2008/12/06 | [
"https://Stackoverflow.com/questions/346973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10757/"
] |
347,010 | <p>I currently am trying to write a Python program using scheme semantics so I can later translate it into Scheme without relying on a lot of Pythonic stuff.</p>
<p>I'm trying solve the sliding puzzle problem (where you have 9 slots and 8 tiles arranged in a square) using a*, depth first, and breadth first search algorithm. I did this ~11 years ago in some AI class in Lisp, but basically at the time I had no idea about lisp, I hated it with all my heart, and only in retrospect do I realize I was programming "C" in Lisp. The prof didn't help in this matter.</p>
<p>I have a python function which can swap two tiles easily: </p>
<pre><code>def swap(p, (r1, c1), (r2, c2)):
# Swaps *any* two locations and returns new configuration
# Does not concern itself with zero location, etc
# Not sure how to do this functionally
p_p = p[:]
temp = p_p[r1][c1]
p_p[r1][c1] = p_p[r2][c2]
p_p[r2][c2] = temp
return p_p
</code></pre>
<p>I'd like to turn this into something you might find in SICP, avoiding side effects, etc. </p>
<p>But this brings up a question. Everything I read in SICP is loops via recursion. I didn't see anything in accessing arrays/vectors/lists in constant time. I can imagine a loopish/recursive way to read an element, but I find it harder to imagine a way to create a new list with a certain element changed, without invoking side-effect producing things like set!, and without resorting to crazy if/then/else clauses concerning which element should be changed. This of course gets more confusing when considering a 2d array. In this case the solution with python is obvious because of its native support for multidimensional arrays.</p>
<p>In C/C++/Python/Matlab/Lua/anything else, accessing lists/arrays via the [i] syntax is easy, and directly translates to a hardware-oriented pointer lookup somewhere underneath. I don't understand how scheme does this, given the atomic operations defined in the SICP version of scheme, which all seem very loop-and-search oriented. How do the vector and list array access functions work to get constant time access? (I'm a total newbie here, so I'm not ever sure what functions I'd be talking about). Is there a C or Assembly library someplace which is secretly being accessed? Are there any inherent constant-time semantics in scheme which could be used for list/array/vector access, and which would allow me a guilt-free way of using that idiom in Python for the moment? </p>
<p>How would can I rewrite the above function in python using Schemish semantics? How would I rewrite the above function in Scheme?</p>
| [
{
"answer_id": 347059,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 2,
"selected": false,
"text": "; getval\n;\n; This function takes a position (r . c) where and returns the corresponding\n; number in the 8-puzzle state.... | 2008/12/06 | [
"https://Stackoverflow.com/questions/347010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
347,056 | <p>While there appears to some documentation on how to expose JMX through various firewall and tunneling schemes, I sort of want the opposite. I want to ensure that JMX is only accessible to local machine. Unfortunately it appears that the "out of the box" management options do not allow restricting the ports to a local interface and netstat shows them listening on any/all interfaces.</p>
<p><a href="http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html#gdevf" rel="noreferrer">http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html#gdevf</a></p>
<p>I have to admit I am bewildered by the layers of indirection in JMX, the RMI registry, connectors, adapters, etc.</p>
<p>I would like to just turn it on and then tunnel through SSH as opposed to exposing it to the world and then having to perform arduous and superfluous user management and security configuration. It would be nice to be able to use a built in RMI registry and not have to run an external one.</p>
| [
{
"answer_id": 660426,
"author": "Fredrik",
"author_id": 59572,
"author_profile": "https://Stackoverflow.com/users/59572",
"pm_score": 2,
"selected": false,
"text": "import java.io.IOException;\nimport java.lang.management.ManagementFactory;\nimport java.net.*;\nimport java.rmi.registry.... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
347,078 | <p>I am just learning about Unit Testing. I am using NUnit to build tests for a VB.NET project.</p>
<p>The project I'm working on is part of a framework which will be used by people who build ASP.NET websites. It includes a base class (which inherits <code>System.Web.HttpApplication</code>) that users of my framework will inherit their application class from.</p>
<p>The project also contains a number of composite controls.</p>
<p>I can't quite work out at the moment how you would go about writing tests for either the application base class or any of the composite controls.</p>
<p>In the case of the application base class, should the Unit Test project include a class which inherits from it and then test against that?</p>
<p>Any pointers would be appreciated!</p>
<p>Thanks.</p>
| [
{
"answer_id": 347104,
"author": "Eugene Yokota",
"author_id": 3827,
"author_profile": "https://Stackoverflow.com/users/3827",
"pm_score": 0,
"selected": false,
"text": "[Test] \npublic void TestExample() \n{ \n // First, instantiate \"Tester\" objects: \n LabelTester label = new Lab... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347078",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/475/"
] |
347,085 | <p>I have a desktop app that needs to send data to a MySQL Server. The app will be for internal company use, but the MySQL is on a server at a hosting company.</p>
<p>The data will need to be massaged a bit before being inserted and standard simple insert, delete and update.</p>
<p>Which should I use PHP or Perl?</p>
<p>I use PHP now for a variety of database driven web pages, but my current task has no need to any web rendering. (I know PHP could do this without an web-rendering too)</p>
<p>I have used Perl in the past (maybe 4 years ago) for a data mining task and Oracle.</p>
<p>What I don't know:
- Can Perl work with MySQL easily?
- The Perl scripts would go in cgi-bin on the webserver, correct?
- Security issues with either?
- Best practice in Perl for connecting to MySQL to insert data?
- Where can I store the Insert, Update, Delete MySQL user name and password so it is not stolen, etc?</p>
<p>What would you all choose?</p>
<p>Thoughts are appreciated</p>
<p>-Jason</p>
| [
{
"answer_id": 22475574,
"author": "vogomatix",
"author_id": 1421665,
"author_profile": "https://Stackoverflow.com/users/1421665",
"pm_score": 0,
"selected": false,
"text": "mysql_"
}
] | 2008/12/07 | [
"https://Stackoverflow.com/questions/347085",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
347,088 | <p>In a PHP project I'm developing I have a couple of requests that can be either POST or GET. Currently, I'm using the $_SERVER[REQUEST_METHOD] value to determine, which request array to use. I know that $_REQUEST values can be manipulated with cookies, is the $_SERVER superglobal vulnerable to attacks? </p>
| [
{
"answer_id": 347130,
"author": "thenickdude",
"author_id": 14431,
"author_profile": "https://Stackoverflow.com/users/14431",
"pm_score": 0,
"selected": false,
"text": "post' priority over"
}
] | 2008/12/07 | [
"https://Stackoverflow.com/questions/347088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
347,092 | <p>I am trying to have a tooltip on multiple lines. how do i do this?</p>
| [
{
"answer_id": 347112,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 6,
"selected": true,
"text": "Environment.NewLine"
},
{
"answer_id": 65444419,
"author": "flodis",
"author_id": 4299943,
"author_pro... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
347,093 | <p>I have been programming in Perl, off and on, for years now, although only sporadically is it my primary language. Because I often go months without writing any perl, I rely heavily on my dog-eared Camel Book to remind me how to do things. However, when I copy recipes verbatim with no understanding, this bothers me. This is one of the most vexing: On page 154 of the 3rd edition Camel, there is an example for "modifying strings <em>en passant</em>, which reads like this:</p>
<pre><code>($lotr = $hobbit) =~ s/Bilbo/Frodo/g;
</code></pre>
<p>Q1) what is going on here? On what, exactly, is the regex operating?</p>
<p>Q2) Is this near-magical syntax necessary for such a basic operation as "take a string from $a, modify it with a regex, place result in $b"?</p>
<p>Q3) How do I do this operation using the loop default variable as the initial string?</p>
<p>Apologies in advance to Perl dreamers for whom the above looks perfectly natural.</p>
| [
{
"answer_id": 347117,
"author": "D.Shawley",
"author_id": 41747,
"author_profile": "https://Stackoverflow.com/users/41747",
"pm_score": 6,
"selected": true,
"text": "($lotr=$hobbit) =~ s/Bilbo/Frodo/g"
},
{
"answer_id": 347138,
"author": "ysth",
"author_id": 17389,
"... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41194/"
] |
347,096 | <p>Consider the following code:</p>
<pre><code>template <int dim>
struct vec
{
vec normalize();
};
template <>
struct vec<3>
{
vec cross_product(const vec& second);
vec normalize();
};
template <int dim>
vec<dim> vec<dim>::normalize()
{
// code to normalize vector here
return *this;
}
int main()
{
vec<3> direction;
direction.normalize();
}
</code></pre>
<p>Compiling this code produces the following error:</p>
<blockquote>
<p>1>main.obj : error LNK2019: unresolved external symbol "public: struct vec<3> __thiscall vec<3>::normalize(void)" (?normalize@?$vec@$02@@QAE?AU1@XZ) referenced in function _main</p>
</blockquote>
| [
{
"answer_id": 347103,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https://Stackoverflow.com/users/338",
"pm_score": 1,
"selected": false,
"text": "template <int dim>\nstruct vec\n{\n};\n\nnamespace impl {\n template <int dim>\n vec<dim> normalize(const vec<dim>... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2222/"
] |
347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual test case for each function (particularly since more functions might be added later). </p>
<p>One way to do this would be to iterate over a list of these functions:</p>
<pre><code>import unittest
import numpy
from somewhere import the_functions
from somewhere.else import TheClass
class Test_the_functions(unittest.TestCase):
def setUp(self):
self.matrix1 = numpy.ones((5,10))
self.matrix2 = numpy.identity(5)
def testOutputShape(unittest.TestCase):
"""Output of functions be of a certain shape"""
for function in all_functions:
output = function(self.matrix1, self.matrix2)
fail_message = "%s produces output of the wrong shape" % str(function)
self.assertEqual(self.matrix1.shape, output.shape, fail_message)
if __name__ == "__main__":
unittest.main()
</code></pre>
<p>I got the idea for this from <a href="http://www.diveintopython.net/unit_testing/romantest.html" rel="noreferrer">Dive Into Python</a>. There, it's not a list of functions being tested but a list of known input-output pairs. The problem with this approach is that if any element of the list fails the test, the later elements don't get tested.</p>
<p>I looked at subclassing unittest.TestCase and somehow providing the specific function to test as an argument, but as far as I can tell that prevents us from using unittest.main() because there would be no way to pass the argument to the testcase.</p>
<p>I also looked at dynamically attaching "testSomething" functions to the testcase, by using setattr with a lamdba, but the testcase did not recognize them.</p>
<p>How can I rewrite this so it remains trivial to expand the list of tests, while still ensuring every test is run?</p>
| [
{
"answer_id": 347175,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 4,
"selected": true,
"text": "import unittest\n\nclass UnderTest(object):\n\n def f1(self, i):\n return i + 1\n\n def f2(self, i):\n r... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37984/"
] |
347,111 | <p>In a CF8 form, I'm using a tag such as the following:</p>
<pre><code><cfinput
type = "Text"
name = "Num"
value = "0"
validate = "range,integer"
range = "0,1000"
validateAt="onBlur,onSubmit"
required = "yes"
message = "Invalid Value"
>
</code></pre>
<p>When the field loses focus (onBlur), the input is validated for only the first of the conditions in the validate parameter (it changes when I swap the order).</p>
<p>This is the html / JS code that is auto generated:</p>
<pre><code><input
name="Num"
id="Num"
type="text"
value="0"
onblur="if( !_CF_hasValue(this, 'TEXT', false)
&&
!_CF_checkrange(this.value,0.0,1000.0, true)
||
!_CF_checkinteger(this.value, true) )
{ _CF_onErrorAlert(new Array('Invalid Value')); }"
/>
</code></pre>
<p>OnSubmit is handled with separate autogenerated JS and works properly.</p>
<p>Am I doing something wrong? Does CF8 not support validating these two conditions together?</p>
| [
{
"answer_id": 347409,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 3,
"selected": true,
"text": "if (!has_value && !in_range || !is_integer) show_error()\n"
},
{
"answer_id": 347548,
"author": "Ben Doom",
... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347111",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26428/"
] |
347,132 | <p>How would you append an integer to a <code>char*</code> in c++?</p>
| [
{
"answer_id": 347140,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 6,
"selected": true,
"text": "char*"
},
{
"answer_id": 347143,
"author": "Sydius",
"author_id": 43496,
"author_profile": "https://Sta... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37875/"
] |
347,142 | <p>Is it common practice to keep project files (i.e. files other that source code files) in the version control repository?</p>
<p>Also, are these files checked in/out on a regular basis?</p>
<p>I always envisioned a SCC repository as 'clean' with only source code files.</p>
<p>How do you manage the non-source code files in a repository?</p>
<p>Take a Visual Studio solution, as an example. Would you "check-in" the entire Solution's directory to the SCCS or would you just add the source code files? What about when it comes time to build the Solution, then the entire solution needs to be checked out? Maybe it's best done with a manual process?</p>
| [
{
"answer_id": 347151,
"author": "Hudson",
"author_id": 14105,
"author_profile": "https://Stackoverflow.com/users/14105",
"pm_score": 0,
"selected": false,
"text": "cvs add -kb filenames\n"
}
] | 2008/12/07 | [
"https://Stackoverflow.com/questions/347142",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21826/"
] |
347,156 | <p>Do you put unit tests in the same project for convenience or do you put them in a separate assembly?</p>
<p>If you put them in a separate assembly like we do, we end up with a number of extra projects in the solution. It's great for unit testing while coding but how do you release the application without all of these extra assemblies?</p>
| [
{
"answer_id": 25076422,
"author": "Andrej Adamenko",
"author_id": 3421814,
"author_profile": "https://Stackoverflow.com/users/3421814",
"pm_score": 4,
"selected": false,
"text": "public static class Ext\n{\n [TestCase(1.1, Result = 1)]\n [TestCase(0.9, Result = 1)]\n public ... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
347,160 | <p>In a brand new program where space isn't really that big a deal, is it better to delete a row or to disable a row by let's say a boolean "Disabled" and have the program just ignore it?</p>
<p>For example, if I wanted to remove a user from a program.</p>
| [
{
"answer_id": 348970,
"author": "Piskvor left the building",
"author_id": 19746,
"author_profile": "https://Stackoverflow.com/users/19746",
"pm_score": 2,
"selected": false,
"text": "users"
}
] | 2008/12/07 | [
"https://Stackoverflow.com/questions/347160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10352/"
] |
347,196 | <p>I have only this in my mxml source code:</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:comp="components.*"
width="770" height="330">
<mx:Label x="185.5" y="150"
text="Placeholder for Future UI." fontSize="30" color="#93A8AD"/>
</mx:Canvas>
</code></pre>
<p>And when I try to use the flex builder's design mode, I get the error "An unknown item is declared as the root of your MXML document. Switch to source mode to correct it." Anyone out there knows how to resolve this issue?</p>
<p>One thing to note here that I've recently upgraded to flash player 10 debugger.</p>
| [
{
"answer_id": 2245923,
"author": "pablo",
"author_id": 271205,
"author_profile": "https://Stackoverflow.com/users/271205",
"pm_score": 0,
"selected": false,
"text": "<?xml..."
}
] | 2008/12/07 | [
"https://Stackoverflow.com/questions/347196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20165/"
] |
347,210 | <p>How do you execute a JavaScript function without <code>onclick</code> like "Grippie" in a new post on SOF, like the <code><div class="grippie" style="margin-right: 59px;"/</code>> on Stack Overflow when you post a question or answer? I get a nice CSS cursor which lets me know of the movable edge, but how is the JavaScript which resizes the field finding out I clicked on the 'grippie'?</p>
<p><strong>Edit:</strong>
Thank you for the answers which lead to jQuery and describe the handler.
Could I please have a simple use of the handler that determines when the element is clicked, like:</p>
<pre><code>addListener('myElement',performFunction();).onclick;
</code></pre>
<p>or however this may work?</p>
| [
{
"answer_id": 352929,
"author": "Supernovah",
"author_id": 36076,
"author_profile": "https://Stackoverflow.com/users/36076",
"pm_score": 2,
"selected": false,
"text": "document.getElementById('ID').addEventListener('click',function();,false); \n//Problems: Has to be terminated and fals... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36076/"
] |
347,219 | <p>I'm using an NSTimer to do some rendering in an OpenGL based iPhone app. I have a modal dialog box that pops up and requests user input. While the user is providing input I'd like to "pause" i.e. something like this:</p>
<pre><code>[myNSTimer pause];
</code></pre>
<p>I'm using this syntax because I've been doing things like:</p>
<pre><code>[myNSTimer invalidate];
</code></pre>
<p>when I want it to stop.</p>
<p>How can I programmatically pause the NSTimer?</p>
| [
{
"answer_id": 3777774,
"author": "kapesoftware",
"author_id": 456090,
"author_profile": "https://Stackoverflow.com/users/456090",
"pm_score": 4,
"selected": false,
"text": "pauseStart = [[NSDate dateWithTimeIntervalSinceNow:0] retain];\npreviousFiringDate = [timer firingDate];\n[timer s... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22471/"
] |
347,226 | <p>I've created a table in Microsoft Sql CE that I'm using to hold some data. I've generated an ORM via SqlMetal and I've pulled the datasource into my WPF project.</p>
<p>I want to create a simple WPF form that can be used to edit a record in the table via the ORM-generated classes. I want this form to support typical OK/Cancel semantics. I've created the form in what I believe to be the typical fashion, using TwoWay databinding on the respective fields to bind against an instance of the object from the ORM. For example, given an object in the ORM that has a property "TaskName", I've included the following in my WPF form:</p>
<pre><code><Label Grid.Column="0" Grid.Row="0" >
Name:
</Label>
<TextBox Name="txtName" Grid.Column="1" Grid.Row="0"
Text="{Binding TaskName, Mode=TwoWay}" AcceptsReturn="False"
MaxLines="1" />
</code></pre>
<p>This, combined with a DataContext assignment in code:</p>
<pre><code>var newRow = new OrmGeneratedClass();
// Populate default values on newRow, e.g.
detailWindow.DataContext = newRow;
detailWindow.ShowDialog();
</code></pre>
<p>can work reasonably well for creation of a new row. All changes made via the form are immediately reflected in the underlying OrmGeneratedClass. The problem is that there's no immediate support for canceling changes if, e.g., the OrmGeneratedClass is filled with previously saved values.</p>
<p><strong>What is a good design for this scenario, or am I designing it wrong before I get to this point?</strong> I'm a newbie with WPF and the Sql Server datasource/ORM integration aspects. (This is a personal project that I'm using to learn both technologies.)</p>
<p>I have a couple of thoughts and will place them in the answers</p>
| [
{
"answer_id": 347230,
"author": "Greg D",
"author_id": 6932,
"author_profile": "https://Stackoverflow.com/users/6932",
"pm_score": 1,
"selected": false,
"text": "var existingRow = GetExistingRow(someConditionOrWhatever);\ndetailWindow.DataContext = existingRow;\nif(!detailWindow.ShowDia... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6932/"
] |
347,235 | <p>I have string which is base64 encoded. How can I search this string to check if this string contains specific sub string which is not encoded? I don't want to decode that string and then search it. </p>
<p>Can I just encode that specific sub string, and search the encoded string by using the encoded sub string?</p>
<p>Thanks,</p>
| [
{
"answer_id": 67880688,
"author": "recvfrom",
"author_id": 9457431,
"author_profile": "https://Stackoverflow.com/users/9457431",
"pm_score": 0,
"selected": false,
"text": "MZ"
}
] | 2008/12/07 | [
"https://Stackoverflow.com/questions/347235",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
347,238 | <p>There seems to be three common approaches for mapping an application end user to a database user. </p>
<ol>
<li><strong>One to One Mapping:</strong> Each Application user (bob, nancy and fred) also get a corresponding database user account (bob nancy and fred).</li>
<li><strong>N to M mapping:</strong> Each application user is mapped to a database user that represents their role. bob and nancy are mapped to the 'clerk' database user while fred is mapped to the 'manager' database user.</li>
<li><strong>N to 1 mapping:</strong> Each application user is mapped to a single database user (app_user) and identity is only managed at the application tier.</li>
</ol>
<p>It seems that #3 is the most common in web application development. <strong>Why is there not a greater emphasis on the other two options?</strong></p>
<p>Oracle encourages techniques like #2 using its proxy authentication features for the following reason:</p>
<p><strong>Limited trust model</strong>-controlling the users on whose behalf middle tiers can connect, and the roles the middle tiers can assume for the user</p>
<p><strong>Scalability</strong>-by supporting lightweight user sessions and eliminating the overhead of re-authenticating clients</p>
<p><strong>Accountability</strong>, by preserving the identity of the real user through to the database, and enabling auditing of actions taken on behalf of the real user</p>
<p><a href="http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/proxya.htm" rel="nofollow noreferrer">Oracle's Proxy Authentication documentation</a></p>
| [
{
"answer_id": 347438,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "USER_NAME()"
}
] | 2008/12/07 | [
"https://Stackoverflow.com/questions/347238",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/700/"
] |
347,242 | <p>by default is a class:</p>
<ol>
<li>private ?</li>
<li>internal ? </li>
<li>sealed ?</li>
</ol>
| [
{
"answer_id": 347395,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": false,
"text": "public string Foo { get; private set; }\n"
}
] | 2008/12/07 | [
"https://Stackoverflow.com/questions/347242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
347,248 | <p>Can I do it with reflection or something like that?</p>
| [
{
"answer_id": 347323,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 5,
"selected": false,
"text": "ServiceLoader"
},
{
"answer_id": 30446248,
"author": "Ahmad Abdelghany",
"author_id": 1998422,
"author_... | 2008/12/07 | [
"https://Stackoverflow.com/questions/347248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1356709/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.