qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
383,565
<p>I'm using Python to <strong>infinitely</strong> iterate over a list, repeating each element in the list a number of times. For example given the list:</p> <pre><code>l = [1, 2, 3, 4] </code></pre> <p>I would like to output each element two times and then repeat the cycle:</p> <pre><code>1, 1, 2, 2, 3, 3, 4, 4, 1, 1, 2, 2 ... </code></pre> <p>I've got an idea of where to start:</p> <pre><code>def cycle(iterable): if not hasattr(cycle, 'state'): cycle.state = itertools.cycle(iterable) return cycle.next() &gt;&gt;&gt; l = [1, 2, 3, 4] &gt;&gt;&gt; cycle(l) 1 &gt;&gt;&gt; cycle(l) 2 &gt;&gt;&gt; cycle(l) 3 &gt;&gt;&gt; cycle(l) 4 &gt;&gt;&gt; cycle(l) 1 </code></pre> <p>But how would I repeat each element?</p> <p><strong>Edit</strong></p> <p>To clarify this should iterate infinitely. Also I've used repeating the element twice as the shortest example - <strong>I would really like to repeat each element n times</strong>.</p> <p><strong>Update</strong></p> <p>Will your solution lead me to what I was looking for:</p> <pre><code>&gt;&gt;&gt; import itertools &gt;&gt;&gt; def ncycle(iterable, n): ... for item in itertools.cycle(iterable): ... for i in range(n): ... yield item &gt;&gt;&gt; a = ncycle([1,2], 2) &gt;&gt;&gt; a.next() 1 &gt;&gt;&gt; a.next() 1 &gt;&gt;&gt; a.next() 2 &gt;&gt;&gt; a.next() 2 &gt;&gt;&gt; a.next() 1 &gt;&gt;&gt; a.next() 1 &gt;&gt;&gt; a.next() 2 &gt;&gt;&gt; a.next() 2 </code></pre> <p>Thanks for the quick answers!</p>
[ { "answer_id": 383573, "author": "rob", "author_id": 43927, "author_profile": "https://Stackoverflow.com/users/43927", "pm_score": 1, "selected": false, "text": "iterable = [1, 2, 3, 4]\nn = 2\n\nwhile (True):\n for elem in iterable:\n for dummy in range(n):\n print elem # or ca...
2008/12/20
[ "https://Stackoverflow.com/questions/383565", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37522/" ]
383,570
<p>What is the easiest way in Java to map strings (Java <code>String</code>) to (positive) integers (Java <code>int</code>), so that</p> <ul> <li>equal strings map to equal integers, and</li> <li>different strings map to different integers?</li> </ul> <p>So, similar to <code>hashCode()</code> but different strings are required to produce different integers. So, in a sense, it would be a hasCode() without the collision possibility.</p> <p>An obvious solution would maintain a mapping table from strings to integers, and a counter to guarantee that new strings are assigned a new integer. I'm just wondering how is this problem usually solved. Would also be interesting to extend it to other objects than strings.</p>
[ { "answer_id": 383582, "author": "Avi", "author_id": 1605, "author_profile": "https://Stackoverflow.com/users/1605", "pm_score": 2, "selected": false, "text": "String s = \"my string\";\nBigInteger bi = new BigInteger(s.getBytes());\n String str = new String(bi.toByteArray());\n" }, ...
2008/12/20
[ "https://Stackoverflow.com/questions/383570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12547/" ]
383,587
<p>The built-in <code>Math.Pow()</code> function in .NET raises a <code>double</code> base to a <code>double</code> exponent and returns a <code>double</code> result.</p> <p>What's the best way to do the same with integers?</p> <p>Added: It seems that one can just cast <code>Math.Pow()</code> result to (int), but will this always produce the correct number and no rounding errors?</p>
[ { "answer_id": 383596, "author": "Vilx-", "author_id": 41360, "author_profile": "https://Stackoverflow.com/users/41360", "pm_score": 7, "selected": true, "text": "int IntPow(int x, uint pow)\n{\n int ret = 1;\n while ( pow != 0 )\n {\n if ( (pow & 1) == 1 )\n r...
2008/12/20
[ "https://Stackoverflow.com/questions/383587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33080/" ]
383,595
<p>I had a typo in my fstab and it boots to a commandline but is readonly, I know what the error is but i can't change it because it's mounted as readonly. I want to mount the filesystem and make the changes. I know I can boot a live distro and edit it that way, but i was wondering if there was an easier way to do it.</p> <p>It's debian lenny by the way.</p>
[ { "answer_id": 383842, "author": "MarkR", "author_id": 13724, "author_profile": "https://Stackoverflow.com/users/13724", "pm_score": 5, "selected": false, "text": "mount / -o remount,rw\n" }, { "answer_id": 383885, "author": "Johannes Schaub - litb", "author_id": 34509, ...
2008/12/20
[ "https://Stackoverflow.com/questions/383595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
383,600
<p>I have a Java web app that reads a MySql db and returns DateTime fields. What is the best way to convert the DateTime fields returned in the resultset into something more readable?</p> <p>Currently the DateTime fields print as:</p> <p>2008-12-14 16:30:00</p> <p>but I would like something more user friendly like:</p> <p>14 Dec 2008 at 16:30</p> <p>I am populating an ArrayList with these dateTimes from a pojo. I would like to format them before adding to the arrayList, so then I can just print the contents of the arrayList in the JSP.</p>
[ { "answer_id": 383612, "author": "Zoredache", "author_id": 20267, "author_profile": "https://Stackoverflow.com/users/20267", "pm_score": 2, "selected": false, "text": "mysql> select date_format(now(),'%d %b %Y at %H:%i') as formated_date;\n+----------------------+\n| formated_date ...
2008/12/20
[ "https://Stackoverflow.com/questions/383600", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16684/" ]
383,623
<p>How do you apply 'or' to all values of a list in Python? I'm thinking something like:</p> <pre><code>or([True, True, False]) </code></pre> <p>or if it was possible:</p> <pre><code>reduce(or, [True, True, False]) </code></pre>
[ { "answer_id": 383637, "author": "Dustin", "author_id": 39975, "author_profile": "https://Stackoverflow.com/users/39975", "pm_score": 2, "selected": false, "text": "reduce(lambda a,b: a or b, [True, True, False])\n" }, { "answer_id": 383638, "author": "PEZ", "author_id": ...
2008/12/20
[ "https://Stackoverflow.com/questions/383623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6068/" ]
383,631
<p>How do I use the <code>json_encode()</code> function with MySQL query results? Do I need to iterate through the rows or can I just apply it to the entire results object?</p>
[ { "answer_id": 383662, "author": "Hugh Bothwell", "author_id": 33258, "author_profile": "https://Stackoverflow.com/users/33258", "pm_score": 5, "selected": false, "text": "mysql_query() json_encode" }, { "answer_id": 383664, "author": "Paolo Bergantino", "author_id": 1641...
2008/12/20
[ "https://Stackoverflow.com/questions/383631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12073/" ]
383,633
<p>I am working on a UNIX box, and trying to run an application, which gives some debug logs to the standard output. I have redirected this output to a log file, but now wish to get the lines where the error is being shown.</p> <p>My problem here is that a simple</p> <pre><code>cat output.log | grep FAIL </code></pre> <p>does not help out. As this shows only the lines which have FAIL in them. I want some more information along with this. Like the 2-3 lines above this line with FAIL. Is there any way to do this via a simple shell command? I would like to have a single command line (can have pipes) to do the above.</p>
[ { "answer_id": 383640, "author": "PEZ", "author_id": 44639, "author_profile": "https://Stackoverflow.com/users/44639", "pm_score": 3, "selected": false, "text": "grep -C 3 FAIL output.log\n" }, { "answer_id": 383641, "author": "jfs", "author_id": 4279, "author_profile...
2008/12/20
[ "https://Stackoverflow.com/questions/383633", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35416/" ]
383,634
<p>Well I run a small video website and on the actual video page there is a strip of "related videos" similar to most video sides (e.g. YouTube) and currently all I'm doing is taking one of its tags randomly and finding other videos with the same tag. Not surprisingly this isn't a great method as some tags are very vague and some videos are mis-tagged.</p> <p>Example of the current query:</p> <pre><code>SELECT video_name FROM videos INNER JOIN videotags ON videos.id=videotags.video_id INNER JOIN tags ON tags.id=videotags.tag_id WHERE tag_name='x' AND videos.id&lt;&gt;'y' LIMIT 5 </code></pre> <p>Where x is any one of the tags from the current video and y is the ID from the current video. (P.S. I'm using parameterized queries don't worry)</p> <p>I'm just curious as to how you all would handle this, maybe it would be better to incorporate similar video titles?</p> <p>Here is how my database tables are setup:</p> <pre><code>VIDEOS TABLE ------------ video_id [PK,auto_increment] int(11) video_name varchar(255) TAGS TABLE ---------- tag_id [PK,auto_increment] int(11) tag_name varchar(255) VIDEOTAGS TABLE --------------- tag_id [PK,FK] int(11) video_id [PK,FK] int(11) </code></pre> <p>There's obviously more columns in the videos table but this just illustrates the simple many-to-many relationship with auto-incrementing primary keys on both sides</p> <p>The site is built on PHP with a MySQL database, but that really doesn't matter :)</p> <p><strong>EDIT:</strong> There's been some talk of going down an organic route so I figure I'd post my other two tables that are semi-related that are to do with video views and video ratings. Now note I don't have any intention of adding more columns specifically to the video views table because of privacy issues (yes I know I store IPs in the rating table)</p> <pre><code>VIDEOVIEWS TABLE ---------------- video_id [FK] int(11) view_time datetime VIDEORATINGS TABLE ------------------ video_id [PK,FK] int(11) ip_address [PK] varchar(15) rating int(1) rate_time datetime </code></pre>
[ { "answer_id": 384185, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 3, "selected": true, "text": "SELECT v2.video_id\nFROM VideoTags AS v1\n JOIN VideoTags AS v2\n USING (tag_id)\nWHERE v1.video_id = ?\n AND v1.vid...
2008/12/20
[ "https://Stackoverflow.com/questions/383634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428190/" ]
383,658
<p>I am programming winforms using c# and vb.net.</p> <p>I love the arrows used in coderush.</p> <p>for those who have not seen coderush arrows ,please see this image.</p> <p><a href="https://i.stack.imgur.com/6IVX6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6IVX6.jpg" alt="http://www.aspnetpro.com/productreviews/2004/08/asp200408bn_p/asp200408bn_p_image002.jpg"></a><br> <sub>(source: <a href="http://www.aspnetpro.com/productreviews/2004/08/asp200408bn_p/asp200408bn_p_image002.jpg" rel="nofollow noreferrer">aspnetpro.com</a>)</sub> </p> <p><code> <a href="http://www.aspnetpro.com/productreviews/2004/08/asp200408bn_p/asp200408bn_p_image002.jpg" rel="nofollow noreferrer">http://www.aspnetpro.com/productreviews/2004/08/asp200408bn_p/asp200408bn_p_image002.jpg</a> </code></p> <p>I want to have something similar in my program. only difference is i will be using it to highlight textboxes and buttons.</p> <p>I only want the arrow , the text on the arrow is not important.</p> <p>So maybe I need to make a general function like DrawHighlightArrow(controlname)</p> <p>and it will somehow manage to draw an arrow next to that control</p> <p>Please suggest a nice geeky way to solve this problem in C# or Vb.net</p> <p>Thank you <br> Anna</p>
[ { "answer_id": 384185, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 3, "selected": true, "text": "SELECT v2.video_id\nFROM VideoTags AS v1\n JOIN VideoTags AS v2\n USING (tag_id)\nWHERE v1.video_id = ?\n AND v1.vid...
2008/12/20
[ "https://Stackoverflow.com/questions/383658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48027/" ]
383,680
<p>I've developed a web service in asp.net and am able to test it from an in-project aspx page and can readily display the information that was returned in JSON format.</p> <p>I now need to consume the web service from a stand-alone html page.</p> <p>Does someone have experience with this? I'm puzzled by the part that would replace this</p> <pre><code>&lt;asp:ScriptManager ID="ScriptManager" runat="server"&gt; &lt;Services&gt; &lt;asp:ServiceReference Path="~\MyService.asmx" /&gt; &lt;/Services&gt; &lt;/asp:ScriptManager&gt; </code></pre> <p>If this is not possible with straight html and javascript, can someone show me a stand-alone php page that would do it?</p>
[ { "answer_id": 383693, "author": "BobbyShaftoe", "author_id": 38426, "author_profile": "https://Stackoverflow.com/users/38426", "pm_score": 4, "selected": true, "text": " $.ajax({\n type: \"POST\",\n url: \"~/MyService.asmx/MyMethod\",\n data: \"{parameterName:'\" aStringArgume...
2008/12/20
[ "https://Stackoverflow.com/questions/383680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36902/" ]
383,686
<p>I've got a "diagnostics" page in my ASP.NET application which does things like verify the database connection(s), display the current appSettings and ConnectionStrings, etc. A section of this page displays the Assembly versions of important types used throughout, but I could not figure out how to effectively show the versions of ALL of the loaded assemblies.</p> <p><strong>What is the most effective way to figure out all <em>currently referenced and/or loaded</em> Assemblies in a .NET application?</strong></p> <p>Note: I'm not interested in file-based methods, like iterating through *.dll in a particular directory. I am interested in what the application is actually <em>using</em> right now.</p>
[ { "answer_id": 383690, "author": "Kent Boogaart", "author_id": 5380, "author_profile": "https://Stackoverflow.com/users/5380", "pm_score": 8, "selected": false, "text": "AppDomain var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();\n var referencedAssemblies = someAssembly.Ge...
2008/12/20
[ "https://Stackoverflow.com/questions/383686", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13960/" ]
383,689
<p>I made a custom TObjectList descendant designed to hold subclasses of a base object class. It looks something like this:</p> <pre><code>interface TMyDataList&lt;T: TBaseDatafile&gt; = class(TObjectList&lt;TBaseDatafile&gt;) public constructor Create; procedure upload(db: TDataSet); end; implementation constructor TMyDataList&lt;T&gt;.Create; begin inherited Create(true); self.Add(T.Create); end; </code></pre> <p>I want each new list to start out with one blank object in it. It's pretty simple, right? But the compiler doesn't like it. It says:</p> <p>"Can't create new instance without CONSTRUCTOR constraint in type parameter declaration" I can only assume this is something generics-related. Anyone have any idea what's going on and how I can make this constructor work?</p>
[ { "answer_id": 383698, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 5, "selected": true, "text": "T T.Create <T: constructor>\n <T: TBaseDatafile, constructor>\n" }, { "answer_id": 7301803, "author": "Atl...
2008/12/20
[ "https://Stackoverflow.com/questions/383689", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32914/" ]
383,692
<p>I've looked on Wikipedia and Googled it and read the official documentation, but I still haven't got to the point where I really understand what JSON is, and why I'd use it.</p> <p>I have been building applications using PHP, MySQL and JavaScript / HTML for a while, and if JSON can do something to make my life easier or my code better or my user interface better, then I'd like to know about it. Can someone give me a succinct explanation?</p>
[ { "answer_id": 383699, "author": "Andreas Grech", "author_id": 44084, "author_profile": "https://Stackoverflow.com/users/44084", "pm_score": 10, "selected": true, "text": "{\n \"firstName\": \"John\",\n \"lastName\": \"Smith\",\n \"address\": {\n \"streetAddress\": \"...
2008/12/20
[ "https://Stackoverflow.com/questions/383692", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11522/" ]
383,728
<p>Well, I have this bit of code that is slowing down the program hugely because it is linear complexity but called a lot of times making the program quadratic complexity. If possible I would like to reduce its computational complexity but otherwise I'll just optimize it where I can. So far I have reduced down to:</p> <pre><code>def table(n): a = 1 while 2*a &lt;= n: if (-a*a)%n == 1: return a a += 1 </code></pre> <p>Anyone see anything I've missed? Thanks!</p> <p>EDIT: I forgot to mention: n is always a prime number.</p> <p>EDIT 2: Here is my new improved program (thank's for all the contributions!):</p> <pre><code>def table(n): if n == 2: return 1 if n%4 != 1: return a1 = n-1 for a in range(1, n//2+1): if (a*a)%n == a1: return a </code></pre> <p>EDIT 3: And testing it out in its real context it is <em>much</em> faster! Well this question appears solved but there are many useful answers. I should also say that as well as those above optimizations, I have memoized the function using Python dictionaries...</p>
[ { "answer_id": 383732, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 3, "selected": false, "text": "while for for a in range(1, n / 2 + 1)\n" }, { "answer_id": 383736, "author": "Adam Rosenfield", "aut...
2008/12/20
[ "https://Stackoverflow.com/questions/383728", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
383,734
<p>What do you recommend for displaying URLs and handling views in Rails for cities, regions, countries?</p> <p>i.e:</p> <p>/us/ca/San-Fransisco</p> <p>/countries/us/regions/ca/cities/San-Fransisco</p> <p>Should be able to: List all countries, list all regions within country and list all cities within a region and country.</p> <p>Where would you put code for displaying all regions in a country?:</p> <p>/us/regions/</p> <p>/us</p> <p>Should the code be in the region (action show) or country (action index) controller?</p>
[ { "answer_id": 383840, "author": "Milan Novota", "author_id": 26123, "author_profile": "https://Stackoverflow.com/users/26123", "pm_score": 3, "selected": true, "text": "GET /us/regions\n class RegionsController < ApplicationController\n # GET /:country_code/regions\n # GET /regions\n ...
2008/12/20
[ "https://Stackoverflow.com/questions/383734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50718/" ]
383,735
<p>Are methods calls really so slow or is there something wrong in my computer?</p> <pre><code>static void Main(string[] args) { Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i &lt; 10000000; i++) { double z = Math.Pow(i,2); } Console.WriteLine(sw.ElapsedMilliseconds); sw = Stopwatch.StartNew(); for (int i = 0; i &lt; 10000000; i++) { Noop(); } Console.WriteLine(sw.ElapsedMilliseconds); } static void Noop() { } </code></pre> <p>The first loop takes 1600 - 1700 milliseconds, while the second loop takes 3100 - 3200 milliseconds in my system (Celeron D 2.53 Ghz 512 MB RAM Windows XP SP3 .NET 3.5). It's a commandline project. I got similar results with VB.Net .</p> <p>EDIT: I think I found the answer.</p>
[ { "answer_id": 383741, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": false, "text": "c:\\Users\\Jon\\Test>csc /o+ /debug- Test.cs\nMicrosoft (R) Visual C# 2008 Compiler version 3.5.30729.1\nfor Microsoft (...
2008/12/20
[ "https://Stackoverflow.com/questions/383735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38561/" ]
383,738
<p>We're developing a Python web service and a client web site in parallel. When we make an HTTP request from the client to the service, one call consistently raises a socket.error in socket.py, in read:</p> <pre>(104, 'Connection reset by peer')</pre> <p>When I listen in with wireshark, the "good" and "bad" responses look very similar:</p> <ul> <li>Because of the size of the OAuth header, the request is split into two packets. The service responds to both with ACK</li> <li>The service sends the response, one packet per header (HTTP/1.0 200 OK, then the Date header, etc.). The client responds to each with ACK.</li> <li>(Good request) the server sends a FIN, ACK. The client responds with a FIN, ACK. The server responds ACK.</li> <li>(Bad request) the server sends a RST, ACK, the client doesn't send a TCP response, the socket.error is raised on the client side.</li> </ul> <p>Both the web service and the client are running on a Gentoo Linux x86-64 box running glibc-2.6.1. We're using Python 2.5.2 inside the same virtual_env.</p> <p>The client is a Django 1.0.2 app that is calling httplib2 0.4.0 to make requests. We're signing requests with the OAuth signing algorithm, with the OAuth token always set to an empty string.</p> <p>The service is running Werkzeug 0.3.1, which is using Python's wsgiref.simple_server. I ran the WSGI app through wsgiref.validator with no issues.</p> <p>It seems like this should be easy to debug, but when I trace through a good request on the service side, it looks just like the bad request, in the socket._socketobject.close() function, turning delegate methods into dummy methods. When the send or sendto (can't remember which) method is switched off, the FIN or RST is sent, and the client starts processing.</p> <p>"Connection reset by peer" seems to place blame on the service, but I don't trust httplib2 either. Can the client be at fault?</p> <p>** Further debugging - Looks like server on Linux **</p> <p>I have a MacBook, so I tried running the service on one and the client website on the other. The Linux client calls the OS X server without the bug (FIN ACK). The OS X client calls the Linux service with the bug (RST ACK, and a (54, 'Connection reset by peer')). So, it looks like it's the service running on Linux. Is it x86_64? A bad glibc? wsgiref? Still looking...</p> <p>** Further testing - wsgiref looks flaky **</p> <p>We've gone to production with Apache and mod_wsgi, and the connection resets have gone away. See my answer below, but my advice is to log the connection reset and retry. This will let your server run OK in development mode, and solidly in production.</p>
[ { "answer_id": 383816, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 6, "selected": true, "text": "time.sleep(0.01)" } ]
2008/12/20
[ "https://Stackoverflow.com/questions/383738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10612/" ]
383,739
<p>I am using the toggle() with jQuery and I have a sidebar on my page and each header is </p> <pre><code>&lt;h2 class="sidebar-header"&gt; </code></pre> <p>One section of my code will look like:</p> <pre><code> &lt;div class="sidebar-section"&gt; &lt;h2 class="sidebar-header"&gt;SUBSCRIBE&lt;/h2&gt; &lt;p class="sidebar"&gt;Make sure you subscribe to stay in touch with the latest articles and tutorials. Click on one of the images below:&lt;/p&gt; &lt;div class="rss-icons"&gt; &lt;a href="http://fusion.google.com/add?feedurl=http://feeds.feedburner.com/ryancoughlin"&gt;&lt;img src="http://gmodules.com/ig/images/plus_google.gif" width="62" height="17" alt="Add to Google Reader or Homepage" class="feed-image"/&gt;&lt;/a&gt; &lt;a href="http://add.my.yahoo.com/rss?url=http://feeds.feedburner.com/ryancoughlin" title="Web/Graphic Design/Development by Ryan Coughlin"&gt;&lt;img src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo3.gif" alt="Add feed to My Yahoo" width="62" height="17" class="feed-image" /&gt;&lt;/a&gt; &lt;a href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http://feeds.feedburner.com/ryancoughlin" title="Web/Graphic Design/Development by Ryan Coughlin"&gt;&lt;img src="http://www.newsgator.com/images/ngsub1.gif" alt="Subscribe in NewsGator Online" class="feed-image" height="17" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;hr /&gt; &lt;p class="sidebar feed"&gt;Don't have those? Grab the &lt;a href="http://feeds.feedburner.com/ryancoughlin" target="_blank" title="Subscribe to this feed"&gt;RSS&lt;/a&gt; url.&lt;/p&gt; &lt;p class="sidebar delicious"&gt;Make sure you add me to &lt;a href="http://del.icio.us/post?url=http://www.ryancoughlin.com&amp;amp;title=Ryan Coughlin - Web/Graphic Design and Development" target="_blank" title="Add to delicious!"&gt;delicious!&lt;/a&gt; &lt;/p&gt; &lt;/div&gt; </code></pre> <p>They are each wrapped in those DIV elements. I am trying to make it for if you click the header, it will shrink up the content. I know toggle can do that, but if I make it for each "sidebar-header", you will click any one element on the page and it will hide them all, how can I do this?</p>
[ { "answer_id": 383750, "author": "Andreas Grech", "author_id": 44084, "author_profile": "https://Stackoverflow.com/users/44084", "pm_score": 1, "selected": false, "text": "<div class=\"topdiv\">\n <h2 class=\"header\">Header 1</h2>\n <div class=\"somecontent\">\n This is the...
2008/12/20
[ "https://Stackoverflow.com/questions/383739", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
383,757
<p>I'm looking for a compiler or interpreter for a language with basic math support and File IO which can be executed directly from a memorystick in either Linux or Windows. Built in functionality for basic datastructures and sorting/searching would be a plus.</p> <p>(I've read about movable python, but it only supports windows)</p> <p>Thank you</p>
[ { "answer_id": 383769, "author": "Arnout", "author_id": 3496, "author_profile": "https://Stackoverflow.com/users/3496", "pm_score": 1, "selected": false, "text": "perl.exe" }, { "answer_id": 384238, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https:...
2008/12/20
[ "https://Stackoverflow.com/questions/383757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12677/" ]
383,760
<p>I am trying to make a search view in Django. It is a search form with freetext input + some options to select, so that you can filter on years and so on. This is some of the code I have in the view so far, the part that does the filtering. And I would like some input on how expensive this would be on the database server.</p> <p><code> soknad_list = Soknad.objects.all()</p> <pre><code>if var1: soknad_list = soknad_list.filter(pub_date__year=var1) if var2: soknad_list = soknad_list.filter(muncipality__name__exact=var2) if var3: soknad_list = soknad_list.filter(genre__name__exact=var3) # TEXT SEARCH stop_word_list = re.compile(STOP_WORDS, re.IGNORECASE) search_term = '%s' % request.GET['q'] cleaned_search_term = stop_word_list.sub('', search_term) cleaned_search_term = cleaned_search_term.strip() if len(cleaned_search_term) != 0: soknad_list = soknad_list.filter(Q(dream__icontains=cleaned_search_term) | Q(tags__icontains=cleaned_search_term) | Q(name__icontains=cleaned_search_term) | Q(school__name__icontains=cleaned_search_term)) </code></pre> <p></code></p> <p>So what I do is, first make a list of all objects, then I check which variables exists (I fetch these with GET on an earlier point) and then I filter the results if they exists. But this doesn't seem too elegant, it probably does a lot of queries to achieve the result, so is there a better way to this?</p> <p>It does exactly what I want, but I guess there is a better/smarter way to do this. Any ideas?</p>
[ { "answer_id": 383797, "author": "Aaron", "author_id": 7503, "author_profile": "https://Stackoverflow.com/users/7503", "pm_score": 2, "selected": false, "text": "soknad_list.query.as_sql()[0]\n" } ]
2008/12/20
[ "https://Stackoverflow.com/questions/383760", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42546/" ]
383,765
<p>How can I get a DataSet with all the data from a SQL Express server using C#?</p> <p>Thanks</p> <p>edit: To clarify, I do want all the data from every table. The reason for this, is that it is a relatively small database. Previously I'd been storing all three tables in an XML file using DataSet's abilities. However, I want to migrate it to a database.</p>
[ { "answer_id": 383794, "author": "Eduardo Campañó", "author_id": 12091, "author_profile": "https://Stackoverflow.com/users/12091", "pm_score": 3, "selected": true, "text": "DbProviderFactory factory = DbProviderFactories.GetFactory(\"System.Data.SqlClient\");\n\nDataTable tables = null;\...
2008/12/20
[ "https://Stackoverflow.com/questions/383765", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12243/" ]
383,777
<p>I'm looking for a good, simple PHP function to get my latest Facebook status updates. Anyone know of one?</p> <p>Thanks!</p> <p><strong>EDIT:</strong> I've added a half-solution below.</p> <p>Or if anyone knows a good way to read in the RSS feed and spit out the recent status update?</p>
[ { "answer_id": 383805, "author": "jasonrm", "author_id": 31341, "author_profile": "https://Stackoverflow.com/users/31341", "pm_score": 1, "selected": false, "text": "http://www.new.facebook.com/feeds/status.php?id=[idnumber]&viewer=[viewer]&key=[key]&format=rss20" }, { "answer_id...
2008/12/20
[ "https://Stackoverflow.com/questions/383777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/396/" ]
383,780
<p>I have a simple text field for "Phone Number" in a contact form on a client's website. The formmail script returns whatever the user types into the field. For example, they'll receive "000-000-0000", "0000000000", (000) 000-000, etc. The client would like to receive all phone numbers in this form: 000-000-0000. Can someone provide a simple script that would strip out all extraneous punctuation, then re-insert the dashes?</p> <p>I'm not a programmer, just a designer so I can't provide any existing code for anyone to evaluate, though I'll be happy to email the formmail script to anyone who can help.</p> <p>Thanks. A. Grant</p>
[ { "answer_id": 383796, "author": "clawr", "author_id": 46201, "author_profile": "https://Stackoverflow.com/users/46201", "pm_score": 0, "selected": false, "text": "function formatPhone($number)\n{\n $number = str_replace(array('(', ')', '-', ' '), '', $number);\n if (strlen($number) ==...
2008/12/20
[ "https://Stackoverflow.com/questions/383780", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48047/" ]
383,781
<p>Is there any other place besides the metabase.xml file where the file upload size can be modified?</p> <p>I am currently running a staging server with IIS6 and it is setup to allow uploading of files up to 20mb. This works perfectly fine. I have a new production server where I am trying to setup this same available size limit. So I edited the metabase.xml file and set it to 20971520. Then I restarted IIS and that didn't work. So I then restarted the entire server, that also didn't work. I can upload files around 2mb so it is definitely allowing file sizes larger then the standard 200kb default size. I try uploading a 5mb file and my upload.aspx page completely crashes. Is it possible there is something else I need to configure? The production server is located on a server farm, could there be some limits set on there end?</p> <p>Thanks </p>
[ { "answer_id": 383835, "author": "netadictos", "author_id": 31791, "author_profile": "https://Stackoverflow.com/users/31791", "pm_score": 5, "selected": false, "text": "<system.web>\n <httpRuntime executionTimeout=\"240\" maxRequestLength=\"20480\" />\n</system.web>\n <system.webServer...
2008/12/20
[ "https://Stackoverflow.com/questions/383781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21664/" ]
383,783
<p>I'm currently wrestling with an Oracle SQL DATE conversion problem using iBATIS from Java.</p> <p>Am using the Oracle JDBC thin driver ojdbc14 version 10.2.0.4.0. iBATIS version 2.3.2. Java 1.6.0_10-rc2-b32.</p> <p>The problem revolves around a column of DATE type that is being returned by this snippet of SQL:</p> <pre><code>SELECT * FROM TABLE(pk_invoice_qry.get_contract_rate(?,?,?,?,?,?,?,?,?,?)) order by from_date </code></pre> <p>The package procedure call returns a ref cursor that is being wrapped in a TABLE to where is then easy to read the result set as though were a select query against a table.</p> <p>In PL/SQL Developer, one of the columns returned, FROM_DATE, of SQL DATE type, has precision to time of day:</p> <pre><code>Tue Dec 16 23:59:00 PST 2008 </code></pre> <p>But when I access this via iBATIS and JDBC, the value only retains precision to day:</p> <pre><code>Tue Dec 16 12:00:00 AM PST 2008 </code></pre> <p>This is clearer when displayed like so:</p> <p>Should have been:</p> <pre><code>1229500740000 milliseconds since epoch Tuesday, December 16, 2008 11:59:00 PM PST </code></pre> <p>But getting this instead:</p> <pre><code>1229414400000 milliseconds since epoch Tuesday, December 16, 2008 12:00:00 AM PST (as instance of class java.sql.Date) </code></pre> <p>No matter what I try, I am unable to expose the full precision of this DATE column to be returned via Java JDBC and iBATIS.</p> <p>What iBATIS is mapping from is this:</p> <pre><code>FROM_DATE : 2008-12-03 : class java.sql.Date </code></pre> <p>The current iBATIS mapping is this:</p> <pre><code>&lt;result property="from_date" jdbcType="DATE" javaType="java.sql.Date"/&gt; </code></pre> <p>I've also tried:</p> <pre><code>&lt;result property="from_date" jdbcType="DATETIME" javaType="java.sql.Date"/&gt; </code></pre> <p>or</p> <pre><code>&lt;result property="from_date" jdbcType="TIMESTAMP" javaType="java.sql.Timestamp"/&gt; </code></pre> <p>But all attempted mappings yield the same truncated Date value. It's as though JDBC has already done the damage of losing data precision before iBATIS even touches it.</p> <p>Clearly I'm losing some of my data precision by going through JDBC and iBATIS that is not happening when I stay in PL/SQL Developer running the same SQL snippet as a test script. Not acceptable at all, very frustrating, and ultimately very scary.</p>
[ { "answer_id": 383897, "author": "ninesided", "author_id": 1030, "author_profile": "https://Stackoverflow.com/users/1030", "pm_score": 0, "selected": false, "text": "java.sql.Date java.sql.Date DATE" }, { "answer_id": 384056, "author": "RogerV", "author_id": 48048, "a...
2008/12/20
[ "https://Stackoverflow.com/questions/383783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48048/" ]
383,801
<p>I believe i have set up Pg properly, but my script doesn't seem to be connecting to the database. I am testing with:</p> <pre> $database="networkem"; $user="postgres"; $password=""; $host="localhost"; $dbh = DBI->connect("DBI:Pg:dbname=$dbname;host=$host", $user, $password); </pre> <p>My pg_hba reads:</p> <pre> host all postgres 127.0.0.1 255.255.255.255 trust </pre> <p>I can use <code>psql</code> just fine via command-line and have started postmaster with -i option. What am I missing? </p> <p>I also tried with another user that works fine via psql:</p> <pre> $user="jimbo"; $password="p2ssw0rd"; </pre> <p>with pg_hba reading:</p> <pre> host all jimbo 127.0.0.1 255.255.255.255 trust </pre>
[ { "answer_id": 383877, "author": "Schwern", "author_id": 14660, "author_profile": "https://Stackoverflow.com/users/14660", "pm_score": 4, "selected": false, "text": "DBI->errstr my $dbh = DBI->connect(...) or die DBI->errstr;\n" }, { "answer_id": 430658, "author": "Dave Pirot...
2008/12/20
[ "https://Stackoverflow.com/questions/383801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
383,813
<p>In a Forms application I'm displaying log output from a long running command-line application that generated a lot of output. I start the program in the background, and capture its output and currently display it in a TextBox using AppendText. I prefer to only display for example the last 1000 lines. Removing lines from a TextBox is expensive, and a TextBox does not really feels like the best approach for rolling log display.</p> <p>Any ideas on the best Control to do a rolling log window in Windows Forms?</p>
[ { "answer_id": 384399, "author": "Serge van den Oever", "author_id": 48050, "author_profile": "https://Stackoverflow.com/users/48050", "pm_score": 4, "selected": false, "text": " delegate void UpdateCCNetWindowDelegate(String msg);\n\n private void Message2CCNetOutput(String messa...
2008/12/20
[ "https://Stackoverflow.com/questions/383813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48050/" ]
383,831
<p>I've got a mySql stored procedure that looks like this--</p> <pre><code>delimiter | create procedure GetEmployeeById(in ID varchar(45)) begin select id, firstName, lastName, phone, address1, address2, city, state, zip, username, password, emptypeid from myschema.tblemployees t where t.id=ID limit 1; end | delimiter; </code></pre> <p>If i don't have the limit 1 in place, it always returns all of the rows in the table--with each record's id value set to the ID parameter. Why can't i just use where id=ID, and why does it return all of the records when i do? What are the implications of me using limit 1? Why am i programming on a saturday night?</p>
[ { "answer_id": 383868, "author": "Rob Kennedy", "author_id": 33732, "author_profile": "https://Stackoverflow.com/users/33732", "pm_score": 2, "selected": false, "text": "id ID where" } ]
2008/12/20
[ "https://Stackoverflow.com/questions/383831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/94958/" ]
383,833
<p>Suppose I'm implementing a queue in java and I have a reference to the initial node, called ini and another to the last one, called last. Now, I start inserting objects into the queue. At one point, I decide I want an operation to clear the queue. Then I do this:</p> <pre><code>ini = null; last = null; </code></pre> <p>Am I leaking memory? The nodes between ini and last are all chained still and still have their data, I guess, but at the same time there's the garbage collector.</p> <p>An alternative would be to access each element and then null their references to the next node, but then I'd be basically doing it like in C++, except I wouldn't be explicitly using delete.</p>
[ { "answer_id": 383836, "author": "sk.", "author_id": 16399, "author_profile": "https://Stackoverflow.com/users/16399", "pm_score": 4, "selected": false, "text": "public class Stack {\n private final Object[] stack = new Object[10];\n private int top = 0;\n public void push(Object obj)...
2008/12/20
[ "https://Stackoverflow.com/questions/383833", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
383,848
<p>I'm looking for some open source F# projects to learn from. Something not snippets but full projects that are good representatives of F# features (i.e. pattern matching, discriminated unions, etc).</p> <p>My objective are mainly to see how all the features fit together, how the project is organized and how the problems are tackled from a functional perspective.</p>
[ { "answer_id": 6272738, "author": "Stephen Swensen", "author_id": 236255, "author_profile": "https://Stackoverflow.com/users/236255", "pm_score": 2, "selected": false, "text": "async Lazy TreeViewNodes" } ]
2008/12/20
[ "https://Stackoverflow.com/questions/383848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21239/" ]
383,850
<p>Is there a convention for naming the private method that I have called "<code>_Add</code>" here? I am not a fan of the leading underscore but it is what one of my teammates suggests.</p> <pre><code>public Vector Add(Vector vector) { // check vector for null, and compare Length to vector.Length return _Add(vector); } public static Vector Add(Vector vector1, Vector vector2) { // check parameters for null, and compare Lengths Vector returnVector = vector1.Clone() return returnVector._Add(vector2); } private Vector _Add(Vector vector) { for (int index = 0; index &lt; Length; index++) { this[index] += vector[index]; } return this; } </code></pre>
[ { "answer_id": 383851, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 5, "selected": false, "text": "*Impl AddImpl" }, { "answer_id": 383854, "author": "Greg Dean", "author_id": 1200558, "author_pro...
2008/12/20
[ "https://Stackoverflow.com/questions/383850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45914/" ]
383,857
<p>I'm having trouble trying to set the value of a property after i cast it. I'm not sure if this is called <em>boxing</em>.</p> <p>Anyways, the new variable is getting set, but the original is not. I thought the new variable is just a <em>reference</em> to the original. But when i check the intellisence/debug watcher, the original property is still null.</p> <p>here's the code.</p> <pre><code>// NOTE: data is either a Foo || FooFoo || FooBar, at this point. // only Foo impliments ITagElement. if (data is ITagElement) { var tags = ((ITagElement)data).TagList; // At this point, tags == null and data.TagList == null. if (tags.IsNullOrEmpty()) { tags = new List&lt;Tag&gt;(); } tags.Add(new Tag { K = xmlReader.GetAttribute("k"), V = xmlReader.GetAttribute("v") }); // At this point, Tags.Count == 1 and data.TagList == null :( :( :( } </code></pre> <p>Notice my inline comments about the values for <code>tags</code> and <code>data.TagList</code> ? Can some explain what I have done wrong? I thought the variable <code>tags</code> is just a reference pointer to the property <code>data.TagList</code> .. but it looks like it's not.</p> <h2>Update / Answer :)</h2> <p>thanks for the answers guys! it's embarassing cause i've been doing ths stuff for years and still forget/not notice simple things like this. (And of course, makes so much sence now that i see the light).</p> <p>Marc got the points because his answer (IMO) was the simplest for my single blond brain cell.</p> <p>Thanks all!</p>
[ { "answer_id": 383863, "author": "Rob Kennedy", "author_id": 33732, "author_profile": "https://Stackoverflow.com/users/33732", "pm_score": 0, "selected": false, "text": "TagList tags TagList tags TagList tags tags TagList" }, { "answer_id": 383864, "author": "Marc Gravell", ...
2008/12/20
[ "https://Stackoverflow.com/questions/383857", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30674/" ]
383,888
<p>Suppose I have this:</p> <pre><code>class test&lt;T&gt; { private T[] elements; private int size; public test(int size) { this.size = size; elements = new T[this.size]; } } </code></pre> <p>It seems this isn't possible because the compiler doesn't know what constructor to call once it tries to replace the generics code or something. What I'm wondering is, how would I go about doing this? I imagine it is possible, given how easily done it is in C++.</p> <p>Edit: Sorry I forgot the [] in the elements declaration.</p>
[ { "answer_id": 383892, "author": "mat", "author_id": 42083, "author_profile": "https://Stackoverflow.com/users/42083", "pm_score": 0, "selected": false, "text": "private T[] elements;\n" }, { "answer_id": 383895, "author": "Johannes Schaub - litb", "author_id": 34509, ...
2008/12/20
[ "https://Stackoverflow.com/questions/383888", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
383,898
<p>This is something I've pondered over for a while, as I've seen both used in practise.</p> <h2>Method 1</h2> <pre><code>&lt;ol&gt; &lt;li&gt;List item 1&lt;/li&gt; &lt;li&gt;List item 2 &lt;ol&gt; &lt;li&gt;List item 3&lt;/li&gt; &lt;/ol&gt; &lt;/li&gt; &lt;li&gt;List item 4&lt;/li&gt; &lt;/ol&gt; </code></pre> <p>This seems semantically correct to me, since the sub-list is a sub-list of that list item, however it isn't very clean (List Item Content<code>&lt;list right next to it&gt;</code>).</p> <h2>Method 2</h2> <pre><code>&lt;ol&gt; &lt;li&gt;List item 1&lt;/li&gt; &lt;li&gt;List item 2&lt;/li&gt; &lt;ol&gt; &lt;li&gt;List item 3&lt;/li&gt; &lt;/ol&gt; &lt;li&gt;List item 4&lt;/li&gt; &lt;/ol&gt; </code></pre> <p>Cleaner, but it's not directly understandable the list is a sub-list of item 2 (although it's understandable by human inference).</p> <p>This is purely a concern for semantic markup by the way, both methods present the same content on the page.</p> <p>So SO, what do you think? Sources where possible are preferable but personal use is good too. I notice that MediaWiki's heirachial TOCs are using Method 1 which encourages me to believe that's the correct use.</p>
[ { "answer_id": 383915, "author": "Rob Kennedy", "author_id": 33732, "author_profile": "https://Stackoverflow.com/users/33732", "pm_score": 5, "selected": true, "text": "OL OL LI OL LI" }, { "answer_id": 383922, "author": "Mark Brackett", "author_id": 2199, "author_pro...
2008/12/20
[ "https://Stackoverflow.com/questions/383898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2025/" ]
383,899
<p>this question is an extension to a <a href="https://stackoverflow.com/questions/383857/why-is-this-property-not-getting-set" title="My previous question about reference and property setting">previous question i asked</a> (and was answered). I'm refactoring my code an playing around with / experimenting with various refactored solutions.</p> <p>One of the solutions i came up with (but wasn't happy with .. remember, i'm just experimenting with some personal coding styles) wsa the following code :-</p> <pre><code>if (data is ITagElement) { if (((ITagElement) data).TagList.IsNullOrEmpty()) { ((ITagElement) data).TagList = new List&lt;Tag&gt;(); } ((ITagElement) data).TagList.Add(new Tag { K = xmlReader.GetAttribute("k"), V = xmlReader.GetAttribute("v") }); } </code></pre> <p>Notice how i'm casting the parent object <code>data</code> to the interface type it impliments a number of times? Code works, but i feel like this is code smell -> that it's not very efficient. I feel like this could be cast improved upon - thoughts from any guru's out there?</p>
[ { "answer_id": 383905, "author": "Tim Merrifield", "author_id": 36706, "author_profile": "https://Stackoverflow.com/users/36706", "pm_score": 5, "selected": true, "text": "ITagElement someData = data as ITagElement\nif (someData != null)\n{\n if (someData.TagList.IsNullOrEmpty())\n ...
2008/12/20
[ "https://Stackoverflow.com/questions/383899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30674/" ]
383,912
<p>I'd like to know if there's an easier way to batch insert a set of records if they don't already exist in a table. For example I have a Tags table in the database having ID, Name columns - given a list of tag names I want to add only those that are not already present. Here's what I came up with:</p> <pre><code>private static void InsertTags(IEnumerable&lt;string&gt; tagNames) { MyDataContext db = new MyDataContext(); var tags = from tagName in tagNames where (db.Tags.Where(tag =&gt; tagName == tag.Name).FirstOrDefault() == null) select new Tag { Name = tagName }; db.Tags.InsertAllOnSubmit(tags); } </code></pre> <p>Is there a better approach?</p>
[ { "answer_id": 383905, "author": "Tim Merrifield", "author_id": 36706, "author_profile": "https://Stackoverflow.com/users/36706", "pm_score": 5, "selected": true, "text": "ITagElement someData = data as ITagElement\nif (someData != null)\n{\n if (someData.TagList.IsNullOrEmpty())\n ...
2008/12/21
[ "https://Stackoverflow.com/questions/383912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48065/" ]
383,918
<p><strong>Question:</strong> For typed in commands invoked via M-x I am having difficulty understanding how Emacs allows recalling and rerunning the commands. The command-history works quite differently from Vim. It puts the commands in a buffer rather than the "minibuffer".</p> <p>Is there a way to get something similar to Vim's approach (i.e., previously typed commands can be scrolled through simply using the arrow up-down keys)?</p>
[ { "answer_id": 383924, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 1, "selected": false, "text": "customize-group minibuffer\n customize-group savehist\n /" }, { "answer_id": 383935, "author": ...
2008/12/21
[ "https://Stackoverflow.com/questions/383918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42223/" ]
383,921
<p>I have the types <code>Rock</code>, <code>Paper</code>, and <code>Scissors</code>. These are components, or "hands" of the Rock, Paper, Scissors game. Given two players' hands the game must decide who wins. How do I solve the problem of storing this chain chart</p> <p><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Rock_paper_scissors.jpg/250px-Rock_paper_scissors.jpg" alt="Rock, Paper, Scissors chart"></p> <p>without coupling the various hands to each other? The goal is to allow adding a new hand to the game (Jon Skeet, for instance) without changing any of the others.</p> <p>I am open to any idea of proxies, but not to large switch statements or duplication of code. For instance, introducing a new type that manages the chain's comparisons is fine as long as I don't need to change it for every new hand I add. Then again, if you can rationalize having a proxy that must change for every new hand or when a hand changes, that is welcome as well.</p> <p>This is sort of a Design 101 problem, but I am curious what solutions people can come up with for this. Obviously, this problem can easily scale to much larger systems with many more components with any arbitrarily complex relationships among them. That's why I'm laying a very simple and concrete example to solve. Any paradigm used, OOP or otherwise, is welcome.</p>
[ { "answer_id": 383926, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 3, "selected": true, "text": "public enum RPSEnum { Rock, Paper, Scissors }\n\nprivate RPSEnum FirtRPS = RPSEnum.Rock;\nprivate RPSEnum LastRPS = RPSE...
2008/12/21
[ "https://Stackoverflow.com/questions/383921", "https://Stackoverflow.com", "https://Stackoverflow.com/users/456/" ]
383,927
<p>Apache is spitting out a HTTP response of code: 400 "Bad Request" with no details whenever I access a page driven that is handled by a FastCGI script.</p> <ul> <li>I've installed the mod_fcgid module and it's loaded and configured in the Apache config files</li> <li>I've tested several FastCGI scripts, all of them run when directly executed.</li> <li>Static resources are served appropriately.</li> <li>Apache is trying to launch the script because it complains when I rewrite the URL to a non-existant script</li> </ul> <p>Anyone have any idea what's wrong with my Apache Config?</p> <pre><code>&lt;VirtualHost ip.ad.re.ss:80&gt; ServerName demo.domain.com:80 DocumentRoot /var/www/vhosts/domain.com/subdomains/demo/rails/public CustomLog /var/www/vhosts/domain.com/statistics/logs/demo_access_log combined ErrorLog /var/www/vhosts/domain.com/statistics/logs/demo_error_log LogLevel info Options +FollowSymLinks +ExecCGI -SymLinksIfOwnerMatch AddHandler fcgid-script .fcgi RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] &lt;/VirtualHost&gt; </code></pre> <p>EDIT -- I've checked the mod_rewrite logs and URI's are being rewritten correctly</p>
[ { "answer_id": 383926, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 3, "selected": true, "text": "public enum RPSEnum { Rock, Paper, Scissors }\n\nprivate RPSEnum FirtRPS = RPSEnum.Rock;\nprivate RPSEnum LastRPS = RPSE...
2008/12/21
[ "https://Stackoverflow.com/questions/383927", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13216/" ]
383,944
<p>When debugging in PHP, I frequently find it useful to simply stick a <a href="http://php.net/var-dump" rel="noreferrer">var_dump()</a> in my code to show me what a variable is, what its value is, and the same for anything that it contains.</p> <p>What is a good Python equivalent for this?</p>
[ { "answer_id": 383951, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 2, "selected": false, "text": "print __str__" }, { "answer_id": 383953, "author": "Martin v. Löwis", "author_id": 33006, "author_profile"...
2008/12/21
[ "https://Stackoverflow.com/questions/383944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20267/" ]
383,947
<p>I have seen this mentioned a few times and I am not clear on what it means. When and why would you do this? </p> <p>I know what interfaces do, but the fact I am not clear on this makes me think I am missing out on using them correctly. </p> <p>Is it just so if you were to do:</p> <pre><code>IInterface classRef = new ObjectWhatever() </code></pre> <p>You could use any class that implements <code>IInterface</code>? When would you need to do that? The only thing I can think of is if you have a method and you are unsure of what object will be passed except for it implementing <code>IInterface</code>. I cannot think how often you would need to do that. </p> <p>Also, how could you write a method that takes in an object that implements an interface? Is that possible?</p>
[ { "answer_id": 383952, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 5, "selected": false, "text": "IInterface classRef = new ObjectWhatever();\n IInterface classRef = container.Resolve<IInterface>();\n container publ...
2008/12/21
[ "https://Stackoverflow.com/questions/383947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35454/" ]
383,966
<p>More specifically, I'm trying to check if given string (a sentence) is in Turkish. </p> <p>I can check if the string has Turkish characters such as Ç, Ş, Ü, Ö, Ğ etc. However that's not very reliable as those might be converted to C, S, U, O, G before I receive the string.</p> <p>Another method is to have the 100 most used words in Turkish and check if the sentence includes any/some of those words. I can combine these two methods and use a point system. </p> <p>What do you think is the most efficient way to solve my problem in Python?</p> <p>Related question: <a href="https://stackoverflow.com/questions/257125/human-language-of-a-document">(human) Language of a document</a> (Perl, Google Translation API)</p>
[ { "answer_id": 383988, "author": "Daniel Naab", "author_id": 32638, "author_profile": "https://Stackoverflow.com/users/32638", "pm_score": 5, "selected": true, "text": "from reverend.thomas import Bayes\nguesser = Bayes()\nguesser.train('french', 'le la les du un une je il elle de en')\n...
2008/12/21
[ "https://Stackoverflow.com/questions/383966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
383,973
<p>This is a fundamental question, but an important one none the less...</p> <p><strong>When starting a C++ program whose main method has the following common signature:</strong></p> <pre><code>int main(int argc, char* args[]) { //Magic! return 0; } </code></pre> <p><strong>is args[0] always guaranteed to be the path to the currently running program? What about cross platform (since I am in a Linux environment but may port later on.)?</strong></p>
[ { "answer_id": 383976, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 6, "selected": true, "text": "exec int execve(const char *filename, char *const argv[],\n char *const envp[]);\n int main() { /*...
2008/12/21
[ "https://Stackoverflow.com/questions/383973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3552/" ]
383,977
<p>I've queued up over 10,000 files to be uploaded to a UNIX based FTP server using a freeware (Windows based) FTP client which as far as i can see has finished without error.</p> <p>Now, when i view the remote directory (using the Windows software) the output is truncated to 10,000 filenames. This ever occurs when i use the Windows command line FTP tool. Is there a way i can see more than this limit using another piece of software? I just need to confirm all files where indeed uploaded.</p> <p>Any ideas?</p> <p>Any information regarding this limit is very welcome.</p>
[ { "answer_id": 384055, "author": "Norman Ramsey", "author_id": 41661, "author_profile": "https://Stackoverflow.com/users/41661", "pm_score": 2, "selected": false, "text": "ftp://hostname/pub/..." } ]
2008/12/21
[ "https://Stackoverflow.com/questions/383977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13227/" ]
383,978
<p>Here's a small test program I wrote:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; int main(int argc, char **argv) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSArray *arr = [NSArray array]; printf("Arr isMemberOfClass NSArray: %d\n", [arr isMemberOfClass:[NSArray class]]); printf("Arr isKindOfClass NSArray: %d\n", [arr isKindOfClass:[NSArray class]]); [pool release]; return 0; } </code></pre> <p>And its output:</p> <pre><code>$ ./ismemberof Arr isMemberOfClass NSArray: 0 Arr isKindOfClass NSArray: 1 </code></pre> <p>How useful is the <code>-isMemberOfClass:</code> method in any of the Foundation classes? I understand this might give the desired results for classes which I subclass, but as for Foundation classes -- I find that a result of false for my arr variable is non-intuitive. Is the reason this happens because NSArray is not a concrete class but instead an abstract class, and underneath the hood NSArray is really a concrete instance of NSCFArray?</p>
[ { "answer_id": 384013, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "isMemberOfClass: [NSArray class]" }, { "answer_id": 384044, "author": "Peter Hosey", "author_id": 30461, "...
2008/12/21
[ "https://Stackoverflow.com/questions/383978", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40882/" ]
384,004
<p>I am using LINQ to EF and have the following LINQ query:</p> <pre><code>var results = (from x in ctx.Items group x by x.Year into decades orderby decades.Count() descending select new { Decade = decades.Key, DecadeCount = decades.Count() }); </code></pre> <p>So this kind of gets me to where I want to be, in that I get the items broken down by year and a count of items in that year. (i.e. 2001 - 10, 1975 - 15, 2005 - 5, 1976 - 1) The thing I really want to do though is to break them down by decade (i.e. 2000s - 15, 1970s - 16).</p> <p>How does one have a "calculated field" in the "by" part of the group clause for a Linq statement. I think what I want is basically something like:</p> <pre><code>var results = (from x in ctx.Items group x by (x =&gt; x.Year.Value.ToString().Substring(0, 3) + "0s") into decades orderby decades.Count() descending select new { Decade = decades.Key, DecadeCount = decades.Count() }); </code></pre> <p>Or more generally the syntax so that I can do some more complicated evaluation/calculation to do the group by on. Any ideas?</p> <p>EDIT (update):</p> <p>(x => x.Year.Value.ToString().Substring(0, 3) + "0s") - Doesn't Work - "LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression."</p> <p>(x.Year / 10 * 10) - Functionally works (thank you) - the only "problem" is that the 's' is not on the end (i.e. 1970 vs. 1970s)</p> <p>Is there anyway to put a function in the by clause? i.e. group x by this.ManipulateYear(x.Year) into decades ... or ... x => x.Year.Value.ToString().Substring(0,3) + "0s" ?? It would be nice to have some technique (such as calling a function or using a lambda expression) so that I can cover any case that I can think of.</p> <p>Thanks again for everyone's help on this.</p>
[ { "answer_id": 384012, "author": "Lucas", "author_id": 24231, "author_profile": "https://Stackoverflow.com/users/24231", "pm_score": 3, "selected": false, "text": "var results = (from x in ctx.Items\n group x by (x.Year / 10 * 10) into decades\n orderby decade...
2008/12/21
[ "https://Stackoverflow.com/questions/384004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25719/" ]
384,016
<p>I've never worked on a professional project with a team, as I'm still in high school. As a consequence, I've never been exposed to this whole "versioning" and "source control" thing. Are they the same? How exactly does a program that manages code manage code? I've heard you have to check out code (copy the existing code?) and merge it back in (what happens if someone changes code that you didn't change and you change something else and merge it in? Surely, his code is not replaced by your older version.) And, finally, what is the best/easiest example of this type of software?</p>
[ { "answer_id": 384165, "author": "dbr", "author_id": 745, "author_profile": "https://Stackoverflow.com/users/745", "pm_score": 3, "selected": false, "text": "svn commit somefile git commit somefile darcs get git svn" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27677/" ]
384,036
<p>I want to set up a continuous integration and test framework for my open source C++ project. The desired features are:</p> <pre><code>1. check out the source code 2. run all the unit and other tests 3. run performance tests (these measure the software quality - for example how long does it take the system to complete the test) 4. produce a report based on 3. and 4. daily 5. archive the reports for future reference </code></pre> <p>To implement this, which test framework and what continuous integration process would you recommend? Right now I am leaning towards Google Test Framework (I am aware of some of the comparisons of unit test frameworks discussed <a href="https://stackoverflow.com/questions/13699/choosing-a-c-unit-testing-toolframework">in other questions</a>) for tests and <a href="http://cruisecontrol.sourceforge.net/" rel="nofollow noreferrer">Cruisecontrol</a> for continuous integration. But I don't know if Cruisecontrol allows easy integration of performance metrics. </p> <p><em>Edit</em>: To answer Wilhelmtell, code should work with both Windows and Linux.</p>
[ { "answer_id": 384065, "author": "wilhelmtell", "author_id": 456, "author_profile": "https://Stackoverflow.com/users/456", "pm_score": 2, "selected": false, "text": "time sed" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19501/" ]
384,042
<p>Is there a built in way to limit the depth of a System.Collection.Generics.Stack? So that if you are at max capacity, pushing a new element would remove the bottom of the stack?</p> <p>I know I can do it by converting to an array and rebuilding the stack, but I figured there's probably a method on it already.</p> <p>EDIT: I wrote an extension method:</p> <pre><code> public static void Trim&lt;T&gt; (this Stack&lt;T&gt; stack, int trimCount) { if (stack.Count &lt;= trimCount) return; stack = new Stack&lt;T&gt; ( stack .ToArray() .Take(trimCount) ); } </code></pre> <p>So, it returns a new stack upon trimming, but isn't immutability the functional way =)</p> <p>The reason for this is that I'm storing undo steps for an app in a stack, and I only want to store a finite amount of steps.</p>
[ { "answer_id": 384047, "author": "Ryan Lundy", "author_id": 5486, "author_profile": "https://Stackoverflow.com/users/5486", "pm_score": 2, "selected": false, "text": "Stack<T> Stack<T> LimitedStack<T> Stack<T> Push Stack<T>" }, { "answer_id": 384097, "author": "Greg Dean", ...
2008/12/21
[ "https://Stackoverflow.com/questions/384042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
384,053
<p>Should be super simple for you guys...div one gets clicked, div two appears. What I don't know how to do is make div 2 go away when div one is clicked again.</p> <pre><code>&lt;img src="/..." width="" height"" onClick="MM_showHideLayers('logo','','show','logoEasterEgg','',show')"&gt; </code></pre> <p>What should I add to this line of code to make the div 'logoEasterEgg' disappear when the image in div 1 is clicked again?</p>
[ { "answer_id": 384057, "author": "Andrew Hare", "author_id": 34211, "author_profile": "https://Stackoverflow.com/users/34211", "pm_score": 0, "selected": false, "text": "MM_showHideLayers logo" }, { "answer_id": 384120, "author": "Jeremy Bade", "author_id": 13284, "au...
2008/12/21
[ "https://Stackoverflow.com/questions/384053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39781/" ]
384,076
<p>Some time ago, I saw a Mono application with colored output, presumably because of its log system (because all the messages were standardized). </p> <p>Now, Python has the <code>logging</code> module, which lets you specify a lot of options to customize output. So, I'm imagining something similar would be possible with Python, but I can’t find out how to do this anywhere. </p> <p>Is there any way to make the Python <code>logging</code> module output in color? </p> <p>What I want (for instance) errors in red, debug messages in blue or yellow, and so on. </p> <p>Of course this would probably require a compatible terminal (most modern terminals are); but I could fallback to the original <code>logging</code> output if color isn't supported.</p> <p>Any ideas how I can get colored output with the logging module?</p>
[ { "answer_id": 384125, "author": "airmind", "author_id": 48087, "author_profile": "https://Stackoverflow.com/users/48087", "pm_score": 8, "selected": false, "text": "BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)\n\n#The background is set with 40 plus the number of the ...
2008/12/21
[ "https://Stackoverflow.com/questions/384076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48087/" ]
384,078
<p>When I have tables in my database that have PK/FK relationships (int) and when they are modeled by the Entity Framework designer everything seems as it should be. I can write the code below and everything seems like it's going to work fine as well but then when I run the code I get an error on the project.Status.StatusName saying the Object reference not set to an instance of an object. I guess I was under the impression that the framework populated the associated entities when you populate the parent entity.</p> <pre><code> Dim db As New MyDbModel.MyDbEntities() Dim project As MyDbModel.Project = (From p In db.Project Where p.ProjectID = 1).First Response.Write(project.ProjectName) Response.Write(project.Status.StatusName) </code></pre>
[ { "answer_id": 384100, "author": "bendewey", "author_id": 37881, "author_profile": "https://Stackoverflow.com/users/37881", "pm_score": 4, "selected": true, "text": "Dim db As New MyDbModel.MyDbEntities() \nDim project As MyDbModel.Project = (From p In db.Project.Include(\"Status\") W...
2008/12/21
[ "https://Stackoverflow.com/questions/384078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47167/" ]
384,089
<p>I am try to use stringWithFormat to set a numerical value on the text property of a label but the following code is not working. I cannot cast the int to NSString. I was expecting that the method would know how to automatically convert an int to NSString.</p> <p>What do I need to do here?</p> <pre><code>- (IBAction) increment: (id) sender { int count = 1; label.text = [NSString stringWithFormat:@"%@", count]; } </code></pre>
[ { "answer_id": 384090, "author": "BobbyShaftoe", "author_id": 38426, "author_profile": "https://Stackoverflow.com/users/38426", "pm_score": 8, "selected": true, "text": "label.text = [NSString stringWithFormat:@\"%d\", count];\n" }, { "answer_id": 384094, "author": "Zach Lang...
2008/12/21
[ "https://Stackoverflow.com/questions/384089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10366/" ]
384,101
<p>Is there a way to use the formatter that comes with eclipse, outside of eclipse? I would like to format some java files using my formatter.xml file that I have configured using eclipse. Does anyone have any code examples that would allow me to do this? I would also like to use this standalone, so the specific jars that are used would be nice.</p>
[ { "answer_id": 51595344, "author": "Brad Parks", "author_id": 26510, "author_profile": "https://Stackoverflow.com/users/26510", "pm_score": 2, "selected": false, "text": "eclipse -vm <path to virtual machine> -application org.eclipse.jdt.core.JavaCodeFormatter [ OPTIONS ] <files>\n" } ...
2008/12/21
[ "https://Stackoverflow.com/questions/384101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17712/" ]
384,108
<p>I read through a bunch of questions asking about simple source code control tools and Git seemed like a reasonable choice. I have it up and running, and it works well so far. One aspect that I like about CVS is the automatic incrementation of a version number.</p> <p>I understand that this makes less sense in a distributed repository, but as a developer, I want/need something like this. Let me explain why:</p> <p>I use Emacs. Periodically I go through and look for new versions of the Lisp source files for third-party packages. Say I've got a file, foo.el, which, according to the header, is version 1.3; if I look up the latest version and see it's 1.143 or 2.6 or whatever, I know I'm pretty far behind.</p> <p>If instead I see a couple of 40-character hashes, I won't know which is later or get any idea of how much later it is. I would absolutely hate it if I had to manually check ChangeLogs just to get an idea of how out of date I am.</p> <p>As a developer, I want to extend this courtesy, as I see it, to the people that use my output (and maybe I'm kidding myself that anyone is, but let's leave that aside for a moment). I don't want to have to remember to increment the damn number myself every time, or a timestamp or something like that. That's a real PITA, and I know that from experience.</p> <p>So what alternatives do I have? If I can't get an $Id:$ equivalent, how else can I provide what I'm looking for?</p> <p>I should mention that my expectation is that the end user will NOT have Git installed and even if they do, will not have a local repository (indeed, I expect not to make it available that way). </p>
[ { "answer_id": 384177, "author": "Otto", "author_id": 9594, "author_profile": "https://Stackoverflow.com/users/9594", "pm_score": 2, "selected": false, "text": "master % git fetch\n master origin/master % git log master..origin/master foo.el\n origin/master master wc % git rev-list maste...
2008/12/21
[ "https://Stackoverflow.com/questions/384108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45978/" ]
384,110
<p>I cannot get std::tr1::shared_ptr for my WinMobile project since the STL for WinCE is maintained by a different team at Microsoft :( aarrgh...</p> <p>Anyone worked with another thread-safe, reference counting smart pointers? I'm actually using yasper which seems to be good. </p> <p>Thank you very much.</p>
[ { "answer_id": 384118, "author": "Hernán", "author_id": 48026, "author_profile": "https://Stackoverflow.com/users/48026", "pm_score": 0, "selected": false, "text": " //preferred \nptr<SomeClass> p1(new SomeClass);\n\n //less safe \nptr<SomeClass> p2 = new SomeClass; \n" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48026/" ]
384,119
<p>If I've queued up some email to be sent via the System.Net.Mail.SMTPClent, where can I find this mail? With the Windows SMTP Client, it's in the C:\inetpub\mailroot folder - is there a similar folder for the .NET client?</p> <p>EDIT: Here's an example. If I turn off the outgoing SMTP server on my XP computer and then run an application that sends a dozen emails, they get queued up somewhere, since the .NET SMTPClient.Send call succeeds. A few hours later, I start the local SMTP server, and the mail leaves in a sudden flurry. Where is it in the meantime? The same behavior happens on my Vista desktop, though I have no local SMTP server - I can duplicate the functionality by blocking port 25 on the firewall, and then mail queues up somewhere. Where?</p> <p>The reason for this question is that I want to re-enable the SMTP Service on a server I have, but I don't know what's been queued up in the meantime, and I want to make sure the queue is clean when I re-enable the service. That way, customers don't get really, really old queued emails all of the sudden.</p> <p><strong>EDIT</strong>: Clearly, I don't know what I'm talking about. When I do this on Vista:</p> <pre><code> Dim mm As New System.Net.Mail.MailMessage("me@me.com", "you@you.com", "Testing", "this is a test") Dim s As New System.Net.Mail.SmtpClient("localhost") s.DeliveryMethod = Mail.SmtpDeliveryMethod.PickupDirectoryFromIis s.Send(mm) </code></pre> <p>I get an exception because I don't have an IIS pickup folder. Changing it to "Mail.SmtpDeliveryMethod.Network" results in an immediate exception because I don't have an SMTP server running. I'll test this on server 2003, but I could have sworn that these both worked in the past. I'll do some more testing and modify the question if needed.</p>
[ { "answer_id": 494496, "author": "labilbe", "author_id": 1195872, "author_profile": "https://Stackoverflow.com/users/1195872", "pm_score": 1, "selected": false, "text": " <mailSettings>\n <!--\n <smtp\n deliveryMethod = \"Network\" [Network | Speci...
2008/12/21
[ "https://Stackoverflow.com/questions/384119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8114/" ]
384,121
<p>How would one go about loading compiled C code at run time, and then calling functions within it? Not like simply calling exec().</p> <p>EDIT: The the program loading the module is in C.</p>
[ { "answer_id": 384132, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 6, "selected": true, "text": "dlopen dlsym dlerror dlclose" }, { "answer_id": 384337, "author": "bortzmeyer", "author_id": 15625, ...
2008/12/21
[ "https://Stackoverflow.com/questions/384121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46431/" ]
384,145
<p>I have a page structure similar to this:</p> <pre><code>&lt;body&gt; &lt;div id="parent"&gt; &lt;div id="childRightCol"&gt; /*Content*/ &lt;/div&gt; &lt;div id="childLeftCol"&gt; /*Content*/ &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>I would like for the parent <code>div</code> to expand in <code>height</code> when the inner <code>div</code>'s <code>height</code> increases.</p> <p><strong>Edit:</strong><br> One problem is that if the <code>width</code> of the child content expands past the <code>width</code> of the browser window, my current CSS puts a horizontal scrollbar on the parent <code>div</code>. I would like the scrollbar to be at the page level. Currently my parent div is set to <code>overflow: auto;</code></p> <p>Can you please help me with the CSS for this?</p>
[ { "answer_id": 384149, "author": "bendewey", "author_id": 37881, "author_profile": "https://Stackoverflow.com/users/37881", "pm_score": 5, "selected": false, "text": "clear:both <body>\n<div id=\"parent\">\n <div id=\"childRightCol\">\n <div>\n <div id=\"childLeftCol\">\n <di...
2008/12/21
[ "https://Stackoverflow.com/questions/384145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10589/" ]
384,157
<p>I am working on a script to send data to a mysql table and I have it all working properly but the success part of the call, it is not loading my results in to my results column on my page. My code is below.</p> <p>Any suggestions on what I can do to fix that? I am guessing the problem is within my "success:" option in my AJAX call.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;Facebook like ajax post - jQuery - ryancoughlin.com&lt;/title&gt; &lt;link rel="stylesheet" href="css/screen.css" type="text/css" media="screen, projection" /&gt; &lt;link rel="stylesheet" href="css/print.css" type="text/css" media="print" /&gt; &lt;!--[if IE]&gt;&lt;link rel="stylesheet" href="css/ie.css" type="text/css" media="screen, projection"&gt;&lt;![endif]--&gt; &lt;script src="js/jquery.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ $(document).ready(function(){ $('p.validate').hide(); $.getJSON("readJSON.php",function(data){ $.each(data.posts, function(i,post){ content = '&lt;div id="post-'+ post.id +'"&gt;\n'; content += '&lt;h3&gt;' + post.author + '&lt;/h3&gt;\n'; content += '&lt;p class="small quiet"&gt;' + post.date_added + '&lt;/p&gt;\n'; content += '&lt;p&gt;' + post.post_content + '&lt;/p&gt;'; content += '&lt;hr/&gt;'; $("#contents").append(content).fadeIn("slow"); }); }); $(".reload").click(function() { $("#posts").empty(); }); $("#add_post").submit(function() { $('p.validate').empty(); // we want to store the values from the form input box, then send via ajax below var author = $('#author').attr('value'); var post = $('#post').attr('value'); if(($('#author').val() == "") &amp;&amp; ($('#post').val() == "")){ $("p.validate").fadeIn().append("Both fields are required."); $('#author,#post').fadeIn().addClass("error"); }else{ $.ajax({ type: "POST", url: "ajax.php", data: "author="+ author + "&amp;post=" + post, success: function(result){ $('#contents').after( "&lt;div&gt;" +result +"&lt;/div&gt;" ); } }); } return false; }); }); /* ]]&gt; */ &lt;/script&gt; &lt;style type="text/css"&gt; h3{margin:10px 0;} p{margin:5px 0;} #posts{display:none;} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="container"&gt; &lt;div class="span-24"&gt; &lt;div id="post-container" class="span-9 colborder"&gt; &lt;h2&gt;Posts loaded via Ajax:&lt;/h2&gt; &lt;div id="contents"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="form" class="span-11"&gt; &lt;h2&gt;New Post:&lt;/h2&gt; &lt;form name="add_post" id="add_post" action=""&gt; &lt;label&gt;Author:&lt;/label&gt;&lt;br /&gt; &lt;input type="text" name="author" id="author" size="15" class="text" /&gt;&lt;br /&gt; &lt;label&gt;Post:&lt;/label&gt;&lt;br /&gt; &lt;textarea name="post" id="post" rows="5" cols="5" class="text"&gt;&lt;/textarea&gt;&lt;br /&gt; &lt;input type="submit" value="Post" id="submit" /&gt;&lt;br /&gt; &lt;/form&gt;&lt;br /&gt; &lt;p class="validate error"&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="span-24"&gt; &lt;a href="#" class="reload"&gt;Reload&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
[ { "answer_id": 384167, "author": "bendewey", "author_id": 37881, "author_profile": "https://Stackoverflow.com/users/37881", "pm_score": 0, "selected": false, "text": "$.ajax({\n type: \"POST\",\n url: \"ajax.php\",\n da...
2008/12/21
[ "https://Stackoverflow.com/questions/384157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
384,184
<p>I'm trying to setup the MVC development enviroment on my laptop. I'm running WinXP Pro with IIS 5.1</p> <p>I got the environment setup with the sample MVC application that come with beta. I can only get to the home page. when i try to open About us page. i run into the page can not be found error. Is it the routing not set in the Global.asax?</p>
[ { "answer_id": 384188, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 1, "selected": false, "text": " routes.Add(new Route(\"{controller}.mvc.aspx/{action}\", \n new MvcRouteHandler()) \n { Defaults = new RouteVal...
2008/12/21
[ "https://Stackoverflow.com/questions/384184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28647/" ]
384,189
<p>I'd like to swap out an sql:query for some Java code that builds a complex query with several parameters. The current sql is a simple select.</p> <pre> &lt;sql:query var="result" dataSource="${dSource}" sql="select * from TABLE "> &lt;/sql:query> </pre> <p>How do I take my Java ResultSet (ie. rs = stmt.executeQuery(sql);) and make the results available in my JSP so I can do this textbook JSP?</p> <p>To be more clear, I want to remove the above query and replace it with Java.</p> <pre> &lt;% ResultSet rs = stmt.executeQuery(sql); // Messy code will be in some Controller %> </pre> <pre> &lt;c:forEach var="row" items="${result.rows}"> &lt;c:out value="${row.name}"/> &lt;/c:forEach> </pre> <p>Do I set the session/page variable in the Java section or is there some EL trick that I can use to access the variable?</p>
[ { "answer_id": 384719, "author": "krosenvold", "author_id": 23691, "author_profile": "https://Stackoverflow.com/users/23691", "pm_score": 0, "selected": false, "text": "ResultSet getResult()\n" }, { "answer_id": 2428468, "author": "BalusC", "author_id": 157882, "autho...
2008/12/21
[ "https://Stackoverflow.com/questions/384189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
384,200
<p>Forgive me, for I am fairly new to C++, but I am having some trouble regarding operator ambiguity. I think it is compiler-specific, for the code compiled on my desktop. However, it fails to compile on my laptop. I think I know what's going wrong, but I don't see an elegant way around it. Please let me know if I am making an obvious mistake. Anyhow, here's what I'm trying to do:</p> <p>I have made my own vector class called Vector4 which looks something like this:</p> <pre><code>class Vector4 { private: GLfloat vector[4]; ... } </code></pre> <p>Then I have these operators, which are causing the problem:</p> <pre><code>operator GLfloat* () { return vector; } operator const GLfloat* () const { return vector; } GLfloat&amp; operator [] (const size_t i) { return vector[i]; } const GLfloat&amp; operator [] (const size_t i) const { return vector[i]; } </code></pre> <p>I have the conversion operator so that I can pass an instance of my Vector4 class to glVertex3fv, and I have subscripting for obvious reasons. However, calls that involve subscripting the Vector4 become ambiguous to the compiler:</p> <pre><code>enum {x, y, z, w} Vector4 v(1.0, 2.0, 3.0, 4.0); glTranslatef(v[x], v[y], v[z]); </code></pre> <p>Here are the candidates:</p> <pre><code>candidate 1: const GLfloat&amp; Vector4:: operator[](size_t) const candidate 2: operator[](const GLfloat*, int) &lt;built-in&gt; </code></pre> <p>Why would it try to convert my Vector4 to a GLfloat* first when the subscript operator is already defined on Vector4? Is there a simple way around this that doesn't involve typecasting? Am I just making a silly mistake? Thanks for any help in advance.</p>
[ { "answer_id": 384211, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": true, "text": "begin end vector vector + 4 v.begin() struct Vector4 {\n // some of container requirements\n typedef G...
2008/12/21
[ "https://Stackoverflow.com/questions/384200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48096/" ]
384,220
<p>I have a crazy navigation menu that I have to code. It's kind of tough. Please see the screenshot of the design here:</p> <p><a href="https://i.stack.imgur.com/l3U7W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l3U7W.png" alt="nav menu"></a> </p> <p><a href="http://i41.tinypic.com/307xfo9.png" rel="nofollow noreferrer">navigation menu screenshot</a></p> <p>As you can see, the background of the "Home" menu item is quite tough! I can't figure out how to make its background "see-through", meaning it cuts through the dark background and shows the patterned green background.</p> <p>Do you know how to do this using css?</p> <p>Thanks in advance.</p>
[ { "answer_id": 384241, "author": "Jonathan Lonowski", "author_id": 15031, "author_profile": "https://Stackoverflow.com/users/15031", "pm_score": 2, "selected": false, "text": "background: transparent;\nbackground: inherit;\n inherit background-image: url('greencheckers'); /* outer */\n\n...
2008/12/21
[ "https://Stackoverflow.com/questions/384220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
384,228
<p>I'm having some trouble updating a row in a MySQL database. Here is the code I'm trying to run:</p> <pre><code>import MySQLdb conn=MySQLdb.connect(host="localhost", user="root", passwd="pass", db="dbname") cursor=conn.cursor() cursor.execute("UPDATE compinfo SET Co_num=4 WHERE ID=100") cursor.execute("SELECT Co_num FROM compinfo WHERE ID=100") results = cursor.fetchall() for row in results: print row[0] print "Number of rows updated: %d" % cursor.rowcount cursor.close() conn.close() </code></pre> <p>The output I get when I run this program is:</p> <blockquote> <p>4<br>Number of rows updated: 1</p> </blockquote> <p>It seems like it's working but if I query the database from the MySQL command line interface (CLI) I find that it was not updated at all. However, if from the CLI I enter <code>UPDATE compinfo SET Co_num=4 WHERE ID=100;</code> the database is updated as expected.</p> <p>What is my problem? I'm running Python 2.5.2 with MySQL 5.1.30 on a Windows box.</p>
[ { "answer_id": 384240, "author": "Zoredache", "author_id": 20267, "author_profile": "https://Stackoverflow.com/users/20267", "pm_score": 7, "selected": true, "text": "conn.commit() close" }, { "answer_id": 384452, "author": "ʞɔıu", "author_id": 41613, "author_profile"...
2008/12/21
[ "https://Stackoverflow.com/questions/384228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38/" ]
384,247
<p>Whenever we make changes to the CSS, it generally takes 24 hours to reflect those changes on my site. I have tried clearing the server cache and browser cache but it doesn't help too. Is there any other way to make the CSS changes reflect immediately after updation?</p> <p>it happens in all the browsers... when i check it in the browser , i can access my css file with two paths eg : i store my css in folder named "Cssfolder" and my css name is say 135.css So when i access the folder paths, <strong>C</strong>ssfolder/135.css &amp; <strong>c</strong>ssfolder/135.css, one of the path shows me latest css whereas other one shows me old css.Notice the "c" is captital in one path whereas small in other path.</p> <p>Thanks. </p>
[ { "answer_id": 384275, "author": "Ian G", "author_id": 31765, "author_profile": "https://Stackoverflow.com/users/31765", "pm_score": -1, "selected": false, "text": "<style type=\"text/css\">\n/* your css */\n</style>\n" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29515/" ]
384,262
<pre><code>var insInvoice = new NpgsqlCommand( @"INSERT INTO invoice_detail( invoice_id, invoice_detail_id, product_id, qty, price, amount) VALUES ( :_invoice_id, :_invoice_detail_id, :_product_id, :_qty, :_price, :_qty * :_price)", c); with(var p = insInvoice.Parameters) { p.Add("_invoice_id", NpgsqlDbType.Uuid, 0, "invoice_id"); p.Add("_invoice_detail_id", NpgsqlDbType.Uuid, 0, "invoice_detail_id"); p.Add("_product_id", NpgsqlDbType.Uuid, 0, "product_id"); p.Add("_qty", NpgsqlDbType.Integer, 0, "qty"); p.Add("_price", NpgsqlDbType.Numeric, 0, "price"); } </code></pre> <hr> <pre><code>kludge: for(var p = insInvoice.Parameters; false;) { p.Add("_invoice_id", NpgsqlDbType.Uuid, 0, "invoice_id"); p.Add("_invoice_detail_id", NpgsqlDbType.Uuid, 0, "invoice_detail_id"); p.Add("_product_id", NpgsqlDbType.Uuid, 0, "product_id"); p.Add("_qty", NpgsqlDbType.Integer, 0, "qty"); p.Add("_price", NpgsqlDbType.Numeric, 0, "price"); } </code></pre>
[ { "answer_id": 384274, "author": "yfeldblum", "author_id": 12349, "author_profile": "https://Stackoverflow.com/users/12349", "pm_score": 0, "selected": false, "text": "var insInvoice = new NpgsqlCommand(...);\ninsInvoice.Parameters.With(p => {\n p.Add(\"_invoice_id\", NpgsqlDbType.Uui...
2008/12/21
[ "https://Stackoverflow.com/questions/384262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11432/" ]
384,264
<p>I want to implement something exactly like "<a href="http://msdn.microsoft.com/en-us/library/aa905322.aspx" rel="nofollow noreferrer">Changing the Default Text in the Search Box</a>" for a WPF search TextBox. The box should show some greyed out "Search.." text when it's empty, and then it should function normally when text is typed in. The linked article shows how to do this in javascript. How would one start down this path in WPF? The best idea I've had so far is another text box on top of the main one that goes invisible whenever the search textbox gets focus or text.</p>
[ { "answer_id": 384330, "author": "Kent Boogaart", "author_id": 5380, "author_profile": "https://Stackoverflow.com/users/5380", "pm_score": 1, "selected": false, "text": "TextBox HintText HintText Text \"\" Text TextBox TextBox Tag UserControl TextBox TextBlock Grid TextBlock TextBox Text...
2008/12/21
[ "https://Stackoverflow.com/questions/384264", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47605/" ]
384,284
<p>Is there a way to rename an open file in Emacs? While I'm viewing it? Something like save-as, but the original one should go away.</p>
[ { "answer_id": 384612, "author": "Chris Conway", "author_id": 1412, "author_profile": "https://Stackoverflow.com/users/1412", "pm_score": 9, "selected": false, "text": "dired C-x d RET C-x C-j dired-jump R dired-do-rename q mv mv" }, { "answer_id": 1834038, "author": "Shawn H...
2008/12/21
[ "https://Stackoverflow.com/questions/384284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6068/" ]
384,286
<p>I'm trying to get:</p> <pre><code>document.createElement('div') //=&gt; true {tagName: 'foobar something'} //=&gt; false </code></pre> <p>In my own scripts, I used to just use this since I never needed <code>tagName</code> as a property:</p> <pre><code>if (!object.tagName) throw ...; </code></pre> <p>So for the second object, I came up with the following as a quick solution -- which mostly works. ;)</p> <p>The problem is, it depends on browsers enforcing read-only properties, which not all do.</p> <pre><code>function isDOM(obj) { var tag = obj.tagName; try { obj.tagName = ''; // Read-only for DOM, should throw exception obj.tagName = tag; // Restore for normal objects return false; } catch (e) { return true; } } </code></pre> <p>Is there a good substitute?</p>
[ { "answer_id": 384301, "author": "finpingvin", "author_id": 46054, "author_profile": "https://Stackoverflow.com/users/46054", "pm_score": 3, "selected": false, "text": "if (obj.nodeName){\n switch (obj.nodeType){\n case 1: return 'element';\n case 3: return (/\\S/).test(obj.node...
2008/12/21
[ "https://Stackoverflow.com/questions/384286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15031/" ]
384,294
<p>While disassembling the .Net Source Code using Reflector, I came upon the Equals implementation in the Object Class and it refers to </p> <pre><code>bool InternalEquals(object objA, object objB); </code></pre> <p>Which again refers to </p> <pre><code>internal static extern bool InternalEquals(object objA, object objB); </code></pre> <p>I am now confused regarding where to find the implementation of this <code>InternalEquals(object objA, object objB)</code> function and how is it using this function and in which .Net assembly is this function defined and also if each and everything is written from scratch for the .Net Source Code, then why am I unable to find this function's implementation.</p>
[ { "answer_id": 384296, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 4, "selected": false, "text": "[MethodImpl(MethodImplOptions.InternalCall)] sscli20/clr/src/vm/comobject.cpp FCIMPL2(FC_BOOL_RET, ObjectNative::Equals, Objec...
2008/12/21
[ "https://Stackoverflow.com/questions/384294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45972/" ]
384,304
<p>How can I create a local user account using .NET 2.0 and c# and also be able to set the "Password never expires" to never. </p> <p>I have tried using "Net.exe" using Process.Start and passing its parameters but it seems that the "net user" is unable to set the "Password never expires" to never.</p>
[ { "answer_id": 384307, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 6, "selected": true, "text": "DirectoryEntry localMachine = new DirectoryEntry(\"WinNT://\" + \n Environment.MachineName);\nDirectoryEntry newUser = lo...
2008/12/21
[ "https://Stackoverflow.com/questions/384304", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34623/" ]
384,306
<p>I am upgrading an unmanaged C++ application to use the XP/Vista style common controls by adding a manifest. According to MSDN's page on <a href="http://msdn.microsoft.com/en-us/library/aa374191.aspx" rel="nofollow noreferrer">application manifests</a>, you are required to specify the name and version in the manifest, and optionally the description:</p> <pre><code>&lt;assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"&gt; &lt;assemblyIdentity version="1.2.3.4" processorArchitecture="*" name="CompanyName.ApplicationName" type="win32" /&gt; &lt;description&gt;Application's description here&lt;/description&gt; &lt;/assembly&gt; </code></pre> <p>How are these details used? There is <a href="http://msdn.microsoft.com/en-us/library/aa374234(VS.85).aspx" rel="nofollow noreferrer">a mention</a> about backward compatibility being implied by having the same major and minor versions for assemblies, but this does not seem to apply to applications. I also haven't been able to see the name, version, or description specified by the manifest in the application's properties on Windows XP.</p> <p>What effect does changing these have? Is it worthwhile to keep the version up-to-date?</p>
[ { "answer_id": 384307, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 6, "selected": true, "text": "DirectoryEntry localMachine = new DirectoryEntry(\"WinNT://\" + \n Environment.MachineName);\nDirectoryEntry newUser = lo...
2008/12/21
[ "https://Stackoverflow.com/questions/384306", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25637/" ]
384,310
<p>On a site with a high number of users, should paging be handled in code, or with a stored procedure. If you have employed caching, please include your success factors.</p>
[ { "answer_id": 384347, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 1, "selected": false, "text": "Skip() Take()" }, { "answer_id": 384388, "author": "netadictos", "author_id": 31791, "author_prof...
2008/12/21
[ "https://Stackoverflow.com/questions/384310", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19799/" ]
384,318
<p>In any class, how do I explicitly refer to a certain method of my class?</p> <p>For example, this code works:</p> <pre><code>class Test : IEnumerable&lt;T&gt; { public IEnumerator&lt;T&gt; GetEnumerator() { return null; } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } </code></pre> <p>But this one doesn't!</p> <pre><code>class Test : IEnumerable&lt;T&gt; { IEnumerator&lt;T&gt; IEnumerable&lt;T&gt;.GetEnumerator() { return null; } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } // error } </code></pre> <p>How do I refer to the generic version of my method? In Java I would simply prefix it with the interface name, but this does't seem to work in C#. Is there a way to do this, other than <code>((IEnumerable&lt;T&gt;)this).GetEnumerator()</code>?</p> <p><strong>EDIT:</strong> I'm not interested in "why" it does't work this way. I'm just looking for a way to do it. Thanks.</p>
[ { "answer_id": 384334, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 1, "selected": false, "text": " IEnumerator<T> IEnumerable<T>.GetEnumerator() { return null; } // TODO\n IEnumerator IEnumerable.GetEnumerator...
2008/12/21
[ "https://Stackoverflow.com/questions/384318", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41283/" ]
384,332
<p>I manage Unix systems where, sometimes, programs like CGI scripts run forever, sometimes eating a lot of CPU time and wasting resources. </p> <p>I want a program (typically invoked from cron) which can kill these runaways, based on the following criteria (combined with AND and OR):</p> <ul> <li>Name (given by a regexp)</li> <li>CPU time used</li> <li>elapsed time (for programs which are blocked on an I/O)</li> </ul> <p>I do not really know what to type in a search engine for this sort of program. I certainly could write it myself in Python but I'm lazy and there is may be a good program already existing?</p> <p>(I did not tag my question with a language name since a program in Perl or Ruby or whatever would work as well)</p>
[ { "answer_id": 384369, "author": "Alex B", "author_id": 23643, "author_profile": "https://Stackoverflow.com/users/23643", "pm_score": 2, "selected": false, "text": "/etc/security/limits.conf /etc/login.conf mod_suid" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15625/" ]
384,336
<p>I'm trying to pass information to a python page via the url. I have the following link text:</p> <pre><code>"&lt;a href='complete?id=%s'&gt;" % (str(r[0])) </code></pre> <p>on the complete page, I have this:</p> <pre><code>import cgi def complete(): form = cgi.FieldStorage() db = MySQLdb.connect(user="", passwd="", db="todo") c = db.cursor() c.execute("delete from tasks where id =" + str(form["id"])) return "&lt;html&gt;&lt;center&gt;Task completed! Click &lt;a href='/chris'&gt;here&lt;/a&gt; to go back!&lt;/center&gt;&lt;/html&gt;" </code></pre> <p>The problem is that when i go to the complete page, i get a key error on "id". Does anyone know how to fix this?</p> <p><em>EDIT</em><br> when i run <code>cgi.test()</code> it gives me nothing</p> <p>I think something is wrong with the way i'm using the url because its not getting passed through.</p> <p>its basically <em>localhost/chris/complete?id=1</em></p> <p><em>/chris/</em> is a folder and complete is a function within <em>index.py</em></p> <p>Am i formatting the url the wrong way?</p>
[ { "answer_id": 384355, "author": "gimel", "author_id": 6491, "author_profile": "https://Stackoverflow.com/users/6491", "pm_score": 1, "selected": false, "text": "form[\"id\"] \"id\" cgi.FieldStorage() import cgitb; cgitb.enable() #!/usr/bin/python\nimport cgi\ncgi.test()\n" }, { ...
2008/12/21
[ "https://Stackoverflow.com/questions/384336", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128/" ]
384,350
<p>It doesn't remove everything inside the 2nd form tag but just hides the and tags from the page</p> <p>Any ideas and workaround?</p>
[ { "answer_id": 384361, "author": "Andreas Grech", "author_id": 44084, "author_profile": "https://Stackoverflow.com/users/44084", "pm_score": 0, "selected": false, "text": "myTextbox.Text = 'Hello';" }, { "answer_id": 67840958, "author": "Colin", "author_id": 3304104, ...
2008/12/21
[ "https://Stackoverflow.com/questions/384350", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48118/" ]
384,373
<p>IS there any way i can do that?</p>
[ { "answer_id": 384381, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "do shell script" }, { "answer_id": 389585, "author": "Jörg W Mittag", "author_id": 2988, "author_profile":...
2008/12/21
[ "https://Stackoverflow.com/questions/384373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
384,391
<p>I have a worker thread that is listening to a TCP socket for incoming traffic, and buffering the received data for the main thread to access (let's call this socket <em>A</em>). However, the worker thread also has to do some regular operations (say, once per second), even if there is no data coming in. Therefore, I use <code>select()</code> with a timeout, so that I don't need to keep polling. (Note that calling <code>receive()</code> on a non-blocking socket and then sleeping for a second is not good: the incoming data should be immediately available for the main thread, even though the main thread might not always be able to process it right away, hence the need for buffering.)</p> <p>Now, I also need to be able to signal the worker thread to do some other stuff immediately; from the main thread, I need to make the worker thread's <code>select()</code> return right away. For now, I have solved this as follows (approach basically adopted from <a href="http://mail.python.org/pipermail/python-list/2002-May/147063.html" rel="noreferrer">here</a> and <a href="http://www.developerweb.net/forum/showthread.php?t=5154" rel="noreferrer">here</a>):</p> <p>At program startup, the worker thread creates for this purpose an additional socket of the datagram (UDP) type, and binds it to some random port (let's call this socket <em>B</em>). Likewise, the main thread creates a datagram socket for sending. In its call to <code>select()</code>, the worker thread now lists both <em>A</em> and <em>B</em> in the <code>fd_set</code>. When the main thread needs to signal, it <code>sendto()</code>'s a couple of bytes to the corresponding port on <code>localhost</code>. Back in the worker thread, if <em>B</em> remains in the <code>fd_set</code> after <code>select()</code> returns, then <code>recvfrom()</code> is called and the bytes received are simply ignored.</p> <p>This seems to work very well, but I can't say I like the solution, mainly as it requires binding an extra port for <em>B</em>, and also because it adds several additional socket API calls which may fail I guess – and I don't really feel like figuring out the appropriate action for each of the cases.</p> <p>I think ideally, I would like to call some function which takes <em>A</em> as input, and does nothing except makes <code>select()</code> return right away. However, I don't know such a function. (I guess I could for example <code>shutdown()</code> the socket, but the side effects are not really acceptable :)</p> <p>If this is not possible, the second best option would be creating a <em>B</em> which is much dummier than a real UDP socket, and doesn't really require allocating any limited resources (beyond a reasonable amount of memory). I guess <a href="http://en.wikipedia.org/wiki/Unix_domain_sockets" rel="noreferrer">Unix domain sockets</a> would do exactly this, but: the solution should not be much less cross-platform than what I currently have, though some moderate amount of <code>#ifdef</code> stuff is fine. (I am targeting mainly for Windows and Linux – and writing C++ by the way.)</p> <p>Please don't suggest refactoring to get rid of the two separate threads. This design is necessary because the main thread may be blocked for extended periods (e.g., doing some intensive computation – and I can't start periodically calling <code>receive()</code> from the innermost loop of calculation), and in the meanwhile, someone needs to buffer the incoming data (and due to reasons beyond what I can control, it cannot be the sender).</p> <p>Now that I was writing this, I realized that someone is definitely going to reply simply "<a href="http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio.html" rel="noreferrer">Boost.Asio</a>", so I just had my first look at it... Couldn't find an obvious solution, though. Do note that I also cannot (easily) affect how socket <em>A</em> is created, but I should be able to let other objects wrap it, if necessary.</p>
[ { "answer_id": 384397, "author": "Alex B", "author_id": 23643, "author_profile": "https://Stackoverflow.com/users/23643", "pm_score": 6, "selected": true, "text": "select() fd_set #ifdef WIN32 fd_set select()" }, { "answer_id": 70470737, "author": "Bruce Lu", "author_id":...
2008/12/21
[ "https://Stackoverflow.com/questions/384391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19254/" ]
384,392
<p>still trying to find where i would use the "yield" keyword in a real situation.</p> <p>I see this thread on the subject </p> <p><a href="https://stackoverflow.com/questions/39476/what-is-the-yield-keyword-used-for-in-c">What is the yield keyword used for in C#?</a></p> <p>but in the accepted answer, they have this as an example where someone is iterating around Integers()</p> <pre><code>public IEnumerable&lt;int&gt; Integers() { yield return 1; yield return 2; yield return 4; yield return 8; yield return 16; yield return 16777216; } </code></pre> <p>but why not just use</p> <pre><code>list&lt;int&gt; </code></pre> <p>here instead. seems more straightforward..</p>
[ { "answer_id": 384403, "author": "Trap", "author_id": 7839, "author_profile": "https://Stackoverflow.com/users/7839", "pm_score": 0, "selected": false, "text": "public IEnumerable<ICustomer> Customers()\n{\n foreach( ICustomer customer in m_maleCustomers )\n {\n ...
2008/12/21
[ "https://Stackoverflow.com/questions/384392", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
384,401
<p>I'm currently trying to implement a class to handle secure communications between instances of my app using RSACrytoServiceProveider class. First question : is it a good idea implement a single class to handle sender/reciever roles or should i split the roles into individual classes ?. This is what i have done so far:</p> <pre><code>using System; using System.Text; using System.Security.Cryptography; namespace Agnus.Cipher { public class RSA { private byte[] plaintextBytes; private byte[] ciphertextBytes; private RSACryptoServiceProvider rSAProviderThis; private RSACryptoServiceProvider rSAProviderOther; public string PublicKey { get { return rSAProviderThis.ToXmlString(false); } } public RSA() { rSAProviderThis = new RSACryptoServiceProvider { PersistKeyInCsp = true }; plaintextBytes = Encoding.Unicode.GetBytes(PublicKey); } public void InitializeRSAProviderOther(string parameters) { rSAProviderOther.FromXmlString(parameters); } public byte[] Encrypt() { return rSAProviderThis.Encrypt(plaintextBytes, true); } public byte[] Decrypt() { return rSAProviderThis.Decrypt(ciphertextBytes, true); } public byte[] Sign() { using (SHA1Managed SHA1 = new SHA1Managed()) { byte[] hash = SHA1.ComputeHash(ciphertextBytes); byte[] signature = rSAProviderThis.SignHash(hash, CryptoConfig.MapNameToOID("SHA1")); return signature; } } public void Verify() { throw new NotImplementedException(); } } } </code></pre> <p>Second question : how do i send and receive data to be fed into the class ? i'm a green horn in this field, pointers would be appreciated.</p>
[ { "answer_id": 384472, "author": "Andrea Celin", "author_id": 47458, "author_profile": "https://Stackoverflow.com/users/47458", "pm_score": 1, "selected": false, "text": "Namespace Crypto\n\n Public Class RSACry\n\n Shared Sub New()\n End Sub\n\n Public Enum Algor...
2008/12/21
[ "https://Stackoverflow.com/questions/384401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48127/" ]
384,419
<p>I have a list that looks like (A (B (C D)) (E (F))) which represents this tree:</p> <pre><code> A / \ B E / \ / C D F </code></pre> <p>How do I print it as (A B E C D F) ?</p> <p>This is as far as I managed:</p> <pre><code>((lambda(tree) (loop for ele in tree do (print ele))) my-list) </code></pre> <p>But it prints:</p> <pre><code>A (B (C D)) (E (F)) NIL </code></pre> <p>I'm pretty new to Common LISP so there may be functions that I should've used. If that's the case then enlight me.</p> <p>Thanks.</p>
[ { "answer_id": 384582, "author": "namin", "author_id": 34596, "author_profile": "https://Stackoverflow.com/users/34596", "pm_score": 2, "selected": false, "text": "(A ((B (C D)) (E (F)))) (defun by-levels (ts)\n (if (null ts)\n '()\n (append\n (mapcar #'(lambda (x) (if (...
2008/12/21
[ "https://Stackoverflow.com/questions/384419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15345/" ]
384,431
<pre><code>game.h needs: - packet.h - socket.h server.h needs: - socket.h socket.h needs: - game.h </code></pre> <p>The problem comes when I try to include socket.h into game.h, because socket.h has game.h included already. How do I solve these kind of problems?</p>
[ { "answer_id": 384434, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 5, "selected": true, "text": "#ifndef GAME_H\n#define GAME_H\n\n.. rest of your header file here\n\n#endif\n" }, { "answer_id": 384439, ...
2008/12/21
[ "https://Stackoverflow.com/questions/384431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
384,442
<p>I have byte array as input. I would like to convert that array to string that contains hexadecimal representation of array values. This is F# code:</p> <pre><code>let ByteToHex bytes = bytes |&gt; Array.map (fun (x : byte) -&gt; String.Format("{0:X2}", x)) let ConcatArray stringArray = String.Join(null, (ByteToHex stringArray)) </code></pre> <p>This produces result I need, but I would like to make it more compact so that I have only one function. I could not find function that would concat string representation of each byte at the end of ByteToHex. <br> I tried Array.concat, concat_map, I tried with lists, but the best I could get is array or list of strings.</p> <p>Questions:</p> <ol> <li>What would be simplest, most elegant way to do this?</li> <li>Is there string formatting construct in F# so that I can replace String.Format from System assembly?</li> </ol> <p>Example input: [|0x24uy; 0xA1uy; 0x00uy; 0x1Cuy|] should produce string "24A1001C"</p>
[ { "answer_id": 384447, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": -1, "selected": false, "text": "raw byte[] StringBuilder sb = new StringBuilder();\n foreach (byte b in raw) {\n sb.Append...
2008/12/21
[ "https://Stackoverflow.com/questions/384442", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25732/" ]
384,451
<p>There's a lot of security advice out there to tell programmers what <em>not</em> to do. What in your opinion are the best practices that <em>should</em> be followed when coding for good security?</p> <p>Please add your suggested security control / design pattern below. Suggested format is a bold headline summarising the idea, followed by a description and examples e.g.:</p> <blockquote> <p><strong>Deny by default</strong></p> <p><em>Deny everything that is not explicitly permitted...</em></p> </blockquote> <p>Please vote up or comment with improvements rather than duplicating an existing answer. Please also put different patterns and controls in their own answer rather than adding an answer with your 3 or 4 preferred controls.</p> <p>edit: I am making this a community wiki to encourage voting.</p>
[ { "answer_id": 384459, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 2, "selected": false, "text": "sudo make install su" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42404/" ]
384,462
<p>if i have a protected method, can i pass in a parameter where the data type is declared internal?</p>
[ { "answer_id": 384464, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "public interface IFoo {}\ninternal class Foo : IFoo {}\npublic class Bar {\n protected void Test(IFoo foo) {}\n}\n ...
2008/12/21
[ "https://Stackoverflow.com/questions/384462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
384,471
<p>So, looking for a mysql-db-lib that is compatible with py3k/py3.0/py3000, any ideas? Google turned up nothing.</p>
[ { "answer_id": 39008521, "author": "Collin Anderson", "author_id": 131881, "author_profile": "https://Stackoverflow.com/users/131881", "pm_score": 2, "selected": false, "text": "MySQLdb pymysql.install_as_MySQLdb() python-mysqldb python3-mysqldb" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/452521/" ]
384,500
<p>Here is the scenario:<br> ThickBox is opened from parent window (when button is pressed) with Ajax content (div based form) that contains the set of inputs with autocomplete support. Once ThickBox(form) is closed the input values should be passed to parent window.</p> <p>Question:<br> The content of ThickBox is loaded dynamically, so what's the correct way to have an initial callback to manipulate ThickBox content with jQuery (kind of $(ThickBox).ready.. )?</p>
[ { "answer_id": 384560, "author": "redsquare", "author_id": 6440, "author_profile": "https://Stackoverflow.com/users/6440", "pm_score": 3, "selected": true, "text": "$.ajaxSuccess( function(evt, request, settings){\n //ajax method has completed\n}); \n" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42512/" ]
384,502
<p>Not to long ago, someone told me that <code>long</code> are not 64 bits on 64 bit machines and I should always use <code>int</code>. This did not make sense to me. I have seen docs (such as the one on Apple's official site) say that <code>long</code> are indeed 64 bits when compiling for a 64-bit CPU. I looked up what it was on 64-bit Windows and found </p> <blockquote> <ul> <li>Windows: <code>long</code> and <code>int</code> remain 32-bit in length, and special new data types are defined for 64-bit integers.</li> </ul> </blockquote> <p>(from <a href="http://web.archive.org/web/20080117221414/http://www.intel.com:80/cd/ids/developer/asmo-na/eng/197664.htm?page=2" rel="noreferrer">http://www.intel.com/cd/ids/developer/asmo-na/eng/197664.htm?page=2</a>)</p> <p>What should I use? Should I define something like <code>uw</code>, <code>sw</code> ((un)signed width) as a <code>long</code> if not on Windows, and otherwise do a check on the target CPU bitsize?</p>
[ { "answer_id": 384544, "author": "Paul de Vrieze", "author_id": 4100, "author_profile": "https://Stackoverflow.com/users/4100", "pm_score": 2, "selected": false, "text": "#include <iostream>\n\nint main() {\n std::cout << sizeof(long)*8 << std::endl;\n}\n" }, { "answer_id": 3846...
2008/12/21
[ "https://Stackoverflow.com/questions/384502", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
384,511
<p>I noticed that <code>List&lt;T&gt;</code> defines its enumerator as a <code>struct</code>, while <code>ArrayList</code> defines its enumerator as a <code>class</code>. What's the difference? If I am to write an enumerator for my class, which one would be preferable?</p> <p><strong>EDIT:</strong> My requirements cannot be fulfilled using <code>yield</code>, so I'm implementing an enumerator of my own. That said, I wonder whether it would be better to follow the lines of <code>List&lt;T&gt;</code> and implement it as a struct.</p>
[ { "answer_id": 384514, "author": "Daniel Earwicker", "author_id": 27423, "author_profile": "https://Stackoverflow.com/users/27423", "pm_score": 3, "selected": false, "text": "yield return class struct struct struct" }, { "answer_id": 384522, "author": "JaredPar", "author_...
2008/12/21
[ "https://Stackoverflow.com/questions/384511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41283/" ]
384,573
<p>What are the reasons when I am connecting to the MySQL server in my laptop(development machine) using MySQL Administrator it is too slow, but when I am connecting to the MySQL server in the prouction machine it is faster. Does setting on the logs have a noticeable performance drop? I have no problems before with slow connections with my laptop.</p>
[ { "answer_id": 721910, "author": "robnardo", "author_id": 56774, "author_profile": "https://Stackoverflow.com/users/56774", "pm_score": 0, "selected": false, "text": "network.dns.disableIPv6 about:config network.dns.disableIPv6" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46893/" ]
384,574
<p>I am trying to figure out a clean way to intercept uncaught exceptions that occur in my application. </p> <p>I have log4j configured for logging the normal application flow and caught exceptions, so that is taken care of. Right now, I have a class that takes all error-level messages and adds them to a queue to be emailed in batches. </p> <p>Ideally, I'm hoping that there is a way I can go about intercepting the uncaught exceptions, so that I may pass them to the same 'email batch' queue, but if this is not posible, I'm certainly open to suggestion.</p> <p>I'm familiar with LogInterceptors on JBoss, but this project is using Tomcat. Is there any way that I might go about this? Is there a LogInterceptor equivelant for Tomcat? Should I try to redirect the Tomcat logging to a custom appender? (If so - any hints on that?) Some other ideas?</p> <p>I figured that this <em>has</em> to be a solved problem by now, so I am hoping to tap some collective wisdom. Thanks, everyone, in advance.</p>
[ { "answer_id": 384585, "author": "kdgregory", "author_id": 42126, "author_profile": "https://Stackoverflow.com/users/42126", "pm_score": 4, "selected": true, "text": "<error-page>\n <exception-type>java.lang.Exception</exception-type>\n <location>/dumpRequest.jsp</location>\n</erro...
2008/12/21
[ "https://Stackoverflow.com/questions/384574", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13812/" ]
384,592
<p>I want to use this pattern:</p> <pre><code>SqlCommand com = new SqlCommand(sql, con); com.CommandType = CommandType.StoredProcedure;//um com.CommandTimeout = 120; //com.Connection = con; //EDIT: per suggestions below SqlParameter par; par = new SqlParameter("@id", SqlDbType.Int); par.Direction = ParameterDirection.Input; com.Parameters.Add(par); HttpContext.Current.Cache["mycommand"] = com; </code></pre> <p>Obviously I don't want to run into odd problems like person A retrieving this from the cache, updating param1, person 2 getting it from the cache and updating param2 and each user running the command with a blend of the two.</p> <p>And cloning the command taken out of the cache is likely more expensive that creating a new one from scratch.</p> <p>How thread safe is the ASP.NET Cache? Am I missing any other potential pitfalls? Would this technique work for parameterless commands despite threading issues?</p> <p><strong>Clarefication:</strong> If I want to metaphorically shoot myself in the foot, how do I aim? Is there a way to lock access to objects in the cache so that access is serialized?</p>
[ { "answer_id": 387087, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 0, "selected": false, "text": "result = getResultFromCache(CacheKey)\nif (result == null)\n{\n result = getResultFromDB();\n InsertIntoCache(result...
2008/12/21
[ "https://Stackoverflow.com/questions/384592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33264/" ]
384,593
<p>Im trying to save a bitmap jpg format with a specified encoding quality. However im getting an exception ("Parameter is not valid.") when calling the save method.</p> <p>If i leave out the two last parameters in the bmp.save it works fine.</p> <pre><code> EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 16); ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); string outfile = outputpath + "\\" + fileaddition + sourcefile.Name; bmp.Save(outfile,ici,eps ); bmp.Dispose(); image.Dispose(); return true; } ImageCodecInfo GetEncoderInfo(string mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); for (j = 0; j &lt; encoders.Length; ++j) { if (encoders[j].MimeType == mimeType) return encoders[j]; } return null; } } </code></pre> <p>Thank you</p>
[ { "answer_id": 1318070, "author": "Mahdi", "author_id": 161505, "author_profile": "https://Stackoverflow.com/users/161505", "pm_score": 2, "selected": false, "text": "eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)16);\n" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384593", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36476/" ]
384,596
<p>i've got a ComboBox that i generate dynamically and fill with some items. i would like to set this control's width to the width of the longest item. how do i count the display width of some text?</p> <p>edit: i'm using windows forms, but i would like to do it in asp.net as well</p>
[ { "answer_id": 55558353, "author": "Adam", "author_id": 1126985, "author_profile": "https://Stackoverflow.com/users/1126985", "pm_score": 0, "selected": false, "text": "private void comboBox_DropDown(object sender, EventArgs e)\n {\n Graphics g = (sender as ComboBox).Cr...
2008/12/21
[ "https://Stackoverflow.com/questions/384596", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40872/" ]
384,610
<p>As an exercise, I'm translating parts of our large and battle-hardened Delphi-framework to C#. </p> <p>Included in this framework is a generic singleton parent class. Of course, implementing a singleton in C# is fairly easy (there is even a Jon Skeet article, so what more could I wish for), but our Delphi singleton has a slightly different take on the pattern: as opposed to publishing an 'instance' property/method, it has a "fake" constructor that always returns the same instance. The essential characteristic of this approach is that the <i>user of the singleton class doesn't know that he is dealing with a singleton</i>: as far as they know, they just construct any old class and request some information from it.</p> <p>I want to accomplish the same thing in C# (as an exercise, so it doesn't have to be production-quality code, evil hackery is fine), but so far I've failed. </p> <p>Any suggestion to make a simple <code>myInstance = new MyClass();</code> always return the same instance is most welcome! </p> <hr> <h2>Additional info</h2> <ul> <li><p>We are talking a convenience-implementation of the singleton pattern, as offered by the framework. It doesn't necessarely have to be a parent-class, but it does have to assist the developers in creating their own singletons as well. Requiring them to manually redirect all their method calls to the single-instance will not make them overflow with joy. :-)</p></li> <li><p>I'm not really interested in debating whether or not this is the right way to deal with singletons, for now I'm just interested in the finer art of c#-tweaking.</p></li> </ul>
[ { "answer_id": 384626, "author": "devios1", "author_id": 238948, "author_profile": "https://Stackoverflow.com/users/238948", "pm_score": 3, "selected": true, "text": "Equals()" }, { "answer_id": 384627, "author": "George Mauer", "author_id": 5056, "author_profile": "h...
2008/12/21
[ "https://Stackoverflow.com/questions/384610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16725/" ]
384,632
<p>The documentation for <a href="http://msdn.microsoft.com/en-us/library/k3e17y47(VS.80).aspx" rel="nofollow noreferrer">Sort</a> says that Sort will throw an ArgumentException if "The implementation of comparer caused an error during the sort. For example, comparer might not return 0 when comparing an item with itself."</p> <p>Apart from the example given, can anyone tell me when this would otherwise happen?</p>
[ { "answer_id": 384647, "author": "Greg Dean", "author_id": 1200558, "author_profile": "https://Stackoverflow.com/users/1200558", "pm_score": 3, "selected": true, "text": "public void Sort(T[] keys, int index, int length, IComparer<T> comparer)\n{\n try\n {\n ...\n Arr...
2008/12/21
[ "https://Stackoverflow.com/questions/384632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38206/" ]
384,633
<p>i am new to .net 3.5. I have a collection of items:</p> <pre><code>IList&lt;Model&gt; models; </code></pre> <p>where</p> <pre><code>class Model { public string Name { get; private set; } } </code></pre> <p>I would like to get the element, which has the longest name's length. I tried </p> <pre><code>string maxItem = models.Max&lt;Model&gt;(model =&gt; model.Name.Length); </code></pre> <p>but it of course returns the maximum length (and I need a <code>Model</code> object). I know there is a way of doing this using the extension methods but I don't know how.</p>
[ { "answer_id": 384649, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": false, "text": "TValue Comparer<TValue>.Default public static TSource MaxBy<TSource, TValue>(this IEnumerable<TSource> source,\n ...
2008/12/21
[ "https://Stackoverflow.com/questions/384633", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40872/" ]