qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
394,921
<p>I am writing a (very small) framework for checking pre- and postconditions of methods. Entry points are (they could be easily be methods; that doesn't matter):</p> <pre><code>public static class Ensures { public static Validation That { get { ... } } } public static class Requires { public stat...
[ { "answer_id": 394929, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "<p>Is this anything that the normal <a href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattr...
2008/12/27
[ "https://Stackoverflow.com/questions/394921", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9204/" ]
I am writing a (very small) framework for checking pre- and postconditions of methods. Entry points are (they could be easily be methods; that doesn't matter): ``` public static class Ensures { public static Validation That { get { ... } } } public static class Requires { public static Validation ...
Any solution that is found here would be slower than the actual checks. Also, since it would not be build into the compiler like `ConditionalAttribute`, the parameters would still be calculated. If the postconditions could be very complicated, such as ``` Ensures.That.IsPositive(ExpensiveCalculation(result)); ``` Yo...
394,942
<p>I am using SimpleModal in jQuery, and I have one confirm dialog. If the result is <code>Yes</code>, I have to call <code>my.php</code> into this dialog. However, I have done the code, and I am still searching for ideas. How can I do it?</p> <pre><code>$(document).ready(function () { $('#confirmDialog input.conf...
[ { "answer_id": 394966, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 1, "selected": false, "text": "<p>I'm not sure what you are trying to accomplish -- are you trying to reuse the confirmation modal dialog to display y...
2008/12/27
[ "https://Stackoverflow.com/questions/394942", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44984/" ]
I am using SimpleModal in jQuery, and I have one confirm dialog. If the result is `Yes`, I have to call `my.php` into this dialog. However, I have done the code, and I am still searching for ideas. How can I do it? ``` $(document).ready(function () { $('#confirmDialog input.confirm, #confirmDialog a.confirm').clic...
I'm not sure that the confirm function best fits your needs, but something like this should work: ``` function confirm(message, callback) { $('#confirm').modal({ close:false, position: ["20%",], overlayId:'confirmModalOverlay', containerId:'confirmModalContainer', onShow: fu...
394,978
<p>So I wrote this short script (correct word?) to download the comic images from explosm.net comics because I somewhat-recently found out about it and I want to...put it on my iPhone...3G.</p> <p>It works fine and all. urllib2 for getting webpage html and urllib for image.retrieve()</p> <p><strong><em>Why I posted t...
[ { "answer_id": 395014, "author": "nosklo", "author_id": 17160, "author_profile": "https://Stackoverflow.com/users/17160", "pm_score": 0, "selected": false, "text": "<p>I suggest using <a href=\"http://www.crummy.com/software/BeautifulSoup/\" rel=\"nofollow noreferrer\">BeautifulSoup</a> ...
2008/12/27
[ "https://Stackoverflow.com/questions/394978", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51518/" ]
So I wrote this short script (correct word?) to download the comic images from explosm.net comics because I somewhat-recently found out about it and I want to...put it on my iPhone...3G. It works fine and all. urllib2 for getting webpage html and urllib for image.retrieve() ***Why I posted this on SO: how do I optimi...
I would suggest using [Scrapy](http://scrapy.org/) for your page fetching and [Beautiful Soup](http://www.crummy.com/software/BeautifulSoup/) for the parsing. This would make your code a lot simpler. Whether you want to change your existing code that works to these alternatives is up to you. If not, then regular expre...
394,984
<p>Services default to starting as <code>root</code> at boot time on my RHEL box. If I recall correctly, the same is true for other Linux distros which use the init scripts in <code>/etc/init.d</code>.</p> <p>What do you think is the best way to instead have the processes run as a (static) user of my choosing?</p> <p...
[ { "answer_id": 394993, "author": "Black", "author_id": 25234, "author_profile": "https://Stackoverflow.com/users/25234", "pm_score": 3, "selected": false, "text": "<ul>\n<li>Some daemons (e.g. apache) do this by themselves by calling <a href=\"http://linux.die.net/man/2/setuid\" rel=\"no...
2008/12/27
[ "https://Stackoverflow.com/questions/394984", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29903/" ]
Services default to starting as `root` at boot time on my RHEL box. If I recall correctly, the same is true for other Linux distros which use the init scripts in `/etc/init.d`. What do you think is the best way to instead have the processes run as a (static) user of my choosing? The only method I'd arrived at was to ...
On Debian we use the `start-stop-daemon` utility, which handles pid-files, changing the user, putting the daemon into background and much more. I'm not familiar with RedHat, but the `daemon` utility that you are already using (which is defined in `/etc/init.d/functions`, btw.) is mentioned everywhere as the equivalent...
394,989
<p>How to handle click event of the linkbutton in gridview in vb.net (windows application )</p> <p>Thanks</p>
[ { "answer_id": 395184, "author": "t3rse", "author_id": 64, "author_profile": "https://Stackoverflow.com/users/64", "pm_score": 4, "selected": true, "text": "<p>You need to consume the DataGridView.CellClick Event and just check that you've got the correct column index. You can do it with...
2008/12/27
[ "https://Stackoverflow.com/questions/394989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49238/" ]
How to handle click event of the linkbutton in gridview in vb.net (windows application ) Thanks
You need to consume the DataGridView.CellClick Event and just check that you've got the correct column index. You can do it with the following steps: > > Create a new Windows Forms application > > > Drag a DataGridView onto the screen > > > In the design time properties, add a column to your grid of type DataGrid...
395,019
<p>I want to have a textarea that's <code>500px</code>, this is the CSS I use for the textarea:</p> <pre><code>width: 498px; padding: 0px; margin: 0px; </code></pre> <p>I noticed IE and Chrome have a <code>1px</code> border by default, on the other hand FF have a <code>2px</code> border which results the textarea to ...
[ { "answer_id": 395022, "author": "Dave Markle", "author_id": 24995, "author_profile": "https://Stackoverflow.com/users/24995", "pm_score": 3, "selected": false, "text": "<p>You can set all of your browsers' default styles to be the same by using a Reset CSS sheet at the top of your docu...
2008/12/27
[ "https://Stackoverflow.com/questions/395019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/676066/" ]
I want to have a textarea that's `500px`, this is the CSS I use for the textarea: ``` width: 498px; padding: 0px; margin: 0px; ``` I noticed IE and Chrome have a `1px` border by default, on the other hand FF have a `2px` border which results the textarea to be `502px` instead of `500px`, any workarounds? Just a not...
You can set all of your browsers' default styles to be the same by using a Reset CSS sheet at the top of your document. I like the [YUI reset CSS](http://developer.yahoo.com/yui/reset/) myself. That should set the base styles for all of the controls to be the same across all browsers to begin with, and that should allo...
395,030
<p>Just for review, can someone quickly explain what prevents this from working (on compile):</p> <pre><code>private HashSet data; ... public DataObject[] getDataObjects( ) { return (DataObject[]) data.toArray(); } </code></pre> <p>...and what makes this the way that DOES work:</p> <pre><code>public DataObject...
[ { "answer_id": 395038, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 6, "selected": true, "text": "<p>Because <code>toArray()</code> creates an array of Object, and you can't make <code>Object[]</code> into <code>DataOb...
2008/12/27
[ "https://Stackoverflow.com/questions/395030", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19825/" ]
Just for review, can someone quickly explain what prevents this from working (on compile): ``` private HashSet data; ... public DataObject[] getDataObjects( ) { return (DataObject[]) data.toArray(); } ``` ...and what makes this the way that DOES work: ``` public DataObject[] getDataObjects( ) { return (Da...
Because `toArray()` creates an array of Object, and you can't make `Object[]` into `DataObject[]` just by casting it. `toArray(DataObject[])` creates an array of `DataObject`. And yes, it is a shortcoming of the Collections class and the way Generics were shoehorned into Java. You'd expect that `Collection<E>.toArray(...
395,045
<p>I want to provide a piece of Javascript code that will work on any website where it is included, but it always needs to get more data (or even modify data) on the server where the Javascript is hosted. I know that there are security restrictions in place for obvious reasons.</p> <p>Consider index.html hosted on xyz...
[ { "answer_id": 395048, "author": "Joel Martinez", "author_id": 5416, "author_profile": "https://Stackoverflow.com/users/5416", "pm_score": 2, "selected": false, "text": "<p>The easiest option for you would be to proxy the call through the server loading the javascript. So some.js would ...
2008/12/27
[ "https://Stackoverflow.com/questions/395045", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1606/" ]
I want to provide a piece of Javascript code that will work on any website where it is included, but it always needs to get more data (or even modify data) on the server where the Javascript is hosted. I know that there are security restrictions in place for obvious reasons. Consider index.html hosted on xyz.com conta...
> > Will some.js be able to use XMLHttpRequest to post data to abc.com? In other words, is abc.com implicitly trusted because we loaded Javascript from there? > > > No, because the script is loaded on to a seperate domain it will not have access... If you trust the data source then maybe JSONP would be the better...
395,051
<p>I know innerHTML is supposedly evil, but I think it's the simplest way to change link text. For example:</p> <pre><code>&lt;a id="mylink" href=""&gt;click me&lt;/a&gt; </code></pre> <p>In JS you can change the text with:</p> <pre><code>document.getElementById("mylink").innerHTML = new_text; </code></pre> <p>And ...
[ { "answer_id": 395055, "author": "PEZ", "author_id": 44639, "author_profile": "https://Stackoverflow.com/users/44639", "pm_score": 2, "selected": false, "text": "<p>innerHTML has side effects (like disconnecting existing DOM nodes and rerendering that might be heavy). One needs to be awa...
2008/12/27
[ "https://Stackoverflow.com/questions/395051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I know innerHTML is supposedly evil, but I think it's the simplest way to change link text. For example: ``` <a id="mylink" href="">click me</a> ``` In JS you can change the text with: ``` document.getElementById("mylink").innerHTML = new_text; ``` And in Prototype/jQuery: ``` $("mylink").innerHTML = new_text; ...
innerHTML is not evil at all. There's nothing wrong with using it, as long as you're aware of the consequences.
395,053
<p>I have two templatetags in my app which contain forms which show entries in db. When I alter data or add new entry to db, the forms show the old data. While in admin panel everything is correct (updated). When I restart the server (I mean <code>manage.py runserver</code>) forms show updated db entries. How to make ...
[ { "answer_id": 395087, "author": "Gonzalo Quero", "author_id": 40996, "author_profile": "https://Stackoverflow.com/users/40996", "pm_score": -1, "selected": false, "text": "<p>Are you using some kind of cache system? It could be that.</p>\n" }, { "answer_id": 397219, "author"...
2008/12/27
[ "https://Stackoverflow.com/questions/395053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36832/" ]
I have two templatetags in my app which contain forms which show entries in db. When I alter data or add new entry to db, the forms show the old data. While in admin panel everything is correct (updated). When I restart the server (I mean `manage.py runserver`) forms show updated db entries. How to make the forms show ...
I have too low rep to comment, but `takes_context` defaults to False, making your assignment redundant. Also, but now I am guessing, but it might be related to your problem.
395,057
<p>Where would</p> <pre><code>set_include_path("../../"); </code></pre> <p>point to?</p> <p>I am trying to run some PHP code on a standard XAMPP server. And put my stuff into the htdocs folder. The includes point to relative paths, But it does not work. Is there any best-practise for includes? The code has to run on...
[ { "answer_id": 395081, "author": "Ólafur Waage", "author_id": 22459, "author_profile": "https://Stackoverflow.com/users/22459", "pm_score": 0, "selected": false, "text": "<p>Two directories down from where the file (or the file which included it) is running from.</p>\n\n<p>As for best pr...
2008/12/27
[ "https://Stackoverflow.com/questions/395057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Where would ``` set_include_path("../../"); ``` point to? I am trying to run some PHP code on a standard XAMPP server. And put my stuff into the htdocs folder. The includes point to relative paths, But it does not work. Is there any best-practise for includes? The code has to run on machines of multiple developers.
Relative path should work fine (warning: apache on windows, as I know, don't follow the simlinks, or whatever are called on that os). Maybe you should use the syntax (in order to avoid problem with different php versions) ``` ini_set('include_path', 'yourdir'); ``` and test the return value to see if all is ok. Tu...
395,060
<p>I drew a little graph in paint that explains my problem:</p> <p>But it doesn't seem to show up when I use the <code>&lt;img&gt;</code> tag after posting?</p> <p>Graph:</p> <p><a href="https://i.stack.imgur.com/DkI1T.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DkI1T.jpg" alt="http://i44.tiny...
[ { "answer_id": 395068, "author": "erikkallen", "author_id": 47161, "author_profile": "https://Stackoverflow.com/users/47161", "pm_score": 3, "selected": true, "text": "<p>You need to instantiate the database outside of main(), otherwise you will just declare a local variable shadowing th...
2008/12/27
[ "https://Stackoverflow.com/questions/395060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I drew a little graph in paint that explains my problem: But it doesn't seem to show up when I use the `<img>` tag after posting? Graph: [![http://i44.tinypic.com/103gcbk.jpg](https://i.stack.imgur.com/DkI1T.jpg)](https://i.stack.imgur.com/DkI1T.jpg)
You need to instantiate the database outside of main(), otherwise you will just declare a local variable shadowing the global one. GameServer.cpp: ``` #include GameSocket.h Database db(1, 2, 3); int main() { //whatever } ```
395,075
<p>I've following problem, which I've not been able to do successfully. Your help will be appreciated. I'm using SQL 2005, and trying to do this using CTE.</p> <p>Table has following 2 columns</p> <pre><code>DocNum DocEntry 1 234 2 324 2 746 3 876 3 ...
[ { "answer_id": 395090, "author": "Turnkey", "author_id": 13144, "author_profile": "https://Stackoverflow.com/users/13144", "pm_score": 2, "selected": false, "text": "<p>Here's an article that describes methods to do that:</p>\n\n<p><a href=\"http://www.sqlteam.com/article/converting-mult...
2008/12/27
[ "https://Stackoverflow.com/questions/395075", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49372/" ]
I've following problem, which I've not been able to do successfully. Your help will be appreciated. I'm using SQL 2005, and trying to do this using CTE. Table has following 2 columns ``` DocNum DocEntry 1 234 2 324 2 746 3 876 3 764 4 10...
``` SELECT DocNum, STUFF((SELECT ', ' + CAST(DocEntry AS VARCHAR(MAX)) AS [text()] FROM Temp5 b WHERE a.DocNum = b.DocNum FOR XML PATH('')), 1, 2, '') AS DocEntry FROM Temp5 a GROUP BY DocNum ``` Itzik Ben-Gan in his excellent book [T-SQL QUERYING](https://rads.stackoverflow.com/amzn/...
395,114
<p>I would like vim to color "long" lines for me. Using 80 columns as an example, I would like to highlight lines that exceed that length. Here is roughly what I think the .vimrc file should contain, although it (1) doesn't work, and (2) uses Perl's regex syntax to illustrate my point, because I don't know Vim's well...
[ { "answer_id": 395117, "author": "terminus", "author_id": 9232, "author_profile": "https://Stackoverflow.com/users/9232", "pm_score": 1, "selected": false, "text": "<p>I use the following method:</p>\n\n<pre><code>hi gitError ctermbg=Red\nmatch gitError /^.*\\s$/\n2match gitError /^.\\{1...
2008/12/27
[ "https://Stackoverflow.com/questions/395114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14356/" ]
I would like vim to color "long" lines for me. Using 80 columns as an example, I would like to highlight lines that exceed that length. Here is roughly what I think the .vimrc file should contain, although it (1) doesn't work, and (2) uses Perl's regex syntax to illustrate my point, because I don't know Vim's well enou...
I needed the autocomand to work for me: ``` augroup vimrc_autocmds autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#111111 autocmd BufEnter * match OverLength /\%75v.*/ augroup END ``` Also like the idea of using 75 if you are aiming at 80 columns in average. Taken from: <http://blog.ezyang.com/...
395,123
<p>In practice with C++, what is <a href="http://en.wikipedia.org/wiki/Resource_acquisition_is_initialization" rel="noreferrer">RAII</a>, what are <a href="http://en.wikipedia.org/wiki/Smart_pointers" rel="noreferrer">smart pointers</a>, how are these implemented in a program and what are the benefits of using RAII wit...
[ { "answer_id": 395132, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<pre>\nvoid foo()\n{\n std::string bar;\n //\n // more code here\n //\n}\n</pre>\n\n<p>No matter what happens, bar is ...
2008/12/27
[ "https://Stackoverflow.com/questions/395123", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25093/" ]
In practice with C++, what is [RAII](http://en.wikipedia.org/wiki/Resource_acquisition_is_initialization), what are [smart pointers](http://en.wikipedia.org/wiki/Smart_pointers), how are these implemented in a program and what are the benefits of using RAII with smart pointers?
A simple (and perhaps overused) example of RAII is a File class. Without RAII, the code might look something like this: ``` File file("/path/to/file"); // Do stuff with file file.close(); ``` In other words, we must make sure that we close the file once we've finished with it. This has two drawbacks - firstly, where...
395,157
<p>I want to scrape the user pages of SO to give the owners of my toolbar the updated information on their questions/answers/etc...</p> <p>This means I need to do this in the background, parse the pages, extract the content, compare it with the last run and then present the results either on the toolbar or the status ...
[ { "answer_id": 395180, "author": "James Brady", "author_id": 29903, "author_profile": "https://Stackoverflow.com/users/29903", "pm_score": 1, "selected": false, "text": "<p>From privileged JavaScript, i.e. JS in an extension, you are allowed to create hidden <code>iframe</code>s; downloa...
2008/12/27
[ "https://Stackoverflow.com/questions/395157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8167/" ]
I want to scrape the user pages of SO to give the owners of my toolbar the updated information on their questions/answers/etc... This means I need to do this in the background, parse the pages, extract the content, compare it with the last run and then present the results either on the toolbar or the status bar, or al...
In case of XUL/Firefox, what you need is the nsIIOService interface, which you can get like this: ``` var mIOS = Components.classes["@mozilla.org/network/io-service;1"]. getService(Components.interfaces.nsIIOService); ``` Then you need to create a channel, and open an asynchronous link: ``` var channel = mIOS.ne...
395,163
<p>In jQuery you can get the top position relative to the parent as a number, but you can not get the css top value as a number if it was set in <code>px</code>.<br> Say I have the following:</p> <pre><code>#elem{ position:relative; top:10px; } </code></pre> <pre><code>&lt;div&gt; Bla text bla this takes op...
[ { "answer_id": 395171, "author": "M4N", "author_id": 19635, "author_profile": "https://Stackoverflow.com/users/19635", "pm_score": 9, "selected": true, "text": "<p>You can use the parseInt() function to convert the string to a number, e.g:</p>\n\n<pre><code>parseInt($('#elem').css('top')...
2008/12/27
[ "https://Stackoverflow.com/questions/395163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35197/" ]
In jQuery you can get the top position relative to the parent as a number, but you can not get the css top value as a number if it was set in `px`. Say I have the following: ``` #elem{ position:relative; top:10px; } ``` ``` <div> Bla text bla this takes op vertical space.... <div id='elem'>bla</div> </di...
You can use the parseInt() function to convert the string to a number, e.g: ``` parseInt($('#elem').css('top')); ``` **Update:** (as suggested by Ben): You should give the radix too: ``` parseInt($('#elem').css('top'), 10); ``` Forces it to be parsed as a decimal number, otherwise strings beginning with '0' might...
395,165
<p>Is it OK - best practise wise - to use the second layer to redirect the user?</p> <p>For example:</p> <pre><code>public static void ForceLogin() { HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName]; if (cookie != null) { if (Regex.IsMatch(cookie.Value, "^[0-9]+\\.[a-f0-9]+$"))...
[ { "answer_id": 395170, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 0, "selected": false, "text": "<p>I would say that you're correct to do it in the business logic. Presentation layer shouldn't be making decisions about...
2008/12/27
[ "https://Stackoverflow.com/questions/395165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46769/" ]
Is it OK - best practise wise - to use the second layer to redirect the user? For example: ``` public static void ForceLogin() { HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName]; if (cookie != null) { if (Regex.IsMatch(cookie.Value, "^[0-9]+\\.[a-f0-9]+$")) { ...
Absolutely not. The business logic layer should make the decision, the UI layer should do the redirect. The business layer shouldn't know anything about HttpContext nor should it be directly reading cookies. Pass the relevant information into the business layer so that the business layer can make the decision, and pass...
395,195
<p>i'm trying to figure out how to layout a simple dialog in WPF using the proper <strong>dialog units</strong> (DLUs). </p> <hr> <blockquote> <h2>What's a dialog unit?</h2> <p>A dialog is a unit of measure based on the user's preferred font size. A dialog unit is defined such that the <em>average character<...
[ { "answer_id": 395200, "author": "Scott Weinstein", "author_id": 25201, "author_profile": "https://Stackoverflow.com/users/25201", "pm_score": 1, "selected": false, "text": "<p>Look into the <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.grid.aspx\" rel=\"nofol...
2008/12/27
[ "https://Stackoverflow.com/questions/395195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
i'm trying to figure out how to layout a simple dialog in WPF using the proper **dialog units** (DLUs). --- > > What's a dialog unit? > --------------------- > > > A dialog is a unit of measure based on the user's preferred font size. > A dialog unit is defined such that the *average character* is 4 dialog > un...
The following XAML will give you the effect you are looking for. Note that I have doubled the DLU units in the markup - thus keeping the same aspect. It looked funny having a Button height of 14units. You may need to tinker with the figures presented in the market. Also, I started to remove some of the "Vista Layout"...
395,198
<p>I've been diving into Erlang recently, and I decided to use Mnesia to do my database work given it can store any kind of Erlang data structure without a problem, scale with ease, be used with list comprehensions, etc.</p> <p>Coming from standard SQL databases, most rows can and should be identified by a primary key...
[ { "answer_id": 395343, "author": "Alexey Romanov", "author_id": 9204, "author_profile": "https://Stackoverflow.com/users/9204", "pm_score": 4, "selected": true, "text": "<p>I prefer using GUIDs instead of auto-incrementing ints as artificial foreign keys. There is an <a href=\"http://git...
2008/12/27
[ "https://Stackoverflow.com/questions/395198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35344/" ]
I've been diving into Erlang recently, and I decided to use Mnesia to do my database work given it can store any kind of Erlang data structure without a problem, scale with ease, be used with list comprehensions, etc. Coming from standard SQL databases, most rows can and should be identified by a primary key, usually ...
I prefer using GUIDs instead of auto-incrementing ints as artificial foreign keys. There is an [Erlang uuid module](http://github.com/travis/erlang-uuid/tree/master) available at GitHub, or you can use `{now(), node()}`, given that `now/0` doc says: "It is also guaranteed that subsequent calls to this BIF returns cont...
395,220
<p>I have been learning to use Emacs for a little while now. So far liking it a lot.</p> <p>My problem is that for little C codes I prefer using Rake instead of Make. However flymake does not seem to want anything else than Make. As it complains that it can not find Makefile. From the command line Rake is used in the ...
[ { "answer_id": 395310, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 0, "selected": false, "text": "<p>Rake is Ruby syntax, so simply turning on the flymake for rby in the file should do it. <a href=\"http://codere...
2008/12/27
[ "https://Stackoverflow.com/questions/395220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5601/" ]
I have been learning to use Emacs for a little while now. So far liking it a lot. My problem is that for little C codes I prefer using Rake instead of Make. However flymake does not seem to want anything else than Make. As it complains that it can not find Makefile. From the command line Rake is used in the same way a...
Right, got it now; sorry about the earlier confusion. Taking a quick look through flymake.el, for \*.c files, the 'make' invocation ultimately comes from here: ``` (defun flymake-get-make-cmdline (source base-dir) (list "make" (list "-s" "-C" base-dir (concat "CHK_SOURCES=" source)...
395,232
<p>I was reading the following article: <a href="http://msdn.microsoft.com/en-us/magazine/cc817398.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/magazine/cc817398.aspx</a> "Solving 11 Likely Problems In Your Multithreaded Code" by Joe Duffy</p> <p>And it raised me a question: "We need to lock a .NET Int32 whe...
[ { "answer_id": 395236, "author": "Steven A. Lowe", "author_id": 9345, "author_profile": "https://Stackoverflow.com/users/9345", "pm_score": 0, "selected": false, "text": "<p>in general, locks are only required when the value will be modified</p>\n\n<p>EDIT: <a href=\"https://stackoverflo...
2008/12/27
[ "https://Stackoverflow.com/questions/395232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48465/" ]
I was reading the following article: <http://msdn.microsoft.com/en-us/magazine/cc817398.aspx> "Solving 11 Likely Problems In Your Multithreaded Code" by Joe Duffy And it raised me a question: "We need to lock a .NET Int32 when reading it in a multithreaded code?" I understand that if it was an Int64 in a 32-bit SO it...
Locking accomplishes two things: * It acts as a mutex, so you can make sure only one thread modifies a set of values at a time. * It provides memory barriers (acquire/release semantics) which ensures that memory writes made by one thread are visible in another. Most people understand the first point, but not the seco...
395,234
<p>"make" is not only useful for building your programming project, but it seems to be under-used in other areas.</p> <p>For example, many shell scripts can be rewritten as Makefiles to allow independent parts to run in parallel (with "make -jXX") to keep all your CPU cores busy, with the explicitly declared dependenc...
[ { "answer_id": 395242, "author": "Joshua", "author_id": 14768, "author_profile": "https://Stackoverflow.com/users/14768", "pm_score": 0, "selected": false, "text": "<p>My work uses a curious one: the dependencies don't exist so it always rebuilds everything.</p>\n\n<p>Might as well have ...
2008/12/27
[ "https://Stackoverflow.com/questions/395234", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128202/" ]
"make" is not only useful for building your programming project, but it seems to be under-used in other areas. For example, many shell scripts can be rewritten as Makefiles to allow independent parts to run in parallel (with "make -jXX") to keep all your CPU cores busy, with the explicitly declared dependencies as an ...
Make's parallelism is particularly handy for shell scripting. Say you want to get the 'uptime' of a whole set of hosts (or basically perform any slow operation). You could do it in a loop: ``` cat hosts | while read host; do echo "$host: $(ssh $host uptime)"; done ``` This works, but is slow. You can parallelise thi...
395,237
<p>I have a View that can vary significantly, depending on the 'mode' a particular user has chosen.</p> <p>I thought I would extract the different behavior into two different Helpers, and then have code like this in the Controller:</p> <pre><code>class MyController &lt; ApplicationController case mode when 'mode1' ...
[ { "answer_id": 395242, "author": "Joshua", "author_id": 14768, "author_profile": "https://Stackoverflow.com/users/14768", "pm_score": 0, "selected": false, "text": "<p>My work uses a curious one: the dependencies don't exist so it always rebuilds everything.</p>\n\n<p>Might as well have ...
2008/12/27
[ "https://Stackoverflow.com/questions/395237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44317/" ]
I have a View that can vary significantly, depending on the 'mode' a particular user has chosen. I thought I would extract the different behavior into two different Helpers, and then have code like this in the Controller: ``` class MyController < ApplicationController case mode when 'mode1' helper "mode1" when 'mo...
Make's parallelism is particularly handy for shell scripting. Say you want to get the 'uptime' of a whole set of hosts (or basically perform any slow operation). You could do it in a loop: ``` cat hosts | while read host; do echo "$host: $(ssh $host uptime)"; done ``` This works, but is slow. You can parallelise thi...
395,256
<p>I am working on a Windows Forms application in VS 2008, and I want to display one image over the top of another, with the top image being a gif or something with transparent parts.</p> <p>Basically I have a big image and I want to put a little image on top if it, so that they kinda appear as one image to the user.<...
[ { "answer_id": 395300, "author": "Jon Grant", "author_id": 18774, "author_profile": "https://Stackoverflow.com/users/18774", "pm_score": 2, "selected": false, "text": "<p>Put the big/bottom image on a <code>PictureBox</code>, then add a handler to the <code>OnPaint</code> event and use o...
2008/12/27
[ "https://Stackoverflow.com/questions/395256", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30025/" ]
I am working on a Windows Forms application in VS 2008, and I want to display one image over the top of another, with the top image being a gif or something with transparent parts. Basically I have a big image and I want to put a little image on top if it, so that they kinda appear as one image to the user. I've been...
I was in a similar situation a couple of days ago. You can create a transparent control to host your image. ``` using System; using System.Windows.Forms; using System.Drawing; public class TransparentControl : Control { private readonly Timer refresher; private Image _image; public TransparentControl() ...
395,261
<p>I know that Hpricot is still a standard but I remember hearing about a faster more expressive HTML parser for Ruby.</p> <p>Does anybody know what it's called and if it is worth switching to from Hpricot??</p> <p>Thanks in advance</p>
[ { "answer_id": 395324, "author": "Wes Oldenbeuving", "author_id": 4187, "author_profile": "https://Stackoverflow.com/users/4187", "pm_score": 5, "selected": true, "text": "<p>You are probably thinking about <a href=\"http://nokogiri.org/\" rel=\"nofollow noreferrer\">Nokogiri</a>.\nI hav...
2008/12/27
[ "https://Stackoverflow.com/questions/395261", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38354/" ]
I know that Hpricot is still a standard but I remember hearing about a faster more expressive HTML parser for Ruby. Does anybody know what it's called and if it is worth switching to from Hpricot?? Thanks in advance
You are probably thinking about [Nokogiri](http://nokogiri.org/). I have not used it myself, but "everyone" is talking about it and the [benchmarks](http://gist.github.com/24605) do look interesting: ``` hpricot:html:doc 48.930000 3.640000 52.570000 ( 52.900035) hpricot2:html:doc 4.500000 0.020000 4.520000 ( 4.518...
395,262
<p>What would be the jquery equivalent for list.detect in prototype?</p>
[ { "answer_id": 395299, "author": "Tautologistics", "author_id": 44481, "author_profile": "https://Stackoverflow.com/users/44481", "pm_score": 2, "selected": false, "text": "<p>Returns the index of the first element with \"value\":</p>\n\n<pre><code>jQuery.inArray(value, array);\n</code><...
2008/12/27
[ "https://Stackoverflow.com/questions/395262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49396/" ]
What would be the jquery equivalent for list.detect in prototype?
Returns the index of the first element with "value": ``` jQuery.inArray(value, array); ```
395,271
<p>Still new to Objective C, and I'm having some trouble that I just can't seem to figure out on my own. The error occurs twice for each of the first three @properties below, and is: error: "syntax error before ')' token".</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface PolygonShape : NSObject {...
[ { "answer_id": 395297, "author": "Marc Charbonneau", "author_id": 35136, "author_profile": "https://Stackoverflow.com/users/35136", "pm_score": 2, "selected": false, "text": "<p>I see a few things that need to be cleaned up here, but the most obvious mistake is that you're treating primi...
2008/12/27
[ "https://Stackoverflow.com/questions/395271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29297/" ]
Still new to Objective C, and I'm having some trouble that I just can't seem to figure out on my own. The error occurs twice for each of the first three @properties below, and is: error: "syntax error before ')' token". ``` #import <Foundation/Foundation.h> @interface PolygonShape : NSObject { int *numberOfSi...
You're using the wrong selectors on your setter properties. The full selector name includes the colon at the end: `setNumberOfSides:` They should look like this: ``` @interface Foo @property (readwrite, setter = setNumberOfSides:) int numberOfSides; @end ``` One thing though, the names you're specifying are the sam...
395,275
<p>I am trying to design an object model (for C#), and can't work out the best way to store the data. I'll try to use a simple example to illustrate this!</p> <p>I have an object "pet", which could be one of, "cat", "dog" etc. So I have created an "pet" class with a "petType" enum to store this.</p> <p>Now this is wh...
[ { "answer_id": 395290, "author": "Tautologistics", "author_id": 44481, "author_profile": "https://Stackoverflow.com/users/44481", "pm_score": 0, "selected": false, "text": "<p>First, <strong><em>cat</em></strong> and <strong><em>dog</em></strong> should probably be subclassed from <stron...
2008/12/27
[ "https://Stackoverflow.com/questions/395275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30025/" ]
I am trying to design an object model (for C#), and can't work out the best way to store the data. I'll try to use a simple example to illustrate this! I have an object "pet", which could be one of, "cat", "dog" etc. So I have created an "pet" class with a "petType" enum to store this. Now this is where it gets trick...
Try #2. Seems to be correct ``` interface IPet { } class Cat : IPet { public void eat(CommonFood food) { } public void eat(CatFood food) { } } class Dog : IPet { public void eat(CommonFood food) { } public void eat(DogFood food) { } } interface IFood { } abstract class CommonFood : IFood { } abstr...
395,317
<p>I am trying to test that a particular method throws an expected exception from a method. As per JUnit4 documentation and <a href="https://stackoverflow.com/questions/156503/how-to-assert-that-a-certain-exception-is-thrown-in-junit45-tests">this answer</a> I wrote the test as:</p> <pre><code>@Test(expected=CannotUnd...
[ { "answer_id": 395331, "author": "krosenvold", "author_id": 23691, "author_profile": "https://Stackoverflow.com/users/23691", "pm_score": 2, "selected": false, "text": "<p>Your test code looks ok to me.</p>\n\n<p>Check that you're running with a junit 4 testrunner, not a junit 3.8 testru...
2008/12/27
[ "https://Stackoverflow.com/questions/395317", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4120/" ]
I am trying to test that a particular method throws an expected exception from a method. As per JUnit4 documentation and [this answer](https://stackoverflow.com/questions/156503/how-to-assert-that-a-certain-exception-is-thrown-in-junit45-tests) I wrote the test as: ``` @Test(expected=CannotUndoException.class) publi...
I have found the problem. The TestRunner I was using was the correct one (JUnit 4), however, I declared my test class as: ``` public class CommandTest extends TestCase ``` Which I assume is causing the test runner to treat it as a JUnit 3 test. I removed `extends TestCase` and received the expected results.
395,321
<p>I've got the following Generic usercontrol declared:</p> <pre><code>public partial class MessageBase&lt;T&gt; : UserControl { protected T myEntry; public MessageBase() { InitializeComponent(); } public MessageBase(T newEntry) { InitializeCo...
[ { "answer_id": 395333, "author": "Vilx-", "author_id": 41360, "author_profile": "https://Stackoverflow.com/users/41360", "pm_score": 1, "selected": false, "text": "<p>For one, althought generic controls are possible under .NET, the Visual Studio designers do not support them, so you're o...
2008/12/27
[ "https://Stackoverflow.com/questions/395321", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5648/" ]
I've got the following Generic usercontrol declared: ``` public partial class MessageBase<T> : UserControl { protected T myEntry; public MessageBase() { InitializeComponent(); } public MessageBase(T newEntry) { InitializeComponent(); ...
Try this ``` public partial class MessageControl : MessageControlBase { public MessageControl() { InitializeComponent(); } } public class MessageControlBase : MessageBase<Post> {} ``` The key to getting the designer to work is that the base class of the class you are editing must not...
395,340
<p>I have the following classes: Ingredients, Recipe and RecipeContent...</p> <pre><code>class Ingredient(models.Model): name = models.CharField(max_length=30, primary_key=True) qty_on_stock = models.IntegerField() def __unicode__(self): return self.name class Recipe(models.Model): name = mod...
[ { "answer_id": 395347, "author": "jb.", "author_id": 37522, "author_profile": "https://Stackoverflow.com/users/37522", "pm_score": 6, "selected": true, "text": "<pre><code>class RecipeContent(models.Model):\n ...\n def __unicode__(self):\n # You can access ForeignKey properties thro...
2008/12/27
[ "https://Stackoverflow.com/questions/395340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48540/" ]
I have the following classes: Ingredients, Recipe and RecipeContent... ``` class Ingredient(models.Model): name = models.CharField(max_length=30, primary_key=True) qty_on_stock = models.IntegerField() def __unicode__(self): return self.name class Recipe(models.Model): name = models.CharField(...
``` class RecipeContent(models.Model): ... def __unicode__(self): # You can access ForeignKey properties through the field name! return self.recipe.name ```
395,341
<p>I've been using John Resig's <code>getStyle</code> function from Pro JavaScript Techniques to get the style of elements:</p> <pre><code>function getStyle(elem, name) { // J/S Pro Techniques p136 if (elem.style[name]) { return elem.style[name]; } else if (elem.currentStyle) { return elem....
[ { "answer_id": 395364, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 4, "selected": true, "text": "<blockquote>\n <p>Is it possible to get only the\n stylesheet specified styles of an\n element (and return null if the style\n...
2008/12/27
[ "https://Stackoverflow.com/questions/395341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37522/" ]
I've been using John Resig's `getStyle` function from Pro JavaScript Techniques to get the style of elements: ``` function getStyle(elem, name) { // J/S Pro Techniques p136 if (elem.style[name]) { return elem.style[name]; } else if (elem.currentStyle) { return elem.currentStyle[name]; }...
> > Is it possible to get only the > stylesheet specified styles of an > element (and return null if the style > is undefined)? > > > That's effectively what is done by the routine you present. The problem is, in most scenarios, most styles are *not* undefined - they're inherited and/or defined by the individua...
395,379
<p>I'm having a strange problem when retrieving JSON formatted text. I use jQuery <code>post</code> to send some data (also JSON formatted) to the server (running PHP) which works fine. Then, when I request the same data from the server using jQuery <code>get</code>, the callback method never executes. This only occurs...
[ { "answer_id": 395390, "author": "ThoKra", "author_id": 38254, "author_profile": "https://Stackoverflow.com/users/38254", "pm_score": 1, "selected": false, "text": "<p>do you get linebreaks like &lt;br /&gt; or newlines like \\n? \nBut try to replace them with PHP.</p>\n\n<pre><code>&lt;...
2008/12/27
[ "https://Stackoverflow.com/questions/395379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4055/" ]
I'm having a strange problem when retrieving JSON formatted text. I use jQuery `post` to send some data (also JSON formatted) to the server (running PHP) which works fine. Then, when I request the same data from the server using jQuery `get`, the callback method never executes. This only occurs when the data is JSON fo...
If you would like to **keep** the line breaks, you might try: ``` function parse($text) { // Damn pesky carriage returns... $text = str_replace("\r\n", "\n", $text); $text = str_replace("\r", "\n", $text); // JSON requires new line characters be escaped $text = str_replace("\n", "\\n", $text); ...
395,401
<p>I wish to print a <code>Stack&lt;Integer&gt;</code> object as nicely as the Eclipse debugger does (i.e. <code>[1,2,3...]</code>) but printing it with <code>out = "output:" + stack</code> doesn't return this nice result.</p> <p>Just to clarify, I'm talking about Java's built-in collection so I can't override its <co...
[ { "answer_id": 395403, "author": "Zach Langley", "author_id": 45230, "author_profile": "https://Stackoverflow.com/users/45230", "pm_score": 9, "selected": true, "text": "<p>You could convert it to an array and then print that out with <code>Arrays.toString(Object[])</code>:</p>\n\n<pre><...
2008/12/27
[ "https://Stackoverflow.com/questions/395401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55094/" ]
I wish to print a `Stack<Integer>` object as nicely as the Eclipse debugger does (i.e. `[1,2,3...]`) but printing it with `out = "output:" + stack` doesn't return this nice result. Just to clarify, I'm talking about Java's built-in collection so I can't override its `toString()`. How can I get a nice printable versio...
You could convert it to an array and then print that out with `Arrays.toString(Object[])`: ``` System.out.println(Arrays.toString(stack.toArray())); ```
395,402
<p>I have some old perl code which recently stopped working on a FreeBSD box. The code which fails looks (in simplest form) like this:</p> <pre><code>#!/usr/local/bin/perl -w use strict; use DBI; my $datasource = "DBI:mysql:dbname:hostname.domain.com"; my $user = "username"; my $pass = "password"; DBI-&gt;connect(...
[ { "answer_id": 395413, "author": "max", "author_id": 49407, "author_profile": "https://Stackoverflow.com/users/49407", "pm_score": 2, "selected": false, "text": "<p>A shot in the dark:</p>\n\n<p>gethostbyname<strong>_r</strong> indicates that Perl uses the \"reentrant\" (also called thre...
2008/12/27
[ "https://Stackoverflow.com/questions/395402", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36754/" ]
I have some old perl code which recently stopped working on a FreeBSD box. The code which fails looks (in simplest form) like this: ``` #!/usr/local/bin/perl -w use strict; use DBI; my $datasource = "DBI:mysql:dbname:hostname.domain.com"; my $user = "username"; my $pass = "password"; DBI->connect($datasource, $user...
A shot in the dark: gethostbyname**\_r** indicates that Perl uses the "reentrant" (also called threaded/multi-threaded) version of the resolver code. Seems something is wrong with that. When compiling the dependencies from the ports tree you often can switch multi-threadedness on or off. You can change you previous c...
395,424
<p>Greetings.</p> <p>1 - Let's say I have about 500 folders of variable size with a total size of 100 GB.</p> <p>2 - I want to distribute these folders automatically in other folders until the size of 700 MB is reached with the best optimization of space.</p> <p>Example: In folder "CD--01" I want to have the maximum...
[ { "answer_id": 395491, "author": "frankodwyer", "author_id": 42404, "author_profile": "https://Stackoverflow.com/users/42404", "pm_score": 0, "selected": false, "text": "<p>If you're on UNIX (inc Mac OSX) you can script something like</p>\n\n<pre><code>tar cvzf allfolders.tgz ./allfolder...
2008/12/27
[ "https://Stackoverflow.com/questions/395424", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49416/" ]
Greetings. 1 - Let's say I have about 500 folders of variable size with a total size of 100 GB. 2 - I want to distribute these folders automatically in other folders until the size of 700 MB is reached with the best optimization of space. Example: In folder "CD--01" I want to have the maximum number of folders possi...
This is a very naive and poorly coded solution, but it works. My bash-fu is not strong, but a shell script seems like the best way to approach this problem. ``` #!/bin/bash dirnum=1 for i in * do if [ `du -b -s "$i" | cut -f 1` -gt 700000000 ] then echo "$i is too big for a single folder, skipp...
395,430
<p>Okay, I have this program and I don't want more than one instance of it running. So what I have right now is it grabs all instances that match it's name, and if there are more than one it quits and lets the user know it's already running in another instance.</p> <p>However, there is a special case in which the new ...
[ { "answer_id": 395449, "author": "frankodwyer", "author_id": 42404, "author_profile": "https://Stackoverflow.com/users/42404", "pm_score": 1, "selected": false, "text": "<p>You can use a shared (named) mutex for this.</p>\n\n<p>See the <a href=\"http://msdn.microsoft.com/en-us/library/ms...
2008/12/27
[ "https://Stackoverflow.com/questions/395430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12243/" ]
Okay, I have this program and I don't want more than one instance of it running. So what I have right now is it grabs all instances that match it's name, and if there are more than one it quits and lets the user know it's already running in another instance. However, there is a special case in which the new instance w...
The thing that complicates this is the fact that you want, in certain conditions, to allow a second invocation of the program to do something if another one is running. Using the named mutex will allow you to detect whether the program is already running -- it should be holding the mutex already. You will still need a ...
395,431
<p>I am working on a legacy system and have introduced fluent nHibernate but have one last mapping that I can not seem to get working.</p> <p>Code:</p> <pre><code>public class Permit { public int PermitId { get; set; } public char Discipline { get; set; } public PermitDetails PermitDetails { get; set;...
[ { "answer_id": 395449, "author": "frankodwyer", "author_id": 42404, "author_profile": "https://Stackoverflow.com/users/42404", "pm_score": 1, "selected": false, "text": "<p>You can use a shared (named) mutex for this.</p>\n\n<p>See the <a href=\"http://msdn.microsoft.com/en-us/library/ms...
2008/12/27
[ "https://Stackoverflow.com/questions/395431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37723/" ]
I am working on a legacy system and have introduced fluent nHibernate but have one last mapping that I can not seem to get working. Code: ``` public class Permit { public int PermitId { get; set; } public char Discipline { get; set; } public PermitDetails PermitDetails { get; set; } } public Perm...
The thing that complicates this is the fact that you want, in certain conditions, to allow a second invocation of the program to do something if another one is running. Using the named mutex will allow you to detect whether the program is already running -- it should be holding the mutex already. You will still need a ...
395,432
<p>I have this on line 56 in my environment.rb:</p> <pre><code>I18n.load_path += Dir[ File.join(RAILS_ROOT, 'lib', 'locale', '*.{rb,yml}') ] </code></pre> <p>I can run the app just fine, but when I try to run: script/generate migration</p> <p>I get this error:</p> <pre><code>environment.rb:56: uninitialized constan...
[ { "answer_id": 396360, "author": "swenson", "author_id": 10524, "author_profile": "https://Stackoverflow.com/users/10524", "pm_score": 2, "selected": true, "text": "<p>By default, <code>active_support</code> (where the <code>I18n</code> module is located) is not loaded in your <code>envi...
2008/12/27
[ "https://Stackoverflow.com/questions/395432", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4025/" ]
I have this on line 56 in my environment.rb: ``` I18n.load_path += Dir[ File.join(RAILS_ROOT, 'lib', 'locale', '*.{rb,yml}') ] ``` I can run the app just fine, but when I try to run: script/generate migration I get this error: ``` environment.rb:56: uninitialized constant I18n (NameError) ``` What gives?
By default, `active_support` (where the `I18n` module is located) is not loaded in your `environment.rb`. The proper way to add directories to your i18n load path is by the following in your `environment.rb`: ``` config.i18n.load_path << Dir[File.join(RAILS_ROOT, 'my', 'locales', '*.{rb,yml}')] ``` I think, as an al...
395,436
<p>I am using statfs() which gives me the free blocks available to a non-superuser.</p> <p>I am unsure how to convert this into KB/MB/GB.</p> <p>The values that are returned are:</p> <pre><code>fundamental file system block size: 4096 total data blocks in file system: 3805452 free blocks in fs: 63425 free blocks ava...
[ { "answer_id": 395463, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 3, "selected": true, "text": "<p>Block size is 4096 bytes, or 4KB. Thus 63425 blocks is 63425 * 4KB = 253,700KB, which is roughly 248MB.</p>\n" }, ...
2008/12/27
[ "https://Stackoverflow.com/questions/395436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26728/" ]
I am using statfs() which gives me the free blocks available to a non-superuser. I am unsure how to convert this into KB/MB/GB. The values that are returned are: ``` fundamental file system block size: 4096 total data blocks in file system: 3805452 free blocks in fs: 63425 free blocks avail to non-superuser: 63425 t...
Block size is 4096 bytes, or 4KB. Thus 63425 blocks is 63425 \* 4KB = 253,700KB, which is roughly 248MB.
395,451
<p>I have a script that I'd like to continue using, but it looks like I either have to find some workaround for a bug in Python 3, or downgrade back to 2.6, and thus having to downgrade other scripts as well...</p> <p>Hopefully someone here have already managed to find a workaround.</p> <p>The problem is that due to ...
[ { "answer_id": 395481, "author": "jb.", "author_id": 37522, "author_profile": "https://Stackoverflow.com/users/37522", "pm_score": 6, "selected": true, "text": "<p>Direct from the Py3k docs: <a href=\"http://docs.python.org/dev/py3k/library/urllib.request.html#examples\" rel=\"noreferrer...
2008/12/27
[ "https://Stackoverflow.com/questions/395451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/267/" ]
I have a script that I'd like to continue using, but it looks like I either have to find some workaround for a bug in Python 3, or downgrade back to 2.6, and thus having to downgrade other scripts as well... Hopefully someone here have already managed to find a workaround. The problem is that due to the new changes i...
Direct from the Py3k docs: <http://docs.python.org/dev/py3k/library/urllib.request.html#examples> ``` import urllib.request # Create an OpenerDirector with support for Basic HTTP Authentication... auth_handler = urllib.request.HTTPBasicAuthHandler() auth_handler.add_password(realm='PDQ Application', ...
395,454
<p>I'm trying to loop through items of a checkbox list. If it's checked, I want to set a value. If not, I want to set another value. I was using the below, but it only gives me checked items:</p> <pre><code>foreach (DataRowView myRow in clbIncludes.CheckedItems) { MarkVehicle(myRow); } </code></pre>
[ { "answer_id": 395471, "author": "devio", "author_id": 21336, "author_profile": "https://Stackoverflow.com/users/21336", "pm_score": 0, "selected": false, "text": "<p>Use the CheckBoxList's GetItemChecked or GetItemCheckState method to find out whether an item is checked or not by its in...
2008/12/27
[ "https://Stackoverflow.com/questions/395454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46064/" ]
I'm trying to loop through items of a checkbox list. If it's checked, I want to set a value. If not, I want to set another value. I was using the below, but it only gives me checked items: ``` foreach (DataRowView myRow in clbIncludes.CheckedItems) { MarkVehicle(myRow); } ```
``` for (int i = 0; i < clbIncludes.Items.Count; i++) if (clbIncludes.GetItemChecked(i)) // Do selected stuff else // Do unselected stuff ``` If the the check is in indeterminate state, this will still return true. You may want to replace ``` if (clbIncludes.GetItemChecked(i)) ``` with ``` if (clbIncl...
395,472
<p>Everytime I run rake or most rails commands, I get an annoying warning. I'm still a beginner with Ruby/Rails, and I would like advice on how to hack boot.rb to stop the annoying warning. I'm using Rails 1.2.6 and RubyGems 1.3.1. (I haven't upgraded Rails to 2.x because I'm still learning Rails from a book that us...
[ { "answer_id": 395754, "author": "diclophis", "author_id": 32678, "author_profile": "https://Stackoverflow.com/users/32678", "pm_score": 0, "selected": false, "text": "<p>First, you should investigate an approach that would remove the warning (like upgrading rails or ruby-gems), rather t...
2008/12/27
[ "https://Stackoverflow.com/questions/395472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48988/" ]
Everytime I run rake or most rails commands, I get an annoying warning. I'm still a beginner with Ruby/Rails, and I would like advice on how to hack boot.rb to stop the annoying warning. I'm using Rails 1.2.6 and RubyGems 1.3.1. (I haven't upgraded Rails to 2.x because I'm still learning Rails from a book that uses 1.2...
There is a call to Gem Source Index in a boot.rb: "Gem.cache.search", just replace "search" with "find\_name".
395,484
<p>Let's say you have the following chunk of code:</p> <pre><code>&lt;div id="container"&gt; &lt;someelement&gt;This is any element.&lt;/someelement&gt; &lt;/div&gt; </code></pre> <p>What's the best CSS I could use to horizontally center "someelement" within its containing div?</p>
[ { "answer_id": 395493, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 2, "selected": false, "text": "<p>Try</p>\n\n<pre><code>&lt;someelement style=\"margin-left:auto;margin-right:auto\"&gt;This is any element&lt;/someelem...
2008/12/27
[ "https://Stackoverflow.com/questions/395484", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1615/" ]
Let's say you have the following chunk of code: ``` <div id="container"> <someelement>This is any element.</someelement> </div> ``` What's the best CSS I could use to horizontally center "someelement" within its containing div?
if your `<someelement>` is an inline element (i.e defaults to display: inline) apply text-align: center to its container. If `<someelement>` is a block element set left and right margin to auto and remember to set a width (block elements default to take all available horizontal space unless a width is stated explicitly...
395,504
<p>I'm wanting to decrement a variable in a MySQL table by one everytime an UPDATE query is ran.</p> <p>What I have is this, which isn't working:</p> <p><code>UPDATE forum SET replys = reply-- WHERE fid = '$id'</code></p> <p>Is this possible in any way, or am I going to have to run a SELECT and get the value first,...
[ { "answer_id": 395521, "author": "stu", "author_id": 12386, "author_profile": "https://Stackoverflow.com/users/12386", "pm_score": 5, "selected": true, "text": "<pre><code>UPDATE forum SET replys = reply - 1 WHERE fid = '$id'\n</code></pre>\n" }, { "answer_id": 395524, "autho...
2008/12/27
[ "https://Stackoverflow.com/questions/395504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36545/" ]
I'm wanting to decrement a variable in a MySQL table by one everytime an UPDATE query is ran. What I have is this, which isn't working: `UPDATE forum SET replys = reply-- WHERE fid = '$id'` Is this possible in any way, or am I going to have to run a SELECT and get the value first, decrement it, and then insert the n...
``` UPDATE forum SET replys = reply - 1 WHERE fid = '$id' ```
395,505
<p>What would be the best compression algorithm to use to compress packets before sending them over the wire? The packets are encoded using JSON. Would LZW be a good one for this or is there something better?</p>
[ { "answer_id": 395513, "author": "Michael Kohne", "author_id": 5801, "author_profile": "https://Stackoverflow.com/users/5801", "pm_score": 2, "selected": false, "text": "<p>Ummm...Correct me if I'm wrong, but if you are implementing on-the-wire compression, then you control both ends of ...
2008/12/27
[ "https://Stackoverflow.com/questions/395505", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49018/" ]
What would be the best compression algorithm to use to compress packets before sending them over the wire? The packets are encoded using JSON. Would LZW be a good one for this or is there something better?
I think two questions will affect your answer: 1) How well can you predict the composition of the data without knowing what will happen on any particular run of the program? For instance, if your packets look like this: ``` { "vector": { "latitude": 16, "longitude": 18, "altitude": 20 ...
395,506
<p>I'm trying to implement a comet style, long polling connection using an XMLHttpResponse object. The idea is to maintain an open connection to a server which sends data when it is available (faking push). As soon as the XHR object completes, I need to spawn a new one to wait for any fresh data.</p> <p>Below is a sni...
[ { "answer_id": 395511, "author": "stu", "author_id": 12386, "author_profile": "https://Stackoverflow.com/users/12386", "pm_score": 0, "selected": false, "text": "<p>What you're doing is effectively polling, why make it more complex than it needs to be, and just poll every few seconds? Or...
2008/12/27
[ "https://Stackoverflow.com/questions/395506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12161/" ]
I'm trying to implement a comet style, long polling connection using an XMLHttpResponse object. The idea is to maintain an open connection to a server which sends data when it is available (faking push). As soon as the XHR object completes, I need to spawn a new one to wait for any fresh data. Below is a snippet of co...
Just use jquery and do something like this: ``` function getData() { $.getJSON(someUrl, gotData); } // Whenever a query stops, start a new one. $(document).ajaxStop(getData, 0); // Start the first query. getData(); ``` My [slosh](http://github.com/dustin/slosh) examples do this (since it's pretty mu...
395,509
<p>I'm new to the Mac OS X, and I'm just about ready to throw my brand new <a href="http://en.wikipedia.org/wiki/MacBook_Pro" rel="nofollow noreferrer">MacBook Pro</a> out the window. Every tutorial on setting up a Django development environment on <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow n...
[ { "answer_id": 395546, "author": "James Cape", "author_id": 41044, "author_profile": "https://Stackoverflow.com/users/41044", "pm_score": 2, "selected": false, "text": "<p>You can use the BSD-alike(?) <a href=\"http://macports.org\" rel=\"nofollow noreferrer\">http://macports.org</a>, wh...
2008/12/27
[ "https://Stackoverflow.com/questions/395509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36680/" ]
I'm new to the Mac OS X, and I'm just about ready to throw my brand new [MacBook Pro](http://en.wikipedia.org/wiki/MacBook_Pro) out the window. Every tutorial on setting up a Django development environment on [Mac OS X Leopard](http://en.wikipedia.org/wiki/Mac_OS_X_Leopard) is insidiously wrong. They are all skipping o...
Did the MySQL and MySQL-dev installations go smoothly? Can you run MySQL, connect to it and so on? Does `/usr/local/mysql/include` contain lots of header files? (I've got 46 header files there, for reference). If so, MySQL should be good to go. There are still a few manual steps required to compile MySQL-python, howev...
395,525
<p>I have a funciton that I am currently using to show a hidden div.a_type</p> <p>How can I modify this code so that instead of fading in the hidden div, I can add the new div to the DOM</p> <pre> jQuery(function(){ // Add Answer jQuery(".add_answer").click(function(){ if(count >= "4"){ alert('On...
[ { "answer_id": 395531, "author": "Pim Jager", "author_id": 35197, "author_profile": "https://Stackoverflow.com/users/35197", "pm_score": 4, "selected": true, "text": "<p>How about adding it after the last div.</p>\n\n<pre><code>$('.a_type:last').insertAfter('&lt;div class=\"a_type\"&gt;c...
2008/12/27
[ "https://Stackoverflow.com/questions/395525", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48973/" ]
I have a funciton that I am currently using to show a hidden div.a\_type How can I modify this code so that instead of fading in the hidden div, I can add the new div to the DOM ``` jQuery(function(){ // Add Answer jQuery(".add_answer").click(function(){ if(count >= "4"){ alert('Only 4 Answers A...
How about adding it after the last div. ``` $('.a_type:last').insertAfter('<div class="a_type">content</div>'); ``` **edit** You can get the information through a AJAX call to somefile.php, somefile should then return the content you want in the div: ``` $.get('path/to/somefile.php', function(data){ $('.a_type:...
395,526
<p>I am building a CMS and the naming convention for classes has been debated between the other developer involved and myself. The problem arises specifically with "Page", as it is a public class available in a typical library.</p> <p>A natural response would be to call it MVCMSPage (where MVCMS is the to-be name of t...
[ { "answer_id": 395545, "author": "Dan Herbert", "author_id": 392, "author_profile": "https://Stackoverflow.com/users/392", "pm_score": 3, "selected": true, "text": "<p>I'd go with something other than '<code>Page</code>'. The '<code>Page</code>' class that is built into .NET is a very ge...
2008/12/27
[ "https://Stackoverflow.com/questions/395526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48266/" ]
I am building a CMS and the naming convention for classes has been debated between the other developer involved and myself. The problem arises specifically with "Page", as it is a public class available in a typical library. A natural response would be to call it MVCMSPage (where MVCMS is the to-be name of the cms) or...
I'd go with something other than '`Page`'. The '`Page`' class that is built into .NET is a very generic class that is commonly known as part of ASP.NET. You could easily confuse other developers (or even yourself, a few months down the road if you don't look at it for a while). I usually go with a naming convention su...
395,527
<p>Which would be the correct format for this XML data, are they equivalent or are there trade offs between the two?</p> <p>1.</p> <pre><code>&lt;sitemap&gt; &lt;category name="Animals"&gt; &lt;section title="Dogs"&gt; &lt;page url="/pics/greatdane.jpg" title="Great Dane"/&gt; &lt;/section&gt; &lt;/...
[ { "answer_id": 395534, "author": "David Norman", "author_id": 34502, "author_profile": "https://Stackoverflow.com/users/34502", "pm_score": 2, "selected": false, "text": "<p>There aren't usually right or wrong answers for this sort of thing. Mostly it depends on how you need to access y...
2008/12/27
[ "https://Stackoverflow.com/questions/395527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46108/" ]
Which would be the correct format for this XML data, are they equivalent or are there trade offs between the two? 1. ``` <sitemap> <category name="Animals"> <section title="Dogs"> <page url="/pics/greatdane.jpg" title="Great Dane"/> </section> </category> </sitemap> ``` 2. ``` <sitemap> <page> ...
The issue of attributes vs elements has been around for the better part of a decade and there is no right answer. Instead consider the differences and from that you should be able to decide which to use: * There can be only one instance of an attribute although you can enforce this with elements using DTD or XML Schem...
395,549
<p>Given this:</p> <pre><code>Interface IBase {string X {get;set;}} Interface ISuper {string Y {get;set;}} class Base : IBase {etc...} class Super : Base, ISuper {etc...} void Questionable (Base b) { Console.WriteLine ("The class supports the following interfaces... ") // The Magic Happens Here } </code></pre> ...
[ { "answer_id": 395559, "author": "Ilya Ryzhenkov", "author_id": 18575, "author_profile": "https://Stackoverflow.com/users/18575", "pm_score": 3, "selected": false, "text": "<p>b.GetType().<a href=\"http://msdn.microsoft.com/en-us/library/system.type.getinterfaces.aspx\" rel=\"nofollow no...
2008/12/27
[ "https://Stackoverflow.com/questions/395549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1736623/" ]
Given this: ``` Interface IBase {string X {get;set;}} Interface ISuper {string Y {get;set;}} class Base : IBase {etc...} class Super : Base, ISuper {etc...} void Questionable (Base b) { Console.WriteLine ("The class supports the following interfaces... ") // The Magic Happens Here } ``` What can I replace "The...
The Magic : ``` foreach (Type iface in b.GetType().GetInterfaces()) Console.WriteLine(iface.Name); ```
395,555
<p>I have a string (of undertermined length) that I want to copy a lot of times replacing one character at a time from an array (of undertermined length) of characters.</p> <p>So say I have this string: 'aa'<br> And this array: ['a', 'b', 'c', 'd'] </p> <p>after some magic for-looping stuff there would be an array l...
[ { "answer_id": 395562, "author": "devio", "author_id": 21336, "author_profile": "https://Stackoverflow.com/users/21336", "pm_score": 0, "selected": false, "text": "<p>The question would be clearer if the string and the array would not both contain an 'a'. The desired output does not show...
2008/12/27
[ "https://Stackoverflow.com/questions/395555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35197/" ]
I have a string (of undertermined length) that I want to copy a lot of times replacing one character at a time from an array (of undertermined length) of characters. So say I have this string: 'aa' And this array: ['a', 'b', 'c', 'd'] after some magic for-looping stuff there would be an array like: ['aa', 'ab', '...
If an order of strings in the result array doesn't matter and all chars from the initial string are in the substitution array then: ``` #!/usr/bin/env python from itertools import product def allreplacements(seed, replacement_chars): assert all(c in replacement_chars for c in seed) for aset in product(replace...
395,586
<p>Can someone tell me why this Grails domain class will not compile (at runtime)?</p> <pre><code>class Person { String name String getSomething(int i) { } } </code></pre> <p>I get this error when I run with <code>grails run-app</code>:</p> <pre><code>2008-12-27 15:26:33.955::WARN: Failed startup of co...
[ { "answer_id": 395686, "author": "andHapp", "author_id": 20301, "author_profile": "https://Stackoverflow.com/users/20301", "pm_score": 1, "selected": false, "text": "<p>Before I answer the question let me tell you my environment:<br />\nGrails 1.0.4<br/>\nJava 1.6.0_10-beta<br/>\nGroovy ...
2008/12/27
[ "https://Stackoverflow.com/questions/395586", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24396/" ]
Can someone tell me why this Grails domain class will not compile (at runtime)? ``` class Person { String name String getSomething(int i) { } } ``` I get this error when I run with `grails run-app`: ``` 2008-12-27 15:26:33.955::WARN: Failed startup of context org.mortbay.jetty.webapp.WebAppContext@187...
I've concluded that this is a bug with Grails. I've created [GRAILS-3760](http://jira.codehaus.org/browse/GRAILS-3760) which has been fixed in Grails 1.1.2.
395,593
<p>I'm having trouble computing reflection angles for a ball hitting an oblique wall. I'm using an algorithm lifted from this <a href="http://www.johanvanmol.org/content/view/45/37/1/6/" rel="nofollow noreferrer">tutorial</a>. It looks like this (in Actionscript 3), with p1 being the current velocity vector and p2 the ...
[ { "answer_id": 395603, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 0, "selected": false, "text": "<p>If it works for perpendicular, maybe <code>wallvec</code> is not right. Have you printed out <code>wallvec</code> ...
2008/12/27
[ "https://Stackoverflow.com/questions/395593", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2942/" ]
I'm having trouble computing reflection angles for a ball hitting an oblique wall. I'm using an algorithm lifted from this [tutorial](http://www.johanvanmol.org/content/view/45/37/1/6/). It looks like this (in Actionscript 3), with p1 being the current velocity vector and p2 the normal of the wall: ``` private functio...
Vectors wallvec and wallnorm must have a magnitude of 1 for the function to work. I suspect that the function getNorm() handles the work for wallvec for you, but wallnorm seems to get an arbitrary magnitude. Also, your implementation doesn't exactly match the algorithm linked on the page. In particular, the page uses ...
395,599
<p>I would like to know the recommended library or procedure for dealing with multi-coloured text within Java. My current usage of java.awt.Graphics, while function, appears to be a bit more complex than necessary.</p> <p>The main issue involves the frequent change of colour, creating a new java.awt.Colour() object ...
[ { "answer_id": 395616, "author": "Simon Groenewolt", "author_id": 31884, "author_profile": "https://Stackoverflow.com/users/31884", "pm_score": 1, "selected": false, "text": "<p>Not a real answer, but if you think/measure that creating lots of Color objects is a performance bottleneck yo...
2008/12/27
[ "https://Stackoverflow.com/questions/395599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33952/" ]
I would like to know the recommended library or procedure for dealing with multi-coloured text within Java. My current usage of java.awt.Graphics, while function, appears to be a bit more complex than necessary. The main issue involves the frequent change of colour, creating a new java.awt.Colour() object whenever a n...
I'm assuming you're rendering text to an arbitrary component (via paintComponent()) rather than trying to modify the color of text in a JTextPane, JLabel, or other pre-existing widget. If this is the case, you should look into using an [AttributedString](http://java.sun.com/javase/6/docs/api/java/text/AttributedString...
395,628
<p>I can easily define a datatype for a node of a directed graph.</p> <pre><code>data Node = Node String [Node] derving (Show, Read) </code></pre> <p>I can save the graph to a file using show function, then restore it using read. However, show will not cope with a cycle. Is there a trivial way to save and restore a g...
[ { "answer_id": 395943, "author": "Paul Johnson", "author_id": 49220, "author_profile": "https://Stackoverflow.com/users/49220", "pm_score": 4, "selected": true, "text": "<p>Not as far as I know. You have to write a graph-traversing function.</p>\n\n<p>First, decide where to break the ci...
2008/12/28
[ "https://Stackoverflow.com/questions/395628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5978/" ]
I can easily define a datatype for a node of a directed graph. ``` data Node = Node String [Node] derving (Show, Read) ``` I can save the graph to a file using show function, then restore it using read. However, show will not cope with a cycle. Is there a trivial way to save and restore a graph?
Not as far as I know. You have to write a graph-traversing function. First, decide where to break the circularity. In this case it is trivial: use the node names (assuming they are unique within a graph). For a more complex structure, such as a graph with nodes and edges as separate types, you would have to decide whe...
395,663
<p>I have a WPF App that implements a ListView. I would like to show an image (a small icon) in one of the columns depending on the type of the data that row represents. Sort of like the display you see in Windows Explorer. </p> <p>I am using DataTriggers elsewhere in my XAML, it seems like a similar method could be u...
[ { "answer_id": 395835, "author": "Brad Leach", "author_id": 708, "author_profile": "https://Stackoverflow.com/users/708", "pm_score": 0, "selected": false, "text": "<p>In the past, I've used <strong>ValueConverters</strong> to provide the Image I want to display, however I am intrigued t...
2008/12/28
[ "https://Stackoverflow.com/questions/395663", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6054/" ]
I have a WPF App that implements a ListView. I would like to show an image (a small icon) in one of the columns depending on the type of the data that row represents. Sort of like the display you see in Windows Explorer. I am using DataTriggers elsewhere in my XAML, it seems like a similar method could be used to swa...
There are three common techniques for this. **1) DataTrigger:** ``` <DataTemplate x:Key="ImageColumn"> <Grid> <Image x:Name="img" Source="MyImage.png"/> <Rectangle x:Name="rect" Fill="Red" Visibility="Hidden"/> </Grid> <DataTemplate.Triggers> <DataTrigger Binding="{Binding TriggerP...
395,667
<p>How can I create a method in the @implementation of a class without defining it in the @interface?</p> <p>For example, I have a constructor that does some initialisation and then reads data from a file. I want to factor out the file-reading code into a separate method that I then call from within the constructor. ...
[ { "answer_id": 395670, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 2, "selected": false, "text": "<p>You could use <a href=\"http://en.wikipedia.org/wiki/Objective-C#Categories\" rel=\"nofollow noreferrer\">categor...
2008/12/28
[ "https://Stackoverflow.com/questions/395667", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41493/" ]
How can I create a method in the @implementation of a class without defining it in the @interface? For example, I have a constructor that does some initialisation and then reads data from a file. I want to factor out the file-reading code into a separate method that I then call from within the constructor. I don't wan...
If you place the implementation of a method before any code that calls it you do not need to define it in the header. So in this case put *loadListWithName:* in front of *initListOfName:* in the @implementation block and it will be good. **Note:** Just because it is not defined in the header does not mean the method ...
395,675
<p>How can I reference a Groovy domain class from Java class using Eclipse?</p> <p>I've put my domain class in package:</p> <pre><code>package com.me.myproject public class Person { String name int age } </code></pre> <p>Then in my Java class I attempt to reference <code>com.me.myproject.Person</code>. This ...
[ { "answer_id": 403589, "author": "branchgabriel", "author_id": 30807, "author_profile": "https://Stackoverflow.com/users/30807", "pm_score": 1, "selected": false, "text": "<p>I haven't been able to make this work in eclipse either. Until spring gets the groovy / grails eclipse plugins wh...
2008/12/28
[ "https://Stackoverflow.com/questions/395675", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24396/" ]
How can I reference a Groovy domain class from Java class using Eclipse? I've put my domain class in package: ``` package com.me.myproject public class Person { String name int age } ``` Then in my Java class I attempt to reference `com.me.myproject.Person`. This works for `grails run-app` (command line) bu...
I haven't been able to make this work in eclipse either. Until spring gets the groovy / grails eclipse plugins whipped up to do something other than mere color coding your best bet is to use an IDE like Intelij which has the best groovy support at the moment.
395,682
<p>I'm having a hell of a time understanding pointers in Objective C. They don't behave like I would assume based on various C tutorials.</p> <p>Example:</p> <pre><code>// Define Name and ID NSString *processName = [[NSProcessInfo processInfo] processName]; NSNumber *processID = [NSNumber numberWithInt:[[NSProcessInf...
[ { "answer_id": 395699, "author": "Ashley Clark", "author_id": 4556, "author_profile": "https://Stackoverflow.com/users/4556", "pm_score": 3, "selected": false, "text": "<p>The <code>%@</code> in your format string tells <code>NSLog</code> to call <code>-description</code> on the relevant...
2008/12/28
[ "https://Stackoverflow.com/questions/395682", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29297/" ]
I'm having a hell of a time understanding pointers in Objective C. They don't behave like I would assume based on various C tutorials. Example: ``` // Define Name and ID NSString *processName = [[NSProcessInfo processInfo] processName]; NSNumber *processID = [NSNumber numberWithInt:[[NSProcessInfo processInfo] proces...
Objects in objective c are represented as pointers to c structures that contain all of the object data. If the object were an actual struct (rather than a pointer to one) it would make things like passing objects as method parameters much less efficient. So once you initialize an object: ``` NSString *aString = /* ini...
395,685
<p>I'd use a singleton like this:</p> <pre><code>Singleton* single = Singleton::instance(); single-&gt;do_it(); </code></pre> <p>I'd use an unnamed class like this:</p> <pre><code>single.do_it(); </code></pre> <p>I feel as if the Singleton pattern has no advantage over the unnamed class other than having readable e...
[ { "answer_id": 395693, "author": "Dustin Getz", "author_id": 20003, "author_profile": "https://Stackoverflow.com/users/20003", "pm_score": 1, "selected": false, "text": "<p>changing the code like that even if it probably shouldn't affect code generation is a terrible idea. sooner or lat...
2008/12/28
[ "https://Stackoverflow.com/questions/395685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/456/" ]
I'd use a singleton like this: ``` Singleton* single = Singleton::instance(); single->do_it(); ``` I'd use an unnamed class like this: ``` single.do_it(); ``` I feel as if the Singleton pattern has no advantage over the unnamed class other than having readable error messages. Using singletons is clumsier than usi...
I think the most important reason is that you cannot put an unnamed class in namespace scope. So, the following is not valid (gcc accepts, but warns. comeau doesn't accept in strict mode): ``` class { } single; int main() { } ``` The type of `single` has *no* linkage because there is no way to declare its name in an...
395,735
<p>I was wondering how to check whether a variable is a class (not an instance!) or not.</p> <p>I've tried to use the function <code>isinstance(object, class_or_type_or_tuple)</code> to do this, but I don't know what type would a class will have.</p> <p>For example, in the following code</p> <pre><code>class Foo: pa...
[ { "answer_id": 395741, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 6, "selected": false, "text": "<pre><code>&gt;&gt;&gt; class X(object):\n... pass\n... \n&gt;&gt;&gt; type(X)\n&lt;type 'type'&gt;\n&gt;&gt;&gt; isins...
2008/12/28
[ "https://Stackoverflow.com/questions/395735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32267/" ]
I was wondering how to check whether a variable is a class (not an instance!) or not. I've tried to use the function `isinstance(object, class_or_type_or_tuple)` to do this, but I don't know what type would a class will have. For example, in the following code ``` class Foo: pass isinstance(Foo, **???**) # i want ...
Even better: use the [`inspect.isclass`](https://docs.python.org/library/inspect.html#inspect.isclass) function. ``` >>> import inspect >>> class X(object): ... pass ... >>> inspect.isclass(X) True >>> x = X() >>> isinstance(x, X) True >>> inspect.isclass(x) False ```
395,739
<p>When I'm naming array-type variables, I often am confronted with a dilemma: Do I name my array using plural or singular?</p> <p>For example, let's say I have an array of names: In PHP I would say: <code>$names=array("Alice","Bobby","Charles");</code> </p> <p>However, then lets say I want to reference a name in t...
[ { "answer_id": 395742, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 7, "selected": true, "text": "<p>I use the plural form. Then I can do something like:</p>\n\n<pre><code>$name = $names[1];\n</code></pre>\n" }, {...
2008/12/28
[ "https://Stackoverflow.com/questions/395739", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1615/" ]
When I'm naming array-type variables, I often am confronted with a dilemma: Do I name my array using plural or singular? For example, let's say I have an array of names: In PHP I would say: `$names=array("Alice","Bobby","Charles");` However, then lets say I want to reference a name in this array. For Bobby, I'd say:...
I use the plural form. Then I can do something like: ``` $name = $names[1]; ```
395,759
<p>I'm trying to make an ajax call to grab session data to insert into my page after it's loaded like this</p> <pre><code>jQuery(function(){ // Add Answer jQuery(".add_answer").livequery('click',function(){ var count = $(this).attr("alt"); count++; var count1 = count-1; $.get('quiz/select', functio...
[ { "answer_id": 396016, "author": "Soviut", "author_id": 46914, "author_profile": "https://Stackoverflow.com/users/46914", "pm_score": 3, "selected": true, "text": "<p>I believe your problem has to do with the scope of $(this). Because you've got your ajax get function nested inside your...
2008/12/28
[ "https://Stackoverflow.com/questions/395759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48973/" ]
I'm trying to make an ajax call to grab session data to insert into my page after it's loaded like this ``` jQuery(function(){ // Add Answer jQuery(".add_answer").livequery('click',function(){ var count = $(this).attr("alt"); count++; var count1 = count-1; $.get('quiz/select', function(p_type){ //...
I believe your problem has to do with the scope of $(this). Because you've got your ajax get function nested inside your livequery function, inside yet another anonymous function, I'd be willing to bet that $(this) is now refering to your $.get() call or something. You need to cache $(this) as soon as possible at the ...
395,779
<p>I am building an MVC application in which I am reading a list of files from the file system and I want to pass the relative URL to that file to the view, preferably prefixed with "~/" so that whatever view is selected cab render the URL appropriately. </p> <p>To do this, I need to enumerate the files in the file s...
[ { "answer_id": 395798, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 6, "selected": true, "text": "<p>At the moment I don't know any built-in method to do it, but it's not difficult, I do it like this:</p>\n\n<u...
2008/12/28
[ "https://Stackoverflow.com/questions/395779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1875/" ]
I am building an MVC application in which I am reading a list of files from the file system and I want to pass the relative URL to that file to the view, preferably prefixed with "~/" so that whatever view is selected cab render the URL appropriately. To do this, I need to enumerate the files in the file system and c...
At the moment I don't know any built-in method to do it, but it's not difficult, I do it like this: * We need to get the Application root, and replace it in our new path with `~` * We need to convert the backslashes to slashes --- ``` public string ReverseMapPath(string path) { string appPath = HttpContext.Curre...
395,783
<p>I have a Rails site, where the content is written in markdown. I wish to display a snippet of each, with a "Read more.." link.</p> <p>How do I go about this? Simple truncating the raw text will not work, for example..</p> <pre><code>&gt;&gt; "This is an [example](http://example.com)"[0..25] =&gt; "This is an [exam...
[ { "answer_id": 395807, "author": "csexton", "author_id": 19839, "author_profile": "https://Stackoverflow.com/users/19839", "pm_score": 1, "selected": false, "text": "<p>You could use a regular expression to find a line consisting of nothing but \"^\" characters:</p>\n\n<pre><code>markdow...
2008/12/28
[ "https://Stackoverflow.com/questions/395783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/745/" ]
I have a Rails site, where the content is written in markdown. I wish to display a snippet of each, with a "Read more.." link. How do I go about this? Simple truncating the raw text will not work, for example.. ``` >> "This is an [example](http://example.com)"[0..25] => "This is an [example](http:" ``` Ideally I wa...
> > * Write/find an intelligent HTML truncating function > > > The following from <http://mikeburnscoder.wordpress.com/2006/11/11/truncating-html-in-ruby/>, with some modifications will correctly truncate HTML, and easily allow appending a string before the closing tags. ``` >> puts "<p><b><a href=\"hi\">Somethin...
395,816
<p>For my Java game server I send the Action ID of the packet which basically tells the server what the packet is for. I want to map each Action ID (an integer) to a function. Is there a way of doing this without using a switch?</p>
[ { "answer_id": 395822, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 2, "selected": false, "text": "<p>Java does not have first-class function pointers. In order to achieve similar functionality, you have to define ...
2008/12/28
[ "https://Stackoverflow.com/questions/395816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49018/" ]
For my Java game server I send the Action ID of the packet which basically tells the server what the packet is for. I want to map each Action ID (an integer) to a function. Is there a way of doing this without using a switch?
What about this one? ``` HashMap<Integer, Runnable> map = new HashMap<Integer, Runnable>(); map.put(Register.ID, new Runnable() { public void run() { functionA(); } }); map.put(NotifyMessage.ID, new Runnable() { public void run() { functionB(); } }); // ... map.get(id).run(); ``` (If you need to pass some ...
395,832
<p>I want to get the UCS-2 code points for a given UTF-8 string. For example the word "hello" should become something like "0068 0065 006C 006C 006F". Please note that the characters could be from any language including complex scripts like the east asian languages.</p> <p>So, the problem comes down to "convert a give...
[ { "answer_id": 395854, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 4, "selected": false, "text": "<p>Use an existing utility such as <a href=\"http://www.gnu.org/software/libiconv/\" rel=\"noreferrer\">iconv</a>, o...
2008/12/28
[ "https://Stackoverflow.com/questions/395832", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47468/" ]
I want to get the UCS-2 code points for a given UTF-8 string. For example the word "hello" should become something like "0068 0065 006C 006C 006F". Please note that the characters could be from any language including complex scripts like the east asian languages. So, the problem comes down to "convert a given characte...
[Scott Reynen](https://stackoverflow.com/users/10837/scott-reynen) wrote a function to [convert UTF-8 into Unicode](http://randomchaos.com/documents/?source=php_and_unicode). I found it looking at the [PHP documentation](http://us.php.net/manual/en/function.unicode-encode.php#73422). ``` function utf8_to_unicode( $str...
395,849
<p>Take the following code for example;</p> <pre><code> if (Convert.ToString(frm.WindowState) == "Minimized") Layout.WindowState = "Maximized"; else Layout.WindowState = Convert.ToString(frm.WindowState); </code></pre> <p>We are analysing the string definition of the window state, i.e. "Minimiz...
[ { "answer_id": 395855, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 4, "selected": true, "text": "<p>The <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.form.windowstate.aspx\" rel=\"nofollow noreferrer\"...
2008/12/28
[ "https://Stackoverflow.com/questions/395849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48499/" ]
Take the following code for example; ``` if (Convert.ToString(frm.WindowState) == "Minimized") Layout.WindowState = "Maximized"; else Layout.WindowState = Convert.ToString(frm.WindowState); ``` We are analysing the string definition of the window state, i.e. "Minimized". Would this string de...
The [`WindowState`](http://msdn.microsoft.com/en-us/library/system.windows.forms.form.windowstate.aspx) value *is* an enumeration - [`System.Windows.Forms.FormWindowState`](http://msdn.microsoft.com/en-us/library/system.windows.forms.formwindowstate.aspx). Just compare to the enumeration constants, skip the `ToString()...
395,874
<p>I've encountered the need to remove comments of the form:</p> <pre><code>&lt;!-- Foo Bar --&gt; </code></pre> <p>I'd like to use a regular expression that matches anything (including line breaks) between the beginning and end 'delimiters.'</p> <p>What would a good regex be for this task?</p>
[ { "answer_id": 395879, "author": "Diadistis", "author_id": 47401, "author_profile": "https://Stackoverflow.com/users/47401", "pm_score": 4, "selected": true, "text": "<p>The simple way :</p>\n\n<pre><code>Regex xmlCommentsRegex = new Regex(\"&lt;!--.*?--&gt;\", RegexOptions.Singleline | ...
2008/12/28
[ "https://Stackoverflow.com/questions/395874", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37971/" ]
I've encountered the need to remove comments of the form: ``` <!-- Foo Bar --> ``` I'd like to use a regular expression that matches anything (including line breaks) between the beginning and end 'delimiters.' What would a good regex be for this task?
The simple way : ``` Regex xmlCommentsRegex = new Regex("<!--.*?-->", RegexOptions.Singleline | RegexOptions.Compiled); ``` And a better way : ``` Regex xmlCommentsRegex = new Regex("<!--(?:[^-]|-(?!->))*-->", RegexOptions.Singleline | RegexOptions.Compiled); ```
395,886
<p>I'm still a newbie to Adobe Air/Flex, and still fairly new with SQL.</p> <p>I've downloaded <a href="http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-air%E2%80%A6-part-1/" rel="nofollow noreferrer">this</a> (<a href="http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-...
[ { "answer_id": 395879, "author": "Diadistis", "author_id": 47401, "author_profile": "https://Stackoverflow.com/users/47401", "pm_score": 4, "selected": true, "text": "<p>The simple way :</p>\n\n<pre><code>Regex xmlCommentsRegex = new Regex(\"&lt;!--.*?--&gt;\", RegexOptions.Singleline | ...
2008/12/28
[ "https://Stackoverflow.com/questions/395886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13713/" ]
I'm still a newbie to Adobe Air/Flex, and still fairly new with SQL. I've downloaded [this](http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-air%E2%80%A6-part-1/) (<http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-air>…-part-1/) code and have been looking over it and I...
The simple way : ``` Regex xmlCommentsRegex = new Regex("<!--.*?-->", RegexOptions.Singleline | RegexOptions.Compiled); ``` And a better way : ``` Regex xmlCommentsRegex = new Regex("<!--(?:[^-]|-(?!->))*-->", RegexOptions.Singleline | RegexOptions.Compiled); ```
395,892
<p>What is the best approach to implementing authorisation/authentication for a Windows Forms app talking to an IIS-hosted RESTful WCF Service?</p> <p>The reason I ask is I am very confused, after sifting through different articles and posts expressing a different method and eventually hitting a ~650 page document on ...
[ { "answer_id": 396108, "author": "Lex Li", "author_id": 11182, "author_profile": "https://Stackoverflow.com/users/11182", "pm_score": 1, "selected": false, "text": "<p>Well, you really should not pay so much attention to WinForms side because WCF side is the key.</p>\n\n<p>By the way, di...
2008/12/28
[ "https://Stackoverflow.com/questions/395892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41211/" ]
What is the best approach to implementing authorisation/authentication for a Windows Forms app talking to an IIS-hosted RESTful WCF Service? The reason I ask is I am very confused, after sifting through different articles and posts expressing a different method and eventually hitting a ~650 page document on WCF Securi...
Well, I don't have any experience with the REST capabilities of WCF, but I did wrestle a lot with understanding the implications of security choices in [my WCF security question](https://stackoverflow.com/questions/345414/aspnet-web-site-windows-forms-app-wcf-service-client-credentials). As you've noticed, there's a re...
395,922
<p>Is there a way to read value for the WiX variable from a text file?</p> <p>What I am trying to do is to include a version-specific information into instlal package.</p> <p>This version information extracted into the text file on the pre-build step, the question is how to propages this text file content into a buil...
[ { "answer_id": 396292, "author": "Stefan", "author_id": 48003, "author_profile": "https://Stackoverflow.com/users/48003", "pm_score": 4, "selected": true, "text": "<p>Create a separate file 'includes.wxi', for example like this:</p>\n\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"utf-8...
2008/12/28
[ "https://Stackoverflow.com/questions/395922", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48829/" ]
Is there a way to read value for the WiX variable from a text file? What I am trying to do is to include a version-specific information into instlal package. This version information extracted into the text file on the pre-build step, the question is how to propages this text file content into a build process. One o...
Create a separate file 'includes.wxi', for example like this: ``` <?xml version="1.0" encoding="utf-8"?> <Include Id="VersionNumberInclude"> <?define MajorVersion="1" ?> <?define MinorVersion="5" ?> <?define MicroVersion="99" ?> <?define BuildVersion="14954" ?> </Include> ``` In your wxs file, you ca...
395,928
<p>I'm try to develop a regex that will be used in a C# program..</p> <p>My initial regex was:</p> <pre><code>(?&lt;=\()\w+(?=\)) </code></pre> <p>Which successfully matches "(foo)" - matching but excluding from output the open and close parens, to produce simply "foo".</p> <p>However, if I modify the regex to:</p>...
[ { "answer_id": 395934, "author": "strager", "author_id": 39992, "author_profile": "https://Stackoverflow.com/users/39992", "pm_score": 3, "selected": false, "text": "<p>Your look-behinds are the problem. Here's how the string is being processed:</p>\n\n<ol>\n<li>We see [ in the string, ...
2008/12/28
[ "https://Stackoverflow.com/questions/395928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49465/" ]
I'm try to develop a regex that will be used in a C# program.. My initial regex was: ``` (?<=\()\w+(?=\)) ``` Which successfully matches "(foo)" - matching but excluding from output the open and close parens, to produce simply "foo". However, if I modify the regex to: ``` \[(?<=\()\w+(?=\))\] ``` and I try to m...
Out of context, it is hard to judge, but the look-behind here is probably overkill. They are useful to exclude strings (as in strager's example) and in some other special circumstances where simple REs fail, but I often see them used where simpler expressions are easier to write, work in more RE flavors and are probabl...
395,952
<p>I'm writing a program that allows developers to write AddIn's for it and I'd like developers to be able to hook into events happening in the program.</p> <p>My code isn't compiling because I can't declare a delegate in the IMyProgram interface.</p> <p>So I suppose this is more of a design question. How would you g...
[ { "answer_id": 395955, "author": "Gutzofter", "author_id": 47623, "author_profile": "https://Stackoverflow.com/users/47623", "pm_score": 1, "selected": false, "text": "<p>IMyProgram is declaring a scope of public for the delegate and the events. Remove them, and I think you will be able ...
2008/12/28
[ "https://Stackoverflow.com/questions/395952", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17211/" ]
I'm writing a program that allows developers to write AddIn's for it and I'd like developers to be able to hook into events happening in the program. My code isn't compiling because I can't declare a delegate in the IMyProgram interface. So I suppose this is more of a design question. How would you go about getting a...
Problem has been solved. I had no idea delegates can be declared at the namespace level without being in a class.
395,973
<p>Hey, I stumbled upon this site looking for solutions for event overlaps in mySQL tables. I was SO impressed with the solution (which is helping already) I thought I'd see if I could get some more help...</p> <p>Okay, so Joe want's to swap shifts with someone at work. He has a court date. He goes to the shift swap f...
[ { "answer_id": 395985, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 1, "selected": false, "text": "<p>You could load the <code>joe_shift{1,2,3}</code> values into a TEMPORARY table and then do a query to join against ...
2008/12/28
[ "https://Stackoverflow.com/questions/395973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49478/" ]
Hey, I stumbled upon this site looking for solutions for event overlaps in mySQL tables. I was SO impressed with the solution (which is helping already) I thought I'd see if I could get some more help... Okay, so Joe want's to swap shifts with someone at work. He has a court date. He goes to the shift swap form and it...
I think you should be able to exclude Joe's other shifts using an inner select instead of the generated string, something like: ``` SELECT * FROM shifts s1 AND shiftstart BETWEEN FROM_UNIXTIME('$startday') AND FROM_UNIXTIME('$endday') AND user_id NOT IN ($busy_users) AND (TIME_TO_SEC(TIMEDIFF(shiftend,shiftstart)) =...
395,981
<p>I have a problem involving a collection of continuous probability distribution functions, most of which are determined empirically (e.g. departure times, transit times). What I need is some way of taking two of these PDFs and doing arithmetic on them. E.g. if I have two values x taken from PDF X, and y taken from ...
[ { "answer_id": 395989, "author": "dmckee --- ex-moderator kitten", "author_id": 2509, "author_profile": "https://Stackoverflow.com/users/2509", "pm_score": 2, "selected": false, "text": "<p>Is there anything that stops you from employing a mini-language for this?</p>\n\n<p>By that I mean...
2008/12/28
[ "https://Stackoverflow.com/questions/395981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49220/" ]
I have a problem involving a collection of continuous probability distribution functions, most of which are determined empirically (e.g. departure times, transit times). What I need is some way of taking two of these PDFs and doing arithmetic on them. E.g. if I have two values x taken from PDF X, and y taken from PDF Y...
No need for histograms or symbolic computation: everything can be done at the language level in closed form, if the right point of view is taken. *[I shall use the term "measure" and "distribution" interchangeably. Also, my Haskell is rusty and I ask you to forgive me for being imprecise in this area.]* Probability d...
395,982
<p>I have read posts like these:</p> <ol> <li><a href="https://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python">What is a metaclass in Python?</a> </li> <li><a href="https://stackoverflow.com/questions/392160/what-are-your-concrete-use-cases-for-metaclasses-in-python">What are your (concrete) use-case...
[ { "answer_id": 396109, "author": "James Brady", "author_id": 29903, "author_profile": "https://Stackoverflow.com/users/29903", "pm_score": 6, "selected": true, "text": "<p>OK, you've thrown quite a few concepts into the mix here! I'm going to pull out a few of the specific questions you ...
2008/12/28
[ "https://Stackoverflow.com/questions/395982", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33612/" ]
I have read posts like these: 1. [What is a metaclass in Python?](https://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python) 2. [What are your (concrete) use-cases for metaclasses in Python?](https://stackoverflow.com/questions/392160/what-are-your-concrete-use-cases-for-metaclasses-in-python) 3. [Pytho...
OK, you've thrown quite a few concepts into the mix here! I'm going to pull out a few of the specific questions you have. In general, understanding super, the MRO and metclasses is made much more complicated because there have been lots of changes in this tricky area over the last few versions of Python. [Python's ow...
395,995
<p>From what I'm reading, <code>$</code> is described as "applies a function to its arguments." However, it doesn't seem to work quite like <code>(apply ...)</code> in Lisp, because it's a binary operator, so really the only thing it looks like it does is help to avoid parentheses sometimes, like <code>foo $ bar quux</...
[ { "answer_id": 396036, "author": "Steven Dee", "author_id": 31077, "author_profile": "https://Stackoverflow.com/users/31077", "pm_score": 3, "selected": false, "text": "<p>You're mostly understanding it right---that is, about 99% of the use of $ is to help avoid parentheses, and yes, it ...
2008/12/28
[ "https://Stackoverflow.com/questions/395995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38803/" ]
From what I'm reading, `$` is described as "applies a function to its arguments." However, it doesn't seem to work quite like `(apply ...)` in Lisp, because it's a binary operator, so really the only thing it looks like it does is help to avoid parentheses sometimes, like `foo $ bar quux` instead of `foo (bar quux)`. A...
`$` is preferred to parentheses when the distance between the opening and closing parens would otherwise be greater than good readability warrants, or if you have several layers of nested parentheses. For example ``` i (h (g (f x))) ``` can be rewritten ``` i $ h $ g $ f x ``` In other words, it represents right...
396,005
<p>Given a set of words, we need to find the anagram words and display each category alone using the best algorithm.</p> <p>input:</p> <pre><code>man car kile arc none like </code></pre> <p>output:</p> <pre><code>man car arc kile like none </code></pre> <p>The best solution I am developing now is based on an hasht...
[ { "answer_id": 396008, "author": "Paulius", "author_id": 1353085, "author_profile": "https://Stackoverflow.com/users/1353085", "pm_score": 2, "selected": false, "text": "<p>I don't think you'll find anything better than a hash table with a custom hash function (that would sort the letter...
2008/12/28
[ "https://Stackoverflow.com/questions/396005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42749/" ]
Given a set of words, we need to find the anagram words and display each category alone using the best algorithm. input: ``` man car kile arc none like ``` output: ``` man car arc kile like none ``` The best solution I am developing now is based on an hashtable, but I am thinking about equation to convert anagra...
Don't bother with a custom hash function at all. Use the normal string hash function on whatever your platform is. The important thing is to make the key for your hash table the idea of a "sorted word" - where the word is sorted by letter, so "car" => "acr". All anagrams will have the same "sorted word". Just have a h...
396,069
<p>I need some help with .NET (C#) and MS Outlook. I'm building a simple desktop application and want to send an e-mail using Outlook.</p> <ol> <li><p>If my desktop app generates a message, it should be able to send it as an email via outlook (we can assume outlook is running on the same PC) - a very simple operation....
[ { "answer_id": 396097, "author": "gimel", "author_id": 6491, "author_profile": "https://Stackoverflow.com/users/6491", "pm_score": 1, "selected": false, "text": "<p>Using MAPI, a p/invoke interface makes using something like <a href=\"http://msdn.microsoft.com/en-us/library/bb175286.aspx...
2008/12/28
[ "https://Stackoverflow.com/questions/396069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I need some help with .NET (C#) and MS Outlook. I'm building a simple desktop application and want to send an e-mail using Outlook. 1. If my desktop app generates a message, it should be able to send it as an email via outlook (we can assume outlook is running on the same PC) - a very simple operation. 2. If I can do ...
This code is adopted straight from the [MSDN example](http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx): ``` using System.Net; using System.Net.Mime; using System.Net.Mail; ... ... public static void CreateMessageWithAttachment(string server) { // Specify the file to be attached and sent ...
396,084
<p>I'm a C++ newbie, but I wasn't able to find the answer to this (most likely trivial) question online. I am having some trouble compiling some code where two classes include each other. To begin, should my #include statements go inside or outside of my macros? In practice, this hasn't seemed to matter. However, i...
[ { "answer_id": 396089, "author": "Nathan Fellman", "author_id": 1084, "author_profile": "https://Stackoverflow.com/users/1084", "pm_score": 0, "selected": false, "text": "<p>I doubt that this can be done. You're not talking about calling two <em>functions</em> from inside each other rec...
2008/12/28
[ "https://Stackoverflow.com/questions/396084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48096/" ]
I'm a C++ newbie, but I wasn't able to find the answer to this (most likely trivial) question online. I am having some trouble compiling some code where two classes include each other. To begin, should my #include statements go inside or outside of my macros? In practice, this hasn't seemed to matter. However, in this ...
By "the macros" I assume you mean the #ifndef include guards? If so, #includes should definitely go inside. This is one of the major reasons why include guards exists, because otherwise you easily end up with an infinite recursion as you noticed. Anyway, the problem is that at the time you use the A and B classes (ins...
396,099
<p>I mean to open the built-in Windows GUI from command line- not to launch by Schtasks</p>
[ { "answer_id": 396119, "author": "Mahendra", "author_id": 36816, "author_profile": "https://Stackoverflow.com/users/36816", "pm_score": 3, "selected": false, "text": "<p>You might want to have look at simple command line scheduler \"at\":</p>\n\n<hr>\n\n<pre><code>C:\\Documents and Setti...
2008/12/28
[ "https://Stackoverflow.com/questions/396099", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I mean to open the built-in Windows GUI from command line- not to launch by Schtasks
**`taskschd.msc` is available in Windows Vista and later.** <http://technet.microsoft.com/en-us/library/cc721871.aspx> I could have sworn I'd seen a little task scheduler GUI like you're talking about prior to Vista, but maybe I was thinking of the "Add Scheduled Task" wizard. You might have to settle for opening th...
396,117
<p>I wonder, whether it is possible to create class-methods in VBA. By class-method I mean methods that can be called without having an object of the class. The 'static'-keyword does that trick in C++ and Java.</p> <p>In the example below, I try to create a static factory method.</p> <p>Example:</p> <pre><code>'Clas...
[ { "answer_id": 396136, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": true, "text": "<p>That (\"Public Shared\") would only work in VB.Net.</p>\n\n<p>There is no way to define Class Methods in VBA (or VB). I'd su...
2008/12/28
[ "https://Stackoverflow.com/questions/396117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34039/" ]
I wonder, whether it is possible to create class-methods in VBA. By class-method I mean methods that can be called without having an object of the class. The 'static'-keyword does that trick in C++ and Java. In the example below, I try to create a static factory method. Example: ``` 'Classmodule Person' Option Expli...
That ("Public Shared") would only work in VB.Net. There is no way to define Class Methods in VBA (or VB). I'd suggest to create a public function in a module.
396,118
<p>I'm porting some code from BSD sockets to Winsock, and I'm not sure how to handle the case below.</p> <p>My original application runs a select on both stdin and the network socket:</p> <pre><code>FD_SET(sock, &amp;fd); FD_SET(0, &amp;fd); ... if (select(..., &amp;fd, ... )...) </code></pre> <p>Trying to run this ...
[ { "answer_id": 396249, "author": "Dave Ray", "author_id": 40310, "author_profile": "https://Stackoverflow.com/users/40310", "pm_score": 2, "selected": false, "text": "<p>I'd love to be corrected, but as far as I know, Winsock does not extend beyond the realm of sockets. That is, Unix's \...
2008/12/28
[ "https://Stackoverflow.com/questions/396118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41308/" ]
I'm porting some code from BSD sockets to Winsock, and I'm not sure how to handle the case below. My original application runs a select on both stdin and the network socket: ``` FD_SET(sock, &fd); FD_SET(0, &fd); ... if (select(..., &fd, ... )...) ``` Trying to run this in Winsock gives an error 10038 (WSAENOTSOCK)...
Winsock's select() only works with sockets. A more 'Windows-y' alternative would be to use [Asynchronous I/O](http://msdn.microsoft.com/en-us/library/aa365683.aspx) on both handles and then [WaitForMultipleObjects](http://msdn.microsoft.com/en-us/library/ms687025.aspx).
396,128
<p>Is there a way that I can get the most used applications via VB.NET? I'm developing a sort of hobby project as a quick launcher kind of thing and thought this would sit perfectly on the main form.</p> <p>If possible, would somebody be able to explain to me how add/remove applications manages to get the frequency of...
[ { "answer_id": 398269, "author": "brendan", "author_id": 225, "author_profile": "https://Stackoverflow.com/users/225", "pm_score": 1, "selected": false, "text": "<p>This might be a decent place to start. It seems like windows does a crappy job of determining frequency of applications us...
2008/12/28
[ "https://Stackoverflow.com/questions/396128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20900/" ]
Is there a way that I can get the most used applications via VB.NET? I'm developing a sort of hobby project as a quick launcher kind of thing and thought this would sit perfectly on the main form. If possible, would somebody be able to explain to me how add/remove applications manages to get the frequency of used appl...
It looks like you can find information on how often a program is run in the registry key: ``` HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\ ``` There's more explanation [here](http://personal-computer-tutor.com/abc3/v29/vic29.htm) and a .NET program [here](http://blog.didiersteven...
396,139
<p>I'm in a ASP.NET project where I need to give several parameters to the administrator that is going to install the website, like:</p> <pre><code>AllowUserToChangePanelLayout AllowUserToDeleteCompany </code></pre> <p>etc...</p> <p>My question is, will be a good thing to add this into the web.config file, using my ...
[ { "answer_id": 396144, "author": "configurator", "author_id": 9536, "author_profile": "https://Stackoverflow.com/users/9536", "pm_score": 5, "selected": true, "text": "<p>I usually use Settings - available via the project properties - Settings. These can be edited and saved in code, and ...
2008/12/28
[ "https://Stackoverflow.com/questions/396139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28004/" ]
I'm in a ASP.NET project where I need to give several parameters to the administrator that is going to install the website, like: ``` AllowUserToChangePanelLayout AllowUserToDeleteCompany ``` etc... My question is, will be a good thing to add this into the web.config file, using my own configSession or add as a pro...
I usually use Settings - available via the project properties - Settings. These can be edited and saved in code, and I write a form / web page to edit them. If you want to use the XML configuration, there's an attribute called file that reads external files. You could have a web.config file and a someothername.config ...
396,142
<p>I am using VSTS Unitesting platform. I am trying to test a method which got references to assemblies which in turn contain DllImport to C++ DLLs.</p> <p>In order for it to work I need to copy C++ DLLs to reside on the same directory the EXE and DLLs are running.</p> <p>Of course when I use the same code with Unit...
[ { "answer_id": 396144, "author": "configurator", "author_id": 9536, "author_profile": "https://Stackoverflow.com/users/9536", "pm_score": 5, "selected": true, "text": "<p>I usually use Settings - available via the project properties - Settings. These can be edited and saved in code, and ...
2008/12/28
[ "https://Stackoverflow.com/questions/396142", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11659/" ]
I am using VSTS Unitesting platform. I am trying to test a method which got references to assemblies which in turn contain DllImport to C++ DLLs. In order for it to work I need to copy C++ DLLs to reside on the same directory the EXE and DLLs are running. Of course when I use the same code with Unittest I also need t...
I usually use Settings - available via the project properties - Settings. These can be edited and saved in code, and I write a form / web page to edit them. If you want to use the XML configuration, there's an attribute called file that reads external files. You could have a web.config file and a someothername.config ...
396,145
<p>I want to center a <code>div</code> vertically with CSS. I don't want tables or JavaScript, but only pure CSS. I found some solutions, but all of them are missing Internet Explorer 6 support.</p> <pre><code>&lt;body&gt; &lt;div&gt;Div to be aligned vertically&lt;/div&gt; &lt;/body&gt; </code></pre> <p>How can I ...
[ { "answer_id": 396255, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "<p>Actually, you need two div's for vertical centering. The div containing the content must have a width and height.</p>\n<p><...
2008/12/28
[ "https://Stackoverflow.com/questions/396145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49380/" ]
I want to center a `div` vertically with CSS. I don't want tables or JavaScript, but only pure CSS. I found some solutions, but all of them are missing Internet Explorer 6 support. ``` <body> <div>Div to be aligned vertically</div> </body> ``` How can I center a `div` vertically in all major browsers, including ...
Below is the best all-around solution I could build to vertically and horizontally center a fixed-width, **flexible height** content box. It was tested and worked for recent versions of Firefox, Opera, Chrome, and Safari. ```css .outer { display: table; position: absolute; top: 0; left: 0; height: 100%; wi...
396,156
<p>I have a <code>JPanel</code> subclass on which I add buttons, labels, tables, etc. To show on screen it I use <code>JFrame</code>:</p> <pre><code>MainPanel mainPanel = new MainPanel(); //JPanel subclass JFrame mainFrame = new JFrame(); mainFrame.setTitle("main window title"); mainFrame.getContentPane().add(mainPan...
[ { "answer_id": 396201, "author": "Richard Walton", "author_id": 15075, "author_profile": "https://Stackoverflow.com/users/15075", "pm_score": 2, "selected": false, "text": "<p>You need to set a layout manager for the JFrame to use - This deals with how components are positioned. A usefu...
2008/12/28
[ "https://Stackoverflow.com/questions/396156", "https://Stackoverflow.com", "https://Stackoverflow.com/users/174644/" ]
I have a `JPanel` subclass on which I add buttons, labels, tables, etc. To show on screen it I use `JFrame`: ``` MainPanel mainPanel = new MainPanel(); //JPanel subclass JFrame mainFrame = new JFrame(); mainFrame.setTitle("main window title"); mainFrame.getContentPane().add(mainPanel); mainFrame.setLocation(100, 100)...
You can set a layout manager like BorderLayout and then define more specifically, where your panel should go: ``` MainPanel mainPanel = new MainPanel(); JFrame mainFrame = new JFrame(); mainFrame.setLayout(new BorderLayout()); mainFrame.add(mainPanel, BorderLayout.CENTER); mainFrame.pack(); mainFrame.setVisible(true);...
396,166
<p>I need to check to see if a variable contains anything OTHER than a-z A-Z 0-9 and the "." character (full stop). Any help would be appreciated.</p>
[ { "answer_id": 396172, "author": "maxnk", "author_id": 45862, "author_profile": "https://Stackoverflow.com/users/45862", "pm_score": 3, "selected": false, "text": "<pre><code>if (preg_match(\"/[^A-Za-z0-9.]/\", $myVar)) {\n // make something\n}\n</code></pre>\n\n<p>The key point here i...
2008/12/28
[ "https://Stackoverflow.com/questions/396166", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26823/" ]
I need to check to see if a variable contains anything OTHER than a-z A-Z 0-9 and the "." character (full stop). Any help would be appreciated.
``` if (preg_match('/[^A-Z\d.]/i', $var)) print $var; ```
396,168
<p>Let's say we have two classes, Foo and Foo Sub, each in a different file, foo.rb and foo_sub.rb respectively.</p> <p>foo.rb:</p> <pre><code>require "foo_sub" class Foo def foo FooSub.SOME_CONSTANT end end </code></pre> <p>foo_sub.rb:</p> <pre><code>require "foo" class FooSub &lt; Foo SOME_CON...
[ { "answer_id": 396184, "author": "Jules", "author_id": 40078, "author_profile": "https://Stackoverflow.com/users/40078", "pm_score": 5, "selected": true, "text": "<p>If you need to access a subclass from a superclass then there's a good chance that your model is broken (i.e. it should be...
2008/12/28
[ "https://Stackoverflow.com/questions/396168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49381/" ]
Let's say we have two classes, Foo and Foo Sub, each in a different file, foo.rb and foo\_sub.rb respectively. foo.rb: ``` require "foo_sub" class Foo def foo FooSub.SOME_CONSTANT end end ``` foo\_sub.rb: ``` require "foo" class FooSub < Foo SOME_CONSTANT = 1 end ``` This isn't going to work ...
If you need to access a subclass from a superclass then there's a good chance that your model is broken (i.e. it should be one class). That said, there are a couple of obvious solutions: 1) just create a file that requires the foo files: all\_foos.rb: ``` require "foo.rb" require "foo_sub.rb" ``` and remove the r...
396,183
<p>I'm trying to use SDL in C++ with Visual Studio 2008 Express. The following program compiles but does not link:</p> <pre><code>#include &lt;SDL.h&gt; int main(int argc, char *argv[]) { return 0; } </code></pre> <p>The link error is:</p> <pre><code>LINK : fatal error LNK1561: entry point must be defined </cod...
[ { "answer_id": 396269, "author": "Stefan", "author_id": 48003, "author_profile": "https://Stackoverflow.com/users/48003", "pm_score": 0, "selected": false, "text": "<p>The linker can't find the entry point. Which means your main() function is not recognized as the entry point.</p>\n\n<p>...
2008/12/28
[ "https://Stackoverflow.com/questions/396183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3102/" ]
I'm trying to use SDL in C++ with Visual Studio 2008 Express. The following program compiles but does not link: ``` #include <SDL.h> int main(int argc, char *argv[]) { return 0; } ``` The link error is: ``` LINK : fatal error LNK1561: entry point must be defined ``` I get this regardless of how or if I link ...
I don't have VC++ available at the moment, but I have seen this issue several times. You need to create a Win32 project as opposed to a console project. A Win32 project expects a [WinMain](http://msdn.microsoft.com/en-us/library/ms633559(VS.85).aspx) function as a program entry point. SDLmain.lib contains this entry p...
396,216
<p>Whenever I notice that something in my workflow is a <strong>repeating task</strong>, I try to automate it.</p> <p>For example the steps necessary to deploy something on a server. It's often a build, followed by a <strong>scp</strong> and finally some remote setup scripts:</p> <ol> <li>mvn package</li> <li>scp tar...
[ { "answer_id": 396220, "author": "PEZ", "author_id": 44639, "author_profile": "https://Stackoverflow.com/users/44639", "pm_score": 0, "selected": false, "text": "<p>Rake is my choice.</p>\n" }, { "answer_id": 396234, "author": "Michael Borgwardt", "author_id": 16883, ...
2008/12/28
[ "https://Stackoverflow.com/questions/396216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4308/" ]
Whenever I notice that something in my workflow is a **repeating task**, I try to automate it. For example the steps necessary to deploy something on a server. It's often a build, followed by a **scp** and finally some remote setup scripts: 1. mvn package 2. scp target/foobar.jar server: 3. ssh server install-foobar ...
For Java development, I'd say Ant is the default choice. **Pro:*** good documentation, * good IDE integration * Lots of third-party extensions and tools **Con:*** Somewhat verbose (well, it's yet anothr XML format) * Some things that should be simple aren't (e.g. any kind of looping) I don't really have any experi...
396,222
<ol> <li>Is the .NET class System.Net.CookieContainer thread safe? --<strong>Update:</strong> Turnkey answered--</li> <li>Is there any way to ensure thread safeness to variables which are modified during asynchronous requests (ie. HttpWebRequest.CookieContainer)?</li> <li>Is there any attribute to highlight thread safe...
[ { "answer_id": 396228, "author": "Turnkey", "author_id": 13144, "author_profile": "https://Stackoverflow.com/users/13144", "pm_score": 3, "selected": false, "text": "<p>From the <a href=\"http://msdn.microsoft.com/en-us/library/system.net.cookiecontainer.aspx\" rel=\"noreferrer\">horses ...
2008/12/28
[ "https://Stackoverflow.com/questions/396222", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48465/" ]
1. Is the .NET class System.Net.CookieContainer thread safe? --**Update:** Turnkey answered-- 2. Is there any way to ensure thread safeness to variables which are modified during asynchronous requests (ie. HttpWebRequest.CookieContainer)? 3. Is there any attribute to highlight thread safe classes? --**Update:** If thre...
No, not all .NET classes are thread safe. In fact, very few have a need to be. In general, static members should be thread-safe, but that is about it. Immutable / semi-immutable objects are automatically thread safe (this includes things like XslTransform etc) - and there are a mutable few cases (such as threaded cont...
396,229
<p>What is the recommended location to save user preference files? Is there a recommended method for dealing with user preferences?</p> <p>Currently I use the path returned from <code>typeof(MyLibrary).Assembly.Location</code> as a default location to store files generated or required by the application.</p> <p>EDIT:...
[ { "answer_id": 396243, "author": "Sailing Judo", "author_id": 42620, "author_profile": "https://Stackoverflow.com/users/42620", "pm_score": 7, "selected": true, "text": "<p>You can use the Application Settings easily enough.</p>\n\n<p>If you haven't done so before just right click on the...
2008/12/28
[ "https://Stackoverflow.com/questions/396229", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47660/" ]
What is the recommended location to save user preference files? Is there a recommended method for dealing with user preferences? Currently I use the path returned from `typeof(MyLibrary).Assembly.Location` as a default location to store files generated or required by the application. EDIT: I found two related/interes...
You can use the Application Settings easily enough. If you haven't done so before just right click on the project and choose Properties. Select the Settings tab. Make sure you chose "User" for the scope (otherwise the setting is read-only). The code to access this is simple: ``` forms.Width = Application1.Properties...
396,245
<p>How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.</p>
[ { "answer_id": 396270, "author": "kdgregory", "author_id": 42126, "author_profile": "https://Stackoverflow.com/users/42126", "pm_score": 2, "selected": false, "text": "<p>I'll assume that you're asking how to push a dependency out to a \"well-known repository,\" and not simply asking how...
2008/12/28
[ "https://Stackoverflow.com/questions/396245", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17712/" ]
How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.
You'll have to do this in two steps: ### 1. Give your JAR a groupId, artifactId and version and add it to your repository. If you don't have an internal repository, and you're just trying to add your JAR to your local repository, you can install it as follows, using any arbitrary groupId/artifactIds: ``` mvn install...
396,260
<p>Here's the scenario: I have a set of buttons that I want to bind to corresponding functions when clicked. The ids of these buttons are the same as the names of their corresponding functions. I could do this:</p> <pre><code>$("#kick").click(kick); $("#push").click(push); $("#shove").click(shove); </code></pre> <p>B...
[ { "answer_id": 396262, "author": "Moran Helman", "author_id": 1409636, "author_profile": "https://Stackoverflow.com/users/1409636", "pm_score": 0, "selected": false, "text": "<pre><code>$(\"#button_holder &gt; span\").each(function () {\n var doThis = this.id;\n $(this).click(funct...
2008/12/28
[ "https://Stackoverflow.com/questions/396260", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11782/" ]
Here's the scenario: I have a set of buttons that I want to bind to corresponding functions when clicked. The ids of these buttons are the same as the names of their corresponding functions. I could do this: ``` $("#kick").click(kick); $("#push").click(push); $("#shove").click(shove); ``` But I'm lazy and would like...
Like the other answerers, I'm not sure that this is "true" laziness (as in the programmer's virtue), but only you know your implementation details. If you really want to do something like this, you can use an object to store your particular functions and then use the string to look them up: ``` var myFunction = { ...