qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
404,186
<p>i have a stored procedure that creates a table then fills this table somehow from tables of the database then selects everything from this table then drops this table.the problem is,how can i use the selected columns from that dropped table im using DataContext i always put the result of the the stored procedure in a list of the type of that stored procedure</p> <p>ex:</p> <pre><code>MyDataContext db=new MyDataContext(); public List&lt;Base_RetriveItemResulte&gt; RetriveItem(int ItemId) { List&lt;Base_RetriveItemResulte&gt; ItemList=db.Base_RetriveItem(ItemId).ToList&lt;Base_RetriveItemResulte&gt;(); return ItemList; } </code></pre> <p>//Base_RetriveItem is a stored procedure from the data context the problem with the stored procedure that drops the table" GetSubcategories " is that it cant be put in a list with its result type db.GetSubcategories(CategoryId) i was expecting to put the result from GetSubcategories(CategoryId) in a list of type </p> <pre><code>List&lt;GetSubcategoriesResult&gt; </code></pre> <p>but there is no type like this!! How can I get the selected columns from the dropped table?</p>
[ { "answer_id": 404224, "author": "StingyJack", "author_id": 16391, "author_profile": "https://Stackoverflow.com/users/16391", "pm_score": 1, "selected": false, "text": "//retrieves a list of strings related to the itemID\npublic List<String> RetriveItem(int itemID)\n{\n\n // declare our...
2008/12/31
[ "https://Stackoverflow.com/questions/404186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,199
<p>This is related to <a href="https://stackoverflow.com/questions/153420/is-it-feasible-to-create-a-rest-client-with-flex">this question</a>. I'm writing a Flex app (a WindowedApplication) that uses REST. Everything's fine when I post with valid authentication, but if I happen to pass an invalid username or password to the REST API (a Twitter REST API, to be specific), an authentication dialog pops up.</p> <p>That's not a desirable user experience, and it happens both when I use HTTPService and URLRequest. There doesn't seem to be an event I can catch to cancel the dialog.</p> <p>Here's what my code looks like:</p> <pre><code> var request:URLRequest = new URLRequest('http://twitter.com/statuses/update.json'); request.method = URLRequestMethod.POST; var encoder : Base64Encoder = new Base64Encoder(); encoder.encode(this.user + ':' + this.password); request.requestHeaders.push(new URLRequestHeader("Authorization", "Basic " + encoder.toString())); var params:Object = new Object(); params.status = msg; request.data = params; var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, HandleRequestComplete); loader.load(request); </code></pre> <p>Am I missing something? Is there a better way to approach this?</p>
[ { "answer_id": 1011216, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "request.authenticate = false;\n" } ]
2008/12/31
[ "https://Stackoverflow.com/questions/404199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/87798/" ]
404,226
<p>I know this is a pretty basic question, and I <em>think</em> I know the answer...but I'd like to confirm.</p> <p>Are these queries truly equivalent?</p> <pre><code>SELECT * FROM FOO WHERE BAR LIKE 'X' SELECT * FROM FOO WHERE BAR ='X' </code></pre> <p>Perhaps there is a performance overhead in using like with no wild cards? </p> <p>I have an app that optionally uses LIKE &amp; wild cards. The SP currently does the like and appends the wild cards -- I am thinking of just updating the query to use like but have the app append the wild cards as needed.</p>
[ { "answer_id": 37788432, "author": "CSharpie", "author_id": 1789202, "author_profile": "https://Stackoverflow.com/users/1789202", "pm_score": 4, "selected": false, "text": "= LIKE LIKE char nchar nvarchar varchar CREATE TABLE #temp (nam [varchar](MAX))\nINSERT INTO [#temp] ([nam])\nVALUE...
2008/12/31
[ "https://Stackoverflow.com/questions/404226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27657/" ]
404,231
<p>I have this enum:</p> <pre><code>enum ButtonState { BUTTON_NORMAL = 0, BUTTON_PRESSED = 1, BUTTON_CLICKED = 2 }; const u8 NUM_BUTTON_STATES = 3; </code></pre> <p>In my Button class I have member variables <code>ButtonState state;</code> and <code>ButtonColors colors[NUM_BUTTON_STATES];</code>. When drawing the button, I use <code>colors[state]</code> to get the colours for whatever state the button is in.</p> <p>My questions:</p> <ol> <li>Is this good programming style? Is there a better way to do it? (I usually only use enums with switch statements... using an enum as an array index doesn't feel right.)</li> <li>Do I <em>have</em> to specify the values of the enum? It seems to start from 0 by default and increment by 1 but is it guaranteed to work that way in all compilers?</li> </ol>
[ { "answer_id": 404253, "author": "Stefan", "author_id": 48003, "author_profile": "https://Stackoverflow.com/users/48003", "pm_score": 4, "selected": false, "text": "enum ButtonState {\n BUTTON_NORMAL = 0,\n BUTTON_PRESSED,\n BUTTON_CLICKED,\n NUM_BUTTON_STATES\n};\n" }, {...
2008/12/31
[ "https://Stackoverflow.com/questions/404231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/813/" ]
404,232
<p>I am trying to pass a reference to a two-dimensional array to a function in C++. I know the size of both dimensions at compile time. Here is what I have right now:</p> <pre><code>const int board_width = 80; const int board_height = 80; void do_something(int[board_width][board_height]&amp; array); //function prototype </code></pre> <p>But this doesn't work. I get this error from g++:</p> <pre><code>error: expected ‘,’ or ‘...’ before ‘*’ token </code></pre> <p>What does this error mean, and how can I fix it?</p>
[ { "answer_id": 404243, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": -1, "selected": false, "text": "void do_something(int array[board_width][board_height]);\n" }, { "answer_id": 404247, "author": "Johannes Sch...
2008/12/31
[ "https://Stackoverflow.com/questions/404232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,258
<p>For some reason the following code fails. You can't simply erase a reverse_iterator by using its base() method. </p> <pre><code>#include &lt;set&gt; #include &lt;iostream&gt; int main() { std::set&lt;int&gt; setOfInts; setOfInts.insert(1); setOfInts.insert(2); setOfInts.insert(3); std::set&lt;int&gt;::reverse_iterator rev_iter = setOfInts.rbegin(); std::set&lt;int&gt;::reverse_iterator nextRevIter = setOfInts.rbegin(); ++nextIter; while ( rev_iter != setOfInts.rend()) { // Find 3 and try to erase if (*rev_iter == 3) { // SEGFAULT HERE setOfInts.erase( rev_iter.base()); } rev_iter = nextRevIter; ++nextRevIter; } } </code></pre> <p>How does one go about correctly doing the above? Given a reverse_iterator that corresponds to something you want to erase, how do you erase it?</p> <p><strong>Note, erase won't take reverse_iterators unfortunately. It wants the real thing.</strong></p>
[ { "answer_id": 404261, "author": "Brian", "author_id": 16457, "author_profile": "https://Stackoverflow.com/users/16457", "pm_score": -1, "selected": false, "text": "erase base #include <set>\n#include <iostream>\n\nint main()\n{\n std::set<int> setOfInts;\n setOfInts.insert(1);\n ...
2008/12/31
[ "https://Stackoverflow.com/questions/404258", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8123/" ]
404,278
<p>Anyone know why the MINUTE method in java.util.Caldendar returns an incorrect minute?</p> <pre><code>import java.util.Calendar; public class Clock { // Instance fields private Calendar time; /** * Constructor. Starts the clock at the current operating system time */ public Clock() { System.out.println(this.time.HOUR_OF_DAY+":"+this.time.MINUTE); } } </code></pre>
[ { "answer_id": 404283, "author": "Marc Novakowski", "author_id": 27020, "author_profile": "https://Stackoverflow.com/users/27020", "pm_score": 5, "selected": false, "text": "System.out.println(this.time.get(Calendar.HOUR_OF_DAY) + \":\" + this.time.get(Calendar.MINUTE));\n" }, { ...
2008/12/31
[ "https://Stackoverflow.com/questions/404278", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,290
<p>I'm trying to create a splash screen that shows assemblies (all referenced library) loading status. I use AppDomain.AssemblyLoad AssemblyLoadEventHandler delegate to catch what assembly is being loaded but the problem is the event is not triggered when the program initializes. I tried register the event handler in application startup "MyApplication_Startup" but it didn't work. Here's my test code:</p> <pre><code> Partial Friend Class MyApplication Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup AddHandler AppDomain.CurrentDomain.AssemblyLoad, AddressOf MyAssemblyLoadEventHandler End Sub Sub MyAssemblyLoadEventHandler(ByVal sender As Object, ByVal args As AssemblyLoadEventArgs) Console.WriteLine("&gt;&gt;&gt; ASSEMBLY LOADED: " + args.LoadedAssembly.FullName) Console.WriteLine() End Sub End Class </code></pre>
[ { "answer_id": 404309, "author": "Michael Bray", "author_id": 50356, "author_profile": "https://Stackoverflow.com/users/50356", "pm_score": 0, "selected": false, "text": "static void Main(string[] args)\n{\n AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentD...
2008/12/31
[ "https://Stackoverflow.com/questions/404290", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,313
<p>I have a table that has about 1/2 million records in it.</p> <p>Each month we get about 1/2 million more records to import. These are currently shoved into another table in the DB, but will eventually be loaded directly from a txt file. For each of these new records, I have to determine if we have that record already, and if we don't, then it needs to be inserted. However, if we do have the record it needs to be updated. There is logic for these updates contained the C# code. </p> <p>A C# command line program is handling the importing of this new data, and so right now there are 1/2 million select statements - one for each record. Then, a bunch (again about 1/2 million) of insert and update statements are generated and ran against the database.</p> <p>It takes about 6 hours for this to run on my workstation. Do you have any ideas on how to speed it up? I need to run through about 60 of these large imports to bring the database up to the current month, and then load the new data once a month.</p> <p>I think one area that could be improved is the 1/2 million select statements. Perhaps I could issue one select statement to get all the rows, and store them in memory, and search it. Could I use an List for this, or is there a better class? I'll have to search based on two properties (or DB fields).</p>
[ { "answer_id": 404324, "author": "Charles Bretana", "author_id": 32632, "author_profile": "https://Stackoverflow.com/users/32632", "pm_score": 2, "selected": true, "text": " Update DestTable Set\n ColName = T.ColName,\n [repeat for all cols]\n From TmpTable T Join DestTa...
2009/01/01
[ "https://Stackoverflow.com/questions/404313", "https://Stackoverflow.com", "https://Stackoverflow.com/users/571/" ]
404,322
<p>I need to be able to programmatically transcode mpeg-2 files to .mp4, .mp3, .wmv, .rm (optional), and .flv (optional), and hopefully generate a thumbnail as well. I found the Java Media Framework, but it frankly looks pretty crappy. This will be running a Linux server, so I could shell out to ffmpeg using Commons Exec - does ffmpeg do everything I need to do? FFmpeg seems pretty daunting, which is why I'm having trouble finding this information, but it definitely seems to be a jack-of-all-trades. Any suggestions?</p>
[ { "answer_id": 404343, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": true, "text": "ffmpeg -i {input}.ext -r {target_frame_rate} -ar {target_audio_rate} -b {target_bitrate} -s {width}x{height} {target}.ext\n ffm...
2009/01/01
[ "https://Stackoverflow.com/questions/404322", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42891/" ]
404,332
<p>In my ASP.NET application, I want to use regular expressions to change URLs into hyper links in user posts, for example:</p> <pre><code>http://www.somesite.com/default.aspx </code></pre> <p>to</p> <pre><code>&lt;a href="http://www.somesite.com/default.aspx"&gt;http://www.somesite.com/default.aspx&lt;/a&gt; </code></pre> <p>This is fairly easy using Regex.Replace(), but the problem I'm having is that I want to truncate the link text if the URL is too long, for example:</p> <pre><code>http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8ed232c23de7f9121d&amp;n=93b34a732e074c934e32d123de19c83d </code></pre> <p>to</p> <pre><code>&lt;a href="http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8ed232c23de7f9121d&amp;n=93b34a732e074c934e32d123de19c83d"&gt;http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8...&lt;/a&gt; </code></pre> <p>so that it displays like this:</p> <pre><code>http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8... </code></pre> <p>I tried to use Regex.Matches() but I don't know how to replace the text, any suggestions?</p> <p>Thanks for your help ...</p> <p>Edit: Never mind guys, I figured it out on my own, it turned out to be incredibly simple, I just used a <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchevaluator.aspx" rel="nofollow noreferrer">MatchEvaluator</a>!</p> <pre><code>public static string Replace( string input, string pattern, MatchEvaluator evaluator ) </code></pre>
[ { "answer_id": 404336, "author": "Vilx-", "author_id": 41360, "author_profile": "https://Stackoverflow.com/users/41360", "pm_score": 0, "selected": false, "text": "Regex.Matches()" }, { "answer_id": 404403, "author": "Leon Tayson", "author_id": 18413, "author_profile"...
2009/01/01
[ "https://Stackoverflow.com/questions/404332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/676066/" ]
404,344
<p>I'm trying to grab a specific bit of raw text from a web site. Using this site and other sources, I learned how to grab specific images using simpleXML and xpath.</p> <p>However the same approach doesn't appear to be working for grabbing raw text. Here's what's NOT working right now.</p> <pre><code>// first I set the xpath of the div that contains the text I want $xpath = '//*[@id="storyCommentCountNumber"]'; // then I create a new DOM Document $html = new DOMDocument(); // then I fetch the file and parse it (@ suppresses warnings). @$html-&gt;loadHTMLFile($url); // then convert DOM to SimpleXML $xml = simplexml_import_dom($html); // run an XPath query on the div I want using the previously set xpath $commcount = $xml-&gt;xpath($xpath); print_r($commcount); </code></pre> <p>Now when I'm grabbing an image, that commcount object would return an array that contains the images source in it somewhere.</p> <p>In this case, I want that object to return the raw text contained in the "storyCommentCountNumber" div. But that text doesn't appear to be contained in the object, just the name of the Div.</p> <p>What am I doing wrong? I can kind of see that this approach is only for grabbing HTML elements and the bits inside of them, not raw text. How do I get the text inside that div?</p> <p>Thanks!</p>
[ { "answer_id": 405386, "author": "Beau Simensen", "author_id": 50453, "author_profile": "https://Stackoverflow.com/users/50453", "pm_score": 1, "selected": false, "text": "if ( count($commcount) > 0 ) {\n $divContent = $commcount[0]->asXml();\n print $divContent;\n}\n" }, { ...
2009/01/01
[ "https://Stackoverflow.com/questions/404344", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,346
<p>Does anyone know how to write a program in Python that will calculate the addition of the harmonic series. i.e. 1 + 1/2 +1/3 +1/4...</p>
[ { "answer_id": 404354, "author": "recursive", "author_id": 44743, "author_profile": "https://Stackoverflow.com/users/44743", "pm_score": 2, "selected": false, "text": "def calc_harmonic(n):\n return sum(1.0/d for d in range(2,n+1))\n" }, { "answer_id": 404361, "author": "z...
2009/01/01
[ "https://Stackoverflow.com/questions/404346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47204/" ]
404,368
<p>In working with objects and interfaces what is the best practice for writing to the database? There is a plethora of opinions regarding the object design but I am unclear about the database end. A simple example: </p> <p>Suppose a Contact base class that contains the common fields such as contact name (Bill, Fred, Sally) and a location (home, work, etc.). Add an IPhone interface (area code, phone number, extension) and an IEmail interface (email address,cc) to abstract out the differences. Then create classes (Phone, Email) that inherit from these as thus:</p> <pre> Phone: Contact, IPhone Email: Contact, IEMail </pre> <p>An alternative would be to create an IContact interface instead of a Contact base class as thus:</p> <pre> Phone: IContact, IPhone Email: IContact, IEMail </pre> <p>Short of implementing NHibernate or Entity Framework what is the best practice for the data access code if these objects are being written to a single database table? What I have seen seems rather clumsy.</p>
[ { "answer_id": 404387, "author": "Andrew Hare", "author_id": 34211, "author_profile": "https://Stackoverflow.com/users/34211", "pm_score": 1, "selected": false, "text": "Phone Contact Phone Contact Contact Phone Email" }, { "answer_id": 404544, "author": "tvanfosson", "au...
2009/01/01
[ "https://Stackoverflow.com/questions/404368", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50622/" ]
404,379
<p>I have an order page that is being rendered from a Model object (Order) with a few properties. One of the properties of the Order object is</p> <pre><code>public List&lt;OrderItem&gt; Items { get; set; }; </code></pre> <p>and the other is</p> <pre><code>public List&lt;OrderComment&gt; Comments { get; set; }; </code></pre> <p>My main page is declared like this:</p> <pre><code>public class OrderView : ViewPage&lt;Order&gt; </code></pre> <p>I want to have a User Control for each OrderItem (named OrderItemControl), and another User Control for each OrderComment (named OrderCommentControl). If I could use a repeater for each collection then that would be great, but I am running into a problem. I want my user control declarations to looks like this:</p> <pre><code>public class OrderItemControl : ViewUserControl&lt;OrderItem&gt; public class OrderCommentControl : ViewUserControl&lt;OrderComment&gt; </code></pre> <p>I get an error when I try to do this saying:</p> <p>{"The model item passed into the dictionary is of type 'Order' but this dictionary requires a model item of type 'OrderItem'."}</p> <p>I am guessing repeater might not be the right way to go, but I really want each User Control to have a model of type OrderItem or OrderComment, and not just Order.</p>
[ { "answer_id": 404431, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": false, "text": "RenderPartial <% foreach (OrderItem orderItem in ViewData.Model.OrderItems)\n {\n %>\n <%= Html.RenderPartial( ...
2009/01/01
[ "https://Stackoverflow.com/questions/404379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14101/" ]
404,391
<p>How do I get the actual value (or text) of the item selected in an HTML select box? Here are the main methods I've tried...</p> <pre><code> document.getElementById('PlaceNames').value </code></pre> <pre><code> $("#PlaceNames option:selected").val() </code></pre> <pre><code> $("#PlaceNames option:selected").text() </code></pre> <p>And I've tried various variations on these. All I ultimately want to do is get that data and send it to a web service via AJAX, I just need the string representation of what the user selected. This seems like it should be really easy and I've even found a question similar to this here, but I'm still having issues getting it worked out. Google doesn't seem to be helping either. I feel like it must be due to some fundamental misunderstanding of Javascript and jQuery. </p> <p>EDIT: I should mention that I'm using IE7</p>
[ { "answer_id": 404396, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 1, "selected": false, "text": "var select = document.getElementById('PlaceNames');\nvar value = select.options[select.selectedIndex].value;\n var sele...
2009/01/01
[ "https://Stackoverflow.com/questions/404391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49294/" ]
404,421
<p>I'm going through SICP and I'd like to have an interpreter analogous to the interactive Python interpreter to play around in while I'm watching the lectures and reading the book. Furthermore, I'd like this interpreter to run inside Emacs so I can jump back and forth between files of scheme code and the interactive interpreter and so forth.</p> <p>However, I'm fairly new to Emacs and have not as of yet been able to get this to work or find one clear set of instructions to use in getting it to work.</p> <p>It seems like I should be able to set it up so that <code>M-x run-scheme</code> will open up an interactive interpreter that at least sounds like exactly what I want, but at the moment this just returns <code>Searching for program: no such file or directory, scheme</code> and I haven't been able to figure out exactly what files I need to put where to remedy this.</p> <p>I'm running <code>GNU Emacs 22.1.1 (mac-apple-darwin, Carbon Version 1.6.0)</code> as installed through the OS X 10.5 install DVD.</p>
[ { "answer_id": 404514, "author": "Cos", "author_id": 49469, "author_profile": "https://Stackoverflow.com/users/49469", "pm_score": 3, "selected": false, "text": "M-x customize-group scheme scheme" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/404421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1512/" ]
404,430
<p>I have heard of regular expressions and only seen use cases for a few things so I don't think of using them very often. In the past I have done a couple of things and it has taken me hours to do. Later I talk to someone and they say "here is how to do it using a regular expression".</p> <p>So what are things for which you have used Regular Expressions? If I get more examples then maybe I can begin to know when to look for and use them.</p>
[ { "answer_id": 404434, "author": "Bill the Lizard", "author_id": 1288, "author_profile": "https://Stackoverflow.com/users/1288", "pm_score": 3, "selected": false, "text": "^[ \\t]+\n" }, { "answer_id": 404505, "author": "Mark A. Nicolosi", "author_id": 1103052, "autho...
2009/01/01
[ "https://Stackoverflow.com/questions/404430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23571/" ]
404,450
<p>I am finishing off a C# ASP.NET program that allows the user to build their own computer by selecting hardware components such as memory, cpu, etc from a drop down lists. The SQL datatable has 3 columns; ComputerID, Attribute and Value. The computerID is an ID that corresponds to a certain computer in my main datatable of products, the Attribtute is the name of the hardware component; memory,cpu, hard drive etc.. and the value is the value assigned to that attribute, such as 1GB or 2.8GHz 320GB. This means that a computer will have multiple attributes. </p> <p>What I am trying to do it narrow down the results by first selecting all computers that meet the first attribute requirements and then getting from that list, all computers that meet the next requirement.. and so on for about 10+ attributes.</p> <p>I thought it might be a good idea to show you an example of my LINQ to SQL query so that you have a btter idea of what I am trying to do. This basically selects the ComputerID where the the computers memory is larger than 1GB.</p> <pre><code>var resultsList = from results in db.ComputerAttributes where computer.Value == "MEMORY" &amp;&amp; computer.Value &gt;= "1" select results.ComputerID; </code></pre> <p>Next I want to select from the resultsList where the CPU is say, faster than 2.8Ghz and so on. </p> <p>I hope I have given you enough information. If anyone could please give me some advice as to how I might go about finishing this project that would be great.</p> <p>Thanks</p>
[ { "answer_id": 404466, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 0, "selected": false, "text": "Dictionary<string,int> attributeMap = new Dictionary<string,int>();\nattributeMap.Add(\"MEMORY\",1000);\nattributeMap....
2009/01/01
[ "https://Stackoverflow.com/questions/404450", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,468
<p>I am writing a library in standard C++ which does the phonetic conversion. I have used std::string as of now. But in future I may have to change this to someother (std::wstring or something else). So I need to write my library in such a way that I can switch this easily. I have done the following so far to achieve this.</p> <ol> <li>Created a header file which will be used by all CPP files</li> <li>Added a "typedef std::string" to this and used the new name everywhere in the file.</li> </ol> <p>If I need to change the type, I can simply change in the header file and it will be reflected everywhere. I'd appreciate if someone can see this is the correct approach or is there a better way to do this?</p> <p>Thanks</p>
[ { "answer_id": 405018, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 1, "selected": false, "text": "std::string std::string" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/404468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50419/" ]
404,470
<p>My REST API returns JSON. </p> <p>I'm currently returning text/plain as the MIME type, but it feels funny. Should I be returning <code>application/x-javascript</code> or some other type?</p> <p>The second question is with regard to the HTTP status code for error conditions. If my REST API is returning an error state, I am returning as JSON</p> <pre><code>{ result: "fail", errorcode: 1024, errormesg: "That sucked. Try again!" } </code></pre> <p>Should the HTTP status code remain at <code>200 OK</code>?</p>
[ { "answer_id": 404472, "author": "Lawrence Dol", "author_id": 8946, "author_profile": "https://Stackoverflow.com/users/8946", "pm_score": 7, "selected": true, "text": "application/json" }, { "answer_id": 6121687, "author": "inquam", "author_id": 357448, "author_profil...
2009/01/01
[ "https://Stackoverflow.com/questions/404470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24457/" ]
404,484
<p>Using Grails 1.1 beta2 and a JSP page. The JSP includes the CSS reference:</p> <pre><code>&lt;link rel="stylesheet" type="text/css" href="styles.css"&gt; </code></pre> <p>When this line is included Grails pukes with the error:</p> <pre><code>[7000] errors.GrailsExceptionResolver java.lang.NumberFormatException: For input string: "styles" org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NumberFormatException: For input string: "styles" at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:92) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061) at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:893) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892) at groovy.lang.Closure.call(Closure.java:279) at groovy.lang.Closure.call(Closure.java:274) at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(Simp leGrailsControllerHelper.java:340) ... </code></pre> <p>If I remove the stylesheet tag then the page loads error free (but no CSS). Any ideas why?</p>
[ { "answer_id": 404472, "author": "Lawrence Dol", "author_id": 8946, "author_profile": "https://Stackoverflow.com/users/8946", "pm_score": 7, "selected": true, "text": "application/json" }, { "answer_id": 6121687, "author": "inquam", "author_id": 357448, "author_profil...
2009/01/01
[ "https://Stackoverflow.com/questions/404484", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24396/" ]
404,498
<p>How do I add rows programmatically to a DataGridTable in C#? When the user selects an option, I want to repopulate a DataGridTable with fresh data, which I am acquiring as shown below:</p> <pre><code> connect.Open(); MySqlCommand comm = connect.CreateCommand(); comm.CommandText = getCustomerInvoices + customerID + "\'"; MySqlDataReader r = comm.ExecuteReader(); while (r.Read()) { DataGridViewRow d = new DataGridViewRow(); String[] parameters = new String[5]; parameters[0] = r.GetValue(0).ToString(); parameters[1] = r.GetValue(1).ToString(); parameters[2] = r.GetValue(2).ToString(); parameters[3] = r.GetValue(3).ToString(); parameters[4] = r.GetValue(4).ToString(); d.SetValues(parameters); invoiceTable.Rows.Add(d); } connect.Close(); </code></pre> <p>What seems to happen is that I get a new row added to the table, but the old rows are still there, and the new row does not appear to have any values in it (a bunch of blank textboxes, and I know that this query is returning one result in my test case).</p> <p>Can someone explain to me what I have to do?</p>
[ { "answer_id": 404472, "author": "Lawrence Dol", "author_id": 8946, "author_profile": "https://Stackoverflow.com/users/8946", "pm_score": 7, "selected": true, "text": "application/json" }, { "answer_id": 6121687, "author": "inquam", "author_id": 357448, "author_profil...
2009/01/01
[ "https://Stackoverflow.com/questions/404498", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23249/" ]
404,513
<p>I am just starting with C++ and got some problems in understanding how the scope for private member variables in a class works. Please see the below code</p> <pre><code>class Foo{ private: std::vector&lt;int&gt; container; public: // other methods }; int main(int argc, char* argv[]) { Foo* foo = new Foo; // other method calls to which foo is passed delete foo; return 0; } </code></pre> <p>In the above code, variable "container" is a private member variable. I am invoking "Foo" instance and passing it to several other methods and classes. Following are my doubts</p> <ol> <li>What will be the scope of variable "container"? Will that variable exist until I delete the instance foo?</li> <li>Do I need to make the "container" as a pointer to vector?</li> </ol> <p>Thanks for the help</p>
[ { "answer_id": 404517, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": true, "text": "delete foo vector<int> foo Foo f = new Foo();\n// just passes the reference (pointer in C++) to doIt. \n// t...
2009/01/01
[ "https://Stackoverflow.com/questions/404513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50419/" ]
404,522
<p>I have a case where the child view sends notification to its parent view. Now I'm calling <code>addObserver:</code> in <code>viewWillAppear:</code> and <code>removeObserver:</code> in <code>viewWillDisappear:</code>. But, I'm guessing this is not correct since <code>viewWillAppear:</code> calls when view is refreshed. </p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver: (id)observer selector: (SEL)aSelector name: (NSString *)aName object: (id)anObject]; [[NSNotificationCenter defaultCenter] removeObserver: (id)observer name: (NSString *)aName object: (id)anObject]; </code></pre> <p>Thanks.</p>
[ { "answer_id": 404720, "author": "Mustafa", "author_id": 49739, "author_profile": "https://Stackoverflow.com/users/49739", "pm_score": 1, "selected": false, "text": "viewDidLoad dealloc" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/404522", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49739/" ]
404,534
<p>I ran across this case of <code>UnboundLocalError</code> recently, which seems strange:</p> <pre><code>import pprint def main(): if 'pprint' in globals(): print 'pprint is in globals()' pprint.pprint('Spam') from pprint import pprint pprint('Eggs') if __name__ == '__main__': main() </code></pre> <p>Which produces:</p> <pre><code>pprint is in globals() Traceback (most recent call last): File "weird.py", line 9, in &lt;module&gt; if __name__ == '__main__': main() File "weird.py", line 5, in main pprint.pprint('Spam') UnboundLocalError: local variable 'pprint' referenced before assignment </code></pre> <p><code>pprint</code> is clearly bound in <code>globals</code>, and is going to be bound in <code>locals</code> in the following statement. Can someone offer an explanation of why it isn't happy resolving <code>pprint</code> to the binding in <code>globals</code> here?</p> <p><strong>Edit:</strong> Thanks to the good responses I can clarify my question with relevant terminology:</p> <p>At compile time the identifier <code>pprint</code> is marked as local to the frame. Does the execution model have no distinction <em>where</em> within the frame the local identifier is bound? Can it say, "refer to the global binding up until this bytecode instruction, at which point it has been rebound to a local binding," or does the execution model not account for this?</p>
[ { "answer_id": 404610, "author": "Kenan Banks", "author_id": 43089, "author_profile": "https://Stackoverflow.com/users/43089", "pm_score": 3, "selected": true, "text": "from pprint import pprint pprint main() pprint.pprint() from..import import" }, { "answer_id": 404709, "aut...
2009/01/01
[ "https://Stackoverflow.com/questions/404534", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
404,547
<p>This problem is a continuation of a previous problem:</p> <p><a href="https://stackoverflow.com/questions/402432/c-returning-and-inserting-a-2d-array-object">C++ Returning and Inserting a 2D array object</a></p> <p>and it is highly recommended to view the link to understand the following.</p> <p>I followed through Adam Rosenfield's answer and it solved the first two problems. However the last problem is not yet to be solved which high involves on the first two. I am uncertain if the problem is how I attempt to right the code, or if there is a problem in what is being attempted.</p> <p>This is a section of what is written in the int main():</p> <pre><code> int i, j; Grid myGrid; Piece myPiece; //First two lines of Adam's Code int (*arrayPtr)[4][4] = myPiece.returnPiece(); int cell = (*arrayPtr)[i][j]; //compiler error myGrid.insertArray(cell); &lt;--- Problem </code></pre> <p>I am uncertain if it is the argument that is wrong, or if it is something that I'm attempting that is wrong. This is what I receive when I tried to compile:</p> <pre> In function `int main()' invalid conversion from `int' to `int(*)[4][4]' initializing argument 1 of `void Grid::insertArray(int(*)[4][4])' [Build Error] [grid test.o] Error 1 </pre> <p>I have tried these:</p> <pre> myGrid.insertArray((*arrayPtr)[4][4]); //Same Error myGrid.insertArray((*arrayPtr)[i][j]); //Same Error </pre> <p>I am unsure what is the problem and uncertain on what to do. I thank Adam and the other for helping me with the previous problems, but does anyone know how to solve this last problem?</p> <p>"having returnpiece() be accepted in the argument of insertArray();</p>
[ { "answer_id": 405830, "author": "Joseph Garvin", "author_id": 50385, "author_profile": "https://Stackoverflow.com/users/50385", "pm_score": 0, "selected": false, "text": "cell (*arrayPtr)[i][j] cell arrayPtr myGrid.insertArray((*arrayPtr)[4][4]);" }, { "answer_id": 413695, "...
2009/01/01
[ "https://Stackoverflow.com/questions/404547", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,549
<p>Sometimes I want to write a "major" comment to describe a large block of code and then write "minor" comments to describe a few of the lines within that block of code:</p> <pre><code>// Major comment // Minor comment ... // Minor comment 2 ... </code></pre> <p>The major comment looks strange without code directly beneath it, and you can't visually tell how much code it is describing below.</p> <p>How do you style these comments?</p> <p>(I remember reading about this in Code Complete a while ago but I don't own the book.)</p>
[ { "answer_id": 404559, "author": "Marc Novakowski", "author_id": 27020, "author_profile": "https://Stackoverflow.com/users/27020", "pm_score": 1, "selected": false, "text": "// ***** Major comment *****\n\n// Minor comment\n...\n\n// Minor comment 2\n...\n" }, { "answer_id": 4045...
2009/01/01
[ "https://Stackoverflow.com/questions/404549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/813/" ]
404,557
<h2>Duplicate</h2> <p><a href="https://stackoverflow.com/questions/308466/modifying-a-collection-while-iterating-through-it-c">Modifying A Collection While Iterating Through It</a></p> <hr> <p>Has anyone a nice pattern to allow me to get around the inability to remove objects while I loop through an enumerable collection (eg, an IList or KeyValuePairs in a dictionary)</p> <p>For example, the following fails, as it modifies the List being enumerated over during the foreach</p> <pre><code>foreach (MyObject myObject in MyListOfMyObjects) { if (condition) MyListOfMyObjects.Remove(myObject); } </code></pre> <p>In the past I have used two methods.</p> <p>I have replaced the foreach with a reversed for loop (so as not to change the any indexes I am looping over if I remove an object).</p> <p>I have also tried storing a new collection of objects to remove within to loop, then looping through that collection and removed the objects from the original collection.</p> <p>These work fine, but neither <em>feels</em> nice, and I was wondering if anyone has come up with a more <em>elegant</em> solution to the issue</p>
[ { "answer_id": 404569, "author": "TheSoftwareJedi", "author_id": 18941, "author_profile": "https://Stackoverflow.com/users/18941", "pm_score": 2, "selected": false, "text": "List myFilteredList = new List();\nforeach (MyObject myObject in myListOfMyObjects)\n{\n if (!condition) myFil...
2009/01/01
[ "https://Stackoverflow.com/questions/404557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5302/" ]
404,604
<p>Lots of IPCs are offered by Unix/Linux: pipes, sockets, shared memory, dbus, message-queues...</p> <p>What are the most suitable applications for each, and how do they perform?</p>
[ { "answer_id": 404622, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 7, "selected": false, "text": "pipe(2) fork(2) mkfifo(3) socket(2) kill(2) shmget(2) CHAR_MAX UINT_MAX char uint" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/404604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27424/" ]
404,615
<p>What are some best practice for "Memory Efficient C programming". Mostly for embedded/mobile device what should be the guidelines for having low memory consumptions ?</p> <p>I guess there should be separate guideline for a) code memory b) data memory</p>
[ { "answer_id": 404659, "author": "strager", "author_id": 39992, "author_profile": "https://Stackoverflow.com/users/39992", "pm_score": 3, "selected": false, "text": "std::vector" }, { "answer_id": 405006, "author": "ChrisN", "author_id": 3853, "author_profile": "https...
2009/01/01
[ "https://Stackoverflow.com/questions/404615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27424/" ]
404,617
<p>We are developing a Flash site with PHP. the problem is that it storing the cache , but we have to disable the cache using JavaScript or PHP.</p> <p>How can I disable caching?</p>
[ { "answer_id": 404647, "author": "cowgod", "author_id": 6406, "author_profile": "https://Stackoverflow.com/users/6406", "pm_score": 5, "selected": false, "text": "<?php\nheader(\"Expires: Tue, 01 Jan 2000 00:00:00 GMT\");\nheader(\"Last-Modified: \" . gmdate(\"D, d M Y H:i:s\") . \" GMT\...
2009/01/01
[ "https://Stackoverflow.com/questions/404617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,651
<p>With a listbox, I have the following code to extract the item selected:</p> <pre><code> private void inventoryList_SelectedIndexChanged(object sender, EventArgs e) { String s = inventoryList.SelectedItem.ToString(); s = s.Substring(0, s.IndexOf(':')); bookDetailTable.Rows.Clear(); ... more code ... } </code></pre> <p>I want to do something similar for a DataGridView, that is, when the selection changes, retrieve the contents of the first cell in the row selected. The problem is, I don't know how to access that data element.</p> <p>Any help is greatly appreciated.</p>
[ { "answer_id": 404663, "author": "Mitchell Gilman", "author_id": 43219, "author_profile": "https://Stackoverflow.com/users/43219", "pm_score": 5, "selected": true, "text": "private void dataGridView1_SelectionChanged(object sender, EventArgs e)\n{\n DataGridView dgv = (DataGridView)se...
2009/01/01
[ "https://Stackoverflow.com/questions/404651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23249/" ]
404,676
<p>Is is that I'm a newbie learning Ruby, or does it really have more ways to write (the same) things than Java/C#? Also, if it is more flexible than Java, are there any linguistic features of Ruby that are generally <strong>not</strong> used to avoid confusion?</p> <p>Examples might be parallel assignment and all the different ways to write Strings, perhaps?</p> <p><strong>Note:</strong> I'm not asking for a comparison with Java/C#... just this language question, please...</p> <p><strong>Edit:</strong> I understand that C#, Java and Ruby are strongly typed, and that only Ruby (like Python and others) is dynamically typed (while Java/C# are statically typed). Some of the answers say that dynamically-typed languages are more flexible. Is this necessarily true, and how does it affect syntax? <strong>I am only asking about syntactic flexibility.</strong> </p> <p>(PHP is also dynamically typed and it does <strong>not</strong> seem more flexible than Java/C#, as far as I've seen. Again, I mean in terms of syntax, not in terms of deployment nor any other aspect...)</p>
[ { "answer_id": 1579720, "author": "deau", "author_id": 121737, "author_profile": "https://Stackoverflow.com/users/121737", "pm_score": 1, "selected": false, "text": "def abs(n); (n < 0) ? -n : n; end\ndef square(n); n * n; end\ndef average(x, y); (x + y) / 2; end\n\ndef fixed_point(x, po...
2009/01/01
[ "https://Stackoverflow.com/questions/404676", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8047/" ]
404,698
<p>In replies to <a href="https://stackoverflow.com/questions/391503/if-condition-continue-or-if-condition-style-preference">one of my questions</a>, I received a number of answers saying that style 2 may perform better than style 1. I don't understand how, since I believe they should emit essentially the same machine instructions (if written in C++). Could you please explain why style 2 might perform better?</p> <p>I'll rewrite the two styles here for easier reference:</p> <p><em>Style 1</em>:</p> <pre><code>while (!String.IsNullOrEmpty(msg = reader.readMsg())) { RaiseMessageReceived(); if (parseMsg) { ParsedMsg parsedMsg = parser.parseMsg(msg); RaiseMessageParsed(); if (processMsg) { process(parsedMsg); RaiseMessageProcessed(); } } } </code></pre> <p><em>Style 2:</em></p> <pre><code>while (!String.IsNullOrEmpty(msg = reader.readMsg())) { RaiseMessageReceived(); if (!parseMsg) continue; ParsedMsg parsedMsg = parser.parseMsg(msg); RaiseMessageParsed(); if (!processMsg) continue; process(parsedMsg); RaiseMessageProcessed(); } </code></pre>
[ { "answer_id": 404947, "author": "Øyvind Skaar", "author_id": 49194, "author_profile": "https://Stackoverflow.com/users/49194", "pm_score": 3, "selected": true, "text": "using System;\nusing System.Collections.Generic;\n\nnamespace ConsoleApplication2\n{\n class Program\n {\n ...
2009/01/01
[ "https://Stackoverflow.com/questions/404698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41283/" ]
404,701
<p>I would like to display tagcloud in my home page. Found this wordpress flash plugin <a href="http://alexisyes.com/tags/wpcumulus" rel="nofollow noreferrer">http://alexisyes.com/tags/wpcumulus</a> , but for that i needed to setup wordpress. I am wondering whether there is any other standalone plugin similar to wpcumulus which can be configurable. </p> <p>I don't want to install wordpress but i would like to make use of wpcumulus. Is it possible? If not wpcumulus, could i make use of any other standalone tag clouds. </p> <p>Just curious, i came across all tag clouds which were implemented in either flash or flex. Can i get the demo link/plugin which has implemented the same in javascript.</p> <p>Thanks, ~shafi</p>
[ { "answer_id": 404714, "author": "Shawn", "author_id": 26, "author_profile": "https://Stackoverflow.com/users/26", "pm_score": 2, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<tags>\n <tag name=\"Books\" count=\"4\" />\n <tag name=\"Magazines\" count=\"20\...
2009/01/01
[ "https://Stackoverflow.com/questions/404701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,717
<p>I have been used to do some refactorings by introducing compilation errors. For example, if I want to remove a field from my class and make it a parameter to some methods, I usually remove the field first, which causes a compilation error for the class. Then I would introduce the parameter to my methods, which would break callers. And so on. This usually gave me a sense of security. I haven't actually read any books (yet) about refactoring, but I used to think this is a relatively safe way of doing it. But I wonder, is it really safe? Or is it a bad way of doing things?</p>
[ { "answer_id": 404749, "author": "Johnno Nolan", "author_id": 1116, "author_profile": "https://Stackoverflow.com/users/1116", "pm_score": 3, "selected": false, "text": "class myClass {\n void megaMethod() \n {\n int x,y,z;\n //lots of lines of code\n z = m...
2009/01/01
[ "https://Stackoverflow.com/questions/404717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41283/" ]
404,729
<p>I've seen a few programs (eg Charles Web Developer Proxy) that are able to modify Firefox's proxy settings. The sequence is:</p> <ol> <li>Firefox is running, with the users proxy settings.</li> <li>User starts the external third party application, which</li> <li>modifies Firefox's proxy settings, and then</li> <li>the user exits the third party program and,</li> <li>Firefox resumes running with its original proxy settings.</li> </ol> <p>Assuming the external application is remembering the old proxy settings and restoring them on exit how can I read and write Firefox's proxy settings? Have tried Googling through the Firefox doco but no luck yet.</p> <p><strong>Options Considered:</strong></p> <ul> <li>Write a new user preferences config file and start a new instance of the browser. Would work but not quite right -- Charles for example can modify the settings of an already running browser and restore them without restarting.</li> <li>Write a plug-in. Could write a Firefox plugin that offered some kind of IPC to the outside and then handled the Firefox preference setting itself. In fact, I think this might be the only way. Disabling Charles' Firefox plug-in seems to disable its ability to modify preferences on the fly.</li> </ul> <p><strong>Possible Resources</strong></p> <ul> <li>Programatically changing Firefox preferences: <a href="https://developer.mozilla.org/en/Code_snippets/Preferences" rel="noreferrer">Preferences - MDC</a></li> <li>Building Firefox Extensions: <a href="https://developer.mozilla.org/en/Extensions" rel="noreferrer">Extensions - MDC</a></li> </ul>
[ { "answer_id": 405665, "author": "bugmagnet", "author_id": 426, "author_profile": "https://Stackoverflow.com/users/426", "pm_score": 2, "selected": false, "text": "# Mozilla User Preferences\n\n/* Do not edit this file.\n *\n * If you make changes to this file while the application is ru...
2009/01/01
[ "https://Stackoverflow.com/questions/404729", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2997/" ]
404,733
<p>I need to identify what natural language my input belongs to. The goal is to distinguish between <em>Arabic</em> and <em>English</em> words in a mixed input, where the input is Unicode and is extracted from XML text nodes. I have noticed the class <code>Character.UnicodeBlock</code>. Is it related to my problem? How can I get it to work?</p> <p><strong>Edit:</strong> The <code>Character.UnicodeBlock</code> approach was useful for Arabic, but apparently doesn't do it for English (or other European languages) because the <code>BASIC_LATIN</code> Unicode block covers symbols and non-printable characters as well as letters. So now I am using the <code>matches()</code> method of the <code>String</code> object with the regex expression <code>"[A-Za-z]+"</code> instead. I can live with it, but perhaps someone can suggest a nicer/faster way.</p>
[ { "answer_id": 410854, "author": "Alan Moore", "author_id": 20938, "author_profile": "https://Stackoverflow.com/users/20938", "pm_score": 2, "selected": false, "text": "[A-Za-z]+ Pattern p = Pattern.compile(\"[\\\\pL&&\\\\p{L1}]+\");\n" }, { "answer_id": 32923176, "author": "...
2009/01/01
[ "https://Stackoverflow.com/questions/404733", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48599/" ]
404,744
<p>I have an application that resides in a single .py file. I've been able to get pyInstaller to bundle it successfully into an EXE for Windows. The problem is, the application requires a .cfg file that always sits directly beside the application in the same directory.</p> <p>Normally, I build the path using the following code:</p> <pre><code>import os config_name = 'myapp.cfg' config_path = os.path.join(sys.path[0], config_name) </code></pre> <p>However, it seems the sys.path is blank when its called from an EXE generated by pyInstaller. This same behaviour occurs when you run the python interactive command line and try to fetch sys.path[0].</p> <p>Is there a more concrete way of getting the path of the currently running application so that I can find files that are relative to it?</p>
[ { "answer_id": 404750, "author": "Soviut", "author_id": 46914, "author_profile": "https://Stackoverflow.com/users/46914", "pm_score": 8, "selected": true, "text": "import os\nimport sys\n\nconfig_name = 'myapp.cfg'\n\n# determine if application is a script file or frozen exe\nif getattr(...
2009/01/01
[ "https://Stackoverflow.com/questions/404744", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46914/" ]
404,774
<p>I have this tiny Qt project with a project file like this:</p> <pre><code>TEMPLATE = lib TARGET = record32 VERSION = 0.0.1 DEPENDPATH += . INCLUDEPATH += . CONFIG += shared SOURCES += recorder.cpp HEADERS += recorder.h </code></pre> <p>When I compile a library from it by <code>qmake &amp;&amp; nmake</code>, it results into files</p> <pre><code>record32.obj record320.lib record320.dll ... </code></pre> <p><strong>Why is that additional 0 added to the lib and dll names?</strong></p> <p>The generated makefiles seem not be appending it but rather just assume it, in <code>Makefile.Release</code> it just says:</p> <pre><code>####### Files SOURCES = recorder.cpp release\moc_recorder.cpp OBJECTS = release\recorder.obj release\moc_recorder.obj DIST = QMAKE_TARGET = recorder DESTDIR = release\ #avoid trailing-slash linebreak TARGET = record320.dll DESTDIR_TARGET = release\record320.dll </code></pre> <p><strong>How can I prevent it and name my libraries as I wish?</strong></p> <p>(Note that manually fix the makefile.release isn't a accetable solution)</p>
[ { "answer_id": 36011195, "author": "vitperov", "author_id": 2915164, "author_profile": "https://Stackoverflow.com/users/2915164", "pm_score": 3, "selected": false, "text": "CONFIG += skip_target_version_ext\n" }, { "answer_id": 42269750, "author": "iamantony", "author_id"...
2009/01/01
[ "https://Stackoverflow.com/questions/404774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40657/" ]
404,795
<p>I was recently teaching myself Python and discovered the LBYL/EAFP idioms with regards to error checking before code execution. In Python, it seems the accepted style is EAFP, and it seems to work well with the language.</p> <p>LBYL (<strong><em>L</strong>ook <strong>B</strong>efore <strong>Y</strong>ou <strong>L</strong>eap</em>):</p> <pre><code>def safe_divide_1(x, y): if y == 0: print "Divide-by-0 attempt detected" return None else: return x/y </code></pre> <p>EAFP (<em>it's <strong>E</strong>asier to <strong>A</strong>sk <strong>F</strong>orgiveness than <strong>P</strong>ermission</em>):</p> <pre><code>def safe_divide_2(x, y): try: return x/y except ZeroDivisionError: print "Divide-by-0 attempt detected" return None </code></pre> <p>My question is this: I had never even heard of using EAFP as the primary data validation construct, coming from a Java and C++ background. Is EAFP something that is wise to use in Java? Or is there too much overhead from exceptions? I know that there is only overhead when an exception is actually thrown, so I'm unsure as to why the simpler method of EAFP is not used. Is it just preference?</p>
[ { "answer_id": 404802, "author": "Yuval Adam", "author_id": 24545, "author_profile": "https://Stackoverflow.com/users/24545", "pm_score": 4, "selected": true, "text": "if (o != null)\n o.doSomething();\nelse\n // handle\n try {\n o.doSomething()\n}\ncatch (NullPointerException n...
2009/01/01
[ "https://Stackoverflow.com/questions/404795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49018/" ]
404,804
<pre><code>public class CovariantTest { public A getObj() { return new A(); } public static void main(String[] args) { CovariantTest c = new SubCovariantTest(); System.out.println(c.getObj().x); } } class SubCovariantTest extends CovariantTest { public B getObj() { return new B(); } } class A { int x = 5; } class B extends A { int x = 6; } </code></pre> <p>The above code prints 5 when compiled and run. It uses the covariant return for the over-ridden method. </p> <p>Why does it prints 5 instead of 6, as it executes the over ridden method getObj in class SubCovariantTest. </p> <p>Can some one throw some light on this. Thanks.</p>
[ { "answer_id": 404812, "author": "Spoike", "author_id": 3713, "author_profile": "https://Stackoverflow.com/users/3713", "pm_score": 4, "selected": false, "text": "x B A x A B SubCovariantTest A.x B.x CovariantTest c = new SubCovariantTest();\n// c is assumed the type of CovariantTest as ...
2009/01/01
[ "https://Stackoverflow.com/questions/404804", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40945/" ]
404,825
<p>How to return a list in Python???</p> <p>When I tried returning a list,I got an empty list.What's the reason???</p>
[ { "answer_id": 404837, "author": "Autoplectic", "author_id": 49994, "author_profile": "https://Stackoverflow.com/users/49994", "pm_score": 0, "selected": false, "text": "In [1]: def pants():\n ...: return [1, 2, 'steve']\n ...: \nIn [2]: pants()\nOut[2]: [1, 2, 'steve']\n" }, ...
2009/01/01
[ "https://Stackoverflow.com/questions/404825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46646/" ]
404,830
<p>I have an application in which I'm trying to capture the shift key modifier to perform an action, however when I run the program and press and normal key without the shift key modifier I get a beep and the modifier and key are not sent to my keyDown event. The relevant code is:</p> <pre><code>NSString* eventChars = [theEvent charactersIgnoringModifiers]; if ([eventChars isEqualTo:@"w"]) { newPlayerRow++; direction = eUp; } else if ([eventChars isEqualTo:@"x"]) { newPlayerRow--; direction = eDown; } else if ([eventChars isEqualTo:@"a"]) { newPlayerCol--; direction = eLeft; } else if ([eventChars isEqualTo:@"d"]) { newPlayerCol++; direction = eRight; } else { [super keyDown:theEvent]; return; } // handle the player firing a bullet if (([theEvent modifierFlags] &amp; (NSShiftKeyMask | NSAlphaShiftKeyMask)) != 0) { NSLog(@"Shift key"); [self fireBulletAtColumn:newPlayerCol row:newPlayerRow inDirection:direction]; [self setNeedsDisplay:YES]; } else { ... } </code></pre> <p>I'm not sure what is causing this, but I'd like to be able to capture shift key presses. Thanks in advance for any help with this problem.</p> <p>EDIT: Also I'm using a MacBook keyboard if that makes any difference.</p> <p>EDIT: This is definitely a shift-centric problem as changing (NSShiftKeyMask | NSAlphaShiftKeyMask) to NSControlKeyMask does have the desired effect.</p>
[ { "answer_id": 405580, "author": "Peter Hosey", "author_id": 30461, "author_profile": "https://Stackoverflow.com/users/30461", "pm_score": 2, "selected": false, "text": "eventChars modifierFlags NSLog NSLog(@\"Chars: %@, modifier flags: 0x%x\", eventChars, [theEvent modifierFlags]);\n is...
2009/01/01
[ "https://Stackoverflow.com/questions/404830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2594/" ]
404,838
<p>I've been programming in C-derived languages for a couple of decades now. Somewhere along the line, I decided that I no longer wanted to write:</p> <pre><code>if (var) // in C if ($var) # in Perl </code></pre> <p>when what I meant was:</p> <pre><code>if (var != 0) if (defined $var and $var ne '') </code></pre> <p>I think part of it is that I have a strongly-typed brain and in my mind, "if" requires a boolean expression.</p> <p>Or maybe it's because I use Perl so much and truth and falsehood in Perl is such a mine-field.</p> <p>Or maybe it's just because these days, I'm mainly a Java programmer.</p> <p>What are your preferences and why?</p>
[ { "answer_id": 404841, "author": "gak", "author_id": 11125, "author_profile": "https://Stackoverflow.com/users/11125", "pm_score": 4, "selected": false, "text": "if (var)\n" }, { "answer_id": 404845, "author": "asalamon74", "author_id": 21348, "author_profile": "https...
2009/01/01
[ "https://Stackoverflow.com/questions/404838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41861/" ]
404,842
<p>I am starting, and loving, TDD, however wondering about the red green light concept. I do understand in theory the importance of ensuring you can fail a test before passing it. In practice, however, I am finding it somewhat a futile practice.</p> <p>I feel I can't properly write a failing or passing test without implementing the code I am intending to test. For example, if I write a test to show my DataProvider is returning a DataRow, I need to write the DAL logical to give a meaningful fail, a fail that is more than a NullException or a Null return from an empty method, something that seems meaningless, as I feel a red light should show that I can create a failed test from the actual logical that I am testing. </p> <p>In other words, if I just return null or false, from a function I am testing to get my fail what is really the value of the red light.</p> <p>However if I have already implemented the logical (which in a way goes against the Test first paradigm), I find I am simply testing mutually exclusive concepts (IsTrue instead of IsFalse, or IsNull instead of IsNotNull) just for the sake of getting a Red light instead of a Green, and then switching them to the opposite to get the Pass.</p> <p>I am not having a go at the concept, I am really posing this question as it is something I have noticed and am wondering if I am doing something wrong.</p> <p><strong>EDIT</strong></p> <p>I accepted Charlie Martin's answer, as it worked best for me, it is in no way suggesting that there was no validity in the other answers, all of which helped me understand a concept I was apparently not grokking properly</p>
[ { "answer_id": 404933, "author": "jwpfox", "author_id": 18665, "author_profile": "https://Stackoverflow.com/users/18665", "pm_score": 1, "selected": false, "text": "bool isIntPrime( int testInt )\n" }, { "answer_id": 405096, "author": "Charlie Martin", "author_id": 35092,...
2009/01/01
[ "https://Stackoverflow.com/questions/404842", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5302/" ]
404,854
<p>when I try to fine-tune my process, I see that the waiting channel is stext, what does it mean?</p>
[ { "answer_id": 8772148, "author": "Otheus", "author_id": 531243, "author_profile": "https://Stackoverflow.com/users/531243", "pm_score": 1, "selected": false, "text": "ps axo pid,cmd,wchan" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/404854", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65724/" ]
404,861
<p>I know:</p> <ul> <li><p>The control points a and d (start and end point of a 2D cubic bezier curve)</p></li> <li><p>The slopes a->b, c->d, and b->c (b,c the other control points)</p></li> <li><p>Where the halfway point of the <a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve" rel="nofollow noreferrer">Bézier curve</a> is.</p></li> </ul> <p>Now, given this information, what is the formula for the positions of control points b and c ?</p>
[ { "answer_id": 404953, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "u * slope(a->b)+a = b, v * slope(c->d)+d = c\n q:=(a+b+c+d)/8 c = 8(q-a-d-b) v * slope(c->d)+d = 8(q-a-d-a-u * slope(a->b))\n"...
2009/01/01
[ "https://Stackoverflow.com/questions/404861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,873
<p>If the free source code editor <a href="http://notepad-plus.sourceforge.net/uk/about.php" rel="noreferrer">Notepad++</a> has the feature "Find in files...", that is without the files being opened in the editor, does it also have the feature "Replace in files..."?</p> <p>Notepad++ is based on the editing component <a href="http://www.scintilla.org/" rel="noreferrer">Scintilla</a> - for which at SourceForge there is a response to a request for this feature: "No need for this to be included in SciTE as you can add this command to the Tools menu using the Parameters dialog." So is it possible to do <strong>multi-line replace in files</strong> in Notepad++?</p>
[ { "answer_id": 4071923, "author": "Alex", "author_id": 265877, "author_profile": "https://Stackoverflow.com/users/265877", "pm_score": 7, "selected": true, "text": "\\n" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/404873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25093/" ]
404,877
<p>How to create a java.awt.Image from image data? Image data is not pure RGB pixel data but encoded in jpeg/png format.</p> <p>JavaME has a simple api Image.createImage(...) for doing this. </p> <pre><code>public static Image createImage(byte[] imageData, int imageOffset, int imageLength) </code></pre> <p>imageData - the array of image data in a supported image format.</p> <p>Is there anything similar to this available in JavaSE?</p>
[ { "answer_id": 404885, "author": "Dmitry Khalatov", "author_id": 18174, "author_profile": "https://Stackoverflow.com/users/18174", "pm_score": 3, "selected": true, "text": "import java.awt.*;\n\nToolkit toolkit = Toolkit.getDefaultToolkit();\n\nImage image = toolkit.createImage(imageData...
2009/01/01
[ "https://Stackoverflow.com/questions/404877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
404,879
<p>I'm working on the development of a C++ API which uses custom-designed plugins to interface with different database engines using their APIs and specific SQL syntax.</p> <p>Currently, I'm attempting to find a way of inserting BLOBs, but since <code>NULL</code> is the terminating character in C/C++, the BLOB becomes truncated when constructing the <em>INSERT INTO</em> query string. So far, I've worked with</p> <pre><code>//... char* sql; void* blob; int len; //... blob = some_blob_already_in_memory; len = length_of_blob_already_known; sql = sqlite3_malloc(2*len+1); sql = sqlite3_mprintf("INSERT INTO table VALUES (%Q)", (char*)blob); //... </code></pre> <p>I expect that, if it is at all possible to do it in the SQLite3 interactive console, it should be possible to construct the query string with properly escaped <code>NULL</code> characters. Maybe there's a way to do this with standard SQL which is also supported by SQLite SQL syntax?</p> <p>Surely someone must have faced the same situation before. I've googled and found some answers but were in other programming languages (Python).</p> <p>Thank you in advance for your feedback.</p>
[ { "answer_id": 404925, "author": "Louis Gerbarg", "author_id": 30506, "author_profile": "https://Stackoverflow.com/users/30506", "pm_score": 1, "selected": false, "text": "sqlite_prepare_v2() sqlite3_bind_blob()" }, { "answer_id": 405907, "author": "Eclipse", "author_id":...
2009/01/01
[ "https://Stackoverflow.com/questions/404879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36145/" ]
404,886
<p>Is there any better alternative for doing string formatting in VC6, with syntax checking before substitution?</p>
[ { "answer_id": 404916, "author": "ChrisN", "author_id": 3853, "author_profile": "https://Stackoverflow.com/users/3853", "pm_score": 4, "selected": true, "text": "CString Format printf std::stringstream std::wstringstream std::basic_string CString printf CString std::string std::string s;...
2009/01/01
[ "https://Stackoverflow.com/questions/404886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
404,887
<p>I'm sorry, but this is beginning to feel like kicking myself in the head. I'm completely baffled by RSpec. Have watched video after video, read tutorial after tutorial, and still I'm just stuck on square one. </p> <p>=== here is what I'm working with</p> <p><strong><a href="http://github.com/fudgestudios/bort/tree/master" rel="nofollow noreferrer">http://github.com/fudgestudios/bort/tree/master</a></strong></p> <p>=== Errors</p> <pre><code>F 1) NoMethodError in 'bidding on an item should work' You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.new_record? spec/controllers/auction_controller_spec.rb:16: spec/controllers/auction_controller_spec.rb:6: Finished in 0.067139 seconds 1 example, 1 failure </code></pre> <p>=== here is my controller action</p> <pre><code> def bid @bid = Bid.new(params[:bid]) @bid.save end </code></pre> <p>=== here is my test</p> <pre><code>require File.dirname(__FILE__) + '/../spec_helper' include ApplicationHelper include UsersHelper include AuthenticatedTestHelper describe "bidding on an item" do controller_name :items before(:each) do @user = mock_user stub!(:current_user).and_return(@user) end it "should work" do post 'bid', :bid =&gt; { :auction_id =&gt; 1, :user_id =&gt; @user.id, :point =&gt; 1 } assigns[:bid].should be_new_record end end </code></pre> <p>=== spec_helper</p> <p><strong><a href="http://github.com/fudgestudios/bort/tree/master/spec/spec_helper.rb" rel="nofollow noreferrer">http://github.com/fudgestudios/bort/tree/master/spec/spec_helper.rb</a></strong></p> <p>It's very disheartening to wake for work at 3 a.m. and accomplish nothing for the day. Please understand.</p>
[ { "answer_id": 405090, "author": "Otto", "author_id": 9594, "author_profile": "https://Stackoverflow.com/users/9594", "pm_score": 2, "selected": false, "text": "require File.dirname(__FILE__) + '/../spec_helper'\ninclude ApplicationHelper\ninclude UsersHelper\ninclude AuthenticatedTestHe...
2009/01/01
[ "https://Stackoverflow.com/questions/404887", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33287/" ]
404,891
<p>I have two pages of jQuery, Page1 and Page2, and I'm able to get input in Page1.</p> <p>The <code>somval=1000$</code>.</p> <p>The page 1 user enters the somevalue. I have stored the value:</p> <pre><code>var val = somval; </code></pre> <p>Now in the second page, I need to get the result of somvalue in page 1. Of course two pages using My1.js My2.js respectively.</p> <p>How do I share the values from one jQuery file to other JavaScript or how do I get the value from page1 value, to page2?</p> <p>How do I tackle this?</p>
[ { "answer_id": 404894, "author": "gak", "author_id": 11125, "author_profile": "https://Stackoverflow.com/users/11125", "pm_score": 5, "selected": true, "text": "window.location = 'page2.html?somval=' + somval;\n var qsParm = new Array();\nfunction qs() {\n var query = window.location....
2009/01/01
[ "https://Stackoverflow.com/questions/404891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44984/" ]
404,899
<p>I found the following rather strange. Then again, I have mostly used closures in dynamic languages which shouldn't be suspectable to the same "bug". The following makes the compiler unhappy:</p> <pre><code>VoidFunction t = delegate { int i = 0; }; int i = 1; </code></pre> <p>It says:</p> <blockquote> <p>A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i', which is already used in a 'child' scope to denote something else</p> </blockquote> <p>So this basically means that variables declared inside a delegate will have the scope of the function declared in. Not exactly what I would have expected. I havn't even tried to call the function. At least Common Lisp has a feature where you say that a variable should have a dynamic name, if you really want it to be local. This is particularly important when creating macros that do not leak, but something like that would be helpful here as well.</p> <p>So I'm wondering what other people do to work around this issue?</p> <p>To clarify I'm looking for a solution where the variables I declare in the delegete doesn't interfere with variables declared <em>after</em> the delegate. And I want to still be able to capture variables declared before the delegate.</p>
[ { "answer_id": 404910, "author": "dalle", "author_id": 19100, "author_profile": "https://Stackoverflow.com/users/19100", "pm_score": 0, "selected": false, "text": "int i = 1;\nVoidFunction t = delegate { Console.WriteLine(i); };\n" }, { "answer_id": 404918, "author": "Øyvind ...
2009/01/01
[ "https://Stackoverflow.com/questions/404899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13995/" ]
404,905
<p>I currently have an anchor tag that, when clicked, appends another anchor tag to the DOM. This is all done via jQuery. I know what the "id" attribute of the anchor tag to be added will be. However, when I try the following code, it fails to handle the newly added anchor tag's click event:</p> <p>$("#id").click(function() { alert("test"); });</p>
[ { "answer_id": 404917, "author": "Beau Simensen", "author_id": 50453, "author_profile": "https://Stackoverflow.com/users/50453", "pm_score": 1, "selected": false, "text": "$(\"#id\").ready(function() {\n $(\"#id\").click(function() { alert(\"test\"); }\n});\n // Listen to clicks, even...
2009/01/01
[ "https://Stackoverflow.com/questions/404905", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1574/" ]
404,941
<p>I want to be able to pass an "array" of values to my stored procedure, instead of calling "Add value" procedure serially.</p> <p>Can anyone suggest a way to do it? am I missing something here?</p> <p>Edit: I will be using PostgreSQL / MySQL, I haven't decided yet.</p>
[ { "answer_id": 405041, "author": "Weej", "author_id": 48172, "author_profile": "https://Stackoverflow.com/users/48172", "pm_score": 2, "selected": false, "text": "CREATE FUNCTION [dbo].[Split]\n(\n @ItemList NVARCHAR(4000), \n @delimiter CHAR(1)\n)\nRETURNS @IDTable TABLE (Item VAR...
2009/01/01
[ "https://Stackoverflow.com/questions/404941", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41391/" ]
404,948
<p>A common scenario when using source control is to have a development branch along with versioned release branches. We use CVS, with HEAD as the development branch, and a branch named e.g. release-6-2 for the current release of a product.</p> <p>Development of new features go into the development branch only, but bug fixes sometimes have to be checked into both the development branch and the current release branch. This can get quite tedious at times, so I am looking for practical ways to accomplish this.</p> <p>When a file to be commited is in synch on the two branches, I am in particular looking for a quick "commit to these branches" solution.</p> <p>(We use CVS as our source control system, so any CVS-specific answers are nice. However, it is also interesting to see whether other source control systems can offer a better way. On the client side we use Eclipse, so Eclipse solutions are good. But if you have a non-Eclipse solution, that is fine too.)</p>
[ { "answer_id": 404996, "author": "orip", "author_id": 37020, "author_profile": "https://Stackoverflow.com/users/37020", "pm_score": 2, "selected": false, "text": "PRE_FOO POST_FOO cvs up -j PRE_FOO -j POST_FOO\n" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/404948", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18651/" ]
404,957
<p>Using iPhone CALayer, I want a rotation animation for my spirit layer, but I also want a callback for the animation end, hot to do that? </p> <p>I think maybe I should use CABasicAnimation, but I don't know how to do rotation using CABasicAnimation, any idea?</p> <p>Thanks</p>
[ { "answer_id": 405395, "author": "Kendall Helmstetter Gelner", "author_id": 6330, "author_profile": "https://Stackoverflow.com/users/6330", "pm_score": 4, "selected": true, "text": "- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag\n" }, { "answer_id": 4071...
2009/01/01
[ "https://Stackoverflow.com/questions/404957", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47936/" ]
404,975
<p>Using java, minus the exception handling, it is as simple as </p> <pre><code>FileOutputStream ostream = new FileOutputStream("\\\\host\\share"); PrintStream printStream = new PrintStream(ostream); printStream.print("HELLO PRINTER"); printStream.close(); ostream.close(); </code></pre>
[ { "answer_id": 405272, "author": "nakajima", "author_id": 39589, "author_profile": "https://Stackoverflow.com/users/39589", "pm_score": 1, "selected": false, "text": "File IO" }, { "answer_id": 405987, "author": "russellkt", "author_id": 12417, "author_profile": "http...
2009/01/01
[ "https://Stackoverflow.com/questions/404975", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12417/" ]
404,989
<p>I'm getting a "FormatException: Input string was not in a correct format" error that I don't understand.</p> <p>I'm using the following lines to write a string to a text file:</p> <pre><code>using (StreamWriter sw = new StreamWriter(myfilename, false, System.Text.Encoding.GetEncoding(enc))) { sw.Write(mystring, Environment.NewLine); } </code></pre> <p>(the encoding part is because I do have an option in my application to set it to utf-8 or iso-8859-1... but I think that's irrelevant).</p> <p>All of my strings write out just fine except this one string that is different from the others because it actually has a snippet of javascript code in it. I'm sure that one of the special characters there might be causing the problem but how do I know?</p> <p>The one thing I tried was to insert the following line just before the sw.Write statement above:</p> <pre><code>System.Console.WriteLine(mystring); </code></pre> <p>and it wrote out to the console just fine - no error.</p> <p>Help?</p> <p>Thanks! (and Happy New Year!)</p> <p>-Adeena</p>
[ { "answer_id": 404994, "author": "Øyvind Skaar", "author_id": 49194, "author_profile": "https://Stackoverflow.com/users/49194", "pm_score": 5, "selected": true, "text": "sw.Write(mystring + Environment.NewLine);\n sw.Write(\"{0}{1}\", mystring, Environment.NewLine);\n" }, { "answ...
2009/01/01
[ "https://Stackoverflow.com/questions/404989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44004/" ]
404,995
<p>My question is how to check if a microphone and a speaker are from the same sound card on Windows platform. If they are from different cards, then the logic to handling timing will be different. I'm using both DSound and WMME API.</p>
[ { "answer_id": 409000, "author": "bugmagnet", "author_id": 426, "author_profile": "https://Stackoverflow.com/users/426", "pm_score": 1, "selected": false, "text": "strComputer = \".\" \nSet objWMIService = GetObject(\"winmgmts:\\\\\" & strComputer & \"\\root\\CIMV2\") \nSet colItems = ob...
2009/01/01
[ "https://Stackoverflow.com/questions/404995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47681/" ]
405,039
<p>Is there any way how to set <code>std::setw</code> manipulator (or its function <code>width</code>) permanently? Look at this:</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;algorithm&gt; #include &lt;iterator&gt; int main( void ) { int array[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256 }; std::cout.fill( '0' ); std::cout.flags( std::ios::hex ); std::cout.width( 3 ); std::copy( &amp;array[0], &amp;array[9], std::ostream_iterator&lt;int&gt;( std::cout, " " ) ); std::cout &lt;&lt; std::endl; for( int i = 0; i &lt; 9; i++ ) { std::cout.width( 3 ); std::cout &lt;&lt; array[i] &lt;&lt; " "; } std::cout &lt;&lt; std::endl; } </code></pre> <p>After run, I see:</p> <pre><code>001 2 4 8 10 20 40 80 100 001 002 004 008 010 020 040 080 100 </code></pre> <p>I.e. every manipulator holds its place except the <code>setw</code>/<code>width</code> which must be set for every entry. Is there any elegant way how to use <code>std::copy</code> (or something else) along with <code>setw</code>? And by elegant I certainly don't mean creating own functor or function for writing stuff into <code>std::cout</code>.</p>
[ { "answer_id": 405068, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 5, "selected": true, "text": ".width #include <boost/function_output_iterator.hpp>\n#include <boost/lambda/lambda.hpp>\n#include <algorith...
2009/01/01
[ "https://Stackoverflow.com/questions/405039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21009/" ]
405,043
<pre><code>Response.Redirect(string.Format("myprofile.aspx?uid={0}&amp;result=saved#main",user.UserID)); </code></pre> <p>said code translates to</p> <p><strong>IE7</strong> - <code>myprofile.aspx?uid=933fdf8e-1be0-4bc2-a269-ac0b01ba4755&amp;result=saved</code></p> <p><strong>FF</strong>- <code>myprofile.aspx?uid=933fdf8e-1be0-4bc2-a269-ac0b01ba4755&amp;result=saved#main</code></p> <p>why does IE7 drop my anchor?</p> <p>edit: I should mention I am using this in conjunction with jQuery UI's tab control. I want the postback to tab into a specific tab.</p>
[ { "answer_id": 405702, "author": "scunliffe", "author_id": 6144, "author_profile": "https://Stackoverflow.com/users/6144", "pm_score": 2, "selected": true, "text": "uid=933fdf8e-1be0-4bc2-a269-ac0b01ba4755&result=saved&hash=main#main\n <!--[if IE]>\n<script>\n if(document.location.href....
2009/01/01
[ "https://Stackoverflow.com/questions/405043", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2763/" ]
405,047
<p>I'm looking for an Objective-C way of sorting characters in a string, as per the answer to <a href="https://stackoverflow.com/questions/401834/how-to-elegantly-compute-the-anagram-signature-of-a-word-in-ruby">this</a> question.</p> <p>Ideally a function that takes an NSString and returns the sorted equivalent. </p> <p>Additionally I'd like to run length encode sequences of 3 or more repeats. So, for example "mississippi" first becomes "iiiimppssss", and then could be shortened by encoding as "4impp4s".</p> <p>I'm not expert in Objective-C (more Java and C++ background) so I'd also like some clue as to what is the best practice for dealing with the memory management (retain counts etc - no GC on the iphone) for the return value of such a function. My source string is in an iPhone search bar control and so is an <code>NSString *</code>. </p>
[ { "answer_id": 405162, "author": "sprintf", "author_id": 50712, "author_profile": "https://Stackoverflow.com/users/50712", "pm_score": 4, "selected": true, "text": "int char_compare(const char* a, const char* b) {\n if(*a < *b) {\n return -1;\n } else if(*a > *b) {\n ...
2009/01/01
[ "https://Stackoverflow.com/questions/405047", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42404/" ]
405,059
<p>I have a datalayer.cs file that was generated using a code gen tool.</p> <p>I am marking the class as a partial class, so I can create another file with my own hand written datalayer code.</p> <p>How should I name my files? </p> <p>Should I do it like this:</p> <p>/data/partial/datalayer.cs /data/datalayer.cs</p> <p>So when I run my codegenerator again, I just dump the file to the /partial/ folder in my source tree.</p> <p>suggestions?</p>
[ { "answer_id": 405069, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 1, "selected": false, "text": "/mydirectory/MyFormName.cs\n/mydirectory/MyFormName.Designer.cs\n /mydirectory/datalayer.cs\n/mydirectory/datalayer.autocod...
2009/01/01
[ "https://Stackoverflow.com/questions/405059", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50700/" ]
405,060
<p>Something like <code>.//div[@id='foo\d+]</code> to capture div tags with <code>id='foo123'</code>.</p> <p>I'm using .NET, if that matters.</p>
[ { "answer_id": 405081, "author": "Cristian Vat", "author_id": 20109, "author_profile": "https://Stackoverflow.com/users/20109", "pm_score": 5, "selected": false, "text": "matches() replace() tokenize() .//div[matches(@id,'foo\\d+')]" }, { "answer_id": 405507, "author": "Dimit...
2009/01/01
[ "https://Stackoverflow.com/questions/405060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11236/" ]
405,072
<p>I am relatively new to The Zend framework having only been working with it probably two months at the most. I am now trying to get a list of results from a query I run, send it through the zend paginator class and display 4 results per page, however it does not seem to be recognising when it has got 4 results, I believe there is an error in my code but I can not for the life of me see it, I was hoping someone here will be able to pick up on it and help me and out and probably tell me it is something stupid that I have missed. Thanks here is the code I have written.</p> <p>This the query in my model</p> <pre><code>public function getAllNews() { $db = Zend_Registry::get('db'); $sql = "SELECT * FROM $this-&gt;_name WHERE flag = 1 ORDER BY created_at"; $query = $db-&gt;query($sql); while ($row = $query-&gt;fetchAll()) { $result[] = $row; } return $result; } </code></pre> <p>This is code in my controller</p> <pre><code>function preDispatch() { $this-&gt;_helper-&gt;layout-&gt;setLayout('latestnews'); Zend_Loader::loadClass('newsArticles'); $allNews = new newsArticles(); $this-&gt;view-&gt;allNews = $allNews-&gt;getAllnews(); //die (var_dump($this-&gt;view-&gt;allNews)); $data = $this-&gt;view-&gt;allNews; // Instantiate the Zend Paginator and give it the Zend_Db_Select instance Argument ($selection) $paginator = Zend_Paginator::factory($data); // Set parameters for paginator $paginator-&gt;setCurrentPageNumber($this-&gt;_getParam("page")); // Note: For this to work of course, your URL must be something like this: http://localhost:8888/index/index/page/1 &lt;- meaning we are currently on page one, and pass that value into the "setCurrentPageNumber" $paginator-&gt;setItemCountPerPage(1); $paginator-&gt;setPageRange(4); // Make paginator available in your views $this-&gt;view-&gt;paginator = $paginator; //die(var_dump($data)); } </code></pre> <p>Below is the view that builds the paginator,</p> <pre><code> &lt;?php if ($this-&gt;pageCount): ?&gt; &lt;div class="paginationControl"&gt; &lt;!-- Previous page link --&gt; &lt;?php if (isset($this-&gt;previous)): ?&gt; &lt;a href="&lt;?= $this-&gt;url(array('page' =&gt; $this-&gt;previous)); ?&gt;"&gt;&amp;lt; Previous&lt;/a&gt; | &lt;?php else: ?&gt; &lt;span class="disabled"&gt;&amp;lt; Previous&lt;/span&gt; | &lt;?php endif; ?&gt; &lt;!-- Numbered page links --&gt; &lt;?php foreach ($this-&gt;pagesInRange as $page): ?&gt; &lt;?php if ($page != $this-&gt;current): ?&gt; &lt;a href="&lt;?= $this-&gt;url(array('page' =&gt; $page)); ?&gt;"&gt;&lt;?= $page; ?&gt;&lt;/a&gt; | &lt;?php else: ?&gt; &lt;?= $page; ?&gt; | &lt;?php endif; ?&gt; &lt;?php endforeach; ?&gt; &lt;!-- Next page link --&gt; &lt;?php if (isset($this-&gt;next)): ?&gt; &lt;a href="&lt;?= $this-&gt;url(array('page' =&gt; $this-&gt;next)); ?&gt;"&gt;Next &amp;gt;&lt;/a&gt; &lt;?php else: ?&gt; &lt;span class="disabled"&gt;Next &amp;gt;&lt;/span&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; </code></pre> <p>And finally the code the makes up my view</p> <pre><code>&lt;div id="rightColumn"&gt; &lt;h3&gt;Latest News&lt;/h3&gt; &lt;?php if (count($this-&gt;paginator)): ?&gt; &lt;ul&gt; &lt;?php foreach ($this-&gt;paginator as $item): ?&gt; &lt;?php foreach ($item as $k =&gt; $v) { echo "&lt;li&gt;" . $v['title'] . "&lt;/li&gt;"; } ?&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt; &lt;?php endif; ?&gt; &lt;?= $this-&gt;paginationControl($this-&gt;paginator, 'Sliding', '/latestnews/partial_pagination_control.phtml'); ?&gt; &lt;/div&gt; </code></pre> <p>I will be greatful for any help you can give me.</p> <p>Thanks</p> <p>Sico</p>
[ { "answer_id": 405259, "author": "Brian Fisher", "author_id": 43816, "author_profile": "https://Stackoverflow.com/users/43816", "pm_score": 1, "selected": false, "text": "public function getAllNews()\n{\n $db = Zend_Registry::get('db');\n\n $sql = \"SELECT * FROM $this->_na...
2009/01/01
[ "https://Stackoverflow.com/questions/405072", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
405,076
<p>I made a drag and drop utility that make it possible for users to drag and drop elements directly on a workplace and create their page, I wound how can I save the user's work as HTML page!</p>
[ { "answer_id": 405087, "author": "Pim Jager", "author_id": 35197, "author_profile": "https://Stackoverflow.com/users/35197", "pm_score": 1, "selected": false, "text": "var positions = new Array();\nfunction savePositionOfAllDivs() {\n $('div').each( function(){\n $this = $(this);\n id ...
2009/01/01
[ "https://Stackoverflow.com/questions/405076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49809/" ]
405,106
<p>All of the questions that I've asked recently about Python have been for this project. I have realised that the reason I'm asking so many questions may not be because I'm so new to Python (but I know a good bit of PHP) and is probably not because Python has some inherent flaw.</p> <p>Thus I will now say what the project is and what my current idea is and you can either tell me I'm doing it all wrong, that there's a few things I need to learn or that Python is simply not suited to dealing with this type of project and language XYZ would be better in this instance or even that there's some open source project I might want to get involved in.</p> <p><strong>The project</strong><br> I run a free turn based strategy game (think the campaign mode from the total war series but with even more complexity and depth) and am creating a combat simulator for it (again, think total war as an idea of how it'd work). I'm in no way deluded enough to think that I'll ever make anything as good as the Total war games alone but I do think that I can automate a process that I currently do by hand.</p> <p><strong>What will it do</strong><br> It will have to take into account a large range of variables for the units, equipment, training, weather, terrain and so on and so forth. I'm aware it's a big task and I plan to do it a piece at a time in my free time. I've zero budget but it's a hobby that I'm prepared to put time into (and have already).</p> <p><strong>My current stumbling block</strong><br> In PHP everything can access everything else, "wrong" though some might consider this it's really really handy for this. If I have an array of equipment for use by the units, I can get hold of that array from anywhere. With Python I have to remake that array each time I import the relevant data file and this seems quite a silly solution for a language that from my experience is well thought out. I've put in a system of logging function calls and class creation (because I know from a very basic version of this that I did in PHP once that it'll help a lot down the line) and the way that I've kept the data in one place is to pass each of my classes an instance to my logging list, smells like a hack to me but it's the only way I've gotten it to work.</p> <p>Thus I conclude I'm missing something and would very much appreciate the insight of anybody willing to give it. Thank you.</p> <p><strong>Code samples</strong></p> <p>This creates a list of formations, so far there's only one value (besides the name) but I anticipate adding more on which is why they're a list of classes rather than just a standard list. This is found within data.py</p> <pre><code>formations = [] formationsHash = [] def createFormations(logger): """This creates all the formations that will be used""" # Standard close quarter formation, maximum number of people per square metre formationsHash.append('Tight') formations.append(Formation(logger, 'Tight', tightness = 1)) # Standard ranged combat formation, good people per square metre but not too cramped formationsHash.append('Loose') formations.append(Formation(logger, 'Loose', tightness = 0.5)) # Standard skirmishing formation, very good for moving around terrain and avoiding missile fire formationsHash.append('Skirmish') formations.append(Formation(logger, 'Skirmish', tightness = 0.1)) # Very unflexible but good for charges formationsHash.append('Arrowhead') formations.append(Formation(logger, 'Arrowhead', tightness = 1)) def getFormation(searchFor): """Returns the fomation object with this name""" indexValue = formationsHash.index(searchFor) return formations[indexValue] </code></pre> <p>I don't have a code sample of when I'd need to access it because I've not gotten as far as making it but I anticipate the code looking something like the following:</p> <pre><code>Python tempFormation = data.getFormation(unit.formationType) tempTerrain = data.getTerrain(unit.currentTerrain) unit.attackDamage = unit.attackDamage * tempTerrain.tighnessBonus(tempFormation.tightness) </code></pre> <p>The unit contains an integer that links to the index/key of the relevant terrain, formation and whatnot in the master list. Temporary variables are used to make the 3rd line shorter but in the long run will possibly cause issues if I forget to get one and it's use a value from earlier which is then incorrect (that's where the logging comes in handy). </p> <pre><code>PHP $unit-&gt;attackDamage *= $terrain[$unit-&gt;currentTerrain]-&gt;tighnessBonus($unit-&gt;currentTerrain) </code></pre> <p>The unit class contains the index (probably a string) of the relevant terrain it's on and the formation it's in.</p> <p>Maybe this will show some massive flaw in my understanding of Python (6 months vs the 3 years of PHP).</p>
[ { "answer_id": 405328, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": false, "text": "formationsHash def createFormations(logger):\n \"\"\"This creates all the formations that will be used\"\"\"\n format...
2009/01/01
[ "https://Stackoverflow.com/questions/405106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
405,112
<p>How are objects stored in memory in C++?</p> <p>For a regular class such as </p> <pre><code>class Object { public: int i1; int i2; char i3; int i4; private: }; </code></pre> <p>Using a pointer of Object as an array can be used to access i1 as follows?</p> <pre><code>((Object*)&amp;myObject)[0] === i1? </code></pre> <p>Other questions on SO seem to suggest that casting a struct to a pointer will point to the first member for POD-types. How is this different for classes with constructors if at all? Also in what way is it different for non-POD types?</p> <p>Edit:</p> <p>In memory therefore would the above class be laid out like the following?</p> <pre><code>[i1 - 4bytes][i2 - 4bytes][i3 - 1byte][padding - 3bytes][i4 - 4bytes] </code></pre>
[ { "answer_id": 405141, "author": "Larry Gritz", "author_id": 3832, "author_profile": "https://Stackoverflow.com/users/3832", "pm_score": 5, "selected": true, "text": "((int*)&myObject)[0] == i1\n" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/405112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16177/" ]
405,113
<p>I have a structure in C which resembles that of a database table record. Now when I query the table using select, I do not know how many records I will get. I want to store all the returned records from the select query in a array of my structure data type.</p> <p>Which method is best?</p> <h3>Method 1: find array size and allocate</h3> <ol> <li>first get the count of records by doing select count(*) from table</li> <li>allocate a static array</li> <li>run select * from table and then store each records in my structure in a loop.</li> </ol> <h3>Method 2: use single linked list</h3> <pre><code>while ( records returned ) { create new node store the record in node } </code></pre> <p>Which implementation is best?</p> <p>My requirement is that when I have all the records, I will probably make copies of them or something. But I do not need random access and I will not be doing any search of a particular record.</p> <p>Thanks</p>
[ { "answer_id": 405124, "author": "Bjarke Ebert", "author_id": 31890, "author_profile": "https://Stackoverflow.com/users/31890", "pm_score": 1, "selected": false, "text": "std::vector<myrecord> List<myrecord>" }, { "answer_id": 405385, "author": "Max", "author_id": 50023, ...
2009/01/01
[ "https://Stackoverflow.com/questions/405113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50706/" ]
405,114
<p>I need to transfer DVD image files between a Windows XP computer and a Mac running Leopard.</p> <p>The machines are not connected via a fast network, and I have a few USB drives floating around that I want to use, e.g. 8GB flash, 60GB and 250GB USB hard drives.</p> <p>Sometimes the files creep above 4GB (the maximum size of a single file on FAT32), and I've had no luck with NTFS on Leopard. I'm not aware of any drivers for XP/Vista that support Mac file systems like HFS.</p> <p>Anyone got any suggestions as to what file system would best suit here?</p> <p>Thanks Tom</p>
[ { "answer_id": 405131, "author": "frankodwyer", "author_id": 42404, "author_profile": "https://Stackoverflow.com/users/42404", "pm_score": 2, "selected": false, "text": "split" }, { "answer_id": 405245, "author": "ewalshe", "author_id": 47429, "author_profile": "https...
2009/01/01
[ "https://Stackoverflow.com/questions/405114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17971/" ]
405,134
<p>I <code>UIButton</code> using + <code>buttonWithType:</code> </p> <p>What I need to figure out is how to manually change the button state. There are times when I need it to be set to "disabled."</p> <p>I read through the <code>UIButton</code> documentation but I cannot seem to find anything about manually setting a button state.</p> <p>Any thoughts would be greatly appreciated.</p>
[ { "answer_id": 405163, "author": "Ben Gottlieb", "author_id": 6694, "author_profile": "https://Stackoverflow.com/users/6694", "pm_score": 7, "selected": true, "text": "button.enabled = NO; button.isEnabled = false\n" }, { "answer_id": 7988158, "author": "roberthuttinger", ...
2009/01/01
[ "https://Stackoverflow.com/questions/405134", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46022/" ]
405,140
<p>How can I achieve the following with a format string: Do 01.01.2009 ? It has to work in all languages (the example would be for Germany). So there should only be the short weekday and then the short date.</p> <p>I tried 'ddd d' (without the '). However, this leads to 'Do 01'. Is there maybe a character I can put before the 'd' so that it is tread on its own or something like that?</p>
[ { "answer_id": 405154, "author": "Darin Dimitrov", "author_id": 29407, "author_profile": "https://Stackoverflow.com/users/29407", "pm_score": 3, "selected": true, "text": "DateTime.Now.ToString(\"ddd dd/MM/yyyy\")\n" }, { "answer_id": 405167, "author": "cowgod", "author_i...
2009/01/01
[ "https://Stackoverflow.com/questions/405140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
405,151
<p>On iPhone, I perform a HTTP request using NSURLRequest for a chunk of data. Object allocation spikes and I assign the data accordingly. When I finish with the data, I free it up accordingly - however instruments doesn't show any data to have been freed!</p> <p>My theory is that by default HTTP requests are cached, however - I don't want my iPhone app to cache this data. </p> <p>Is there a way to clear this cache after a request or prevent any data from being cached in the first place?</p> <p>I've tried using all the cache policies documented a little like below:</p> <pre><code>NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; theRequest.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData; </code></pre> <p>but nothing seems to free up the memory!</p>
[ { "answer_id": 405711, "author": "catlan", "author_id": 23028, "author_profile": "https://Stackoverflow.com/users/23028", "pm_score": 3, "selected": false, "text": "- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse\n...
2009/01/01
[ "https://Stackoverflow.com/questions/405151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1221378/" ]
405,161
<p>I need to find a fairly efficient way to detect syllables in a word. E.g.,</p> <p>Invisible -> in-vi-sib-le</p> <p>There are some syllabification rules that could be used:</p> <p>V CV VC CVC CCV CCCV CVCC</p> <p>*where V is a vowel and C is a consonant. E.g., </p> <p>Pronunciation (5 Pro-nun-ci-a-tion; CV-CVC-CV-V-CVC)</p> <p>I've tried few methods, among which were using regex (which helps only if you want to count syllables) or hard coded rule definition (a brute force approach which proves to be very inefficient) and finally using a finite state automata (which did not result with anything useful).</p> <p>The purpose of my application is to create a dictionary of all syllables in a given language. This dictionary will later be used for spell checking applications (using Bayesian classifiers) and text to speech synthesis. </p> <p>I would appreciate if one could give me tips on an alternate way to solve this problem besides my previous approaches. </p> <p>I work in Java, but any tip in C/C++, C#, Python, Perl... would work for me.</p>
[ { "answer_id": 4103234, "author": "hoju", "author_id": 105066, "author_profile": "https://Stackoverflow.com/users/105066", "pm_score": 5, "selected": false, "text": "from nltk.corpus import cmudict\nd = cmudict.dict()\ndef nsyl(word):\n return [len(list(y for y in x if y[-1].isdigit()))...
2009/01/01
[ "https://Stackoverflow.com/questions/405161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50705/" ]
405,164
<p>I've done quite a bit of research into this but it seems that the methods used are inconsistent and varied.</p> <p>Here are some methods I have used in the past:</p> <pre><code>/* 1: */ typeof myFunc === 'function' /* 2: */ myFunc.constructor === Function /* 3: */ myFunc instanceof Function </code></pre> <p>As part of my research I had a look at how some well-known libraries accomplished this:</p> <pre><code> /* jQuery 1.2.6: */ !!fn &amp;&amp; typeof fn != "string" &amp;&amp; !fn.nodeName &amp;&amp; fn.constructor != Array &amp;&amp; /^[\s[]?function/.test( fn + "" ) /* jQuery 1.3b1: */ toString.call(obj) === "[object Function]" /* Prototype 1.6: */ typeof object == "function" /* YUI 2.6: */ typeof o === 'function' </code></pre> <p>I'm amazed there are so many different methods beings used, surely a single acceptable test has been agreed upon? And I'm completely clueless as to what the intentions were with jQuery 1.2.6's rendition, looks a bit OTT...</p> <p>So, my quesiton remains, what is the best* way of testing for a function?</p> <p>I would also appreciate some insight into some of the above methods, especially jQuery 1.2.6's. (I can see what they're doing, it just seems odd)</p> <p>[*] By 'best', I mean the most widely accepted cross-browser compatible method.</p> <hr> <p>EDIT: Yes, I know it's been discussed before but I'd still like some discussion on the most effective method. Why are there so many different used methods?</p> <p>The discussions on SO thus far have only mentioned the typeof operator (mostly) but nobody has hinted at the effectiveness of alternate methods.</p>
[ { "answer_id": 405202, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 2, "selected": false, "text": "toString.call(obj) === \"[object Function]\"\n typeof typeof o === \"function\"\n" }, { "answer_id": 405314,...
2009/01/01
[ "https://Stackoverflow.com/questions/405164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21677/" ]
405,165
<p>I am a C++ developer, slowly getting into web development. I like LISP a lot but don't like AllegroCL and web-frameworks available for LISP. I am looking for more freedom and ability to do cool hacks on language level. I don't consider tabs as a crime against nature.</p> <p>Which one is closer to LISP: Python or Ruby? </p> <p>I can't seem to be able to choose from Python and Ruby: they seem very similar but apparently Ruby is more functional and object-oriented, which are good things, while Python is more like Perl: a simple scripting language. Do I have the right impression?</p> <p>PS - This might seem like a flame bait but it's not really, I'm just trying not to go crazy from OCD about switching from RoR to Python/Django and back.</p>
[ { "answer_id": 405188, "author": "zenazn", "author_id": 46848, "author_profile": "https://Stackoverflow.com/users/46848", "pm_score": 6, "selected": true, "text": "2.days.from_now" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/405165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47937/" ]
405,176
<p>The Table - Query has 2 columns (functionId, depFunctionId)</p> <p>I want all values that are either in functionid or in depfunctionid</p> <p>I am using this:</p> <pre><code>select distinct depfunctionid from Query union select distinct functionid from Query </code></pre> <p>How to do it better?</p>
[ { "answer_id": 405350, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "select depfunctionid , functionid from Query\ngroup by depfunctionid , functionid\n select asrt2.function_id\nfrom a_self_re...
2009/01/01
[ "https://Stackoverflow.com/questions/405176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30546/" ]
405,189
<p>I'm using following for a simple database application:</p> <ul> <li>SQL Server Compact Edition .sdf file as database, with int primary key IDs.</li> <li>Typed DataSet and BindingSource as data access layer</li> <li>DataGridView for displaying data.</li> </ul> <p>My problem is, I'm having trouble with the last inserted record/row ID. When I add a row to datagridview, using Append button of a navigator component, the ID of the new record/row is -1. It's still -1 even after save data to database using TableAdapter.Update(). I know I can get last ID using a seperate query with @@identity or scope_identity() but it doesn't sound right that you just <em>have to</em> use another query to update your data, manually at that. Am I missing something here? Is there an automatic way to update your data after saving to database and getting the ID of the record you just inserted?</p> <p>Also, I saw a "refresh the datatable" option in dataset designer->table adapter configuration->advanced window, but it's disabled for some reason. But I don't know if it's related..</p> <p>I'd appreciate any help with this..</p>
[ { "answer_id": 405227, "author": "Toran Billups", "author_id": 2701, "author_profile": "https://Stackoverflow.com/users/2701", "pm_score": 0, "selected": false, "text": "Public Sub InsertSupplier(ByVal SupplierObject As Supplier) Implements ISupplierRepository.InsertSupplier\nSupplierObj...
2009/01/01
[ "https://Stackoverflow.com/questions/405189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
405,229
<p>I have a script of MySQL queries that I use and that work.</p> <p>I'm trying to execute the same queries in Microsoft SQL server and there's one thing I don't understand.</p> <p>MySql uses "key" to define a key made up of different fields.</p> <p>What is the way to do the same thing in SQL Server?</p> <p>Thanks!</p> <p>-Adeena</p>
[ { "answer_id": 405234, "author": "recursive", "author_id": 44743, "author_profile": "https://Stackoverflow.com/users/44743", "pm_score": 2, "selected": false, "text": "ALTER TABLE product\n ADD CONSTRAINT prim_prod PRIMARY KEY(product_foo, product_bar)\n" }, { "answer_id": 405...
2009/01/01
[ "https://Stackoverflow.com/questions/405229", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44004/" ]
405,233
<p>In the below code sample, what does <code>{0:X2}</code> mean? This is from the reflection section of the MCTS Application Development Foundation book (covering dynamic code, etc.).</p> <pre><code>foreach(Byte b in body.GetILAsBodyArray()) { Console.Write("{0:X2}", b); } </code></pre>
[ { "answer_id": 55142597, "author": "Niels Gjeding Olsen", "author_id": 769779, "author_profile": "https://Stackoverflow.com/users/769779", "pm_score": 2, "selected": false, "text": " long a = 123456789;\n Console.Write(\"{0:X2}\", a);\n -> 75BCD15\n long a = -1;\n Console.Write(\"{0:X...
2009/01/01
[ "https://Stackoverflow.com/questions/405233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32484/" ]
405,246
<p>I'm writing a a very small daemon that must remain responsive even when a system is under severe stress. I'm looking at the differences between SCHED_FIFO and SCHED_RR in regards to scheduling, as well as trying to determine a sensible priority.</p> <p>Which scheduler would be appropriate for a small but critical monitoring daemon, what priority would be reasonably safe? I'm still coming up a little fuzzy when trying to understand the differences between the two.</p> <p>My program is allocating under 3k (and uses mlockall()), it writes about 600 bytes to xenbus then sleeps, but its impossible for me to tell how much time (in ms) it will take to actually write the data.. since what is written depends on a configuration file. </p> <p>Thanks in advance for any suggestions / explanations.</p>
[ { "answer_id": 405271, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 2, "selected": false, "text": "man sched_setscheduler\n" }, { "answer_id": 405353, "author": "Norman Ramsey", "author_id":...
2009/01/01
[ "https://Stackoverflow.com/questions/405246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50049/" ]
405,282
<p>I am trying to write a life simulation in python with a variety of animals. It is impossible to name each instance of the classes I am going to use because I have no way of knowing how many there will be.</p> <p>So, my question:</p> <p>How can I automatically give a name to an object?</p> <p>I was thinking of creating a "Herd" class which could be all the animals of that type alive at the same time...</p>
[ { "answer_id": 405297, "author": "Jiaaro", "author_id": 2908, "author_profile": "https://Stackoverflow.com/users/2908", "pm_score": 2, "selected": false, "text": "\nfrom new import classobj\nmy_class=classobj('Foo',(object,),{})\n\n" }, { "answer_id": 405331, "author": "S.Lot...
2009/01/01
[ "https://Stackoverflow.com/questions/405282", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
405,288
<p>Consider this trigger:</p> <pre><code>ALTER TRIGGER myTrigger ON someTable AFTER INSERT AS BEGIN DELETE FROM someTable WHERE ISNUMERIC(someField) = 1 END </code></pre> <p>I've got a table, someTable, and I'm trying to prevent people from inserting bad records. For the purpose of this question, a bad record has a field "someField" that is all numeric.</p> <p>Of course, the right way to do this is NOT with a trigger, but I don't control the source code... just the SQL database. So I can't really prevent the insertion of the bad row, but I can delete it right away, which is good enough for my needs.</p> <p>The trigger works, with one problem... when it fires, it never seems to delete the just-inserted bad record... it deletes any OLD bad records, but it doesn't delete the just-inserted bad record. So there's often one bad record floating around that isn't deleted until somebody else comes along and does another INSERT.</p> <p>Is this a problem in my understanding of triggers? Are newly-inserted rows not yet committed while the trigger is running?</p>
[ { "answer_id": 405295, "author": "ConcernedOfTunbridgeWells", "author_id": 15401, "author_profile": "https://Stackoverflow.com/users/15401", "pm_score": 7, "selected": true, "text": "Inserted Deleted create table Foo (\n FooID int\n ,SomeField varchar (10)\n)\ngo\n\ncreate tri...
2009/01/01
[ "https://Stackoverflow.com/questions/405288", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4/" ]
405,320
<p>Each page of my site has 10 (almost) identical divs, varying only in the text within. When a certain part of a div is clicked, I want a different part of that div to be modified.</p> <p>I'm using this code:</p> <pre><code>$(document).ready(function(){ $(".notLogged img").mouseover(function(){ $(this).parent()&gt;$("span").html("You must be logged in to vote."); }) }) </code></pre> <p>I thought this would work as follows: For all <code>img</code> elements within a "notLogged" classed div, a mouseover would cause a different part of that div to change.</p> <p>However, that's not what happens. Whenever that mouseover event is triggered, <em>all</em> divs with the "notLogged" class are modified.</p> <p><strong>How can I modify this code so only the div in which the mouseover originated is modified?</strong></p>
[ { "answer_id": 405330, "author": "Andreas Grech", "author_id": 44084, "author_profile": "https://Stackoverflow.com/users/44084", "pm_score": 4, "selected": true, "text": "$(document).ready(function(){\n $(\".notLogged img\").mouseover(function(){\n $(this).parent().find(\"span\").html(\...
2009/01/01
[ "https://Stackoverflow.com/questions/405320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1615/" ]
405,336
<p>Netbeans tells me it's bad to access a static method from a non static method. Why is this bad? "Accessing static method getInstance" is the warning:</p> <pre><code>import java.util.Calendar; public class Clock { // Instance fields private Calendar time; /** * Constructor. Starts the clock at the current operating system time */ public Clock() { System.out.println(getSystemTime()); } private String getSystemTime() { return this.time.getInstance().get(Calendar.HOUR)+":"+ this.time.getInstance().get(Calendar.MINUTE); } </code></pre> <p>}</p>
[ { "answer_id": 405348, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": false, "text": "Thread.sleep Thread t = new Thread(someRunnable);\nt.start();\nt.sleep(1000);\n suspend Thread.sleep" }, { "answ...
2009/01/01
[ "https://Stackoverflow.com/questions/405336", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
405,338
<p>Using the standard MVC set up in Zend Framework, I want to be able to display pages that have anchors throughout. Right now I'm just adding a meaningless parameter with the '#anchor' that I want inside the .phtml file.</p> <pre><code>&lt;?= $this-&gt;url(array( 'controller'=&gt;'my.controller', 'action'=&gt;'my.action', 'anchor'=&gt;'#myanchor' )); </code></pre> <p>This sets the URL to look like /my.controller/my.action/anchor/#myanchor</p> <p>Is there a better way to accomplish this? After navigation to the anchor link, the extra item parameter gets set in the user's URL which is something I would rather not happen.</p>
[ { "answer_id": 406720, "author": "Martin Rázus", "author_id": 39014, "author_profile": "https://Stackoverflow.com/users/39014", "pm_score": 5, "selected": true, "text": "class My_View_Helper_Url extends Zend_View_Helper_Url\n{ \n public function url(array $urlOptions = array(), $na...
2009/01/01
[ "https://Stackoverflow.com/questions/405338", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42523/" ]
405,364
<p>This question is for the java language in particular. I understand that there is a static protion of memory set aside for all static code.</p> <p>My question is how is this static memory filled? Is a static object put into static memory at import, or at first reference? Also, do the same garbage collection rules apply to static objects as they do for all other objects?</p> <pre><code> public class Example{ public static SomeObject someO = new SomeObject(); } /********************************/ // Is the static object put into static memory at this point? import somepackage.Example; public class MainApp{ public static void main( Sting args[] ){ // Or is the static object put into memory at first reference? Example.someO.someMethod(); // Do the same garbage collection rules apply to a // static object as they do all others? Example.someO = null; System.gc(); } } </code></pre>
[ { "answer_id": 405402, "author": "erickson", "author_id": 3474, "author_profile": "https://Stackoverflow.com/users/3474", "pm_score": 6, "selected": true, "text": "ClassLoader public class Foo {\n private static Foo instance = new Foo();\n private static final int DELTA = 6;\n private...
2009/01/01
[ "https://Stackoverflow.com/questions/405364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48728/" ]
405,379
<p>I am designing a helper method that does lazy loading of certain objects for me, calling it looks like this:</p> <pre><code>public override EDC2_ORM.Customer Customer { get { return LazyLoader.Get&lt;EDC2_ORM.Customer&gt;( CustomerId, _customerDao, ()=&gt;base.Customer, (x)=&gt;Customer = x); } set { base.Customer = value; } } </code></pre> <p>when I compile this code I get the following warning:</p> <blockquote> <p>Warning 5 Access to member 'EDC2_ORM.Billing.Contract.Site' through a 'base' keyword from an anonymous method, lambda expression, query expression, or iterator results in unverifiable code. Consider moving the access into a helper method on the containing type.</p> </blockquote> <p>What exactly is the complaint here and why is what I'm doing bad?</p>
[ { "answer_id": 405396, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": false, "text": "this" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/405379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
405,394
<p>Now I'm trying to work with System.Web.Routing. All is just fine, but I can't understand how to make form authentication work with url routing (return url, redirection, etc). Google says nothing. Help! :)</p> <p><strong>UPD:</strong> I forgot - I <strong>don't use MVC</strong>. That's the problem. How to use rounig and form authentication without MVC</p> <p><strong>UPD2:</strong> more about my problem <br /> What I want to get: urls such “<code>mysite.com/content/123</code>”, “<code>mysite.com/login/</code>”, etc using Routes. It’s important to make login page works like “regular” ASP.NET login form (redirects to login from secure area when not login on, and redirect back to secure area when loggined).<br /> That’s what I’m doing.<br /> In <code>global.asax</code> on <code>Application_Start</code>, register routes like this:<br /></p> <pre><code>routes.Add("LoginPageRoute", new Route("login/", new CustomRouteHandler("~/login.aspx"))); routes.Add("ContentRoute", new Route("content/{id}", new ContentRoute("~/content.aspx")) { Constraints = new RouteValueDictionary {{ "id", @"\d+" }} }); </code></pre> <p>Where <code>CustomRouteHandler</code> and <code>ContentRoute</code> – simple <code>IRouteHandler</code> classes, just like: ...</p> <pre><code>public IHttpHandler GetHttpHandler(RequestContext requestContext) { var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(Page)) as IHttpHandler; return page; } </code></pre> <p>...</p> <p>All seems to be perfect: I’m getting <code>content.aspx</code> when go to <code>“/content/10”</code> and <code>login.aspx</code> when go to <code>“/login/”</code>. But…<br /> When I make content secured (in <code>web.config</code>, with <code>deny=”?”</code>), login form doesn’t work like expected.<br /> Now I can’t reach the <code>“/content/10”</code> page: <br /> <br /><strong>0.</strong> I’m typing <code>“/content/10”</code> in my browser. <br /><strong>1.</strong> Site redirects to <code>“/login/?ReturnUrl=%2fcontent%2f10”</code>. (Hm… seems like all problems starts here, right? :) <br /><strong>2.</strong> I’m trying to log in. No matter what credentials I’m entered… <br /><strong>3.</strong> …site redirects me to <code>“login?ReturnUrl=%2fContent%2f10”</code> (yellow screen of error - <code>Access is denied.</code> Description: <code>An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL</code>.)<br /> So, the problem is how to get ASP.NET understand real <code>ReturnUrl</code> and provide redirection after login.</p>
[ { "answer_id": 435218, "author": "Dominic Betts", "author_id": 50911, "author_profile": "https://Stackoverflow.com/users/50911", "pm_score": 4, "selected": true, "text": " <?xml version=\"1.0\"?>\n <configuration>\n <system.web>\n <httpHandlers>\n <add path=\"*\" verb=\"...
2009/01/01
[ "https://Stackoverflow.com/questions/405394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50737/" ]
405,409
<p>I have</p> <pre><code>$.ajax({ url: identity, success: function(data) { ProcessIdentityServer(data) } }); </code></pre> <p>When 'data' is returned, is there a way to run selectors against it without adding it into the DOM. So for example, how can I get all the href values of any LINK tags contained in the HTML held in 'data' without adding it to the DOM first? Seems a shame to have to add it into the DOM if all I want to do is extract some stuff into an array. Anyone got any ideas?</p>
[ { "answer_id": 405417, "author": "nakajima", "author_id": 39589, "author_profile": "https://Stackoverflow.com/users/39589", "pm_score": 4, "selected": false, "text": "data $(data).find('a');\n" }, { "answer_id": 405427, "author": "Beau Simensen", "author_id": 50453, "...
2009/01/01
[ "https://Stackoverflow.com/questions/405409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39655/" ]
405,415
<p>Given this line of code in C:</p> <blockquote> <p><code>printf("%3.0f\t%6.1f\n", fahr, <strong>(</strong>(5.0/9.0) * (fahr-32)<strong>)</strong>);</code></p> </blockquote> <p>Is there a way to delete or yank from the first bold parenthesis to its matching parenthesis? I thought about <strong>df)</strong>, but that only will get you to just after the 9.0.</p> <p>Is there a similar way to get vim to grab everything between matching braces, regardless of newlines?</p>
[ { "answer_id": 405420, "author": "David Norman", "author_id": 34502, "author_profile": "https://Stackoverflow.com/users/34502", "pm_score": 4, "selected": false, "text": "v%y v%d" }, { "answer_id": 405425, "author": "ahy1", "author_id": 42761, "author_profile": "https...
2009/01/01
[ "https://Stackoverflow.com/questions/405415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50111/" ]
405,426
<p>In Java, it would look like this:</p> <pre><code>class Foo { float[] array; } Foo instance = new Foo(); instance.array = new float[10]; </code></pre>
[ { "answer_id": 405431, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 5, "selected": true, "text": "float *array;\n// Allocate 10 floats -- always remember to multiple by the object size\n// when calling malloc\narray...
2009/01/01
[ "https://Stackoverflow.com/questions/405426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50335/" ]
405,429
<p>Coming from a C++ background, I've run into a snag with overloading based on a specific instance of a generic type. The following doesn't work since only once instance of the code for the <code>Foo&lt;T&gt;</code> class is ever generated, so inside the <code>Method</code>, the type of <code>this</code> is simply <code>Foo&lt;T&gt;</code>, not <code>Foo&lt;A&gt;</code> or <code>Foo&lt;B&gt;</code> as I'd hoped. In C++ I'm used to templates being instantiated as unique types.</p> <pre><code>using System.Collections.Generic; class A { // Concrete class } class B { // Concrete class } class Bar { public void OverloadedMethod(Foo&lt;A&gt; a) {} // do some A related stuff public void OverloadedMethod(Foo&lt;B&gt; b) {} // do some B related stuff public void OverloadedMethod(OtherFoo of) {} // do some other stuff public void VisitFoo(FooBase fb) { fb.Method(this); } } abstract class FooBase { public abstract void Method(Bar b); } class Foo&lt;T&gt; : FooBase { // Class that deals with As and Bs in an identical fashion. public override void Method(Bar b) { // Doesn't compile here b.OverloadedMethod(this); } } class OtherFoo : FooBase { public override void Method(Bar b) { b.OverloadedMethod(this); } } class Program { static void Main(string[] args) { List&lt;FooBase&gt; ListOfFoos = new List&lt;FooBase&gt;(); ListOfFoos.Add(new OtherFoo()); ListOfFoos.Add(new Foo&lt;A&gt;()); ListOfFoos.Add(new Foo&lt;B&gt;()); Bar b = new Bar(); foreach (FooBase fb in ListOfFoos) b.VisitFoo(fb); // Hopefully call each of the Bar::Overloaded methods } } </code></pre> <p>Is there a way to get something like this to work in C#? I'd rather not have to duplicate the code in Foo as separate classes for every type I want to use it for.</p> <p>Edit: Hopefully this is a little clearer.</p>
[ { "answer_id": 405451, "author": "BenAlabaster", "author_id": 40650, "author_profile": "https://Stackoverflow.com/users/40650", "pm_score": 0, "selected": false, "text": "class Stuff<T>\n{\n public T value { get; set; }\n}\n\nclass Program\n{\n static void DummyFunc(Stuff<int> inst...
2009/01/01
[ "https://Stackoverflow.com/questions/405429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8701/" ]
405,432
<p>I want to fill a map with class name and method, a unique identifier and a pointer to the method.</p> <pre><code>typedef std::map&lt;std::string, std::string, std::string, int&gt; actions_type; typedef actions_type::iterator actions_iterator; actions_type actions; actions.insert(make_pair(class_name, attribute_name, identifier, method_pointer)); //after which I want call the appropriate method in the loop while (the_app_is_running) { std::string requested_class = get_requested_class(); std::string requested_method = get_requested_method(); //determine class for(actions_iterator ita = actions.begin(); ita != actions.end(); ++ita) { if (ita-&gt;first == requested_class &amp;&amp; ita-&gt;second == requested_method) { //class and method match //create a new class instance //call method } } } </code></pre> <p>If the method is static then a simple pointer is enough and the problem is simple, but I want to dynamically create the object so I need to store a pointer to class and an offset for the method and I don't know if this works (if the offset is always the same etc).</p> <p>The problem is that C++ lacks reflection, the equivalent code in a interpreted language with reflection should look like this (example in PHP):</p> <pre><code>$actions = array ( "first_identifier" =&gt; array("Class1","method1"), "second_identifier" =&gt; array("Class2","method2"), "third_identifier" =&gt; array("Class3","method3") ); while ($the_app_is_running) { $id = get_identifier(); foreach($actions as $identifier =&gt; $action) { if ($id == $identifier) { $className = $action[0]; $methodName = $action[1]; $object = new $className() ; $method = new ReflectionMethod($className , $methodName); $method -&gt; invoke($object); } } } </code></pre> <p>PS: Yes I'm trying to make a (web) MVC front controller in C++. I know I know why don't use PHP, Ruby, Python (insert your favorite web language here) etc?, I just want C++.</p>
[ { "answer_id": 405452, "author": "strager", "author_id": 39992, "author_profile": "https://Stackoverflow.com/users/39992", "pm_score": 3, "selected": false, "text": "class MyClass\n{\n public:\n void function();\n};\n\nvoid (MyClass:*function_ptr)() = MyClass::function;\n\nMyCl...
2009/01/01
[ "https://Stackoverflow.com/questions/405432", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47537/" ]
405,433
<p>I'm am looking for specific suggestions or references to an algorithm and/or data structures for encoding a list of words into what would effectively would turn out to be a spell checking dictionary. The objectives of this scheme would result in a very high compression ratio of the raw word list into the encoded form. The only output requirement I have on the encoded dictionary is that any proposed target word can be tested for existence against the original word list in a relatively efficient manner. For example, the application might want to check 10,000 words against a 100,000 word dictionary. It is <strong><em>not</em></strong> a requirement for the encoded dictionary form to be able to be [easily] converted back into the original word list form - a binary yes/no result is all that is needed for each word tested against the resulting dictionary.</p> <p>I am assuming the encoding scheme, to improve compression ratio, would take advantage of known structures in a given language such as singular and plural forms, possessive forms, contractions, etc. I am specifically interested in encoding mainly English words, but to be clear, the scheme must be able to encode any and all ASCII text "words".</p> <p>The particular application I have in mind you can assume is for embedded devices where non-volatile storage space is at a premium and the dictionary would be a randomly accessible read-only memory area.</p> <p><strong><em>EDIT</em></strong>: To sum up the requirements of the dictionary:</p> <ul> <li>zero false positives</li> <li>zero false negatives</li> <li>very high compression ratio</li> <li>no need for decompression</li> </ul>
[ { "answer_id": 405454, "author": "jamesh", "author_id": 4737, "author_profile": "https://Stackoverflow.com/users/4737", "pm_score": 2, "selected": false, "text": "/usr/share/dict/words" } ]
2009/01/01
[ "https://Stackoverflow.com/questions/405433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1553/" ]
405,478
<p>Currently I am binding a dataset with a datagrid.</p> <pre><code>ds = query.ExecuteReadQuery("select PollQuestionText as 'Survey Question', PollAnswer1Text as 'Selection 1', PollAnswer2Text as 'Selection 2', PollAnswer3Text as 'Selection 3', PollEnabled 'Status' from tbl_pollquestions") For Each row As Data.DataRow In ds.Tables(0).Rows If row.ItemArray(4).ToString = "0" Then row.ItemArray."&lt;a href=""""&gt; &lt;img src=""img/box_icon_edit_pencil1.gif"" border=""0""&gt; &lt;/a&gt;" ElseIf row.ItemArray(4).ToString = "1" Then row.Item(4) = "&lt;a href=""""&gt; &lt;img src=""img/box_icon_edit_pencil2.gif"" border=""0""&gt; &lt;/a&gt;" End If Next GridView1.DataSource = ds GridView1.DataBind() </code></pre> <p>Since I am inserting html code, why this is not being converted to html?</p> <p>The output result is all text. (Suppose an icon is being displayed with no redirect url)</p> <p>I dont know why.</p> <p>Thanks</p>
[ { "answer_id": 405755, "author": "Salamander2007", "author_id": 10629, "author_profile": "https://Stackoverflow.com/users/10629", "pm_score": 3, "selected": true, "text": "RowDataBound <asp:GridView ID=\"GridView1\" runat=\"server\" onrowdatabound=\"GridView1_RowDataBound\">\n</asp:GridV...
2009/01/01
[ "https://Stackoverflow.com/questions/405478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44973/" ]