input
stringlengths
51
42.3k
output
stringlengths
18
55k
PHP Regex Question <p>I have a series of urls in a web doc, something like this:</p> <pre><code>&lt;a href="somepage.php?x=some_document.htm"&gt;click here&lt;/a&gt; </code></pre> <p>What I want to do is replace the bold piece:</p> <p>&lt;a href="somepage.php?x=<strong>some_document.htm</strong>"&gt;click here&lt;/a...
<p>I think you are looking for something like this:</p> <pre><code>function doSomething($matches) { return base64_encode($matches[1]); } preg_replace_callback('/href="somepage.php?x=([^"]+)"/', 'doSomething', $webdoc); </code></pre> <p>The <code>preg_replace</code> answer works similarly. If you want to do someth...
jQuery: Making simultaneous ajax requests, is it possible? <p>I am using jQuery to try and retrieve multiple pieces of data at the same time. The background of the requirement is that different bits of data take various lengths of time to become available, so I want to display each piece as it is returned.</p> <p>The ...
<p>You want asynchronous (which is the default). The browser limits you to two requests at any given time. This is part of the HTTP specification. (<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.4">HTTP 1.1 specification, section 8.1.4</a>)</p> <p>Putting the requests into the queue is your best...
How to prevent "This program might not have installed correctly" messages on Vista <p>I have a product setup executable that copies some files to the user's hard drive. It's not a typical installer in the normal sense (it doesn't add anything to the Start Menu or Program Files folders). </p> <p>Each time the setup pro...
<p>Include this section in the program's manifest file:</p> <pre><code>&lt;compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"&gt; &lt;application&gt; &lt;!--The ID below indicates application support for Windows Vista --&gt; &lt;supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/&gt; ...
EntityKey and ApplyPropertyChanges() <p>I need to set an EntityObject's EntityKey. I know its type and its id value. I don't want to query the database unnecessarily.</p> <p>This works...</p> <pre><code>// // POST: /Department/Edit/5 [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(Guid id, Department Model) ...
<p>The reason your second block of code fails is because EF can't find the object in the ObjectStateManager - i.e. when it pulls objects from the db it puts them in the state manager so it can track them - this is similar to the <a href="http://www.martinfowler.com/eaaCatalog/identityMap.html" rel="nofollow">Identity M...
Antonyms of "parsing" in terms of XML <p>What is the antonyms of "parsing" in terms of XML document.</p> <p>For Example:</p> <ul> <li>When you are reading an XML file by using DOM parser, it is called "Parsing".</li> <li>When you create an XML file by using DOM parser, what does it called?</li> </ul>
<p>Serialization</p>
How to disable SQL Server Management Studio for a user <p>Is there a way to prevent users from getting into SQL Server Management Studio so that they can't just edit table rows manually? They still need to access the tables by running my application.</p>
<p>You can use the <strong><a href="http://msdn.microsoft.com/en-us/library/ms189077.aspx">DENY VIEW ANY DATABASE</a></strong> command for the particular user(s). This is a new feature available in SQL Server 2008. </p> <p>It prevents the user from seeing the system catalog (sys.databases, sys.sysdatabases, etc.) and ...
Searching sub-models with Ferret <p>I have a rails app in which I am trying to do some full text searching on. Ferret seems to be the most popular choice. However, I have an issue.</p> <p>I have a 'thing' which contains an id which determines if a user can see it (and therefore search it), but I want to search sub-m...
<p>I think it would be very wrong to assume that Ferret is the most popular choice for this. Most people I know have ditched Ferret and replaced it with Sphinx. And the people who can't use Sphinx for some reason have opted for Xapian.</p> <p>That said, the answer to your question is likely to be largely the same re...
Using JXPath to Query a List <p>I have a simple class (for testing purposes) that I am trying to Query against using JXPath. </p> <p>I create a list of various animal objects, and I want to get an Iterator for:</p> <ol> <li><p>All Animals where type='CAT' </p></li> <li><p>All Animals where numLegs = 4</p></li> </ol...
<p>I've never used JXPath, but i would expect there to be a root node, in which case </p> <pre><code>/*[type='CAT'] </code></pre> <p>would mean "give me the root node, only if it has an attribute of type equal to CAT"</p> <p>I think what you are after is something more like </p> <pre><code>/*/*[type='CAT'] </co...
What are the best learning resources to teach ASP.NET MVC to an ASP.NET programmer? <p>What materials do you recommend for an experienced ASP.NET to learn ASP.NET MVC?</p>
<p>If you learn by reading books I would suggest checking out <a href="http://rads.stackoverflow.com/amzn/click/0470384611" rel="nofollow">Professional ASP.NET MVC 1.0</a>. It is written by Scott Hanselman, <a href="http://stackoverflow.com/users/598/haacked">Phil Haack</a>, Scott Guthrie and Rob Conery. <a href="http...
Does Enterprise Library 1.0 support sql server 2005 <p>I used to connect to SQL Server2000. If it is possible to change to SQL Server2005? If yes, how to change the settings? thanks a lot.</p>
<p>You can connect to MSSQL2k5 using basically the same connection strings, backwards compatibility is a major feature of the MS platform.</p> <p>Be aware that you'll need to migrate tables, and possibly databases, into the new server's mounted databases.</p> <p>The EntLib 1.0 code doesn't to my recollection take adv...
using sessions in asp.net <p>I would like the data that i enter in a text box on pageA to be accessable on pageB</p> <p>eg: User enters their name in text box on page A</p> <p>page B says Hello (info they entered in text box)</p> <p>I heard this can be accomplished by using a session but i don't know how.</p> <p>c...
<pre><code>Session["valueName"]=value; </code></pre> <p>or </p> <pre><code>Session.Add("valueName",Object); </code></pre> <p>And You can retrieve the value in label (for Example) By</p> <pre><code>/*if String value */ Label1.Text=Session["valueName"].ToString(); </code></pre> <p>or </p> <pre><code>Label1.Tex...
Expression parsing: how to tokenize <p>I'm looking to tokenize Java/Javascript-like expressions in Javascript code. My input will be a string containing the expression, and the output needs to be an array of tokens.</p> <p>What's the best practice for doing something like this? Do I need to iterate the string or is th...
<p>Learn to write a recursive-descent parser. Once you understand the concepts, you can do it in any language: Java, C++, JavaScript, SystemVerilog, ... whatever. If you can handle strings then you can parse.</p> <p>Recursive-descent parsing is a basic technique for parsing that can easily be coded by hand. This is us...
nant script doesn't display unit test details <p>Can someone please tell me why my build script (nant) doesn't display the unit test details in the command prompt window? I have verbose set to true, but it doesn't want to display any details about my unit tests. Here's the target:</p> <pre><code>&lt;target name="run-u...
<p>I found the answer. I looked at the source for CodeCampServer and saw a line </p> <pre><code>&lt;formatter type="Plain" /&gt; </code></pre> <p>and added it to my build script so it looks like this:</p> <pre><code>&lt;nunit2 haltonfailure="true" failonerror="true" verbose="true"&gt; &lt;formatter type="Xml" ...
LINQ - Where not exists <p>What is the equivalent of following statement in LINQ:</p> <pre><code>Select t1.appname, t1.julianDte, t1.cat From table1 t1 Where NOT EXISTS ( Select * from table t2 where t1.cat = t2.cat AND t2.julianDte &lt; t1.julianDte ) </code></pre>
<p>Try this <code>Not Any</code> pattern.</p> <pre><code>var query = db.table1 .Where(t1 =&gt; !db.table2 .Any(t2 =&gt; t2.cat == t1.cat &amp;&amp; t2.julianDte &lt; t1.julianDte) ); </code></pre>
Is it possible to use VBScript or JScript to instantiate SharePoint objects? <p>I want to be able to run VBScript or JScript on a server using cscript.exe to manipulate SharePoint through the object model.</p> <p>For example, to update the log file location:</p> <pre><code>Microsoft.SharePoint.Administration.SPDiagno...
<p>OTTOMH, you could probably create <a href="http://msdn.microsoft.com/en-us/library/f07c8z1c.aspx" rel="nofollow">COM-callable wrappers</a> for the classes you need, if you have relatively simple needs. My guess is that this will be more trouble than it's worth and that some small console apps would be a better use ...
BC30560: 'default_aspx' is ambiguous in the namespace 'ASP' <p>When I compiled my latest asp.net program and trying to run on the test server, I am getting this error</p> <pre><code>Line 46: Dim dependencies() As String Line 47: CType(Me,Global.System.Web.UI.Page).AppRelativeVirtualPath = "~/de...
<p>Okay here is what I found after spending three days on this problem.</p> <p>Finally I figured that if I removed all the projects from the solution except one (that was causing problem) I could isolated it to default.skin. The problem seemed to be very erratic because it started going away if I deleted certain lines...
How can I set the background color of a cell in UITableView on iphone? <p>How can I set the background color of a cell in UITableView?</p> <p>Thanks.</p>
<p>I know this is an old post, but I am sure some people are still looking for help. You can use this to set the background color of an individiual cell, which works at first:</p> <pre><code>-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { [cell setBackgroundCol...
database encryption <p>I have a desktop application that needs to read data from a database, both installed on client computer.</p> <p>That data in database must be encrypted, to deny client access, and protect data.</p> <p>I need to know what kind of database to use that can supports encryption, because the amount o...
<p>SQL Server 2008 includes a feature called Transparent Data Encryption which may do what you need. I don't know if Compact Edition contains this feature. A little googling with those keywords should get you started. I don't normally advocate using SQL Server, but in this case I'm not aware of any similar features ...
Losing network connectivity on iPhone <p>I am developing a network application on iPhone that requires internet connection all the time. However, once I login to the server and keep the iPhone idle for a while, the iPhone goes to sleep mode and disconnects my network connection (it logs me out). </p> <p>If I run the s...
<p>In your application delegate ("appDelegate"), disable the idle timer in the <code>+initialize</code> method:</p> <pre><code>myApp.idleTimerDisabled = YES; </code></pre> <p>Note that this will keep your iPhone from sleeping while your app is open. This can present issues with battery life.</p> <p>Another option mi...
Resharper on VS2010? <p>Did anybody get resharper 4.5 working on V2010 ? </p>
<p>Wait few days and try ReSharper for VS2010 - <a href="http://blogs.jetbrains.com/dotnet/2009/05/preview-of-resharper-for-visual-studio-2010-coming-soon/" rel="nofollow">http://blogs.jetbrains.com/dotnet/2009/05/preview-of-resharper-for-visual-studio-2010-coming-soon/</a></p>
How to copy the contents of a String to the clipboard in C#? <p>If I have some text in a String, how can I copy that to the clipboard so that the user can paste it into another window (e.g. from my application to Notepad)?</p>
<p>You can use <code>System.Windows.Forms.Clipboard.SetText(...)</code>.</p>
Can you require a function parameter to be a static constant of the function's Class? <p>Let's say I have a Custom Event Class, and it has several Event types stored in static Constant:</p> <pre><code>package customEvents { public class { public static const DISAPPEAR_COMPLETELY:String = "disappearCom...
<p>To extend off of Dan R's answer, you could create a strict event (like the way you'd do enums) class like so:</p> <pre><code>import flash.utils.Dictionary; import flash.utils.describeType; import flash.utils.getQualifiedClassName; public class StrictEvent { private static var VALID_EVENTS:Dictionary = new Dic...
Programmatically creating list from CheckoutStepsTemplate throws exception <p>(This question has been cross-posted on the MSDN forums <a href="http://social.msdn.microsoft.com/Forums/en-US/commserver2007/thread/e85820a0-1436-4926-8b07-ad5f008ea884" rel="nofollow">here</a>.)</p> <p>I'm working on a custom SharePoint/Co...
<p>I never found a full solution to this issue, but I did diagnose enough of the issue that we found an acceptable workaround. It turns out that the problem only occurred when provisioning elements through modules in the same feature, but when those modules are included in a different feature, everything worked fine.</...
How do I write unit tests in PHP with a procedural codebase? <p>I'm mostly convinced of the benefits of unit testing, and I would like to start applying the concept to a large existing codebase written in PHP. Less than 10% of this code is object-oriented.</p> <p>I've looked at several unit testing frameworks (PHPUni...
<p>You can unit-test procedural PHP, no problem. And you're definitely not out of luck if your code is mixed in with HTML.</p> <p>At the application or acceptance test level, your procedural PHP probably depends on the value of the superglobals (<code>$_POST, $_GET, $_COOKIE</code>, etc.) to determine behavior, and en...
Getting the application executable name from T-SQL stored procedure <p>From a stored procedure in SQL Server, is it possible to get the name of the executable (ie MyApp.exe) that owns the connection? I know there is APP_NAME(), but that appears to just return whatever string was passed into the 'Application Name' para...
<p>Unless you modify your stored procedure to pass the app name, you're stuck with the results of APP_NAME(). Hopefully, developers are placing meaningful values in there rather than just accepting the default value which is generally an indication of the development tool used to build the app.</p> <p>Hope this helps...
How can I recursively visit links without revisiting links? <p>I want to check a site for links, and then recursively check those sites for links. But I don't want to fetch the same page twice. I'm having trouble with the logic. This is Perl code:</p> <pre><code>my %urls_to_check = (); my %checked_urls = (); &amp;...
<p>Simplest thing to do would be to not reinvent the wheel and use <a href="http://search.cpan.org/dist/W3C-LinkChecker/" rel="nofollow">the CPAN</a>.</p>
American cities with special characters in the name <p>Is there any site or reference which would list any American cities with special characters (such as &aacute; or even just weird punctuation) in the name? While this isn't technically a programming question, it's related to a regular expression we're trying to de...
<p>Here's a <a href="http://en.wikipedia.org/wiki/List%5Fof%5Fcities,%5Ftowns,%5Fand%5Fvillages%5Fin%5Fthe%5FUnited%5FStates" rel="nofollow">list of every city and town in the US</a>. You'll have to put everything together and then search for irregular characters.</p>
Suggestions for software architecture style to use between Java and Windows <p>Here is an interesting combination, I need to transfer data between an "appliance" running Windows XP Home and a remote Linux server on the internet. Let me itemize what needs to happen:</p> <ol> <li>The "xp home" system needs to transfer ...
<p>Since the application is new and if you need a strong real time data share I could recommend you to use shared database. You can install on one of these hosts.</p> <p>Any way web services solution is too complex. Use the same technology on both machines and you will be able to use the language-specific features of ...
Can't add to a Double type <p>I have a double value I would like to increment, using the following snippet:</p> <pre><code> Total = CDbl(Total + CDbl(Workbooks(1).Worksheets(1).Cells(1,1).Value)) </code></pre> <p>The code continuously returns a type mismatch error, even though the cell it points to has a decim...
<p>Make sure that the cell you are pointing to actually contains a number, and not merely the number's text representation.</p> <p>To convert a text cell to a number, select the cell, and then select Format/Cells from the menu bar, and then on the number tab, click General.</p>
VS2008 and SQL Express 2008 <p>How do I make the SQL Express 2008 the default for VS2008 instead of SQL Express 2005?</p>
<p>If you're adding MDF's to your web site folder, I think you're using a feature called <a href="http://technet.microsoft.com/en-us/library/bb264564%28SQL.90%29.aspx" rel="nofollow">User Instances</a>. That's hardly advisable, and it's <a href="http://msdn.microsoft.com/en-us/library/ms143684.aspx" rel="nofollow">bei...
How can I add CGPoint objects to an NSArray the easy way? <p>I have about 50 CGPoint objects that describe something like a "path", and I want to add them to an NSArray. It's going to be a method that will just return the corresponding CGPoint for an given index. I don't want to create 50 variables like p1 = ...; p2 = ...
<p>With <code>UIKit</code> Apple added support for CGPoint to <code>NSValue</code>, so you can do:</p> <pre><code>NSArray *points = [NSArray arrayWithObjects: [NSValue valueWithCGPoint:CGPointMake(5.5, 6.6)], [NSValue valueWithCGPoint:CGPointMake(7.7, 8.8)], ...
Is there a way to put a scalar type like CGPoint (or any self created) into a NSArray? <p>Probably I could create a class that holds an CGPoint as instance variable, like a wrapper. Does that make sense? I feel uncomfortable with that, though. I hope there is an better solution.</p> <p>How about any self-created scala...
<p>Make it an object. You could try this: </p> <pre><code>CGPoint point = CGPointMake(1.f,1.f); [NSValue valueWithCGPoint:point]; </code></pre> <p>This goes for pretty much every scalar you want to put in an NSArray:</p> <pre><code>CGFloat foo = 1.f; [NSNumber numberWithFloat:foo]; </code></pre>
JFrame in Java <p>I am using a JFrame as a pop-up from a main frame, where the user is supposed to enter some information and then press OK. But the problem is that once this sub-frame has opened up, I want the program to ignore any other signal until the OK button is pressed, similar as how it is done with JOptionPane...
<p>You need a <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html" rel="nofollow"><code>JDialog</code></a> with <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog%28java.awt.Frame,%20boolean%29" rel="nofollow"><code>modal = true</code></a>. From the Javadocs:</p> <block...
Is there a faster way to get a random record from a MySQL table through ActiveRecord? <p>In a Rails application, I'm using this to get a random row from a MySQL table:</p> <pre><code>contact = Contact.find(:all, :limit =&gt; 1, :order =&gt; 'RAND()')[0] </code></pre> <p>Even though the table only has about 20,000 row...
<p>I don't think my first answer will help you. <a href="http://akinas.com/pages/en/blog/mysql%5Frandom%5Frow/" rel="nofollow">Perhaps this Article will</a></p>
How can I programmatically determine CPU usage rate or how busy / occupied the system is in iPhone-OS? <p>My app is doing some pretty but heavy weight core animations during scrolling. Sometimes it crashes due to bad performance. So I need some way to find out if there is enough capability to make the animations, and i...
<p>By animation, do you mean frames that play after one another (like an animated GIF) or some CoreAnimation (OpenGL) effect that is moving polygons with mapped textures around?</p> <p>If it's the former, I'd really consider some way of optimizing the animation or eliminating it in all cases.</p> <p>If it's the latte...
Example of a Multi Condition Delete with Zend framework <p>Can someone give me an example of how I would delete a row in mysql with Zend framework when I have two conditions?</p> <p>i.e: (trying to do this)</p> <pre><code>"DELETE FROM messages WHERE message_id = 1 AND user_id = 2" </code></pre> <p>My code (that is f...
<p>Better to use this:</p> <pre><code>$condition = array( 'message_id = ?' =&gt; $messageId, 'profile_id = ?' =&gt; $userId ); </code></pre> <p>The placeholder symbols (?) get substituted with the values, escapes special characters, and applies quotes around it.</p>
My scratchbox 2 installation is using an ARM gcc build to compile for the ARM target. How do I fix this? <p>I'm using scratchbox 2, the maemo development cross-compilation environment. When compiling code for the ARM target, I think scratchbox 2 is using the native ARM gcc compiler, which runs very slow on my x86 machi...
<p>After wrestling with this for a really long time, it seems the best solution is to simply reinstall Scratchbox 2.</p> <p>Make sure to delete the following directories:</p> <pre><code>~/.maemo-sdk ~/.scratchbox2 /opt/maemo </code></pre> <p>And then run:</p> <pre><code>apt-get install maemo-sdk --reinstall </code>...
Prototype PeriodicExecutor doesn't update source <p>I have a script that updates a table when there are new entries in the database. It pulls a time from the last row in the table and then grabs all the entries that were entered since then.</p> <p>It runs fine the first time, it grabs the new entries and updates the t...
<p>I've not used Prototype before, so this is a wild guess, but it could just be caching the call as it's defaulting to GET. Try the following parameters is your call after the url</p> <pre><code>{ asynchronous:true, method: 'post', evalScripts:true, parameters:'authenticity_token=' + encodeURICompon...
Java: Does Collections.unmodifiableXYZ(...) in special cases make a collection object a flyweight? <p>The possible answers are either <strong>"never"</strong> or <strong>"it depends"</strong>.</p> <p>Personally, I would say, <strong>it depends</strong>.</p> <p>Following usage would make a collection appear (to me) to...
<p>i think you are referring to the <a href="http://en.wikipedia.org/wiki/Flyweight%5Fpattern" rel="nofollow">flyweight pattern.</a> the fundamental idea of this pattern is that you are dealing with complex objects whose instances can be reused, and put out different representations with its methods. </p> <p>to make s...
Difference between long and int data types <p>Considering that the following statements return <code>4</code>, what is the difference between the <code>int</code> and <code>long</code> types in C++?</p> <pre><code>sizeof(int) sizeof(long) </code></pre>
<p>From <a href="http://tsemba.org/c/inttypes.html">this</a> reference:</p> <blockquote> <p>An int was originally intended to be the "natural" word size of the processor. Many modern processors can handle different word sizes with equal ease.</p> </blockquote> <p>Also, this bit:</p> <blockquote> <p>On ma...
C++ project source code layout <p>One of the popular way to organize project directory is more or less like this:</p> <pre> MyLib +--mylib_class_a.h mylib_class_a.cpp mylib_library_private_helpers.h mylib_library_private_helpers.cpp MyApp +--other_class.h other_class.cpp ...
<p>Well, it all depends on how big these projects are. If you've only got a few files, then whack them all in one folder.</p> <p>Too many folders when you haven't got many files to manage is in my opinion overkill. It gets annoying digging in and out of folders when you've only got a few files in them.</p> <p>Also, i...
Set the text color in a Java textbox <p>How does one set the color of text in a Java Swing textbox at run-time? At startup, the color is grayish and when the user enters the textbox, I wish to change the color to the normal text color. I am currently using the following code:</p> <pre><code>private void txtScheduleInf...
<p>Did you make sure the JTextBox is enabled? You can call <code>setEnabled(true)</code> on it to make sure. Not trying to be rude, that's just the most likely cause (there's code in Swing to force graying-out of disabled components).</p> <p>If that doesn't fix it, you can also trigger a repaint by calling txtSchedu...
Elegant way to compare sequences <p>Does python provide an elegant way to check for "equality" of sequences of different types? The following work, but they seem rather ugly and verbose for python code:</p> <pre><code>def comp1(a, b): if len(a) != len(b): return False for i, v in enumerate(a): ...
<p>Convert both sequences to lists, and use builtin list comparison. It should be sufficient, unless your sequences are really large.</p> <pre><code>list(a) == list(b) </code></pre> <p>Edit:</p> <p>Testing done by schickb shows that using tuples is slightly faster:</p> <pre><code>tuple(a) == tuple(b) </code></pre>
RegExp in ActionScript 3: How to exclude a complex prefix? <p>AS3 RegExp engine (and ECMAScript based JavaScript) do not support <strong>complex</strong> "lookbehind" expressions. (lookahead expressions are fully supported.) </p> <p>For example:</p> <pre><code> (?&lt;=&lt;body&gt;)(.*?)(?=&lt;\/body&gt;) </code></pre...
<p>This is coming from my JavaScript RegExp experience, but it should be relatively similar...</p> <p>I don't think you need look-behind, you just need non-capturing groups. They still match input, but they aren't captured by the match:</p> <pre><code>(?:&lt;body\b[^&gt;]*&gt;)(.*?)(?:&lt;\/body&gt;) </code></pre> ...
system.web.routing on a web server not working <p>I have read all these articles about how to make system.web.routing work but all these articles explains on localhost:port. I can get this working on the local machine, but as soon as I upload the site on the server, the Routing stops working no matter what I do. </p> ...
<p>For IIS7+ i found adding to the web.config's section suddenly made everything work:</p> <pre><code>&lt;modules runAllManagedModulesForAllRequests="true" /&gt; </code></pre> <p>Confusing as in VS running on the Cassini web server, it worked just fine.</p>
what could some of the reason be to why a cookie wont be destroyed? <p>i have a cookie named MVCID that's set and its value is some generated hash. when i write this</p> <pre><code>setcookie("MVCID","", time()-60*60*24); </code></pre> <p>and load the page, not only is the contents of the cookie not being erased but i...
<p>Try passing "/" as the fourth parameter -- <em>path</em>.</p>
Git: checking out a file from a previous commit and amending it to HEAD <p>I recently committed a file to the HEAD of my branch which has errors in it. I need to do the following things:</p> <ul> <li> Get that file from one commit previous to HEAD </li><br /> <li> Commit that file back into HEAD </li><br /> </ul> ...
<p>You've practically said it yourself:</p> <p>First get the file back from one commit before:</p> <pre><code>$&gt; git checkout HEAD~1 path/to/file.ext </code></pre> <p>Then commit it:</p> <pre><code>$&gt; git commit -a -m 'Retrieved file from older revision' </code></pre> <p>If only the changes to that file wher...
General String Encryption <p>I am looking for a general string encryption class in .NET. (Not to be confused with the 'SecureString' class.)</p> <p>I have started to come up with my own class, but thought there must be a .NET class that already allows you to encrypt/decrypt strings of any encoding with any Cryptograp...
<p>The <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.aes.aspx" rel="nofollow">AES</a> algorithm for symmetric encryption is generally the way to go for generic encryption of strings. However, I'm afraid that the .NET BCL doesn't simplify things any further for you the providing the basic...
Can I access the href of my ajax request in the javascript of my request? <p>Here a sample use case:</p> <p>I request a simple form via an ajax request. I want to submit the result to the same page that I requested. Is there a way to access the URL of that request in the resulting request's javascript?</p> <p>Below i...
<p>You can store the url to submit to in the <code>action</code> attribute of the form, and then set the <code>url</code> to <code>frm.action</code>:</p> <pre><code>jQuery.ajax({ url : frm.action, type : 'POST', data : data, dataType: "html", success : f...
How can I use a SQL Scripts in a Database Project with the System.Data.SQLite data provider? <p>I've got a project where I'm attempting to use SQLite via <a href="http://sqlite.phxsoftware.com/" rel="nofollow">System.Data.SQLite</a>. In my attempts to keep the database under version-control, I went ahead and created a ...
<p>Well, your script looks like a SQL Server stored procedure. SQLite most likely doesn't support this, because</p> <ol> <li>It doesn't support stored procedures, and</li> <li>It doesn't understand SQL Server T-SQL</li> </ol> <p>SQL is actually a pseudo-standard. It differs between vendors and sometimes even betwee...
If I have limited time to learn a few design patterns, which ones should I learn? <p>If I have limited time, but I want to start learning a few design patterns, which ones should I learn first?</p>
<p>I'd suggest Inversion of Control/Dependency Injection. This comes in very handy when unit testing as it enables you to supply mock dependencies for the class under test. Proxy is also very useful when wrapping a sealed class to make it more usable in testing scenarios.</p> <p>If I make another suggestion, I would...
Is there a way to nest one of these (Crystal Reports) <p>I need to use these two formulas for one field. Can someone help me combine them?</p> <p><code></p> <pre> stringvar input := {tbl.col}; stringvar output := ''; numbervar i; input := Trim(input); for i := 1 to Length(input) Step 1 do if not(input[i] in [Chr(...
<p>Instead of doing a loop to remove the white space and line breaks you should be using the Replace function.</p>
how to make better use of the coding platform if 800MB out of 4GB RAM is not used? <p>My coding platform is a Vista machine with 4GB RAM. And while the machine is slick, I know there are 800MB of RAM that is not used at all. (only about 3.2GB or 4GB is used).</p> <p>can I installed something to help my platform for ...
<p>The upper 500MB-1GB of RAM is reserved for Windows and device drivers on 32 bit Windows. It varies in size by a number of factors but the largest is the amount of RAM your graphics card has as this amount will generally be reserved from the top of the 32 bit address space. The only way to use that is to install a 64...
Is the maven-native-plugin widely used to build C++ projects using maven? <p>It's been a little while since I did C++ development professionally and I'd like to get caught up on what the current state of C++ development is in a number of areas. Most of my recent work has been Java, making heavy use of Maven. When I l...
<p>In my experience, the C++ community still hasn't standardised on a common build tool. While the GNU autotools (and GNU make) are still popular for Open Source projects, other options include <a href="http://www.scons.org/">SCons</a>, <a href="http://www.cmake.org/">CMake</a>, <a href="http://makepp.sourceforge.net/"...
How to send data to COM PORT using JAVA? <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/264277/java-serial-communication-on-windows">Java Serial Communication on Windows</a> </p> </blockquote> <p>Friends, I want to connect and transfer data to COM PORT (eith...
<p>This question has been asked and answered many times:</p> <p><a href="http://stackoverflow.com/questions/544824/read-file-from-serial-port-java">Read file from serial port using Java</a></p> <p><a href="http://stackoverflow.com/questions/336714/reading-serial-port-in-java">Reading serial port in Java</a></p> <p><...
finding substring <p><br /> Thanks in advance.I want to find all the substring that occurs between K and N,eventhough K and N occurs in between any number of times. for example<br /> a='KANNKAAN'</p> <p>OUTPUT;<br /> [KANNKAAN, KANN , KAN ,KAAN]</p>
<pre><code>import re def occurences(ch_searched, str_input): return [i.start() for i in re.finditer(ch_searched, str_input)] def betweeners(str_input, ch_from, ch_to): starts = occurences(ch_from, str_input) ends = occurences(ch_to, str_input) result = [] for start in starts: for end in en...
SQLCacheDependency with ADO.NET Entity Model <p>Does SQL Cache Dependency work with the ADO.NET Entity Model? Please give me some example link of something.</p>
<p>This is an msdn link to <a href="http://msdn.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx" rel="nofollow">SqlCacheDependency</a> </p> <p>and here's for <a href="http://www.andrewdothay.net/blog/2009/01/28/LINQAndTheSqlCacheDependency.aspx" rel="nofollow">LINQ &amp; SqlCacheDependency</a><...
The remote name could not be resolved <p>i m creating mobile application for windows mobile 6.i m uploading an image on url/website. for this i m using webrequest and webresponse class.at the time of getting response i m getting this type of error-</p> <p>The remote name could not be resolved.. my code is- String url ...
<p>While I don't have specific experience with Windows Mobile this error message generally indicates a failure to resolve a hostname to an IP address. This can happen for a number of reasins including:</p> <ul> <li>The client can not contact the DNS server to attempt to resolve the name. This suggests a lack of networ...
Functional Specifications <p>Whereever I have looked, the functional specifcations are some sort of documents with the requirements/proposed features represented and elaborated. I was recently in a position to make a standard template for our company for functional specifications. The format I have settled for, tentati...
<p>In my experience the functional specification was generally a use case document (with or without a corresponding diagram or diagrams). The spreadsheet sounds pretty cool, but functional requirements are generally for communicating with the business stakeholders with the goal of obtaining agreement and ultimately si...
Good Gantt-diagram software? <p>I have multiple projects on my own, each one with a deadline and a (personal) estimate of the time that I should invest to get the thing done.</p> <p>At a particular time I can be involved in multiple projects.</p> <p>What I need is a software that lets me plan and display a "timeline"...
<p>On the Feeware java-based front, you have <a href="http://www.ganttproject.biz/" rel="nofollow"><strong>GanttProject</strong></a>.</p> <p>You can launch it from this <a href="http://ganttproject.googlecode.com/svn/webstart/ganttproject-2.0.9/ganttproject-2.0.9.jnlp" rel="nofollow">jnlp link</a>.</p>
Finding exception in Objective c code <p>Hi I am debugging my application on iphone (OS 2.0) using X-code 3.1 iphone SDK 3.0 beta 5 . My application crashes giving message <strong>* Terminating app due to uncaught exception 'NSRangeException', reason: '*</strong> -[NSCFArray insertObject:atIndex:]: index (8) beyond bo...
<p>The easiest way to find where your exception is happening is to set breakpoints on -[NSException raise] and objc_exception_throw in gdb. Then you'll break as soon as it happens, and you can examine the stack at that point.</p>
How do I get the cell value from a formula in Excel using VBA? <p>I have a formula in a range of cells in a worksheet which evaluate to numerical values. How do I get the numerical values in VBA from a range passed into a function?</p> <p>Let's say the first 10 rows of column A in a worksheet contain rand() and I am ...
<p>The following code works for me when running from VBA (Excel 2003):</p> <pre><code>Public Function X(data As Range) As Double For Each c In data.Cells a = c.Value 'This works b = c.Value2 'This works too (same value) f = c.Formula 'This contains =RAND() Next End Function </code></pre> <p>a a...
Why does my iPhone app update from App Store fail while upgrading the database? <p>I've released an app update which does an upgrade of the database ie. executes a script file in the bundle that adds a column to existing table , etc. I've tested this by deploying previous version builds on my device from xcode and th...
<p>You aren't allowed to modify files in your application bundle (see epatel's <a href="http://tinyurl.com/pkeu9m" rel="nofollow">link</a>). As part of your build process, the app gets signed, and modifying files in the bundle will break the signature.</p> <p>You should be using your application's document directory. ...
Alternative User management in ASP.NET MVC <p>I am in the planning phase of a new ASP.NET MVC application and one of the requirements is storing some user information that is not part of the standard set found in the User class that comes with ASP.NET MVC. I suppose it comes down to two questions.</p> <p>1) Can I edit...
<p>Profiles are one option as @Burt says, and offers a lot of flexibility.</p> <p>I had a similar need to track Employee information, but I opted to roll my own Employee class and create a relationship to a standard User. I really like how this has worked out as I can keep any Employee specific business logic separat...
Core Data Primary Key <p>This may seem stupid, but I still couldn't figure out how to mark a attribute as a primary key in the xcdatamodel file. My persistent storage is sqlite file. Can anyone help me?</p> <p>In that case, how can I "validate" a ID to be unique? Should I write a validation method or something?</p>
<p>Your options are:</p> <ul> <li>Use <code>-[NSManagedObject objectID]</code>. Note that this ID is temporary until either the object is saved for the first time or you call <code>-[NSManagedObjectContext obtainPermanentIDsForObjects:error:]</code></li> <li>Use the <code>CFUUID</code> family of functions to generate ...
IEnumerable and string array - find matching values <p>Background: I have an ASP.NET MVC view page with a MultiSelectList in the View Model. I want to populate a label with the list of SelectedValues from that MultiSelectList object. The list is stored within the MultiSelectList with a type of IDName:</p> <pre><code>p...
<p>Try the following.</p> <pre><code>var selected = MultiSelectList.Items .Cast&lt;IDName&gt;() .Where(x =&gt; MultiSelectList.SelectedItems.Contains(x.Name)); </code></pre> <p>What this does is process all of the items in the MultiSelectList.Items collection. It will then cast all of them to a strongly typed ID...
Upgrading from boost 1.38 to 1.39 causes my call to boost::algorithm::split not to compile <p>I was using Boost 1.38, and I just upgraded to 1.39. Upgrading broke the following bit of code:</p> <pre><code>std::vector&lt;std::wstring&gt; consoleParser::loadStringsFromFile(const std::wstring &amp;fileName) { std::ve...
<p>Your compile failed because there's a new warning being emitted (<code>boost::detail::addr_impl_ref&lt;T&gt;' : assignment operator could not be generated</code>), and your settings are set to treat warnings as errors. Judging from <a href="http://www.nabble.com/-utility--foreach--1.39.0--warning-C4512-td23446419.ht...
Can one implement a image background in his forms? <p>Is there a way that one could implement an image background in hos application(from)</p>
<p>Per <a href="http://forums.netbeans.org/topic4381.html&amp;highlight=" rel="nofollow">http://forums.netbeans.org/topic4381.html&amp;highlight=</a> , "make your panel a JLayeredPane and put the Component that you're attaching the image to the "lowest" one" should work,</p>
Compare lots of texts (clustering) with a matrix <p>I have the following PHP function to calculate the relation between to texts:</p> <pre><code>function check($terms_in_article1, $terms_in_article2) { $length1 = count($terms_in_article1); // number of words $length2 = count($terms_in_article2); // number of w...
<p>You can split the text on adding it. Simple example: <code>preg_match_all(/\w+/, $text, $matches);</code> Sure real splitting is not so simple... but possible, just correct the pattern :)</p> <p>Create table id(int primary autoincrement), value(varchar unique) and link-table like this: word_id(int), text_id(int), w...
Writing a cookie from a static class <p>I have a static class in my solution that is basically use a helper/ultility class.</p> <p>In it I have the following static method:</p> <pre><code>// Set the user public static void SetUser(string FirstName, string LastName) { User NewUser = new User { Name = S...
<p>Creating the cookie object is not enough to have it sent to the browser. You have to add it to the Response object also.</p> <p>As you are in a static method, you don't have direct access to the page context and it's <code>Response</code> property. Use the <code>Current</code> property to access the Context of the ...
Advantages and Disadvantages of using MVC Design Pattern (Model View Controller) <p>I am at the point in my design where I am contemplating dropping the MVC design for performance reasons, not sure if straight out PHP pages with header/footer includes would out perform my MVC setup (using PHP/Zend). I have a feeling i...
<p>What's the value of your time? Of your productivity? Of your code's maintainability?</p> <p>vs.</p> <p>What's the cost of an additional server?</p>
Why doesn't git know I merged? Is there a way to tell it? <p>I'm using git-svn; I typically create a topic branch, make commits to it, then checkout master, git svn rebase, git merge --squash topic_branch, git commit -m "summary comment", then git svn dcommit.</p> <p>That works fine, but git doesn't seem to know I mer...
<p>I think it's because you used <code>--squash</code>. I'm not sure why you did, but you shouldn't need to. From the <code>--squash</code> documentation for git merge:</p> <blockquote> <p>Produce the working tree and index state as if a real merge happened, but do not actually make a commit or move the HEAD, ...
Why won't my website use the Tahoma font? <p>I have my fonts set in my style.css:</p> <pre><code>font-family: "Arial, Verdana, sans-serif"; </code></pre> <p>But my website still seems to use sans serif. What is the problem here?</p>
<p>The commas in your CSS font-family specification need to be outside the quotes.</p> <p>For example:</p> <pre><code>font-family: "Arial", "Verdana", sans-serif; /* And you should really omit the quotes if it's only one word */ </code></pre> <p>Not</p> <pre><code>font-family: "Arial, Verdana, sans-serif"; </code>...
How to improve the quality of enterprise applications? <p>Many enterprise applications I've used cause me much frustration, whether it's a bad UI/UX, sluggishness, or jumping through hoops to get something simple done. This is a completely different world from the open-source applications I've used. What problems hav...
<p>It's common to hear this from developers working on enterprise applications:</p> <ul> <li>It will be on the Intranet anyway so bandwidth is not an issue. Let's not waste our time on optimizing and caching.</li> <li>We'll just add another web server if the load goes high. The entire org is 15K users anyway.</li> <li...
No Hits Found Using Zend Lucene Search <p>So I've been working on a crawler script to index all the pages on the my site using Zend Lucene search. I've been able to get the script to work but for some reason will not find the other links on the pages. The problem seems to be when the script hits the find method:</p> <...
<p>There is a tool to view the lucene index, that will let you see what is being indexed. <a href="http://www.getopt.org/luke/" rel="nofollow">Luke</a> should let you see what has been indexed and test some searches.</p> <p>Are you sure that the url field is indexed when you are creating the index, it is possible you ...
unzip strings in javascript <p>Anyone knows a simple JavaScript library implementing the UNZIP algorithm? No disk-file access, only zip and unzip a string of values.</p> <p>There are ActiveX, using WinZIP and other client dependent software for ZIP, written in JS. But no pure JavaScript algorithm implementation.</p> ...
<p>No need to unzip the KMZ file as <a href="http://maps.google.com/support/bin/answer.py?hl=en&amp;answer=41136" rel="nofollow">Google Maps absolutely understands it.</a> You can check it, simply search for the URL where your KMZ file is located in the <a href="http://maps.google.com/" rel="nofollow">Google Maps web i...
Inaccurate division of doubles (Visual C++ 2008) <p>I have some code to convert a time value returned from QueryPerformanceCounter to a double value in milliseconds, as this is more convenient to count with.</p> <p>The function looks like this:</p> <pre><code>double timeGetExactTime() { LARGE_INTEGER timerPerform...
<p>Adion,</p> <p>If you don't mind the performance hit, cast your QuadPart numbers to decimal instead of double before performing the division. Then cast the resulting number back to double.</p> <p>You are correct about the size of the numbers. It throws off the accuracy of the floating point calculations. </p> <p...
If I'm querying a database, how can I get the 5th row back from a given row? <p>If I have a row id and I want the 5th row back from that row how would I do this?</p> <p>Normally I could just go </p> <p>rowId - 5</p> <p>and that would be the id of the 5th row back...</p> <p>However, I need to account for if a row ha...
<p>You can use the ROW_NUMBER ranking functions of T-SQL...</p> <p>Here's some pseudo-SQL code:</p> <pre><code>SELECT id, value, ROW_NUMBER() OVER ( ORDER BY id) AS RowNo FROM ranking AS r1 WHERE RowNo = selectedRowNo - 5 </code></pre>
Error parsing .dae,Error#1009 in flash player,Augmented Reality flash <p>Whenever I am trying to use an animate.dae file(I am creating small project using flartoolkit+papervision3d+ascollada) .The flash player is reporting me the errors pasted below.If I am pressing continue then I can see my .dae file but without anim...
<p>Fenomas is right, this has to do with how the COLLADA data was made. There is some very specific work arounds that can be used to help cleanup the XML which is all COLLADA/DAE is.</p> <p>I touched deeply on this all <a href="http://stackoverflow.com/questions/673059/as3-dae-augmented-reality-papervision-3d">here</...
Problem with my hangman game <p>I'm trying to learn python and I'm attempting a hangman game. But when I try and compare the user's guess to the word, it doesn't work. What am I missing?</p> <pre><code>import sys import codecs import random if __name__ == '__main__': try: wordlist = codecs.open("words.txt...
<p>In your "<code>for word in wordlist</code>" loop, each word will end in a newline. Try adding <code>word = word.strip()</code> as the next line.</p> <p>By the way your last loop could be replaced with:</p> <pre><code>if guess in word: print ("Yessssh") </code></pre> <p>Bonus tip: when adding "debug prints", i...
Can I change the error page (404) with a standalone WCF web service? <p>I have a standalone (non-IIS) WCF service that - besides the services - provides some simple HTML pages via a WebServiceHost.</p> <p>When I enter <a href="http://localhost:1234/SomeRandomWords" rel="nofollow">http://localhost:1234/SomeRandomWords<...
<p>You cant in W32 Service Host. You can in IIS Host.</p> <p>You cant change the default WCF endpoint error message because your code is not yet executed.</p> <p>For you API documentation, you could use the new <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24644" rel="nofollow">WCF REST S...
healthy garbage collection metrics? <p>i profiled a jdbc/hibernate batch-importer. it takes a csv transforms it slighly and imports it to the database sitting at localhost.</p> <p>to my surprise the operation was not I/O bound but rather cpu-bound.</p> <p>according to jmx/jconsole as well as the netbeans profiler it ...
<p>Sixty percent is real high. This is often an indication of someone using a lot of temporary Strings, or something similar. The fact that it's happening in the "old generation" suggests it might be happening in the database end, maybe while waiting for database transactions to happen. But that's just a horseback g...
iphone cocoa "error:request for member ____ in something not a structure or union" <p>this way works:</p> <pre><code>type1ViewController *viewController = [[type1ViewController alloc] initWithNibName:@"Type1View" bundle:nil]; viewController.parentViewController = self; self.type1ViewController = viewController; [self....
<p>When you call <code>self.type1ViewController.parentViewController</code> instead of <code>viewController.parentViewController</code>, it's giving you an error because you have <code>self.type1ViewController</code> declared as some superclass, not a type1ViewController. When the compiler looks at this declaration it'...
Is there a way to read input directly from the keyboard in standard C++? <p>And I know there's <code>std::cin</code>, but that requires the user to enter a string, then press ENTER. Is there a way to simply get the next key that is pushed without needing to press ENTER to confirm</p>
<p>What you're looking for is related to manipulating the console, and is OS-dependent. If you're in a UNIX-based OS, check out the <a href="http://en.wikipedia.org/wiki/Curses%5F(programming%5Flibrary)">curses library</a>, and in Windows, there are <code>getch()</code> and <code>kbhit()</code> functions from <code>&lt...
Better way to deploy to Windows Mobile Device <p>I have been working on a Windows Mobile app for a little while now (havnt done much work with mobile before) and i have been having a problem when deploying to my mobile, at the moment i can only run the application once then if i want to run it again i have to do a soft...
<p>CAB files are the preferred way to deploy Windows Mobile applications. Check out this MSDN article:</p> <p><a href="http://msdn.microsoft.com/en-us/library/bb158712.aspx" rel="nofollow">CAB Files for Delivering Windows Mobile Applications</a></p> <p>I've had some success with putting a CAB file on a web server and...
Google App Engine + GWT + Eclipse: where do your unit tests live? <p>I'm just getting started with a project that combines GWT, Google App Engine and the Google Eclipse plugin. Where is the best place to store my tests? I normally keep my code organized Maven-style, with <code>src/main/java</code>, and tests in <code...
<p>I've faced a kind of problem woth GAE testing: Some tests require an appengine-testing.jar wich conflicts with the main appengine-api-xxx.jar of the poject. That way, I was able to run tests for GAE but it conflicted with a normal run/debug launch. To be able to run the app in my local machine, I had to remove the a...
says if i develop a Ruby on Rails application using Rails 2.3.2, will that usually be compatible with Passenger on my hosting company? <p>says if i develop a Ruby on Rails application using Rails 2.3.2, will that usually be compatible with Passenger on my hosting company?</p> <p>If i ssh to my hosting company and type...
<p>Freeze rails into vendor/rails using the built in rake task. That way your app will ue the version of rails you want it to no matter where you deploy it.</p> <pre><code>rake rails:freeze:gems </code></pre> <p>And the easiest way to do a specific version I know of.</p> <pre><code>rake rails:freeze:edge RELEASE=2.3...
Overriding stylesheets <p>I have a link, where I want to change the color of the text away from the color that I set for hyperlinks. My code is:</p> <pre><code>&lt;span class="button"&gt;&lt;%= link_to "Create new scenario", :action =&gt; "create" %&gt;&lt;/span&gt; </code></pre> <p>And my CSS is:</p> <pre><code>a:l...
<p>You could make a css style .button a:link {color: black;}</p>
Data storage to ease data interpolation in Python <p>I have 20+ tables similar to table 1. Where all letters represent actual values.</p> <pre><code>Table 1: $ / cars |&lt;1 | 2 | 3 | 4+ &lt;10,000 | a | b | c | d 20,000 | e | f | g | h 30,000 | i | j | k | l 40,000+ | m | n | o | p </code></pre> <p>A user inpu...
<p>If you want the most computationally efficient solution I can think of and are not restricted to the standard library, then I would recommend scipy/numpy. First, store the a..p array as a 2D numpy array and then both the $4k-10k and 1-4 arrays as 1D numpy arrays. Use scipy's interpolate.interp1d if both 1D arrays ...
iPhone: Convert date string to a relative time stamp <p>I've got a timestamp as a string like:</p> <blockquote> <p>Thu, 21 May 09 19:10:09 -0700</p> </blockquote> <p>and I'd like to convert it to a relative time stamp like '20 minutes ago' or '3 days ago'.</p> <p>What's the best way to do this using Objective-C fo...
<pre><code>-(NSString *)dateDiff:(NSString *)origDate { NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setFormatterBehavior:NSDateFormatterBehavior10_4]; [df setDateFormat:@"EEE, dd MMM yy HH:mm:ss VVVV"]; NSDate *convertedDate = [df dateFromString:origDate]; [df release]; NSDate *tod...
asp.net active directory logging in <p>i would like to be able to login on a webpage using a valid active directory username and password.</p> <p>user name and password are entered in textboxes. if they are correct then i would like to redirect to another page.</p> <p>how can this be coded.</p> <p>in a second task</...
<p>You need to look at implementing the <a href="http://msdn.microsoft.com/en-us/library/system.web.security.activedirectorymembershipprovider.aspx" rel="nofollow">ActiveDirectoryMembershipProvider</a>. Here's a good <a href="http://msdn.microsoft.com/en-us/library/ms998347.aspx" rel="nofollow">walk through</a> on how ...
How do I get the fullname of a file in Adobe AIR? <p>I'm using something like this to browse for a file in AIR. I can get the filename, but what I need is the fullname of the file. Is there a way to do that? </p> <pre><code>var file:FileReference = new FileReference(); file.addEventListener(Event.SELECT, selectHan...
<p>I am not sure if <code>FileReference</code> can give you the absolute path of the file you selected. So I suggest you to use <code>nativePath</code> property of the <code>File</code> rather than <code>FileReference</code>.</p> <pre><code>var file:File = File.userDirectory; file.addEventListener(Event.SELECT, select...
Should I always give a return value to my function? <p>I write JavaScript code and I try to use its functional language nature.</p> <p>In other functional languages (or even in Ruby), if I don't explicitly set the return value of a function, it will return the value of the last evaluated expression. JavaScript does no...
<p>A "pure" functional programming environment would have no side effects -- each function's work would be <em>entirely</em> in computing its return value; that's not really feasible in typical uses of Javascript, and so it's perfectly acceptable, when a function has done its work through side effects, to have it retur...
hasattr() vs try-except block to deal with non-existent attributes <pre><code>if hasattr(obj, 'attribute'): # do somthing </code></pre> <p>vs</p> <pre><code>try: # access obj.attribute except AttributeError, e: # deal with AttributeError </code></pre> <p>Which should be preferred and why?</p>
<p><em>Any benches that illustrate difference in performance?</em></p> <p>timeit it's your friend</p> <pre><code>$ python -mtimeit -s 'class C(object): a = 4 c = C()' 'hasattr(c, "nonexistent")' 1000000 loops, best of 3: 1.87 usec per loop $ python -mtimeit -s 'class C(object): a = 4 c = C()' 'hasattr(c, "a")' 100000...
How to get the html List value through Javascript? <p>I am trying to get values from html list <code>&lt;li&gt;</code>. </p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;a&gt;Main Menu&lt;/a&gt; &lt;ul class="leftbutton" &gt; &lt;li value="List1"&gt;&lt;a&gt;Sampe 1&lt;/a&gt;&lt;/li&gt; &lt;li value="List2...
<p>You get several things wrong here. </p> <ol> <li>a HTML list item (<code>&lt;li&gt;</code>) does not have a value</li> <li>a HTML list has no "selected item"</li> <li>you cannot get any "selected" item by calling <code>getElementById()</code></li> </ol> <p>Here is my alternative suggestion:</p> <pre><code>&lt;ul&...
in Ruby on Rails 2.3.2, how to print out params during a create action? <p>there is a scaffold created Story... and in the create action, there is</p> <pre><code>@story = Story.new(params[:story]) </code></pre> <p>i was curious as to what is in params... so i want to dump out params... but there is no view associated...
<p>The easiest thing to do is just dump params out to the log:</p> <pre><code>Rails.logger.info("PARAMS: #{params.inspect}") </code></pre> <p>If you're in development mode, just look in your development.log and that line will be there.</p> <p>The params scope is a combination of URL/FORM (GET/POST) fields, and it wi...
how to make a screen saver preview in Delphi? <p>I want my screensaver appears in the screensaver preview box?</p>
<p>When you make a screen saver you need to support a command line argument (/p [HWND]) that will tell you in which windows to show your screen saver. The command line will be pass to you thru the screen saver control panel. <a href="http://support.microsoft.com/kb/182383" rel="nofollow">here is a link to the full spec...
Indexing a 'non guessable' key for quick retrieval? <p>I'm not fully getting all i want from Google analytics so I'm making my own simple tracking system to fill in some of the gaps.</p> <p>I have a session key that I send to the client as a cookie. This is a GUID. I also have a surrogate IDENTITY int column.</p> <p>...
<p>In this case, I'd just create an index on the GUID. Thousands of sessions a day is a completely trivial load for a modern database.</p> <p>Some notes:</p> <ul> <li>If you create the GUID index as non-clustered, the index will be small and probably be cached in memory. By default most databases cluster on primary ...
What are the new features of C# v4.0? <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/292265/new-cool-features-of-c-4-0">New Cool Features of C# 4.0</a> </p> </blockquote> <p>Hello,</p> <p>There are several(many) questions at SO about "what do you want in C# v...
<p>In <a href="http://code.msdn.microsoft.com/csharpfuture/Release/ProjectReleases.aspx?ReleaseId=1686" rel="nofollow">C# Future page @ MSDN</a> you'll find a documentation of the new features which were added to the Beta1 version of C# 4.0, along with samples.</p>
maven jetty does not shutdown properly in eclipse <p>I am currently running jetty from eclipse as an external java program. The problem is when I terminate jetty and I try to relaunch it again, it cannot due to the port still being in use.</p> <p>What I have to do is open up Windows Task Manager and kill the java proc...
<p>If a java application does not shutdown it is because of an alive non-daemon thread. Try getting a thread dump of the running maven process, e.g. using <a href="https://visualvm.dev.java.net/" rel="nofollow">VisualVM</a> and see what keeps the application alive.</p>