instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>Is there a way (without installing any libraries) of validating XML using a custom DTD in PHP?</p>
<p>Take a look at <a href="http://us3.php.net/dom" rel="noreferrer">PHP's DOM</a>, especially <a href="http://us3.php.net/manual/en/domdocument.schemavalidate.php" rel="noreferrer">DOMDocument::schemaValidate</a> and <a href="http://us3.php.net/manual/en/domdocument.validate.php" rel="noreferrer">DOMDocument::validate<...
<h2>Trying to complete "owenmarshall" answer:</h2> <p><strong>in xml-validator.php:</strong></p> <p>add html, header, body, ...</p> <pre><code>&lt;?php $dom = new DOMDocument; &lt;br/&gt; $dom-&gt;Load('template-format.xml');&lt;br/&gt; if ($dom-&gt;validate()) { &lt;br/&gt; echo "This document is valid!\n"; &l...
12,744
<p>How do you implement an <strong>efficient and thread safe reference counting system</strong> on X86 CPUs in the C++ programming language? </p> <p>I always run into the problem that the <strong>critical operations not atomic</strong>, and the available X86 Interlock operations are not sufficient for implementing the...
<p>Nowadays, you can use the Boost/TR1 shared_ptr&lt;> smart pointer to keep your reference counted references.</p> <p>Works great; no fuss, no muss. The shared_ptr&lt;> class takes care of all the locking needed on the refcount.</p>
<p>If the instruction itself is not atomic then you need to make the section of code that updates the appropriate variable a critical section.</p> <p><b>i.e.</b> You need to prevent other threads entering that section of code by using some locking scheme. Of course the locks need to be atomic, but you can find an ato...
11,856
<p>I have a following SQL Server 2005 database schema:</p> <pre><code>CREATE TABLE Messages ( MessageID int, Subject varchar(500), Text varchar(max) NULL, UserID NULL ) </code></pre> <p>The column "UserID" - which can be null - is a foreign key and links to the table</p> <pre><code>CREATE TABLE Users ( ...
<p>You forgot to include the declaration of your "Message" class but I suspect that the UserID property in that class is not declared as a nullable type. If that is the case, change it from "int" to "int?" (nullable int).</p>
<p>I suspect your relationship is not 1 to 1.</p>
16,975
<p>I'm trying to build the example described at <a href="http://support.microsoft.com/kb/178749/EN-US/" rel="nofollow noreferrer">http://support.microsoft.com/kb/178749/EN-US/</a> in order to build an application that programatically accesses Excel using Automation. I have Visual C++ 2005/Visual Studio 2005. Some of...
<p>I'm not familiar with the ClassWizard wrapper generator, but it looks like it may have #imported the Excel COM type library without a namespace, and you're getting conflicts with the SDK header files. Check the <code>.tlh</code> file and ensure there's a namespace around the definitions. If not, I'd look at importin...
<p>I don't know if this helps but generally you <code>#import</code> the type library but you do NOT <code>#include</code> the .tli and .tlh files (the <code>#import</code> implicitly does this).</p> <p>Also, remember there are two ways of calling a COM server in MFC.</p> <ol> <li><p>Use <code>#import</code> which ba...
22,440
<p>I've got some Java code using a servlet and Apache Commons FileUpload to upload a file to a set directory. It's working fine for character data (e.g. text files) but image files are coming out garbled. I can open them but the image doesn't look like it should. Here's my code:</p> <p>Servlet</p> <pre><code>protec...
<p>One thing I don't like is here in this block from StreamUtils.getBytes():</p> <pre><code> 1 while (true) { 2 int nBytesRead = src.read(buff); 3 if (nBytesRead &lt; 0) { 4 break; 5 } 6 byteStream.write(buff); 7 } </code></pre> <p>At line 6, it writes the entire buffer, no matter how many bytes are...
<p>Are you sure that the image isn't coming through garbled or that you aren't dropping some packets on the way in. </p>
6,306
<p>Just started getting into jQuery and have an issue with a jQuery Post call working perfectly on my local dev box (VS 2008 built-in web server), but failing when I deploy to a windows 2003 server (IIS 6) box.</p> <p>The post works and the page being posted to process things correctly, but a response is never receive...
<p>The problem is probably due to caching.<br> Try adding a random number to the post URL</p> <pre><code>$.post('CustomPostHandler.aspx?step=criteria&amp;random=' + Math.random().toString(), { selected: idString }, </code></pre>
<p>I agree that is probably due to caching. The more general <code>$.ajax</code> function allows you to set the cache option to false in order to disable caching.</p> <p>Have a look at the <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options" rel="nofollow noreferrer">documentation</a>.</p>
38,314
<p>Besides the syntactic sugar and expressiveness power what are the differences in runtime efficiency. I mean, plpgsql can be faster than, lets say plpythonu or pljava? Or are they all approximately equals?</p> <p>We are using stored procedures for the task of detecting nearly-duplicates records of people in a modera...
<p>plpgsql provides greater type safety I believe, you have to perform explicit casts if you want to perform operations using two different columns of similar type, like varchar and text or int4 and int8. This is important because if you need to have your stored proc use indexes, postgres requires that the types match ...
<p>Without doing actual testing, I would expect plpgsql to be somewhat more efficient than other languages, because it's small. Having said that, remember that SQL functions are likely to be even faster than plpgsql, if a function is simple enough that you can write it in just SQL.</p>
30,716
<p>I have two branches : X and Y. I want to replace a Y's subdirectory (y1) by its equivalent from X (x1).</p> <p>For the time being, I do the following : copy x1 to Y, remove y1, rename (move) x1 to y1 :</p> <pre><code>a) svn copy https://path/to/branches/X/x1 https://path/to/branches/Y/ b) svn delete https://path/t...
<p>If you really want to replace the directory, you can do that with two operations:</p> <pre><code>svn delete https://path/to/branches/Y/y1 svn copy https://path/to/branches/X/x1 https://path/to/branches/Y/y1 </code></pre> <p>If Y/y1 is really already an older copy of X/y1, you shouldn't replace it all the time, but...
<p>Why not just two steps:</p> <pre><code>a) svn delete https://path/to/branches/Y/y1 b) svn copy https://path/to/branches/X/x1 https://path/to/branches/Y/y1 </code></pre>
48,908
<p>I need to get a list of all documents in a site collection, which I believe I can do with either the alldocs table or the alluserdata table (MOSS 2007 SP1) but do not see how I can get the author information for the document. I do not need the contents of the document (e.g. AllDocStreams content)</p> <p><strong>S...
<p>People that claim that you cannot query SharePoint databases because it is not supported are wrong. From reading the documentation, it is fine to query the database as long as you use the 'With(NoLock)' clause. It is clearly not supported to update, delete, or insert records.</p> <p>The below query is supported:<...
<p>MOSS provides many <a href="http://www.infoq.com/articles/swanson-moss-web-services" rel="nofollow noreferrer">webservices</a> out of the box which make life a little easier. They are always worth exploring.</p> <p>For this particular instance, I think the article, <a href="http://sqlblogcasts.com/blogs/drjohn/arc...
26,281
<p>I'm now to this point of my project that I need to design my database (Oracle). Usually for the status and countries tables I don’t use a numeric primary key, for example</p> <pre><code>STATUS (max 6) AC --&gt; Active DE --&gt; Deleted COUNTRIES (total 30) UK --&gt; United Kingdom IT --&gt; Italy GR --&gt; Greece ...
<p>Both the status and country tables are so small that they are going to be memory resident in practice, whether formally stated as such or not. Indeed, except that a foreign key normally requires an index on the referenced primary key field, you might be tempted not to bother with any indexes on the tables.</p> <p>...
<p>If 'status' is (and will always be?) a binary active/deleted field why bother with the table at all. It seems like normalization taken to an impractical extreme.</p> <p>It would <em>certainly</em> be quicker, not to mention easier, to simply use a tinyint(1) field and record the active/deleted state as a 1 or 0.</p...
41,981
<p>I'm talking about an action game with no upper score limit and no way to verify the score on the server by replaying moves etc. </p> <p>What I really need is the strongest encryption possible in Flash/PHP, and a way to prevent people calling the PHP page other than through my Flash file. I have tried some simple me...
<p>This is a classic problem with Internet games and contests. Your Flash code works with users to decide a score for a game. But users aren't trusted, and the Flash code runs on the user's computer. You're SOL. There is nothing you can do to prevent an attacker from forging high scores:</p> <ul> <li><p>Flash is even ...
<p>Whenever your highscore system is based on the fact that the Flash application sends unencrpyted/unsigned highscore data via the network, that can be intercepted and manipulated/replayed. The answer follows from that: encrypt (decently!) or cryptographically sign highscore data. This, at least, makes it harder for p...
9,965
<p>How do you calculate the least common multiple of multiple numbers?</p> <p>So far I've only been able to calculate it between two numbers. But have no idea how to expand it to calculate 3 or more numbers.</p> <p>So far this is how I did it </p> <pre><code>LCM = num1 * num2 / gcd ( num1 , num2 ) </code></pre> <...
<p>You can compute the LCM of more than two numbers by iteratively computing the LCM of two numbers, i.e.</p> <pre><code>lcm(a,b,c) = lcm(a,lcm(b,c)) </code></pre>
<p>If there's no time-constraint, this is fairly simple and straight-forward:</p> <pre><code>def lcm(a,b,c): for i in range(max(a,b,c), (a*b*c)+1, max(a,b,c)): if i%a == 0 and i%b == 0 and i%c == 0: return i </code></pre>
17,761
<p>I'm interested in finding out why this is used on some Web sites for processing user-initiated search submissions, how it affects the request and response flow, and programmatically why it would be necessary (or beneficial). In an MVC framework it seems difficult to execute since you are injecting another page into ...
<p>It is often used in long running requests to prevent the web server from timing out the request. With an interstitial page, you are able to continuously refresh the page until you get results back.</p> <p>EDIT:</p> <p>Also, for long running requests, it is beneficial to have a "Loading.." page in order to show th...
<p>I believe the vast majority of interstitial pages are there to run advertising.</p>
25,596
<p>On SO 18 Joel mentioned an algorithm that would rank items based on their age and popularity and it's based on gravity. Could someone post this? C# would be lovely, but really any language (well, I can't do LISP) would be fine. </p>
<p>My understanding is that it is approximately the following from another <a href="https://stackoverflow.com/questions/24066/what-formula-should-be-used-to-determine-hot-questions">Jeff Atwood</a> post</p> <pre><code>t = (time of entry post) - (Dec 8, 2005) x = upvotes - downvotes y = {1 if x &gt; 0, 0 if x = 0, -1 ...
<p><a href="http://www.mt-soft.com.ar/wordpress/wp-content/plugins/wp-o-matic/cache/0ad4d_reddit_cf_algorithm.png">alt text http://www.mt-soft.com.ar/wordpress/wp-content/plugins/wp-o-matic/cache/0ad4d_reddit_cf_algorithm.png</a></p>
5,232
<p>What is the best way to calculate Age using Flex?</p>
<p>I found an answer at <a href="http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=08_Dates_and_times_164_2.html" rel="nofollow noreferrer">the bottom of this page in comments section (which is now offline)</a>. </p> <blockquote> <p><strong>jpwrunyan s...
<p>You could also do it roughly the same as discussed <a href="https://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c" title="Jeff Atwodd&#39;s Question about calculating age in C#">here</a>: (translated to AS3)</p> <pre><code>var age:int = (new Date()).fullYear - bDay.fullYear; if ((new Date()) &l...
6,314
<p>In order to know how many times a pattern exists in current buffer, I do:</p> <pre><code>:%s/pattern-here/pattern-here/g </code></pre> <p>It gives the number of occurrences of the pattern, but is obviously cumbersome and also has the side-effect of setting the 'changed' status.</p> <p>Is there a more elegant way ...
<p>To avoid the substitution, leave the second pattern empty, and add the “n” flag:</p> <pre><code>:%s/pattern-here//gn </code></pre> <p>This is described as <a href="http://vimdoc.sourceforge.net/htmldoc/tips.html#count-items" rel="noreferrer">an official tip</a>.</p>
<p>vimgrep is your friend here:</p> <pre><code>vimgrep pattern % </code></pre> <p>Shows:</p> <pre><code>(1 of 37) </code></pre>
9,595
<p>We are producing a portable code (win+macOs) and we are looking at how to make the code more rubust as it crashes every so often... (overflows or bad initializations usually) :-(</p> <p>I was reading that Google Chrome uses a process for every tab so if something goes wrong then the program does not crash compleate...
<p>I've developed on numerous multi-platform C++ apps (the largest being 1.5M lines of code and running on 7 platforms -- AIX, HP-UX PA-RISC, HP-UX Itanium, Solaris, Linux, Windows, OS X). You actually have two entirely different issues in your post.</p> <ol> <li><p>Instability. Your code is not stable. Fix it. </p> ...
<p>You can always add exception handling to your program to catch these kinds of faults and ignore them (though the details are platform specific) ... but that is very much a two edged sword. Instead consider having the program catch the exceptions and create dump files for analysis.</p> <p>If your program has behaved...
11,031
<p>I'm looking for some image library that can work with multiple formats (jpg,gif,png), and is fast at displaying the images to the screen.</p> <p>Also, it would be nice if I could specify only part of the image to render to the screen.</p> <p>In the end I want to have lots of images on the screen that I can pan and...
<p><a href="http://freeimage.sourceforge.net/" rel="nofollow noreferrer">FreeImage.</a></p> <p>That's for loading.</p> <p>For displaying, you can either use the FreeImage methods to make a bitmap that you can then display in some control (depending on your UI).</p> <p>For the real hotness in display, you'll then wan...
<p><a href="http://www.imagemagick.org/Magick++/" rel="nofollow noreferrer">ImageMagick</a> has libraries in several languages to do what you want.</p>
34,543
<p>I'm opening a new browser window from my site for some of the members. However, some may later close it, or it might have initially failed to open.</p> <p>Is there a snippet of fairly plain Javascript that can be run on each page to confirm if another browser window is open, and if not, to provide a link to re-open...
<p>This <a href="http://www.irt.org/articles/js205/index.htm" rel="nofollow noreferrer">excellent, comprehensive article</a> <em>("Almost complete control of pop-up windows")</em> should answer all your questions about javascript popup windows.</p> <p><em>"JavaScript 1.1 also introduced the window <strong>closed</stro...
<p>There is no universal way to check it as each pop-up blocker has a different behaviour. For example, Opera will not shown the pop-up but the widow.closed will return false as behind the scene Opera keep a shadow copy of the blocked window, just in case the user would like to see it anyway.</p>
27,292
<p>I have Visual Studio 2008 with SP1 installed and it is crashing when I'm using lambda expressions in the Moq Framework.</p> <p>At first I thought the problem was Resharper...but now that I have uninstalled it, VS 2008 still crashes. I'm able to replicate the issue every time.</p> <p>I'm thinking perhaps it may be ...
<p>Just a few days ago, I learned about <a href="http://blogs.msdn.com/saraford/archive/2008/11/27/did-you-know-there-s-a-way-to-have-visual-studio-log-its-activity-for-troubleshooting-366.aspx" rel="noreferrer"><code>devenv.exe</code>'s <code>/log</code> switch</a>. I suggest you give that a try.</p>
<p>I'd suggest using WinDbg to run an instance of VS, and when it crashes look at managed and unmanaged callstacks. </p>
43,156
<p>I'm in need of a macro that will enter data into a webpage search field and than copy the results to excel.</p>
<p>It's just a simple "File Open". No need for a macro.</p> <p>Excel can open URLs directly. If the URL contains any tables, those will be formatted appropriately.</p> <p>Try this: </p> <ul> <li>Run Excel</li> <li>File | Open</li> <li>Type <code>http://finance.yahoo.com/q?s=MSFT</code> as the file name</li> <li>Igno...
<p>if using excel is not a constraint in your question.. i.e. you can use other software to get the job done.. you should check out Google Spreadsheet.. its a lot more webfriendly... has functions that can retrieve some page.. or alternatively google for something nd then put the results in your table.. <a href="http:/...
32,529
<p>I can't find documentation for it, even on MSDN...</p>
<p>It's not Win32; it's MFC. Ordinarily, a Win32 control raises events by sending a message to its parent window. However, if you've got your own class derived from one of MFC's wrappers (e.g. you've wrapped CTreeCtrl with CMyFunkyTreeCtrl), you might want to handle these events in the derived class.</p> <p>MFC uses t...
<p>Some reasoning here:<br> <a href="http://www.tech-archive.net/Archive/VC/microsoft.public.vc.language/2005-08/msg00589.html" rel="nofollow noreferrer">http://www.tech-archive.net/Archive/VC/microsoft.public.vc.language/2005-08/msg00589.html</a></p>
24,626
<p>I have created the following style for a listbox that will have an image displayed next to some text:</p> <pre><code>&lt;Style x:Key="ImageListBoxStyle" TargetType="{x:Type ListBox}"&gt; &lt;Setter Property="SnapsToDevicePixels" Value="true"/&gt; &lt;Setter Property="BorderThickness" Value="1"/&gt; &lt;...
<p>There is also another way. You can add in your <code>ContentPresenter</code> this attribute</p> <pre><code>TextBlock.Foreground="YourColour" </code></pre> <p>In this case you can also use animations over that property.</p>
<pre><code> &lt;Storyboard x:Key="Storyboard1"&gt; &lt;ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="myContentPresenter"&gt; &lt;EasingColorKeyFrame KeyTime="0" Value="Black"/&gt; &lt;EasingColorKeyFrame KeyTime="...
31,047
<p>I have found ASP.Net PageMethods very handy and easy to use, but I have just started developing using MVC and am not sure how to use them?</p> <p>What is the equivalent of <code>PageMethods.MyFunction()</code> in MVC where MyFunction is a Controller action?</p> <p>I know I can use the <code>Json</code> function t...
<blockquote> <p>I know I can use the Json function to return a value, but how do I call the action from the client?</p> </blockquote> <p>I think you're looking for either <a href="http://docs.jquery.com/Ajax/jQuery.getJSON" rel="noreferrer">getJSON</a></p> <pre><code>$.getJSON("/controller/action", function(jso...
<p>I don't think you need page methods. Page methods in asp.net are a way to expose methods in the page class to your client-side code.</p> <p>In MVC, you don't have a page class, so you can just issue an XHR to a url (../controller/action/params, or whatever), and return JSON from the action.</p> <p><strong>Update</...
48,276
<p>When working with WCF services, is it better to create a new instance of the service every time you use it? Or is it better to create one and re-use it? Why is either approach better? Is it the same for asynchronous proxies? </p>
<p>in addition to the things Guy Starbuck mentioned a key factor would be the security model you're using (in conjunction with the session requirements) - if you don't re-use your proxy, you can't re-use a security sessions. </p> <p>This means that the client would have to authenticate itself with each call which is w...
<p>There is a corollary here to Server Activated Objects in .NET Remoting (one of the technologies that is replaced by WCF), which have two modes, "Single Call" (stateless) and "Singleton" (stateful).</p> <p>The approach you take in WCF should be based on your performance and scaling requirements in conjunction with t...
42,940
<p>I understand benefits of dependency injection itself. Let's take Spring for instance. I also understand benefits of other Spring featureslike AOP, helpers of different kinds, etc. I'm just wondering, what are the benefits of XML configuration such as:</p> <pre><code>&lt;bean id="Mary" class="foo.bar.Female"&gt; &...
<p>For myself one of the main reasons to use an IoC (and make use of external configuration) is around the two areas of:</p> <ul> <li>Testing</li> <li>Production maintenance</li> </ul> <p><strong>Testing</strong></p> <p>If you split your testing into 3 scenarios (which is fairly normal in large scale development):</...
<p>One of the most appealing reasons is the "<a href="http://en.wikipedia.org/wiki/Hollywood_Principle" rel="nofollow noreferrer">Hollywood principle</a>": don't call us, we'll call you. A component is not required to do the lookups to other components and services itself; instead they are provided to it automatically....
16,005
<p>Does anyone know of an RTF control that can be used on Linux/Windows/Mac? It's unfortunate that I have to mention it, but it actually has to be able to save and open rtf files... unlike wxWidgets wxRichTextCtrl for instance.</p> <p>Edit: Thanks to HappySmileMan for his reply. Better still if it's more of a standalo...
<p>RTF is simply not that common; it's a messy format controlled by Microsoft, basically a text dump of the .doc format. The only open source RTF implementations I know of are in Abiword, OpenOffice, and KWord. All are cross-platform, but none probably qualify as "controls" to your liking (though abiword has a bonobo i...
<p>If I understand the question correctly, the feature you are looking for is in the Qt toolkit.</p> <p>Some info on this can be found at <a href="https://doc.qt.io/qt-5/richtext.html" rel="nofollow noreferrer">https://doc.qt.io/qt-5/richtext.html</a></p>
10,360
<p>Does anyone know of an algorithm that I could use to find an "interesting" representative thumbnail for a video? </p> <p>I have say 30 bitmaps and I would like to choose the most representative one as the video thumbnail. </p> <p>The obvious first step would be eliminate all black frames. Then perhaps look for the...
<p>If the video contains structure, i.e. several shots, then the standard techniques for video summarisation involve (a) shot detection, then (b) use the first, mid, or nth frame to represent each shot. See [1].</p> <p>However, let us assume you wish to find an interesting frame in a single continuous stream of frames...
<p>Wow, what a great question - I guess a second step would be to iteratively remove frames where there's little or no change between it and it's successors. But all you're really doing there is reducing the set of <em>potentially</em> interesting frames. How exactly you determine "interestingness" is the special sauce...
36,397
<p>In the same way that you can use JSON in javascript? At least the static properties?</p> <p>Or maybe even for hash-table streaming?</p> <p>Is it oversimplistic about hoping to find something like </p> <p>Object.Serialize(stream) where stream is a file, overrideable with your choice of other likely candidate targ...
<p>Java supports this with the <a href="http://java.sun.com/products/jfc/tsc/articles/persistence4/" rel="nofollow noreferrer">XMLEncoder</a> since 1.4. The format is quite compact and XMLEncoder allows to override the serialization of specific object classes, so you can use the default where it fits and do whatever yo...
<p>I suggest you look at <a href="http://code.google.com/p/xstream-dot-net/" rel="nofollow noreferrer">XStream for .Net</a>. I haven't used that variant, but found the original XStream quite straightforward to use in Java.</p>
46,687
<p>A lot of my C# code follows this pattern:</p> <pre><code>void foo(string param1, string param2, string param3) { try { // do something... } catch(Exception ex) { LogError(String.Format("Error in foo(param1={0}, param2={1}, param3={2}), exception={3}", param1, param2, param3, ex....
<p>You could use Reflection and the convention that you must pass the parameters to the LogError with the right order:</p> <pre><code>private static void MyMethod(string s, int x, int y) { try { throw new NotImplementedException(); } catch (Exception ex) { LogError(MethodBase.GetCur...
<p>There are scenarios of a few parameters or Large number of parameters...</p> <ol> <li><p>Few parameters, without much ado, better write them as part of the logging/exception message.</p></li> <li><p>In large parameters, a multi-layer application would be using ENTITIES ( like customer, CustomerOrder...) to transfer...
16,440
<p>Setup is following: Drupal project, one svn repo with trunk/qa/production-ready branches, vhosts for every branch, post-commit hook that copies files from repository to docroots.</p> <p>Problem is following: Drupal website often relies not only on source code but on DB data too (node types, their settings, etc.). <...
<p>It sounds like you've already got some infrastructure there that you've written.</p> <p>So I'd start coding! There's not anything that I'm aware of thats especially good for this at the moment. And if there is, I imagine that it would take some effort to get it going with your existing infrastructure. So starting c...
<blockquote> <p>My approach to this is to use sql patch files (files containing the sql statements to upgrade the db schema/data) with a version number at the start of the filename. </p> </blockquote> <p>I was thinking of file (xml or something) with needed DB structure, and tool that applies necessary changes.</p> ...
49,450
<ul> <li>The GoDiagram object model has a GoDocument. </li> <li>GoViews have a reference to a GoDocument.</li> <li>If the user does any modification on the diagramming surface, a GoDocument.Changed event is raised with the relevant information in the event arguments.</li> </ul> <p>I would like to be notified when some...
<p>JFYI... The component-vendor recommendation is to subclass and override appropriate methods for this. Override the bool CanXXX() method, raise a cancelable custom event. If the subscriber returns false, bail out (<strong>return false to abort the user action</strong>) of CanXXX. <strong>No built-in mechanism for th...
<p>The event arguments (GoChangedEventArgs) for the change event has a property IsBeforeChanging which indicates whether the change event was raised from the "RaiseChanging" method (true), or the RaiseChanged (false). That should tell you whether the change has occurred yet, but I know of no way to cancel it. </p> <...
13,696
<p>I have a wrapper around a C++ function call which I call from C# code. How do I attach a debugger in Visual Studio to step into the native C++ code?</p> <p>This is the wrapper that I have which calls GetData() defined in a C++ file:</p> <pre><code> [DllImport("Unmanaged.dll", CallingConvention=CallingConvention...
<p>Check the Debug tab on your project's properties page. There should be an "Enable unmanaged code debugging" checkbox. This worked for me when we developed a new .NET UI for our old c++ DLLs.</p> <p>If your unmanaged DLL is being built from another project (for a while ours were being built using VS6) just make sur...
<p>To anyone using WinDbg:</p> <p>1>Setup symbols</p> <p>Look at these commands. (Help: in console .hh &lt; command> )</p> <pre><code>.sympath .sympath+ .symfix </code></pre> <p>2>Set up source path</p> <pre><code>.srcpath </code></pre> <p>3>Load SOS extention to debug managed / mixed mode programs.</p> <p>(Mak...
8,224
<p>I've got an SQL query that looks like this:</p> <pre><code>INSERT INTO DB..incident ( incident_number --nvarchar(10) ) VALUES ( N'I?' ) </code></pre> <p>What does the ? do in the value statement?</p> <p>EDIT:: Turns out there's some funny business via triggers and custom datatypes that occur on i...
<p>At the risk of sounding flippant... Nothing... It puts an I? into the field... Try this... </p> <pre><code>DECLARE @TestTable TABLE (test NVARCHAR(10)) INSERT INTO @TestTable ( test ) VALUES ( N'I?' ) SELECT * FROM @TestTable </code></pre>
<p>The question in my mind when I read this was, what does the N do?</p> <p>In Oracle, N before a character string literal indicates that the string should be encoded in the national (i.e. localized) character set rather than the default character set for the database.</p> <p>So as the others have said, you're insert...
36,220
<p>The ASP.NET calendar always displays 6 weeks of dates in a 7x6 grid. My problem is that the first day of the target month does <em>not necessarily</em> appear in the first row... in some cases, the entire first row displays dates from the previous month. In other cases, the entire last row displays dates from the ne...
<p>Looking at the public members exposed by the ASP.NET Calendar control I do not believe that this information is something that you can just get from the calendar control. </p> <p>You have a few options as "workarounds" to this though, although not nice....but they would work.</p> <ol> <li>You could manually calcu...
<p>see this one.</p> <p><a href="https://stackoverflow.com/questions/2514065/how-to-remove-the-last-week-of-a-calendar/6145946#6145946">How to Remove the Last Week Of a Calendar</a></p>
32,903
<p>I am making my switch from coding in C++ to C#. I need to replace my C++ error logging/reporting macro system with something similar in C#.</p> <p>In my C++ source I can write</p> <p>LOGERR("Some error"); or LOGERR("Error with inputs %s and %d", stringvar, intvar);</p> <p>The macro &amp; supporting library code ...
<p>Lots of log4net advocates here so I'm sure this will be ignored, but I'll add my own preference:</p> <pre><code>System.Diagnostics.Trace </code></pre> <p>This includes listeners that listen for your <code>Trace()</code> methods, and then write to a log file/output window/event log, ones in the framework that are i...
<p>Log4Net, as others have said, is fairly common and similar to Log4j which will help you if you ever do any Java.</p> <p>You also have the option of using the Logging Application Block <a href="http://www.codeproject.com/KB/architecture/GetStartedLoggingBlock.aspx" rel="nofollow noreferrer">http://www.codeproject.co...
17,767
<p>I get the following warning when using <code>java.net.URLEncoder.encode</code>:</p> <pre>warning: [deprecation] encode(java.lang.String) in java.net.URLEncoder has been deprecated</pre> <p>What should I be using instead?</p>
<p>Use the other <code>encode</code> method in <a href="http://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html#encode-java.lang.String-java.lang.String-" rel="noreferrer">URLEncoder</a>:</p> <pre><code>URLEncoder.encode(String, String) </code></pre> <p>The first parameter is the text to encode; the second ...
<p>As an additional reference for the other responses, instead of using <strong>"UTF-8"</strong> you can use:</p> <p><code>HTTP.UTF_8</code> </p> <p>which is included since Java 4 as part of the org.apache.http.protocol library, which is included also since Android API 1.</p>
26,247
<p>I am trying to use the Google Maps API in a ColdFusion template that is a border type cflayoutarea container. However, the map simply doesn't show up:</p> <pre><code>&lt;cfif isdefined("url.lat")&gt; &lt;cfset lat="#url.lat#"&gt; &lt;cfset lng="#url.lng#"&gt; &lt;/cfif&gt; &lt;head&gt; &lt;script src= ...
<p>Success! (sort of...)</p> <p>Finally got it working, but not in the way Adam suggested:</p> <pre><code>&lt;script src= "http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=xxxx" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; getMap=function(lat,lng){ ...
<p>Maybe the layout area doesn't have the right <strong>style</strong>. I think you may have to give the map_canvas a</p> <pre><code>position: absolute </code></pre> <p>or </p> <pre><code>position: relative </code></pre> <p>That's just a hunch.</p>
10,570
<p>Let's say I have four tables: <code>PAGE</code>, <code>USER</code>, <code>TAG</code>, and <code>PAGE-TAG</code>:</p> <pre><code>Table | Fields ------------------------------------------ PAGE | ID, CONTENT TAG | ID, NAME USER | ID, NAME PAGE-TAG | ID, PAGE-ID, TAG-ID, USER-ID </code></p...
<p>This might work:</p> <pre><code>select page.content, count(page-tag.tag-id) as tagcount from page inner join page-tag on page-tag.page-id = page.id group by page.content having page-tag.tag-id in (1, 3, 8) </code></pre>
<p>In T-Sql:</p> <pre><code>select count(distinct name) from page-tag where tag-id in (1, 3, 8) </code></pre> <p>This will give you a count of the number of different tag names for your list of ids</p>
5,202
<p>How do you compare two instances of structs for equality in standard C?</p>
<p>C provides no language facilities to do this - you have to do it yourself and compare each structure member by member.</p>
<p>if the 2 structures variable are initialied with calloc or they are set with 0 by memset so you can compare your 2 structures with memcmp and there is no worry about structure garbage and this will allow you to earn time </p>
17,131
<p>All,</p> <p>I'm working on a SharePoint project, but this isn't a SharePoint-specific question per-se. I have an assembly I've deployed to a SharePoint farm, and I'd like to verify whether my "newest version" is sitting in the GAC, or if an older version from late yesterday is sitting there instead. This is a test ...
<p>Assembly Version is the intended mechanism for this, but you could roll your own by comparing an MD5 hash of the GAC assembly with the MD5 of your latest version.</p>
<p>You could use AssemblyFileVersion attribute. From the docs, the AssemblyFileVersion</p> <p><em>Instructs a complier to use a specific version number for the Win32 file version resource. The Win32 file version is not required to be the same as the assembly's version number.</em></p>
26,930
<p>It is often handy to have a canonical representation of a language (in my case they are usually domain specific languages); however, I believe there are strict limits on the expressiveness of the languages involved that determine whether a canonical form can be determined and/or created for an arbitrary program in t...
<p>By "canonical representation" I assume you mean the following: Call programs <em>P</em> and <em>Q</em> <em>equivalent</em> if they "do the same thing" on the same inputs. "Doing the same thing" means that the programs have the same output, and either both programs halt after a finite time or both enter an infinite l...
<p>It seems to me that compiling into an assembly language could be categorized as translation into a canonical form in a practical fashion.</p>
22,380
<p>I am serving all content through apache with <code>Content-Encoding: zip</code> but that compresses on the fly. A good amount of my content is static files on the disk. I want to gzip the files beforehand rather than compressing them every time they are requested.</p> <p>This is something that, I believe, <code>m...
<p>This functionality was misplaced in mod_gzip anyway. In Apache 2.x, <a href="http://httpd.apache.org/docs/2.2/content-negotiation.html" rel="noreferrer">you do that with content negotiation</a>. Specifically, you need to enable <code>MultiViews</code> with the <a href="http://httpd.apache.org/docs/2.2/mod/core.html#...
<p>You can use <a href="http://httpd.apache.org/docs/2.2/mod/mod_cache.html" rel="nofollow noreferrer"><code>mod_cache</code></a> to proxy local content in memory or on disk. I don't know if this will work as expected with <code>mod_deflate</code>.</p>
10,110
<p>Navigation systems like the Garmin and TomTom have always fascinated me. I've wanted to implement small map/navigation applications to try out various pathing algorithms and expand on my knowledge of them.</p> <p>This is a two part question:</p> <p><strong>1.) How is Map data stored?</strong> - When you have a n...
<p>I don't know specifics about navigation system units, but in the standard GIS world, map data is stored basically as a collection of polygons, lines and points, each described by its coordinates (and the projection used and some other parameters). For instance, one of the most common formats, shapefiles, is describe...
<p>For improved drawing speed at the cost of more storage and limited resolution, many applications will use a georeferenced raster format such as <a href="http://www.remotesensing.org/geotiff/geotiff.html" rel="nofollow noreferrer">GeoTiff</a>. </p> <p>Given the rather insistent comment by Zich below that </p> <bloc...
21,364
<p>I'm currently working on a DNA database class and I currently associate each row in the database with both a match score (based on edit distance) and the actual DNA sequence itself, is it safe to modify first this way within an iteration loop?</p> <pre><code>typedef std::pair&lt;int, DnaDatabaseRow&gt; DnaPairT; ty...
<p>To answer your first question, yes. It is perfectly safe to modify the members of your pair, since the actual data in the pair does not affect the vector itself.</p> <p><b>edit:</b> I have a feeling that you were getting an error when using a map because you tried to modify the <code>first</code> value of the map's...
<p>You can't modify since the variable first of std::pair is defined const</p>
42,775
<p>I have been sick and tired Googling the solution for doing case-insensitive search on Sybase ASE (Sybase data/column names are case sensitive). The Sybase documentation proudly says that there is only one way to do such search which is using the Upper and Lower functions, but the adage goes, it has performance probl...
<p>Try creating a <code>functional index</code>, like </p> <pre><code>Create Index INDX_MY_SEARCH on TABLE_NAME(LOWER(@MySearch) </code></pre>
<p>If you cannot change the sort-order on the database(best option), then the indexes on unknown case fields will not help. There is a way to do this and keep performance if the number of fields is manageable. You make an extra column MyFieldLower. You use a trigger to keep the field filled with a lower case of MyFi...
10,685
<p>I want to provide silverlight app to my customer while hosting the app at my own site for streamlined maintenance.</p> <ul> <li>my Silverlight .xap is hosted in, let say, domain <em>me-supplier.com</em></li> <li>i want to embed it in, let say, domain <em>my-customer.com</em></li> </ul> <p>It works perfectly for ...
<p>The short story is that it isn't <a href="http://forums.asp.net/p/1006669/1336527.aspx" rel="nofollow noreferrer">easily</a> accomplished. That code is added to the header by the menu during the prerender phase. </p> <p>A possible workaround might be overriding the menu's onprerender in a custom menu control and do...
<p>The short story is that it isn't <a href="http://forums.asp.net/p/1006669/1336527.aspx" rel="nofollow noreferrer">easily</a> accomplished. That code is added to the header by the menu during the prerender phase. </p> <p>A possible workaround might be overriding the menu's onprerender in a custom menu control and do...
27,366
<p>If I have a VB.Net function that returns an Int32, but uses an unsigned int (UInt32) for calculations, etc. How can I convert a variable "MyUintVar32" with a value of say "3392918397 into a standard Int32 in VB.Net? </p> <p>In c# if I just do a "return (int)(MyUintVar32);", I get -902048899, not an error.</p> <p...
<p>I realize this is an old post, but the question has not been answered. Other people my want to know:</p> <pre><code>Dim myUInt32 As UInt32 = 3392918397 Dim myInt32 As Int32 = Convert.ToInt32(myUInt32.ToString("X"), 16) </code></pre> <p>the reverse operation: </p> <pre><code>myUInt32 = Convert.ToUInt32(myInt...
<p>Or after doing the Uint32 work check it against MAXINT and 0. </p> <p>If > MAXINT and &lt; 0 then you're ok. If not you "overflowed" and should throw an exception.</p> <p>I don't remember if MAXINT is defined. You can use: 2^31 - 1 instead.</p>
25,822
<p>When using Groovy <code>MarkupBuilder</code>, I have places where I need to output text into the document, or call a function which outputs text into the document. Currently, I'm using the undefined tag <em>"text"</em> to do the output. Is there a better way to write this code?</p> <pre><code>li { text("${type.g...
<p>Actually, the recommended way now is to use <code>mkp.yield</code>, e.g.,</p> <pre><code>src.p { mkp.yield 'Some element that has a ' strong 'child element' mkp.yield ' which seems pretty basic.' } </code></pre> <p>to produce</p> <pre><code>&lt;p&gt;Some element that has a &lt;strong&gt;child element&...
<p>Include a method:</p> <pre><code>void text(n){ builder.yield n } </code></pre> <p>Most likely you (I) copied this code from somewhere that had a text method, but you didn't also copy the text method. Since MarkupBuilder accepts any name for the name of a tag and browsers ignore unknown markup, it just happene...
4,314
<p>We're thinking of buying a PETG-powered printer. When researching printers available on the market, there are machines with a 100 microns. I was wondering if there are machines with a 50 microns or close to 50 micros? Otherwise, why not?</p>
<blockquote> <p>I was wondering the other day why don't all three motors move at the same time?</p> </blockquote> <p>That is perfectly possible for most printers (with limitations, &quot;3D Printing&quot; with all steppers being used is called &quot;non-planar&quot; printing), but there are some major cons you need to ...
<p>The Z axis moves between each layer so you are indeed printing in the 3rd dimension. There are some techniques that move all three axis at the same time.</p>
1,925
<p>Half a year passed since <a href="https://3dprinting.meta.stackexchange.com/questions/430/tag-maintenance-summer-2019">Tag Maintenance Summer 2019</a>. A lot was done, some wasn't, so cleanup and rinse and repeat: Let's do some tag maintenance, especially regarding printers to make them easier to read. Use an answer...
<h1>Laundry list:</h1> <h2>Open</h2> <ul> <li><a href="https://3dprinting.meta.stackexchange.com/a/458/8884">Filled PLA</a></li> <li><a href="https://3dprinting.meta.stackexchange.com/a/459/8884">Repair vs. Maintenance</a></li> </ul> <h2>Done</h2> <ul> <li><a href="https://3dprinting.meta.stackexchange.com/a/456/8884">...
<h1>Manufacturer: E3D</h1> <p>Status: <strong>Done</strong>/split up</p> <p><a href="https://3dprinting.meta.stackexchange.com/a/438/8884">Takeover from Summer 2019</a></p> <p>We have a lot of questions tagged <a href="https://3dprinting.stackexchange.com/questions/tagged/e3d" class="post-tag" title="show questions tag...
73
<p>I have many items inside a list control. I want each item to have a different item template depending on the type of the item. So the first item in the list is a ObjectA type and so I want it to be rendered with ItemTemplateA. Second item is a ObjectB type and so I want it to have ItemTemplateB for rendering. At the...
<p>the <code>ItemTemplateSelector</code> will work but I think it is easier to create multiple <code>DataTemplate</code>s in your resource section and then just giving each one a <code>DataType</code>. This will automatically then use this <code>DataTemplate</code> if the items generator detects the matching data type?...
<p>Have a look at the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemtemplateselector.aspx" rel="noreferrer">ItemTemplateSelector</a> property of your list control. You can point it to a custom TemplateSelector and decide which template to use in code.</p> <p>Here's a blog po...
18,418
<p>I wrote this small script to pull the office property from get-user by piping the exchange mailbox object. </p> <pre><code>$server = "tms08" $arrUser = get-mailbox -Server $server |Get-MailboxStatistics |select identity foreach ( $id in $arrUuser) { $office = get-user -Identity $id.Identity |select office $...
<p>Check this out: <a href="http://msdn.microsoft.com/en-us/library/6t9t5wcf.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/6t9t5wcf.aspx</a></p> <p>And this: <a href="http://www.xenocode.com/Products/Postbuild-for-NET/?AdGroup=Linking&amp;gclid=CNGCo-7zopcCFSYMDQod0giG_A" rel="nofollow norefe...
<p><a href="http://www.dcl.hpi.uni-potsdam.de/research/lego.NET/release.htm" rel="nofollow noreferrer">Lego.NET</a> can create native binaries, but it's still fairly limited.</p>
43,516
<p>Is there a CPAN module that can read a string like this:</p> <pre><code>"[[&lt;asdf&gt;, &lt;foo&gt;], (abc, def, ghi), ({'jkl'})]" </code></pre> <p>...and parse it into some sort of tree structure that's easy to walk and pretty-print?</p>
<p>I think that you could build on top of <a href="http://search.cpan.org/dist/Text-Balanced/" rel="nofollow noreferrer">Text::Balanced</a>, which will do a lot of the heavy lifting for you. You'll still need to build a tree structure, though.</p>
<p>If the string is identical to the <a href="http://perldoc.perl.org/Data/Dumper.html" rel="nofollow noreferrer">Data Dumper</a> format, then it can be <code>eval</code>-ed back into the original structure.</p>
46,150
<p>Inspired by <a href="https://devblogs.microsoft.com/oldnewthing/20080902-00/?p=21003" rel="noreferrer">Raymond Chen's post</a>, say you have a 4x4 two dimensional array, write a function that rotates it 90 degrees. Raymond links to a solution in pseudo code, but I'd like to see some real world stuff.</p> <pre><code...
<p><strong>O(n^2) time and O(1) space algorithm</strong> ( without any workarounds and hanky-panky stuff! )</p> <p><strong>Rotate by +90:</strong></p> <ol> <li>Transpose</li> <li>Reverse each row</li> </ol> <p><strong>Rotate by -90:</strong></p> <p><em>Method 1 :</em></p> <ol> <li>Transpose</li> <li>Reverse each c...
<p>The O(1) memory algorithm:</p> <ol> <li><p>rotate the outer-most data, then you can get below result:</p> <pre><code>[3][9][5][1] [4][6][7][2] [5][0][1][3] [6][2][8][4] </code></pre></li> </ol> <p>To do this rotation, we know </p> <pre><code> dest[j][n-1-i] = src[i][j] </code></pre> <p>Observe below: ...
6,405
<p>I've been developing an internal website for a portfolio management tool. There is a lot of text data, company names etc. I've been really impressed with some search engines ability to very quickly respond to queries with "Did you mean: xxxx".</p> <p>I need to be able to intelligently take a user query and respon...
<p>Here's the explanation directly from the source ( almost ) </p> <h2><strong><a href="http://www.youtube.com/watch?v=syKY8CrHkck#t=22m03s" rel="noreferrer">Search 101!</a></strong></h2> <p>at min 22:03</p> <p>Worth watching!</p> <p>Basically and according to Douglas Merrill former CTO of Google it is like this:<...
<p>Easiest way to figure it out is to Google dynamic programming.</p> <p>It's an algorithm that's been borrowed from Information Retrieval and is used heavily in modern day bioinformatics to see how similiar two gene sequences are.</p> <p>Optimal solution uses dynamic programming and recursion.</p> <p>This is a very...
39,541
<p>Our team is creating a new recruitment workflow system to replace an old one. I have been tasked with migrating the old data into the new schema. I have decided to do this by creating a small Windows Forms project as the schema are radically different and straight TSQL scripts are not an adequate solution.</p> <p>T...
<p>Maybe you can try the BackgroundWorker component. It makes threading easier. Examples here:</p> <ul> <li><a href="http://www.codeproject.com/KB/cpp/BackgroundWorker_Threads.aspx" rel="nofollow noreferrer">BackgroundWorker Threads and Supporting Cancel</a></li> <li><a href="http://www.c-sharpcorner.com/UploadFile/Li...
<p>Are you sure that the UI thread is running freely during all this process? i.e. it's not sitting blocked-up on a Join or some other wait? That's what it looks like to me.</p> <p>The suggestion of using BackgroundWorker is a good one - definitely superior to trying to sledge-hammer your way out of the problem with...
3,318
<p>I'm writing what will be an intranet application, and one of its features is roughly analogous to content voting - not unlike what SO, Amazon, and many other sites do.</p> <p>Assuming each votable piece of content has a unique ID, and each user (they're authenticated) has a unique ID, the easiest way would seem to ...
<p>Personally as long as you have good indexes in place, you are going about it the right way. Depending on your usage, for performance you might try to avoid hitting the votes table by storing secondary count information, but overall if you must track WHO has voted something, you need to do it in the way you have lis...
<p>I'd say you need to figure out how these votes will be used and design specific queries for your data model first. This is not necessarily SQL model. If you're coming from SQL world, passing through official MongoDB tutorial helps to clear the mind for the start.</p> <p>For example, if you only need to store and di...
44,546
<p>Many times, a Java app needs to connect to the Internet. The most common example happens when it is reading an XML file and needs to download its schema.</p> <p>I am behind a proxy server. How can I set my JVM to use the proxy ?</p>
<p>From the Java documentation (<em>not</em> the javadoc API):</p> <p><a href="http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html" rel="noreferrer">http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html</a></p> <p>Set the JVM flags <code>http.proxyHost</code> and <code>http.p...
<p>You can utilize the http.proxy* JVM variables if you're within a standalone JVM but you SHOULD NOT modify their startup scripts and/or do this within your application server (except maybe jboss or tomcat). Instead you should utilize the JAVA Proxy API (not System.setProperty) or utilize the vendor's own configurati...
14,690
<p>I want to add the link tags to redirect my web-site to my OpenID provider. These tags should go in the head element. What's the best way to add them in Plone?</p> <p>I understand that filling the head_slot is a way to do it, but that can only happen when you are adding a template to the page and that template is be...
<p>You need fill the <code>head_slot</code> defined in <code>main_template.pt</code></p> <p>In your base plone template, add the following:</p> <pre><code>&lt;head&gt; &lt;metal:block metal:fill-slot="head_slot"&gt; &lt;link rel="openid.server" href="http://your.provider"&gt; &lt;link rel="openid....
<p>Plone documentation on supporting OpenID can be found here.</p> <p><a href="http://plone.org/documentation/how-to/openid-support/view?searchterm=openid" rel="nofollow noreferrer">http://plone.org/documentation/how-to/openid-support/view?searchterm=openid</a></p> <p>Hope this helps.</p>
16,680
<p>Do you know of a JAXB setting to prevent <strong>standalone="yes"</strong> from being generated in the resulting XML?</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; </code></pre>
<p>This property:</p> <pre class="lang-java prettyprint-override"><code>marshaller.setProperty(&quot;com.sun.xml.bind.xmlDeclaration&quot;, false); </code></pre> <p>...can be used to have no:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quo...
<p>If you have <code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;</code> </p> <p>but want this: <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code></p> <p>Just do:</p> <pre><code>marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshaller.setProperty("com.sun.xml.internal.bind.x...
35,091
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/336859/javascript-var-functionname-function-vs-function-functionname">JavaScript: var functionName = function() {} vs function functionName() {}</a> </p> </blockquote> <p>What's the difference between:</p> <pr...
<p>The first is known as a named function where the second is known as an anonymous function.</p> <p>The key practical difference is in when you can use the sum function. For example:-</p> <pre><code>var z = sum(2, 3); function sum(x, y) { return x+y; } </code></pre> <p><code>z</code> is assigned 5 whereas this...
<p>They mean the exact same thing. It's just syntactic sugar. The latter is IMO more revealing of what JavaScript is really doing; i.e. "sum" is just a variable, initialised with a function object, which can then be replaced by something else:</p> <pre><code>$ js js&gt; function sum(x,y) { return x+y; } js&gt; sum(1,2...
13,982
<p>We will need to call out to a 3rd party to retrieve a value using REST, however if we do not receive a response within 10ms, I want to use a default value and continue processing.</p> <p>I'm leaning towards using an asynchronous WebRequest do to this, but I was wondering if there was a trick to doing it using a syn...
<p>If you are doing a request and waiting on it to return I'd say stay synchronous - there's no reason to do an async request if you're not going to do anything or stay responsive while waiting.</p> <p>For a sync call:</p> <pre><code>WebRequest request = WebRequest.Create("http://something.somewhere/url"); WebRespons...
<p>You could encapsulate your call to the 3rd party in a WebService. You could then call this WebService synchronously from your application - the web service reference has a simple timeout property that you can set to 10 seconds or whatever.</p> <p>Your call to get the 3rd party data from your WebService will throw ...
16,341
<p>When I turn an image (<code>&lt;img&gt;</code>) into a hyperlink (by wrapping it in <code>&lt;a&gt;</code>), Firefox adds a black border around the image. Safari does not display the same border. </p> <p>What CSS declaration would be best to eliminate the border?</p>
<pre><code>img { border: 0 } </code></pre> <p>Or old-fashioned:</p> <pre><code>&lt;img border="0" src="..." /&gt; ^^^^^^^^^^ </code></pre>
<p>Try this:</p> <pre><code>img { border-style: none; } </code></pre>
7,260
<p>Where can I find comprehensive documentation for MOQ? I'm just starting with mocking and am having difficulty getting my head around it. I've read through all the links at <a href="http://code.google.com/p/moq/wiki/QuickStart" rel="noreferrer">http://code.google.com/p/moq/wiki/QuickStart</a> but can't seem to find a...
<p>Moq's latest documentation is now available at github wiki page:</p> <p><a href="https://github.com/Moq/moq4/wiki/Quickstart" rel="noreferrer">https://github.com/Moq/moq4/wiki/Quickstart</a></p> <p>Previously they were on Google Code. As well as the wiki and other online resources, there's full documentation in Wi...
<blockquote> <p>I am trying to determine whether an event was raised from the mocked class.</p> </blockquote> <p>Are you? Or are you trying to determine if the <code>Id</code> property was set? Remember, by default a mock has no behavior. It's not raising notification events.</p> <p>I'd do:</p> <pre><code>const ...
28,614
<p>Let's say I've got some Perl code that increments a column in a specific row of a database each time it's hit, and I'm expecting it to be hit pretty frequently, so I'd like to optimize it with FCGI. Right now, I basically wrapped most of the code in something like this:</p> <pre><code>while (FCGI::accept() &gt;= 0...
<p>bmdhacks is right that if you're using MySQL or PostgreSQL it doesn't matter as much since connections are pretty cheap. But no matter your database you will have speed gains by using persistent connections.</p> <p>But if you do decide to go with persistent connections you will need to worry about connection timeou...
<p>You would still gain from FCGI even if you do keep your DB connection in the loop - but you would gain even more if you moved it out.</p>
25,353
<p>I've been trying to understand how Ruby blocks work, and to do that I've been trying to implement them in C.</p> <p>One easy way to implement closures is to pass a <code>void*</code> to the enclosing stack to the closure/function but Ruby blocks also seem to handle returns and break statements from the scope that u...
<p>The concept of closures requires the concept of contexts. C's context is based on the stack and the registers of the CPU, so to create a block/closure, you need to be able to manipulate the stack pointer in a correct (and reentrant) way, and store/restore registers as needed.</p> <p>The way this is done by interpre...
<p>There's a good set of slides on Ruby Blocks as part of the "Rails with Passion" course:</p> <p><a href="http://www.javapassion.com/rubyonrails/ruby_blocks.pdf" rel="nofollow noreferrer">Ruby_Blocks.pdf</a></p> <p>This covers representing a block, how they get passed arguments and executed, and even further into th...
4,022
<p>I'd like to have an application monitor written in C# monitoring a set of Forex trading positions. It would be connected via USB to a real set of "traffic lights" sat on a desk which it would use to indicate system status. Can anybody suggest a good solution?</p>
<p>Normally I'd say parallel port or some other such thing, but if you've got your hopes up for USB, then <em>definitely</em> have a look at the <a href="http://www.arduino.cc/" rel="nofollow noreferrer">Arduino</a>. It's a very low cost microcontroller that can run standalone, or can talk to a PC through a number of f...
<p>Try using simple usb experimentation interfaces such as Phidgets (Www.phidgets.com) or the Velleman k8055 USB experimentation board (<a href="http://www.velleman.be/ot/en/product/view/?id=351346" rel="nofollow noreferrer">http://www.velleman.be/ot/en/product/view/?id=351346</a>).</p>
34,267
<p>In Office 2003 if I recall correctly you had a "record macro" option.</p> <p>In PowerPoint 2007, under View->Macros, you get a macro box. None of the options are "record". If you put in a name, you can select "create", but that takes you to the VB editor. If you edit the slide manually, it does not generate the VBA...
<p>It seems you are out of luck <a href="http://office.microsoft.com/en-us/powerpoint/HA101181981033.aspx?pid=CH101030561033" rel="nofollow noreferrer">What happened to the macro recorder?</a></p> <p>I have since read:</p> <blockquote> <p>Contrary to what Microsoft says, use the legacy keyboard commands Alt+T, M,...
<p>The Keystroke activated record doesen't work it creates an empty macro with very few(usually none!) of the actual actions that you performed.</p>
49,963
<p>I'm trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example:</p> <pre><code>var results = from myRow in myDataTable where results.Field("RowNo") == 1 select results; </code></pre> <p>This is not allowed. How do I...
<p>You can't query against the <code>DataTable</code>'s <em>Rows</em> collection, since <code>DataRowCollection</code> doesn't implement <code>IEnumerable&lt;T&gt;</code>. You need to use the <code>AsEnumerable()</code> extension for <code>DataTable</code>. Like so:</p> <pre><code>var results = from myRow in myDataTabl...
<p>I propose following solution:</p> <pre><code>DataView view = new DataView(myDataTable); view.RowFilter = "RowNo = 1"; DataTable results = view.ToTable(true); </code></pre> <p>Looking at the <a href="https://learn.microsoft.com/de-de/dotnet/api/system.data.dataview?view=netframework-4.8" rel="nofollow noreferrer">...
3,202
<p>In particular, I am interested in: 1) Getting up a <em>free</em> environment setup to do workflows. 2) How to use existing workflow items/states and what is involved in that.</p> <p>Thanks!</p>
<p>Are you looking for a virtual lab like this one from <a href="http://blogs.msdn.com/pandrew/archive/2007/04/16/new-msdn-virtual-lab-for-windows-workflow-foundation.aspx" rel="nofollow noreferrer">MSDN</a>?</p> <p>For some How Tos, try downloading <a href="http://www.microsoft.com/downloadS/details.aspx?familyid=2E5...
<p>Are you looking for a virtual lab like this one from <a href="http://blogs.msdn.com/pandrew/archive/2007/04/16/new-msdn-virtual-lab-for-windows-workflow-foundation.aspx" rel="nofollow noreferrer">MSDN</a>?</p> <p>For some How Tos, try downloading <a href="http://www.microsoft.com/downloadS/details.aspx?familyid=2E5...
21,332
<p>There's <a href="http://developer.apple.com/quicktime/download/" rel="nofollow noreferrer">Quicktime SDK</a> for Windows, but any application that uses it needs quicktime runtime libraries to be installed on the system (SDK itself just has headers and library stubs, and not the actual DLLs).</p> <p>If my applicatio...
<p>If you need to redistribute QuickTime, see <a href="http://developer.apple.com/softwarelicensing/agreements/quicktime.html" rel="nofollow noreferrer">QuickTime Licensing</a> for details. You're not allowed to redistribute any of the QuickTime libraries without a written agreement with Apple. Many CD-replication comp...
<p>You could include, with your setup package, a program called Quicktime Lite. It comes with the same libraries as Quicktime uses, but is much, much smaller.</p> <p>Here"s the link: <a href="http://www.codecguide.com/qt_lite.htm" rel="nofollow noreferrer">Download Quicktime Lite</a></p>
10,022
<p>How do I embed a WMV file in an ASP.NET Web page? I want it visible as a player, not just a link. Is there an ASP.NET control for this? I don't see one on the VS 2008 toolbar, and can't find one in the help. And I'm not yet ready to move this site to Silverlight, where media is really easy.</p>
<p>Check if your project is targeted for 3.5. If it is, you should be able to see the mediaplayer control in your toolbox.</p> <p>WMV can be shown in Firefox with this plugin: <a href="http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx" rel="nofollow noreferrer">http://port25.technet.com...
<p>WMV is primarily a Microsoft file format. There is no inherent browser support for this format, so you're going to need a browser plugin to play it.</p> <p>I'm pretty sure you can embed Windows Media Player on a page to play it, but that'll limit you to clients running Windows and who happen to have Media Player i...
42,697
<p>Does anyone know of any good library that abstracts the problem of path manipulation in a nice way? I'd like to be able to combine and parse paths with arbitrary separators ('/' or ':' for example) without reinventing the wheel.</p> <p>It's a shame that <code>System.IO.Path</code> isn't more reusable.</p> <p>Thank...
<p>System.IO.Path.Combine will work great for many different types of paths:</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx</a></p> <p>System.IO.Path.Combine uses the current platform st...
<p>You're describing regular expressions! Use that as the underpinning for what you need to do. </p>
7,529
<p>I've recently gotten charged with designing and implementing a source code version control, testing, and deployment scheme at the company I work.</p> <p>Personally I've worked with Subversion for a few years on my own projects. But I've never dealt with it at this big scale. Hence I thought I'd ask here if anyone h...
<p>If you want the same busy indicator for all actions, then use a counter.</p> <p>Instead of "show_busy_icon()", do a "increment_busy_count()", which calls "show_busy_icon()" if busy count goes from 0 to 1. Instead of "hide_busy_icon()", do a "decrement_busy_count()", which calls "hide_busy_icon()" if busy count goes...
<p>Please see my answer here: </p> <p><a href="https://stackoverflow.com/questions/244183/how-to-display-a-loading-screen-while-site-content-loads#244190">How to display a loading screen while site content loads</a></p> <p>I give a small, working JavaScript example of how to do exactly this, hope it helps.</p>
46,080
<p>When I go back to school after Thanksgiving, I'll be taking a course in CS Theory covering topics such as deterministic and nondeterministic finite state machines, turing machines, pushdown automata and a few other things. However, I haven't found a good application that can produce a visual representation of them a...
<p>It was <a href="http://www.cs.duke.edu/csed/jflap/" rel="nofollow noreferrer">JFlap</a> that I used in college. I didn't find it that awkward to use, but it looks like it may have changed since then. Sorry I don't have a better answer for you than that.</p>
<p><a href="http://www.iar.com/website1/1.0.1.0/371/1/index.php" rel="nofollow noreferrer">IAR visualSTATE</a> might be of interest.</p>
24,174
<p>I'd like to find an opensource software that communicates directly with the RAMPS board (or any other 3D printer driver) without using the arduino...</p> <p>It doesn't matter if it runs on Windows or linux as long as it's opensource. Also, I'm not worried about how this communication is done (USB, serial port, para...
<p>No, there exists no software like that. You can't communicate with a RAMPs board because a RAMPs board has no logic built-in; it's just a dumb breakout board that connects the Arduino Mega to your printer's components (such as stepper drivers, MOSFETs for controlling heaters, endstops,...).</p> <p>If you wanted to ...
<p>No, there exists no software like that. You can't communicate with a RAMPs board because a RAMPs board has no logic built-in; it's just a dumb breakout board that connects the Arduino Mega to your printer's components (such as stepper drivers, MOSFETs for controlling heaters, endstops,...).</p> <p>If you wanted to ...
267
<p>I am creating a website in CakePHP and I am kind of new on it. I couldn't find good resources on this matter, so there you go:</p> <p>I have a three table structure for registering users: <code>Users</code>, <code>Addresses</code> and <code>Contacts</code>. I have to build a view with info of all three tables like:...
<p>If your using the latest 1.2 code, check out Model::saveAll in the api</p> <p>eg. Your view might look something like this:</p> <pre><code>echo $form-&gt;create('User', array('action' =&gt; 'add'); echo $form-&gt;input('User.name'); echo $form-&gt;input('Address.line_1'); echo $form-&gt;input('Contact.tel'); echo ...
<blockquote> <p>3 models : User, Address, Contact</p> </blockquote> <pre><code>User hasOne Address, Contact Address belongsTo User Contact belongsTo User </code></pre> <p>in your model you define this like this :</p> <pre><code>class User extends AppModel { var $name = 'User'; var $hasOne = array('Address','Contac...
13,544
<p>Since Rails 2.1, if you define a new column in a migration with the type set to :integer and the :limit set to 5 or more, the column actually created in your MySQL database will be of type BigInt. That's perfect.</p> <p>But I cannot figure out how to create a table with a BigInt primary key.</p> <p>Any clues?</p>...
<p>Not sure about the Apple ones, but this one has been really good at getting started:</p> <p><a href="http://iphone.christosblog.com/" rel="nofollow noreferrer">Christos Blog</a></p> <p>They hop into the code and tools rather than spending too much time explaining the tools. I think they will help you. </p>
<p>I believe you need to download them from iTunes which requires either a Mac or PC but they are standard mpeg-4 videos and should be viewable in vlc.</p>
40,364
<p>How do I split strings in J2ME in an effective way?</p> <p>There is a <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/util/StringTokenizer.html" rel="noreferrer"><code>StringTokenizer</code></a> or <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#split%28java.lang.Strin...
<p>There are a few implementations of a StringTokenizer class for J2ME. This one by <a href="http://ostermiller.org/utils/StringTokenizer.html" rel="nofollow noreferrer">Ostermiller</a> will most likely include the functionality you need</p> <p>See also <a href="https://web.archive.org/web/20120206073031/http://mobilep...
<p>Another alternative solution:</p> <pre><code> public static Vector split(String stringToSplit, String separator){ if(stringToSplit.length&lt;1){ return null; } Vector stringsFound = new Vector(); String remainingString = stringToSplit; while(remainingString.length()&gt;0){ ...
24,499
<p>Has anybody had any success ever attaching a debugger to a tethered device? I am able to debug my j2me application in the emulator, but have a lot of trouble sorting out phone-specific problems when they come up. The phone I'm using is a Nokia N95, but ideally the debug process would work on any phone.</p> <p>Is ...
<p>Motorola phones support a debugging interface called <a href="https://developer.motorola.com/docstools/technicalarticles/KDWP_20060501.pdf/" rel="nofollow noreferrer">KDWP</a>(Motodev registration required).Their MIDway tool can also be useful for getting debug trace information from a midlet running on a device.</...
<p>I think it is possible to add additional debugging information on preprocess step. Like this:</p> <pre> public void myMethod() { Debug.traceMethod("myMethod"); int var = 1; Debug.newLine(); var++; Debug.newLine(); ... } </pre>
42,963
<p>I'm trying to use the Windows API to set the primary monitor. It doesn't seem to work - my screen just flicks and nothing happens.</p> <pre><code> public const int DM_ORIENTATION = 0x00000001; public const int DM_PAPERSIZE = 0x00000002; public const int DM_PAPERLENGTH = 0x00000004; public const int DM_PAPERWIDTH...
<p>I ran into exactly the same problem, both from C# and after following the advice here to try it in C++. I eventually discovered that the thing the Microsoft documentation doesn't make clear is that the request to set the primary monitor will be ignored (but with the operation reported as successful!) unless you als...
<p>I can't really help you with the winapi-stuff but if you are using a Nvidia card you may have a look at the <a href="http://developer.download.nvidia.com/SDK/9.5/Samples/DEMOS/common/src/NvCpl/docs/NVControlPanel_API.pdf" rel="nofollow noreferrer">NVcontrolPanel Api Documentation</a> Then you could make the secondar...
23,717
<p>Delphi 2009 introduced a hierarchical system for project options configuration, where you set "base" options and then have different build styles with their own option sets. But can you extend the hierarchy even further? I do most of my coding with debug options on, of course, but sometimes there are special cases w...
<p>Yes, it's straightforward.</p> <p>In the project manager, just right-click on the "Debug" configuration, and select "New Configuration". Your new configuration will appear as descended from "Debug" in the way that you expect.</p>
<p>Build Configurations are completely hierarchical. You can create any depth of hierarchies that you want in your configurations. Any build configuration can be descended from, and the hierarchies can be as deep as you like.</p> <p>In addition, you can use Option Sets to alter any given configuration. Save an Opti...
33,247
<p>I need to have a routine/function/stored proc/whatever to archive particular accounts from our 'active' table, to an inactive table.</p> <p>I can write this out as a group of queries, all executed in order by PHP one at a time, but I'm looking to offload most of the work to mysql because it's not necessary for PHP ...
<p>You might want to use scheduled tasks aka events if you want this to be run daily, automatically. You can read about them in the MySQL documentation <a href="http://dev.mysql.com/tech-resources/articles/event-feature.html" rel="nofollow noreferrer">here</a>.</p> <p>Keep in mind you need to use MySQL 5.1.6 or newer...
<p>You might want to use scheduled tasks aka events if you want this to be run daily, automatically. You can read about them in the MySQL documentation <a href="http://dev.mysql.com/tech-resources/articles/event-feature.html" rel="nofollow noreferrer">here</a>.</p> <p>Keep in mind you need to use MySQL 5.1.6 or newer...
48,203
<p>My application has a WCF service tier between the front-end and the database. Since we currently host in IIS6 we are using SOAP over HTTP. How can I find out how much real world time I am spending doing serialization activities in my application?</p>
<p>Not about measuring - but about improving: I've been working on <a href="http://code.google.com/p/protobuf-net/" rel="nofollow noreferrer">protobuf-net</a>, an implementation of Google's "protocol buffers" (a compact, low-CPU binary serialization format) for use with .NET - including a WCF hook (to replace the DataC...
<p>One of the dead simple things old mainframes always used to to was to include a "sever time" field in the response. Therefore you'd know that anything that happened between your observed time and server time is network/serialization overhead. I know it kind of 1960-ish, but it still works well.</p> <p>If you want a...
32,002
<p>I've been a longtime ASP.NET developer in the web forms model, and am using a new project as an opportunity to get my feet wet with ASP.NET MVC.</p> <p>The application will need an API so that a group of other apps can communicate with it. I've always built API's out just using a standard web service prior to this...
<p>I'd agree with Kilhoffer. Try using a "Facade" wrapper class that inherits from an "IFacade". In your Facade class put your code to consume your web service. In this way your controllers will simply make calls to the Facade. The plus side of this being that you can swap a "DummyFacade" that implements the same I...
<p>I would still recommend a service layer that can serve client side consumers or server side consumers. Possibly even returning data in a variety of formats, depending on the consuming caller.</p>
16,333
<p>I've got a SQLServer Database and an application (.NET) that configures data on that database. On the other hand, I've got an application (VC++) that reads that data from the database and must be 'informed' a soon as possible of any change in the data saved on the database.</p> <p>I would like to receive a signal f...
<p>You can use a SQL Agent Job that will notify the other app starting it with sp_start_job. Check <a href="http://www.windows-tech.info/15/830e5ff5a0c026bf.php" rel="nofollow noreferrer">this</a> out.</p>
<p>You can use a SQL Agent Job that will notify the other app starting it with sp_start_job. Check <a href="http://www.windows-tech.info/15/830e5ff5a0c026bf.php" rel="nofollow noreferrer">this</a> out.</p>
41,383
<p>I understand how Lucene.net can work for text indexing. Will I be able to efficiently search for documents based on a given date range? Or will Lucene.net just use text matching to match the dates?</p>
<p>Lucene.Net will just use text matching, so you'd need to format the dates correctly before adding to the index:</p> <pre><code> public static string Serialize(DateTime dateTime) { return dateTime.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture); } public static DateTime Deserialize(s...
<p>I went in to trouble when i converted date in to <code>yyyymmddHHmmssff</code>. When i tried sorting the data, it gave me an exception that too big to convert..something. Hence i search and found then you need to have two columns. one in <code>yyyymmdd</code> and the other <code>HHmmss</code>, and then use <code>Sor...
37,920
<p>I need to change in a text input the character '.' to ',' while typing. In IE I change the keyCode event property in the keypress event, like this</p> <pre><code>document.getElementById('mytext').onkeypress = function (evt) { var e = evt || window.event; if (e.keyCode &amp;&amp; e.keyCode==46) e.keyCode = ...
<p>Try this. It works on all browsers:</p> <pre><code>window.onload = function () { var input = document.getElementById("mytext"); input.onkeypress = function () { var evt = arguments[0] || event; var char = String.fromCharCode(evt.which || evt.keyCode); // Is it a period? if ...
<p>Does this really need to be done on the fly? If you are collecting the information to be posted to a form or submitted to a database, would it not be better to modify the data once it was submitted? That way the user never sees the confusing change.</p>
26,848
<p>I am intercepting Win32 API calls a native dll or exe is doing from C# using some kind of hooking. In this particular case I am interested in DrawText() in user32.dll. It is declared like this in Win32 API:</p> <pre><code>INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags) </code></pre> ...
<p><a href="http://www.pinvoke.net/default.aspx/user32.DrawText" rel="noreferrer">http://www.pinvoke.net/default.aspx/user32.DrawText</a></p>
<p>Part of the problem is the use of String where a StringBuilder should be used. </p> <p>Try this signature (Generated with <a href="http://codeplex.com/clrinterop" rel="nofollow noreferrer">PInvoke Interop Assistant</a>)</p> <pre><code> [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropSe...
24,855
<p>I just set up my new homepage at <a href="http://ritter.vg" rel="noreferrer">http://ritter.vg</a>. I'm using jQuery, but very minimally.<br> It loads all the pages using AJAX - I have it set up to allow bookmarking by detecting the hash in the URL. </p> <pre><code> //general functions function getUrl(u) { ...
<p>Use the <a href="https://github.com/cowboy/jquery-hashchange" rel="noreferrer">jQuery hashchange event</a> plugin instead. Regarding your full ajax navigation, try to have <a href="http://www.chazzuka.com/blog/?p=90" rel="noreferrer">SEO friendly ajax</a>. Otherwise your pages shown nothing in browsers with JavaScri...
<p>I do the following, if you want to use it then paste it in some where and set your handler code in locationHashChanged(qs) where commented, and then call changeHashValue(hashQuery) every time you load an ajax request. Its not a quick-fix answer and there are none, so you will need to think about it and pass sensibl...
20,843
<pre><code>- Unit Testing - Mocking - Inversion of Control - Refactoring - Object Relational Mapping - Others? </code></pre> <p>I have found <a href="http://www.lastcraft.com/simple_test.php" rel="nofollow noreferrer">simpletest</a> for unit testing and mocking and, though it leaves much to be desired, it k...
<p><a href="http://www.phpundercontrol.org/" rel="nofollow noreferrer">phpUnderControl</a> - continuous integration.</p> <p>Don't forget about version control (e.g. using <a href="http://www.nongnu.org/cvs/" rel="nofollow noreferrer">CVS</a> or <a href="http://subversion.tigris.org/" rel="nofollow noreferrer">Subversi...
<p>Unit Testing - PHPUnit <a href="http://www.phpunit.de/" rel="nofollow noreferrer">phpunit.de</a></p> <p>ORM - Doctrine <a href="http://www.phpdoctrine.org/" rel="nofollow noreferrer">phpdoctrine.org</a>, Propel <a href="http://propel.phpdb.org/" rel="nofollow noreferrer">propel.phpdb.org</a></p>
7,311
<p>I'm in the process of learning Erlang. As an exercise I picked up the <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="noreferrer">Sieve of Eratosthenes</a> algorithm of generating prime numbers. Here is my code:</p> <pre><code>-module(seed2). -export([get/1]). get(N) -&gt; WorkList = lists:duplic...
<p>Here's a simple (but not terribly fast) sieve implementation:</p> <pre><code>-module(primes). -export([sieve/1]). -include_lib("eunit/include/eunit.hrl"). sieve([]) -&gt; []; sieve([H|T]) -&gt; List = lists:filter(fun(N) -&gt; N rem H /= 0 end, T), [H|sieve(List)]; sieve(N) -&gt; sieve(li...
<p>my fastest code so far (faster than Andrea's) is with using array:</p> <pre><code>-module(seed4). -export([get/1]). get(N) -&gt; WorkList = array:new([{size, N}, {default, empty}]), get(2, N, WorkList, []). get(thats_the_end, _N, _WorkList, ResultList) -&gt; lists:reverse(ResultList); get(CurrentPrime, ...
17,654
<p>I wish to implement my software on a shareware basis, so that the user is given a maximum trial period of (say) 30 days with which to try out the software. On purchase I intend the user to be given a randomly-generated key, which when entered enables the software again.</p> <p>I've never been down this route before...
<p>With regards to a random-generated key, how will you verify a key is legit or if a key is bogus if it is actually random? Have a look at the article "<a href="http://www.brandonstaggs.com/2007/07/26/implementing-a-partial-serial-number-verification-system-in-delphi/" rel="nofollow noreferrer">Implementing a Partial ...
<p>On the first start, you can store the actual date somewhere.<br> Each following start, you look for the stored date, if it exist you read it an if it is more than 30 days after the first start, you stop the program.</p>
20,962
<p>I would like to create (in code) tree of controls that would render as a table with several TBODY tags, i.e.:</p> <p> </p> <pre><code>&lt;TBODY&gt; &lt;TR&gt; &lt;TD&gt;&lt;/TD&gt; &lt;/TR&gt; &lt;TR&gt; &lt;TD&gt;&l...
<p>How are you generating your data? You could use a templated control like a Repeater or ListView as that gives you full control of the HTML you're generating.</p> <p>If you're wanting to create the controls purely in C# you can use the HtmlGenericControl (<a href="http://msdn.microsoft.com/en-us/library/system.web.u...
<p>I am writing a class that implements IBindableTemplate, so all of the rendering has to be done in code. I will give the HtmlGenericControl a try. Thanks!</p>
24,968
<p>I have the following enum declared:</p> <pre><code> public enum TransactionTypeCode { Shipment = 'S', Receipt = 'R' } </code></pre> <p>How do I get the value 'S' from a TransactionTypeCode.Shipment or 'R' from TransactionTypeCode.Receipt ?</p> <p>Simply doing TransactionTypeCode.ToString() gives a string of the E...
<p>You have to check the underlying type of the enumeration and then convert to a proper type:</p> <pre><code>public enum SuperTasks : int { Sleep = 5, Walk = 7, Run = 9 } private void btnTestEnumWithReflection_Click(object sender, EventArgs e) { SuperTasks task = Super...
<p>Marking this as not correct, but I can't delete it.</p> <p>Try this:</p> <pre><code>string value = (string)TransactionTypeCode.Shipment; </code></pre>
12,287
<p>With ASP.NET's view engine/template aspx/ashx pages the way to spit to screen seems to be: </p> <pre><code>&lt;%= Person.Name %&gt; </code></pre> <p>Which was fine with webforms as alot of model data was bound to controls programatically. But with MVC we are now using this syntax more oftern. </p> <p>The issue I ...
<p>Consider something like this, instead:</p> <pre><code>&lt;% foreach(var Person in People) { Response.Write(Person.Name); } %&gt; </code></pre> <p>I believe that'll work. (Although I haven't tested it; I've only just begun with MVC and don't have the toolset here at the office.)</p> <p>EDIT: I apparently mis...
<p>What you're looking for is probably a different View engine -- they each handle embedded code like that in their own way. Check out <a href="http://andrewpeters.net/2007/12/19/introducing-nhaml-an-aspnet-mvc-view-engine/" rel="nofollow noreferrer">NHaml</a>, an ASP.Net port of Rails' <a href="http://haml.hamptoncatl...
24,048
<p>Is anyone aware of general UI design guidelines for increasing ad revenue from web ads? Obviously many SO users use adblock, and probably find this type of question reprehensible, but I believe that it is possible to integrate advertising (and other revenue streams) into sites so that they are visually appealing, on...
<p>In fact, <a href="https://stackoverflow.com/users/1">one of the people who created this site</a> made a <a href="http://www.codinghorror.com/blog/archives/000893.html" rel="nofollow noreferrer">post regarding this</a> on his <a href="http://www.codinghorror.com/" rel="nofollow noreferrer">blog</a> </p>
<p>You may be interested in seeing <a href="https://www.google.com/adsense/support/bin/answer.py?hl=en&amp;answer=17954" rel="nofollow noreferrer">what Google has to say</a> about the placement of ads.</p>
14,369
<p>I have an object.</p> <pre><code> fp = open(self.currentEmailPath, "rb") p = email.Parser.Parser() self._currentEmailParsedInstance= p.parse(fp) fp.close() </code></pre> <p>self.currentEmailParsedInstance, from this object I want to get the body of an email, text only no HTML....</p> <p>How do I do...
<p>This will get you the contents of the message</p> <pre><code>self.currentEmailParsedInstance.get_payload() </code></pre> <p>As for the text only part you will have to strip HTML on your own, for example using BeautifulSoup.</p> <p>Check <a href="http://www.python.org/doc/2.2.3/lib/module-email.Message.html" rel="...
<p>ended up with this</p> <pre><code> parser = email.parser.Parser() self._email = parser.parse(open('/home/vinko/jlm.txt','r')) parts=self._email.get_payload() check=parts[0].get_content_type() if check == "text/plain": return parts[0].get_payload() elif chec...
35,424
<p>I'm currently in the process of writing my first Windows Forms application. I've read a few C# books now so I've got a relatively good understanding of what language features C# has to deal with exceptions. They're all quite theoretical however so what I haven't got yet is a feel for how to translate the basic conce...
<p>There is an excellent code <a href="http://www.codeproject.com/Articles/9538/Exception-Handling-Best-Practices-in-NET" rel="noreferrer">CodeProject article here</a>. Here are a couple of highlights:</p> <ul> <li>Plan for the worst*</li> <li>Check it early</li> <li>Don't trust external data</li> <li>The only reliabl...
<p>You have to think about the user. The application crash is the <strong>last</strong> thing the user wants. Therefore any operation that can fail should have a try catch block at the ui level. It's not necessary to use try catch in every method, but every time the user does something it must be able to handle generic...
22,201