instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>The first one is definitely something that works, but which one below is the efficient way?</p> <pre><code>switch($type) { case 1: print 'success'; break; case 2: print 'success'; break; case 3: print 'success'; break; case 4: print 'success for type 4'...
<pre><code> switch($type) { case 1: case 2: case 3: print 'success'; break; case 4: print 'success for type 4'; break; } </code></pre> <p>Is the way to go!</p>
<p>PHP manual lists an example like your 3rd for <a href="http://us3.php.net/manual/en/control-structures.switch.php" rel="nofollow noreferrer">switch</a>:</p> <pre><code>&lt;?php switch ($i) { case 0: case 1: case 2: echo "i is less than 3 but not negative"; break; case 3: echo "i is 3"; } ?&gt; </code></...
28,574
<p>I'm trying to find the actual class of a django-model object, when using model-inheritance.</p> <p>Some code to describe the problem:</p> <pre><code>class Base(models.model): def basemethod(self): ... class Child_1(Base): pass class Child_2(Base): pass </code></pre> <p>If I create various ob...
<p>Django implements model inheritance with a OneToOneField between the parent model's table and the child model's table. When you do <code>Base.object.all()</code>, Django is querying just the Base table, and so has no way of knowing what the child table is. Therefore, unfortunately, it's not possible to go directly...
<p>It feels brittle because it is. (This is a reprint of an answer in a different context. <a href="https://stackoverflow.com/questions/243082/c-casting-programmatically-can-it-be-done">See C++ casting programmatically : can it be done ?</a>)</p> <p>Read up on polymorphism. Almost every "dynamic cast" situation is a...
45,440
<p>I am trying to understand left outer joins in LINQ to Entity. For example I have the following 3 tables:</p> <p>Company, CompanyProduct, Product</p> <p>The CompanyProduct is linked to its two parent tables, Company and Product.</p> <p>I want to return all of the Company records and the associated CompanyProduct w...
<p>Solved it!</p> <p><strong>Final Output:</strong></p> <pre><code>theCompany.id: 1 theProduct.id: 14 theCompany.id: 2 theProduct.id: 14 theCompany.id: 3 </code></pre> <hr> <p><strong>Here is the Scenario</strong></p> <p><strong>1 - The Database</strong></p> <pre class="lang-sql prettyprint-override"><c...
<p>Please try something like this:</p> <pre><code>from s in db.Employees join e in db.Employees on s.ReportsTo equals e.EmployeeId join er in EmployeeRoles on s.EmployeeId equals er.EmployeeId join r in Roles on er.RoleId equals r.RoleId where e.EmployeeId == employeeId &amp;&amp; er.Status == (int)DocumentStatus.Draf...
10,390
<p>At the moment the outside surface temperature is around 30 °C. Can I put my PETG spools outside with a fan in order to dry them cheaply?</p>
<p>The answer to this specific instance appeared in the comments:</p> <blockquote> <p>Also, <a href="https://3dprinting.stackexchange.com/a/6092/">a thorough cleaning of the nozzle/hotend</a> might also be a good idea to get rid of all the stuck ABS residue inside. – 0scar Mar 26 at 8:44</p> <p>The problem solv...
<p>That looks pretty bad for a number of reasons. If you've got an all-metal hotend, you can be pretty sure that your PLA issues are probably at least partially cooling-related. I'd recommend you try and find a better fan duct design for your hotend, if possible, and possibly upgrade to a better fan.</p> <p>You can te...
1,260
<p>Because I need to display a <a href="http://codeflow.org/ubuntu.png" rel="nofollow noreferrer">huge number of labels</a> that <a href="http://www.youtube.com/watch?v=A_ah-SE-cNY" rel="nofollow noreferrer">move independently</a>, I need to render a label in <a href="http://pyglet.org" rel="nofollow noreferrer">pyglet...
<p>You want to set <code>glEnable(GL_COLOR_MATERIAL)</code>. This makes the texture color mix with the current OpenGL color. You can also use the <code>glColorMaterial</code> function to specify whether the front/back/both of each polygon should be affected. Docs <a href="http://www.glprogramming.com/blue/ch05.html#id3...
<p>Isn't that when you use decaling, through <code><a href="http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texenv.html" rel="nofollow noreferrer">glTexEnv()</a></code>?</p>
30,350
<p>Here's the scenario:</p> <p>You have a Windows server that users remotely connect to via RDP. You want your program (which runs as a service) to know who is currently connected. This may or may not include an interactive console session.</p> <p>Please note that this is the <strong>not</strong> the same as just ret...
<p>Here's my take on the issue:</p> <pre><code>using System; using System.Collections.Generic; using System.Runtime.InteropServices; namespace EnumerateRDUsers { class Program { [DllImport("wtsapi32.dll")] static extern IntPtr WTSOpenServer([MarshalAs(UnmanagedType.LPStr)] string pServerName); [DllIm...
<pre><code>using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace TerminalServices { class TSManager { [DllImport("wtsapi32.dll")] static extern IntPtr WTSOpenServer([MarshalAs(UnmanagedType.LPStr)] String pServerName); [DllImport("wtsapi...
16,080
<p>I am having trouble getting Team Build to execute my MbUnit unit tests. I have tried to edit TFSBuild.proj and added the following parts:</p> <pre><code>&lt;Project ...&gt; &lt;UsingTask TaskName="MbUnit.MSBuild.Tasks.MbUnit" AssemblyFile="path_to_MbUnit.MSBuild.Tasks.dll" /&gt; ... ... &lt;ItemGroup&gt; ...
<p>Above suggestion didn't help me a lot, but I found some documentation for Team Build and adjusted my build script to override the AfterCompile target:</p> <p><em>(EDIT: Now that I have a better understanding of Team Build, I have added some more to the test runner. It will now update the Build Explorer/Build monito...
<p>The way ItemGroups in MSBuild work is that they are evaluated at the very start of the MSBuild scripts, before any targets are ran. Therefore if the assemblies don't exist yet (which they will not because they have not been built yet) then the ItemGroups will not find any files.</p> <p>The usual pattern in MSBuild...
18,660
<p>If I have a subclass that has yet to implement a function provided by the base class, I can override that function and have it throw a <code>NotSupportedException</code>. Is there a way to generate a compile-time error for this to avoid only hitting this at runtime?</p> <p>Update: I can't make the base class abstr...
<p>You can make the base class abstract:</p> <pre><code>abstract class Foo { public abstract void Bar(); } </code></pre> <p>Now, any subclass must implement <code>Bar()</code>, or it won't compile.</p>
<p>Make it abstract with no implementation and fail to implement it in the derived class.</p>
15,637
<p>What do the clever programmers here do to keep track of handy programming tricks and useful information they pick up over their many years of experience? Things like useful compiler arguments, IDE short-cuts, clever code snippets, etc.</p> <p>I sometimes find myself frustrated when looking up something that I used ...
<p>Two Things I do:</p> <ul> <li>I blog about it - this allows me to go back and search my own blog.</li> <li>We use the code snippet feature in Visual Studio.</li> </ul> <p>Cheers.</p>
<p>I agree with emailing, the wiki and the blog. Emailing is the most useful. If you can't use GMail and you're on windows, install a desktop search utility (Windows search, Google Desktop, Copernic, etc)</p> <p>I also like to jot it into a textfile and save it in my documents folder. Whatever desktop search utility y...
3,834
<p>I have a <code>JFrame</code> that contains a "display" <code>JPanel</code> with <code>JTextField</code> and a "control" <code>JPanel</code> with buttons that should access the contents of the display <code>JPanel</code>. I think my problem is related on how to use the observer pattern, which in principle I understan...
<p>You need to reduce the coupling between these objects.</p> <p>You can have a master object, that owns all the text fields and the button ( the panels are irrelevant ) </p> <p>Then a separete actionlistener within that master object ( I call it mediator see mediator pattern ) </p> <p>That action listener performs ...
<p>We have so called builders, which will build the parent panel out of the children. In this builder you will have access to all the subcomponents you need to listen to and can thus can implement any logic there.</p> <p>Finally the builder will then return the parent panel with the complete logic.</p> <p>Once you've...
41,416
<p>Does .NET come with a class capable of representing extremely large integers, such as 100 factorial? If not, what are some good third party libraries to accomplish this?</p>
<p>.NET 4 has a <a href="http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx" rel="noreferrer">BigInteger</a> class</p> <blockquote> <p>Represents an arbitrarily large signed integer.</p> <p>The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in ...
<p>Mono has a public BigInteger implementation already:</p> <p><a href="http://www.go-mono.com/docs/index.aspx?link=T:Mono.Math.BigInteger" rel="nofollow noreferrer">http://www.go-mono.com/docs/index.aspx?link=T:Mono.Math.BigInteger</a></p> <p>You can just grab the Mono.Security assembly to use it; since its a Mono c...
4,502
<p>How can I make a local drive visible to a Windows XP VMWare image?</p> <p>Preferably, I'd like to make local drives available as Drive Letters within the VM Ware Image.</p>
<p>If both OSs are windows:</p> <pre><code>vm &gt; settings &gt; options &gt; shared folders </code></pre> <p>That way you can map a drive in the virtual machine as a folder on the host. :)</p>
<p>If you want to really make the drive visible (e.g to use gparted etc.), and not just copy some files:</p> <p>You can create a pseudo-vmdk that will in fact be a link to an existing physical drive ( or one/more of its partitions) The command is e.g.</p> <pre><code>VBoxManage internalcommands createrawvmdk -filename...
34,715
<p>The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up.</p> <p>So, what language should I learn to bridge between Python to C</p>
<p>It's not clear why you need a bridge language. Why don't you start working with C directly? C is a very simple language itself. I think that hardest part for C learner is pointers and everything else related to memory management. Also C lang is oriented on structured programming, so you will need to learn how to imp...
<p>I'm feeling your pain, I also learned PHP first and I'm trying to learn C++, it's not easy, and I am really struggling, It's been 2 years since I started on c++ and Still the extent of what I can do is cout, cin, and math.</p> <p>If anyone reads this and wonders where to start, START LOWER.</p>
7,166
<p>I want to display the "infinity" symbol using </p> <pre><code>CGContextSelectFont(context, "HelveticaNeue", textSize, kCGEncodingMacRoman); CGContextShowTextAtPoint(context, myCenter.x, myCenter.y + textHeight, [sName cStringUsingEncoding:NSMacOSRomanStringEncoding], [sName length]); </code></pre> <p>It i...
<p>It turns out that CGContextSelectFont only supports MacRoman encoding, which is basically has only a small set of characters. In order to display Unicode characters in a string, you have to use CGSetFont or the Cocoa drawing system. CGSetFont requires that you use Cocoa anyway to map characters to glyphs and then dr...
<p>You want to avoid drawInRect:withFont: (in MonoTouch: DrawString (string, RectangelF, UIFont font) as this API up until iPhoneOS 4.0 does not render strings that might contain certain unicode characters (like dingbats) and will silently cut rendering at that point.</p> <p>Instead you must use drawInRect:withFont:li...
34,713
<p>I teach a C++ course using Visual Studio. One of my students has a Mac and was looking for an IDE to use on his machine. What would be good to recommend?</p>
<p><a href="http://developer.apple.com/tools/xcode/" rel="noreferrer">Xcode</a> which is part of the MacOS Developer Tools is a great IDE. There's also <a href="http://www.netbeans.org" rel="noreferrer">NetBeans</a> and <a href="http://www.eclipse.org" rel="noreferrer">Eclipse</a> that can be configured to build and co...
<p><a href="http://developer.apple.com/tools/xcode/" rel="nofollow noreferrer">Xcode</a> is free and good, which is lucky because it's pretty much the only option on the Mac.</p>
27,172
<p>The <a href="http://submain.com/landing/codeit.right/?utm_campaign=codeit.right&amp;utm_medium=textad&amp;utm_source=stackoverflow" rel="nofollow noreferrer">.NET coding standards PDF from SubMain</a> that have started showing up in the "Sponsored By" area seems to indicate that properties are only appropriate for l...
<p>They seem sound, and basically in line with MSDN member design guidelines:</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms229059.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms229059.aspx</a></p> <p>One point that people sometimes seem to forget (*) is that callers should be a...
<p>Fully agreed.</p> <p>According to the coding guidelines properties are "nouns" and methods are "verbs". Keep in mind that a user may call the property very often while thinking it would be a "cheap" operation. </p> <p>On the other side it's usually expected that a method may "take more time", so a user considers a...
19,826
<p>I have a WCF service running on the IIS with a ServiceHostFactory. It's running fine with the WSHttpBinding but because of the speed and everything being on the same network (no firewalls) i want to speed up things a bit using the NetTcpBinding instead.</p> <p>When i try to do that i get this error:</p> <blockquot...
<p>Check out <a href="https://web.archive.org/web/20160611103146/http://marc.bloggingabout.net/2007/10/23/wcf-hosting-non-http-protocols-in-iis-7-0/" rel="nofollow noreferrer">this post</a> on enabling non-HTTP bindings in IIS 7.0. By default, you have to explicitly enable net.tcp in IIS 7.0.</p> <p>Hope this helps.</p...
<p>Could it be something as simple as your firewall rules on the service host disallowing port 808?</p>
24,539
<p>I've been a bad programmer because I am doing a copy and paste. An example is that everytime i connect to a database and retrieve a recordset, I will copy the previous code and edit, copy the code that sets the datagridview and edit. I am aware of the phrase code reuse, but I have not actually used it. How can i uti...
<p>The essence of code reuse is to take a common operation and parameterize it so it can accept a variety of inputs.</p> <p>Take humble <code>printf</code>, for example. Imagine if you did not have <code>printf</code>, and only had <code>write</code>, or something similar:</p> <pre><code>//convert theInt to a string ...
<p>For the example you give, the appropriate solution is to write a function that takes as parameters whatever it is that you edit whenever you paste the block, then call that function with the appropriate data as parameters.</p>
29,412
<p>We are bringing a new project in house and whereas previously all our work was on SQL Server the new product uses an oracle back end.</p> <p>Can anyone advise any crib sheets or such like that gives an SQL Server person like me a rundown of what the major differences are - Would like to be able to get up and runnin...
<p>@hamishcmcn</p> <p>Your assertion that '' == Null is simply not true. In the relational world Null should only ever be read to mean "I don't know". The only result you will get from Oracle (and most other decent databases) when you compare a value to Null is 'False'.</p> <p>Off the top of my head the major differe...
<p>If you need to you can create and drop temporary tables in procedures using the <a href="http://www.dbasupport.com/oracle/ora9i/execute_immediate.shtml" rel="nofollow noreferrer">Execute Immediate</a> command.</p>
6,048
<p>We are in the process of porting a legacy system to .NET, both to clean up architecture but also to take advantage of lots of new possibilities that just aren't easily done in the legacy system.</p> <p><strong>Note: When reading my post before submitting it I notice that I may have described things a bit too fast i...
<p>I would suggest that eventually a database refactoring (normalization) is probably in order. You could work on the refactoring and use views to provide the legacy application with an interface to the database consistent with what it expects. That is, for example, break the employe table down in to employee_info, e...
<p>Although I haven't used this particular ORM, views can be useful in some cases in providing lighter-weight objects for display and reporting in these types of databases. According to their documentation they do support such a concept: <a href="http://www.devexpress.com/Help/?document=XPO/CustomDocument2068.htm&amp;l...
37,507
<p>So I like the OpenID idea. I support it on my site, and use it wherever it's possible (like here!). But I am not clear about one thing. </p> <p>A site that supports OpenID basically accepts any OpenID provider out there, right? How does that work with sites that want to reduce bot-signups? What's to stop a mal...
<p>You have confused two different things - identification and authorization. Just because you know who somebody is, it doesn't mean you have to automatically give them permission to do anything. Simon Willison covers this nicely in <a href="http://blog.simonwillison.net/post/57956829720/account" rel="nofollow norefe...
<p>Possible solution - you can still ask new IDs to pass a CAPTCHA test. Just like bots can sign up with fake/multiple email addresses to any site, but fail the "verification" step there as well.</p> <p>Or are we going to have to start maintaining provider blacklists? Those won't really work very well, given how tri...
11,158
<p>I'm no DBA, and I'm having a bit of a hard time understanding Oracle's transaction management process.</p> <p>From what I understood by reading some reliable-looking pages on the Internet (most notably this <a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:275215756923" rel="noreferrer">A...
<p>Lots to cover here! The person in your company is essentially right, except that the changes are written to the data block <em>in memory</em> as they are made, even before the commit; and they are written out to disk entirely independently of when you commit (possibly before, possibly after, never as part of the co...
<p>My understanding is (basically) the later, <a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/transact.htm#i8072" rel="nofollow noreferrer">This link</a> has the details.</p> <p>The data blocks don't have to be written, just updated in the buffer, they may or may not be written out to disk. The...
23,148
<p>Does anyone know of a good tool or plugin that enables Microsoft Word or OpenOffice Writer to add code snippets to a document in a clean manner? </p> <p>I'm not sure if such a plug-in even exists, so redirecting me to any other tool that can help me would be appreciated.</p>
<p>I simply type out the snippet in Visual Studio and then copy paste it into word. It preserves all the code formatting.</p> <p>The only other thing I do is change the font to Consolas.</p>
<p>I love codekeep for VS.. But it's only available for VS</p>
26,286
<p>In other words, a block of code like this:</p> <pre><code>(setq initial-major-mode (lambda () (text-mode) (font-lock-mode) )) </code></pre> <p>... would come out looking like something like this:</p> <p><img src="https://i.stack.imgur.com/kiaIG.gif" alt="alt text"></p> <p>If something like this alr...
<p>I think you are looking for something like <a href="http://www.foldr.org/~michaelw/emacs/mwe-color-box.el" rel="noreferrer">mwe-color-box.el</a></p>
<p>If you need this to help editing, then I suggest turning on coloring the <em>innermost</em> sexp which contains the cursor with a different background color. At least I'm used to this and it is sufficient.</p>
16,698
<p>I've seen a lot of different takes on this subject so I figured if there's a preferred way on this.</p> <p>Is there any best practices on how to setup Visual Studio Projects and Solutions in regards to multiple solutions for the same solutions?</p> <p>For example: Let's say I have a task that calls for a web app, ...
<p>Indeed, there are some guidelines for this sort of setup on <a href="http://msdn.microsoft.com/en-us/library/ee817674.aspx" rel="nofollow noreferrer">MSDN</a>. I wrote a short summary in my <a href="https://stackoverflow.com/questions/200954/solution-per-application-or-per-application-suite#201064">answer to a simi...
<p>I like to include all projects for a certain task, in a solution. So based on the example you mention, I would have a solution containing the three projects that belong to the solution I was asked to do. That keeps all elements to complete a task together, I find this simplifies the inclusion of other elements requ...
36,151
<p>I am using C#. By default, when I add a web form in Visual Studio 2008 with or without a master page, the AutoEventWireup attribute is set to true in the page directive. This attribute is also set to true inside the master page master directive.</p> <p>What value should I have AutoEventWireup set to (true/false)?<...
<p>That is a way of automatically wiring up event handlers to events based on naming conventions that Microsoft has setup.</p> <p>The way this is implemented is with reflection, if I remember correctly. At runtime, ASP.NET will inspect your class, look for methods with signatures that match the naming convention expec...
<p>If it's set to false, then if you have methods like Page_Load or Page_PreInit, they wouldn't ever fire. AutoEventWireup means that IF there are events named like that, they should have the event handler wired up to those events.</p>
28,507
<p>I've just discovered that Oracle lets you do the following:</p> <pre><code>SELECT foo.a, (SELECT c FROM bar WHERE foo.a = bar.a) from foo </code></pre> <p>As long as only one row in bar matches any row in foo.</p> <p>The explain plan I get from PL/SQL developer is this:</p> <pre>...
<p>The plan you have there does not provide much information at all. </p> <p>Use SQL*Plus and use dbms_xplan to get a more detailed plan. Look for a script called utlxpls.sql.</p> <p>This gives a bit more information:-</p> <pre><code>-------------------------------------------------------------------------- | Id ...
<p>If you create a normal index on bar(a) the CBO should be able to use, but I'm pretty sure that it won't be able to do hash joins. These kind of queries only make sense if you're using an aggregate function and you got multiple single-row subqueries in your top SELECT. Even so, you can always rewrite the query as:</p...
21,781
<p>This isn't really a programming question, more of an <em>ideas</em> question. Bear with me.</p> <p>My sister gave me a well-used Nokia N95. I don't really need it, but I wanted it to do some programming for it. It supports a few languages, of which I can do Python.</p> <p>My question is this: what to do with it? I...
<p>"Gotta Leave" - A reminder that figures out the bus time, how far you are from a stop on your bus and shows a countdown till you "Could" leave (green), "Should" Leave (yellow), "Must" leave (orange), and "Gotta Run to get there" (red).</p> <p>As inputs it needs what bus number you want to ride. You turn it on, it ...
<p>"Late for Work" - Determines if you are not at work, buzzes you with a reminder and preps the phone to call into the sick line. Could be used if you are going to be late as well.</p> <p>Inputs: Your sick line number. Time you should be at work. Where your home is, where your work is</p> <p>Optional: </p> <ul...
47,586
<p>2 tables: </p> <pre><code>Employees - EmployeeID - LeadCount Leads - leadID - employeeID </code></pre> <p>I want to update the <code>Employees.LeadCount</code> column by counting the # of leads in the <code>Leads</code> table that have the same <code>EmployeeID</code>.</p> <p>Note: There may be more than 1 lea...
<pre><code>UPDATE Employees E SET E.LeadCount = ( SELECT COUNT(L.EmployeeID) FROM Leads L WHERE L.EmployeeID = E.EmployeeID ) </code></pre>
<p>Steeling from above and removing the dependent subquery.</p> <pre><code>// create tmp -&gt; TBL (EmpID, count) insert into TBL SELECT employeeID COUNT(employeeID) Di FROM Leads WHERE Leads.employeeId = Employees.employeeId GROUP BY EmployeeId UPDATE Employees SET LeadCount = ( SELECT count FROM TBL WHERE ...
16,572
<p>Is it possible to avoid the automatic collapse of a Silverlight ComboBox after LostFocus?</p>
<p>I don't think there is an easy way around this. The code below is copied from the disassembled code from the ComboBox Class. As you can see it closes always when hasFocus is false. I don't think there is any way around this. Writing your own ComboBox is a solution.</p> <pre><code>private void FocusChanged(bool hasF...
<p>I don't think there is an easy way around this. The code below is copied from the disassembled code from the ComboBox Class. As you can see it closes always when hasFocus is false. I don't think there is any way around this. Writing your own ComboBox is a solution.</p> <pre><code>private void FocusChanged(bool hasF...
48,186
<p>I am working on a robotics project and need to print some gears. These will probably by under a LOT of pressure. Which material/filament should I choose so that the gears don't wear off easily?</p> <p>PS: Newbie here...</p> <p><strong>EDIT:</strong> According to my instuctor, it has to be some sort of plastic (not...
<p>So, as you say you want to materials for printing robotics parts. And as you have not given any budget constraint, I would give you a list of materials which would help you achieve the task, and you can choose amongst them accordingly.</p> <ol> <li>Plastics: Basically used for building prototypes. Nylon Polyamide s...
<p>Filaments that are intended for making parts that require strange should be rated by the manufacturer for strength and flexibility.</p> <p>You need to calculate the required strength and then choose a material with higher rating</p> <p>For example the rating for filaments made by Taulman are at <a href="http://www...
116
<p>I have a rails app that I have serving up XML on an infrequent basis. This is being run with mongrel and mysql. I've found that if I don't exercise the app for longer than a few hours it goes dead and starts throwing Errno::EPIPE errors. It seems that the mysql connection get timed out for inactivity or something li...
<p>Here's a solution:</p> <p><a href="https://boxpanel.blueboxgrp.com/public/the_vault/index.php/Mongrel_/_MySQL_Timeout" rel="nofollow noreferrer">https://boxpanel.blueboxgrp.com/public/the_vault/index.php/Mongrel_/_MySQL_Timeout</a></p> <p>The timeouts on the above solution seem a little high to me. You don't want...
<p>In other places, I also got the following suggestions:</p> <ol> <li><p>Try setting <strong>config.active_record.verification_timeout</strong> to something lower than whatever your mysql connection timeout setting is.</p></li> <li><p>There's a gem to work around this problem: <strong>mysql_retry_lost_connection</str...
15,955
<p>I am storing a PNG as an embedded resource in an assembly. From within the same assembly I have some code like this:</p> <pre><code>Bitmap image = new Bitmap(typeof(MyClass), "Resources.file.png"); </code></pre> <p>The file, named "file.png" is stored in the "Resources" folder (within Visual Studio), and is marke...
<p>This will get you a string array of all the resources:</p> <pre><code>System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames(); </code></pre>
<p>The name of the resource is the name space plus the "pseudo" name space of the path to the file. The "pseudo" name space is made by the sub folder structure using \ (backslashes) instead of . (dots).</p> <pre><code>public static Stream GetResourceFileStream(String nameSpace, String filePath) { String pseduoName...
4,742
<p>I know about "class having a single reason to change". Now, what is that exactly? Are there some smells/signs that could tell that class does not have a single responsibility? Or could the real answer hide in YAGNI and only refactor to a single responsibility the first time your class changes?</p>
<h3>The Single Responsibility Principle</h3> <p>There are many obvious cases, e.g. <code>CoffeeAndSoupFactory</code>. Coffee and soup in the same appliance can lead to quite distasteful results. In this example, the appliance might be broken into a <code>HotWaterGenerator</code> and some kind of <code>Stirrer</code>. ...
<p>If you're finding troubles extending the functionality of the class without being afraid that you might end up breaking something else, or you cannot use class without modifying tons of its options which modify its behavior smells like your class doing too much.</p> <p>Once I was working with the legacy class whic...
30,532
<p>Is there any list of blog engines, written in Django?</p>
<p>EDIT: Original link went dead so here's an updated link with extracts of the list sorted with the most recently updated source at the top.</p> <p><a href="http://blog.montylounge.com/2010/02/10/eleven-django-blog-engines-you-should-know/" rel="noreferrer">Eleven Django blog engines you should know</a></p> <p>by Mo...
<p>Nathan Borror has a great package of 'basic apps' that has a blog. These are well written, well documented apps that you should try out, get ideas from, etc.</p> <p><a href="http://code.google.com/p/django-basic-apps/" rel="nofollow noreferrer">http://code.google.com/p/django-basic-apps/</a></p>
10,834
<p>I am creating a data source for reporting model (SQL Server Reporting Services). The reports requires a lot of joins and calculations (let's say, calculating financial parameters like money spent on this, that, amount A vs amount B)...all this involves subobjects.</p> <p>It makes a lot of sense to me to write unit ...
<p>There is a lot of excellent material available on the web once you get in the groove, but the links below are (IMO) good starting points (the ones I used).</p> <p><a href="https://people.eng.unimelb.edu.au/pstuckey/book/course.html" rel="nofollow noreferrer">Programming with Constraints: An Introduction - (Course w...
<p>The <a href="http://books.google.com.au/books?id=Kjap9ZWcKOoC" rel="nofollow noreferrer">handbook of constraint programming</a> is well thought of. </p> <p>In trivia, <a href="http://portal.acm.org/author_page.cfm?id=81100589552" rel="nofollow noreferrer">my supervisor from fourth year</a> university (which was ...
41,622
<p>Can anyone recommend an SVN client for use in Excel with VBA (code modules only). Ideally, I would also like SVN to ignore case when diffing prior to committing changes so as to avoid excessive churn in the repository (VBA has an annoying habit of changing the case of variables all over the project).</p>
<p><a href="http://tortoisesvn.net/" rel="nofollow noreferrer">TortoiseSVN</a> integrates well with the Windows File Explorer and allows for the integration of an external diff tool (like <a href="http://www.scootersoftware.com/" rel="nofollow noreferrer">Beyond Compare</a>.</p> <p><a href="http://www.scootersoftware....
<p>Have a look at the following applications. </p> <p><a href="http://officesvn.codeplex.com/" rel="nofollow noreferrer">http://officesvn.codeplex.com/</a></p> <p><a href="http://code.google.com/p/msofficesvn/" rel="nofollow noreferrer">http://code.google.com/p/msofficesvn/</a></p>
32,757
<p>What should I type on the Mac OS X terminal to run a script as root?</p>
<p>As in any unix-based environment, you can use the <a href="http://xkcd.com/149/" rel="noreferrer"><code>sudo</code></a> command:</p> <pre><code>$ sudo script-name </code></pre> <p>It will ask for your password (your own, not a separate <code>root</code> password).</p>
<p>sudo ./scriptname</p> <p>sudo bash will basically switch you over to running a shell as root, although it's probably best to stay as su as little as possible.</p>
10,045
<p>I'm new to iPhone and Apple development and working on my first application. It simple with only a TableView and a "detail view" when an item in a table is selected.</p> <p>What I want to do is change the background color of the cell in the TableView based on some action taken in my "detail view".</p> <p>When the ...
<p>Use <code>[tableView reloadData]</code> - that will make the tableview run though the rows and rebuild itself.</p>
<p>I would add that if it is in a editing view that then saves some modified information stored in your table you should have a delegate that detects when the data was actually saved then reload your tableview. viewWillAppear will be fired every time your view appears. What I think you are after is only after data has ...
45,231
<p>I'm a single developer looking to get off of Visual Source Safe and move to svn.</p> <p>A quick search brings up several tools, but I don't see a clear winner and I can't afford to spend a lot of time testing different tools.</p> <p>Has anyone done this successfully, and can recommend a method?</p>
<p>I recommend just adding your code to a new Subversion repository rather than importing from VSS. VSS has a convoluted version control model that doesn't translate well to many other systems, and just starting fresh is usually the best way to avoid taking that clutter with you.</p> <p>If you need to keep the history...
<p>I have used some script (I can't remember which one) to assist in a VSS to SVN conversion. It was a bit painful and finicky but ended up working, and kept all history. I had to keep all the history for political reasons at the time; if I had my way I probably would have thrown away the history and imported all the c...
8,395
<p>I'm looking for the total <a href="http://en.wikipedia.org/wiki/Commit_charge" rel="nofollow noreferrer">commit charge</a>.</p>
<pre><code> public static long GetCommitCharge() { var p = new System.Diagnostics.PerformanceCounter("Memory", "Committed Bytes"); return p.RawValue; } </code></pre>
<p>Here's an example using WMI:</p> <pre><code>strComputer = "." Set objSWbemServices = GetObject("winmgmts:\\" &amp; strComputer) Set colSWbemObjectSet = _ objSWbemServices.InstancesOf("Win32_LogicalMemoryConfiguration") For Each objSWbemObject In colSWbemObjectSet Wscript.Echo "Total Physical Memory (kb): " &amp...
12,137
<p>In asp.net mvc, when do we use:</p> <p>and</p> <p>Do we ever need to put a ; (colon) ?</p>
<p><code>&lt;%= %&gt;</code> renders the output (string) of the contained command to the response. <code>&lt;% %&gt;</code> wraps executable statements (logic) in the view to control what gets executed. You don't use semicolons in the <code>&lt;%= %&gt;</code> blocks, but may in the <code>&lt;% %&gt;</code> depending...
is used when you are calling some HtmlHelper method which returns a string e.g.: is used when you are calling some HtmlHelper method which is void:
39,620
<p>I have just been re-working an old bit of compiler-like code written using bison. While I was doing this, I was wondering what the modern equivalent is? Is there a nice .NET ( or similar ) compiler writing framework that takes a BNF grammar and splits out a DLL that does the parsing?</p>
<p>There's also <a href="http://www.antlr.org" rel="noreferrer">ANTLR</a>, a very widely used parser generator implemented in Java.</p>
<p>A quick google search found the <a href="http://plas.fit.qut.edu.au/gppg/" rel="nofollow noreferrer">Gardens Point Parser Generator</a>. </p>
33,817
<p>Here's my code in a gridview that is bound at runtime:</p> <pre><code>... &lt;asp:templatefield&gt; &lt;edititemtemplate&gt; &lt;asp:dropdownlist runat="server" id="ddgvOpp" /&gt; &lt;/edititemtemplate&gt; &lt;itemtemplate&gt; &lt;%# Eval("opponent.name") %&gt; &lt;/itemtemplate&gt; ...
<p>Ok, I guess I'm just dumb. I figured it out.</p> <p>In the RowDataBound event, simply add the following conditional:</p> <pre><code>if (myGridView.EditIndex == e.Row.RowIndex) { //do work } </code></pre>
<p>This code will be do what you want:</p> <pre><code>&lt;asp:TemplateField HeaderText="garantia" SortExpression="garantia"&gt; &lt;EditItemTemplate&gt; &lt;asp:DropDownList ID="ddgvOpp" runat="server" SelectedValue='&lt;%# Bind("opponent.name") %&gt;'&gt; &lt;asp:ListItem Text="Si" Value="True"&gt;&lt;/as...
20,750
<p>I use remote desktop quite a bit and I've noticed that on one of my machines when another user is already logged in it prompts them to allow me to log in, even for users with less privileges; however, with another computer, there is no prompt, it just proceeds with the remote logoff even for users with the same priv...
<p>Indeed I suggest where VonC already mentioned, but more specifically: gpedit.msc, Computer/User configuration -> Administrative Templates -> Windows Components -> Terminal Services -> Connections -> <em>Set rules for remote control of Terminal Services user sessions</em></p>
<p>Windows Server editions support one console plus two remote connections simultaneously. When configured as a Terminal Server, they support one per license. All other editions support one total session, local or remote.</p> <p>Are the pre-existing connections local or Domain accounts? Look around in the local or g...
37,254
<p>How do you show your clients/employers that you understood their requirements?</p> <p>What do you recommend to use? Use-Case diagrams? Flow-Charts? Data-Flow-Diagrams? Decision Trees?</p> <p>I'm not really asking for a very detailed answer. Just something simple to help me communicate with the person who wrote the...
<p>I usually put together a PowerPoint deck fairly early in a project, giving a high-level overview of the project, along with some architectural diagrams (the simpler the better) and screen mockups/wireframes. Then I have a "kick-off" meeting for requirements review, and talk through the business problem and proposed...
<p>I think that the best way to show that you really understand the client idea is to build prototypes.</p> <p>By the way I was present in the last edition of the Requirements Engineering conference and in one of the workshops (MERE), Siemens was showing and interesting software based on composing a video of the clien...
14,250
<p>I have these two lines of code. </p> <pre><code>CString strHost = AfxGetApp()-&gt;GetProfileString(_T("WebServices"), _T("Server")); AfxMessageBox(strHost); </code></pre> <p>Nowhere in the app do I set the value. (the installer does that). So the strHost, should be the same no matter where or when this line is run...
<p>GetProfileString() can also read from a .ini file, besides the registry. If the call to GetProfileString() is done on a different CWinApp-derived object than the one in the main application (in a dll for example), it might try to read from the application's .ini file. Try stepping into GetProfileString() to find out...
<p>I found the answer.. Sort of. The AfxGetApp function returns different objects depending on where it's called.. If it's called in a dll, for instance, it returns a pointer to that. I think it even returns the wrong thing when the app is using the OS calls. This means the GetProfileString is for a different "profile...
49,950
<p>I was just browsing through questions on stack overflow, and i've come up to a post where it suggests of deploying database by simply copying the mdf file in the app_data folder and modifying your connection string. </p> <p>I know that some people do create an mdf file in the app_code during development, but for go...
<p>I personally prefer your method of deploying Databases and I see one big advantage with this: usually the Web and the DBServer should not be one machine (Security, Maintainability, ...) and utilizing the app_code folder to hold your Database seems a little credulously.</p>
<p>In my experience, the best practice involves using some sort of build process (perhaps automated or a script like you have mentioned). Then you divide your database into the following: 1) One time events - typically you would create the database once; you might insert data once or initial deployment; schema changes...
17,557
<p>I have a Tomcat application which, the first time I start Tomcat after starting Eclipse, I get an odd NoClassDefFoundError. <strong>If I then stop and restart Tomcat through Eclipse, it works fine.</strong> I have single, double, and triple checked the classpath and everything seems fine. Anyone ever seen anythin...
<p>I notice that this is a pretty old version of Tomcat, that might be contributing to the problem. You could try the following</p> <ol> <li>Start Eclipse.</li> <li>Clean your webapp project (build if automatic build is off)</li> <li>Start the Tomcat server.</li> </ol> <p>That's the only thing I can think of. Other t...
<p>Nope, never saw it. It is very unlikely that the class is present and that it is a classloader problem. What is the class that is missing. It is probably that it is occasionally going through some error condition </p> <p>e.g. trying to open a port that is already open </p> <p>and the error is causing it to try an...
22,702
<p>So, I'm reasonably new to both unit testing and mocking in C# and .NET; I'm using xUnit.net and Rhino Mocks respectively. I'm a convert, and I'm focussing on writing behaviour specifications, I guess, instead of being purely TDD. Bah, semantics; I want an automated safety net to work above, essentially.</p> <p>A ...
<p>Maybe you can find the solution here in <a href="http://forums.asp.net/t/1305800.aspx" rel="nofollow noreferrer">this ASP.NET Forum post</a> (Known Issues / Breaking Changes for ASP.NET in .NET 3.5 Service Pack 1).</p> <h2>Issue</h2> <p>The HtmlForm action attribute is now honored when defined in declarative marku...
<p>What we did in the end was just overode the action user a controladapter. This works for us but is <strong>NOT</strong> a general solution. </p> <pre><code>public class HtmlFormAdapter : ControlAdapter { protected override void Render(HtmlTextWriter writer) { HtmlForm form = this.Co...
37,354
<p>I have a solution with several projects, where the startup project has a post-build event that does all the copying of "plugin" projects and other organizing tasks. After upgrading the solution from VS 2005 to VS 2008, it appears as though the post-build event only fires if I modify the startup project, which means ...
<p>Why not just add a dependency to the "startup" project for each of the plugins? This will force the project to be rebuilt if any of the others change, and you won't have to mess with any other pre/post-build events.</p>
<p>Starting from @lomaxx suggestion, I got a very similar setup working by adding the following line at the <em>end</em> of the <em>post-build</em> event of the startup project:</p> <pre><code>"$(DevEnvDir)devenv.exe" "$(ProjectPath)" /clean </code></pre> <p>Note that this makes the startup project build the <em>next...
3,644
<p>I have the FlashForge Dreamer NX which prints with good quality on small models. However, when the model is taller than 2 cm or 2.5 cm (around 0.8 or 1 inch), it really loses quality.</p> <p>Here there is a picture so you can understand what I mean. Which setting do I have to change? Have a look the the base is very...
<p>The cause of the meshing is under-extrusion. When under-extrusion happens, several problems can cause this. E.g. heat creep (probably not the issue here because heat creep is usually not recoverable, but not unimaginable since this is an enclosed printer, you could try printing at a lower temperature and look into l...
<p>That looks horribly familiar; I call it meshing.</p> <p>It's underextrusion, which can be caused by lots of things.</p> <p>I cleaned, then replaced the hot end, Bowden tube, and both couplers trying to solve the problem, but then the Z axis was binding. Tried a couple things for that, what seems to have worked was ...
2,012
<p>I was wondering if there is a native C++ (or STL/Boost) function which will search a CString for a specified string?</p> <p>e.g.</p> <pre><code>CString strIn = "Test number 1"; CString strQuery = "num"; bool fRet = SomeFn(strIn, StrQuery); if( fRet == true ) { // Ok strQuery was found in strIn ... </code></pr...
<p><a href="http://msdn.microsoft.com/ja-jp/library/ms928981.aspx" rel="noreferrer">CString::Find()</a> is what you want, one of the overloads does sub-string searching.</p> <pre><code>CString strIn = "test number 1"; int index = strIn.Find("num"); if (index != -1) // ok, found </code></pre>
<p><a href="http://www.cplusplus.com/reference/string/string/find.html" rel="nofollow noreferrer">string::find</a></p>
26,809
<p>Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow us...
<p>Most languages have functions or libraries that do this, usually called a Bignum library (<a href="http://gmplib.org/" rel="noreferrer">GMP</a> is a good one.)</p> <p>If you want to do it yourself, I would do it the same way that people do long multiplication on paper. To do this you could either work with strings ...
<p>Here is my code piece in C. Good old multiply method</p> <pre class="lang-c prettyprint-override"><code>char *multiply(char s1[], char s2[]) { int l1 = strlen(s1); int l2 = strlen(s2); int i, j, k = 0, c = 0; char *r = (char *) malloc (l1+l2+1); // add one byte for the zero terminating string in...
23,507
<p>I've seen this all over the place: </p> <blockquote> <p>Download here! SHA1 = 8e1ed2ce9e7e473d38a9dc7824a384a9ac34d7d0</p> </blockquote> <p>What does it mean? How does a hash come into play as far as downloads and... What use can I make of it? Is this a legacy item where you used to have to verify some checks...
<p>It's a security measure. It allows you to verify that the file you just downloaded is the one that the author posted to the site. Note that using hashes from the same website you're getting the files from is not especially secure. Often a good place to get them from is a mailing list announcement where a PGP-sign...
<p>With a has (MD5, SHA-1) one input matches only with one output, and then if you down load the file and calculate the hash again should obtain the same output. If the output is different the file is corrupt.</p> <pre><code>If (hash(file) == “Hash in page”) validFile = true; else validFile = false; </code></p...
4,096
<p>How can I check if a given number is even or odd in C?</p>
<p>Use the modulo (%) operator to check if there's a remainder when dividing by 2:</p> <pre><code>if (x % 2) { /* x is odd */ } </code></pre> <p>A few people have criticized my answer above stating that using x &amp; 1 is "faster" or "more efficient". I do not believe this to be the case. </p> <p>Out of curiosity, I...
<p>Modulus operator '%' can be used to check whether a number is odd or even.That is when a number is divided by 2 and if the remainder is 0 then its an even number else its an odd number.<br></p> <pre><code>#include &lt;stdio.h&gt; int main() { int n;//using modulus operator scanf("%d",&amp;n);//take input n ...
19,449
<p>This <a href="http://my.php.net/static" rel="nofollow noreferrer">example</a> is from php.net:</p> <pre><code>&lt;?php function Test() { static $a = 0; echo $a; $a++; } ?&gt; </code></pre> <p>And this is my code:</p> <pre><code>function getNextQuestionID() { static $idx = 0; return $idx++; } <...
<p>I believe you misunderstand what static vars do. Try this code and you may understand better:</p> <pre><code>echo getNextQuestionID() . ", " getNextQuestionID() . ", " getNextQuestionID(); </code></pre> <p>And you will see what I mean.</p> <p>The static var only lives as long as the script does.</p> <p>The reaso...
<p>If you want your data to persist across multiple pages, you need to use <a href="http://www.php.net/session" rel="nofollow noreferrer">sessions</a>.</p>
23,966
<p>After reading this answer: <a href="https://stackoverflow.com/questions/136474/best-way-to-pick-a-random-subset-from-a-collection#136513">best way to pick a random subset from a collection?</a></p> <p>It got me wondering, how does one pick a random seed in Java?</p> <p>And don't say use System.currentTimeMillis() ...
<p>Take a look at <a href="https://uncommons-maths.dev.java.net" rel="noreferrer">Uncommons Maths</a> (full disclosure: I wrote it). It should solve most of the problems you'll ever have with random numbers in Java.</p> <p>Even, if you don't use it you should be able to get some ideas from the various <a href="https:...
<p>Combine <code>System.currentTimeMillis()</code> with a global counter that you increment every time you generate the seed. Use <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/atomic/AtomicLong.html" rel="nofollow noreferrer">AtomicLong</a> for the counter so you can increment with efficiency a...
16,559
<p>I wrote a small PHP application that I'd like to distribute. I'm looking for best practices so that it can be installed on most webhosts with minimal hassle.</p> <p>Briefly: It's simple tool that lets people download files once they login with a password.</p> <p>So my questions are:</p> <p>1) How should I handle ...
<h1>Configuration</h1> <p>You can use a php file like this:</p> <pre><code>&lt;?php return array( 'option1' =&amp;gt; 'foobar', 'option2' =&amp;gt; 123, //and so on... ); ?&gt; </code></pre> <p>And in the main class just use:</p> <pre><code>$config = (array) include 'path/to/config/file'; </code></pre> <p>...
<p>In addition to Krzysztof's good advice:</p> <ul> <li>Use <code>&lt;?php</code> only</li> <li>If you use functions that can be disabled, use <code>function_exists()</code> to ensure they're available. <code>@missing_function()</code> makes PHP die silently without any error logged.</li> <li>You can't rely on things ...
36,079
<p>From an earlier post about trying to improve my sites performance I have been looking at HTTP compression. I have read about setting it up in IIS but it seems to be a global thing for all IIS application pools I may not be allowed to do this as there is another site running on it as well. I then saw some code to put...
<p>If you move forward with this, I'd suggest implementing a HttpModule versus global.asax. The HttpModule allows you to disable compression with a config change versus rebuilding and allows you to monkey with your compression Assembly separate from your web app.</p> <p>Rich Crane has a pretty nice 2.0 module here: <a...
<p>I think the Global.asax option will be a good if you are in a shared hosting environment for example, where you don't have access to IIS configuration. </p> <p>IIS 6 provides basic compression support, but if you're already in IIS 7, it provides you great <a href="http://blogs.iis.net/ksingla/archive/2006/06/13/cha...
24,783
<p>If I have a clone of a git repository as a cached copy on a remote server for capistrano/vlad style deployment, is it better to do A) </p> <pre><code>git archive --format=tar origin/master | (cd #{destination} &amp;&amp; tar xf -) </code></pre> <p>or B)</p> <pre><code>cp -R cached-copy #{destination} &amp;&amp; r...
<p>I'd say actually</p> <pre><code>rsync -avP /local/repo/* server:/remote/repo </code></pre> <p>This works as long as it's OK to <strong>skip all the dot files</strong> in the repo, not only <code>.git</code>. If you want to skip <em>only</em> <code>.git</code> then you'll need the <code>-f</code> option and the ma...
<p><strong>A)</strong></p> <p>You save the network overhead of transferring the .git directory which could possibly be quite large depending on how much history and objects not in the current HEAD.</p> <p>If you ever wanted to have an actual git repository on the remote end you're better off pushing to a real reposit...
48,864
<p>How do I set up a network between the Host and the guest OS in Windows vista?</p>
<p>Give the guest two network adapters, one NAT and the other Host-only. The NAT one will allow the guest to see the Internet, and the Host-only one will allow the host to see the guest.</p> <p>One of them also allows the guest to see the host. I'm not sure which, but I know it works since I've tested web server stu...
<p>I don't run vista, but virtualbox should do most of the setup for you - all you need to do is assign an IP address, subnet mask, and (optionally) a default gateway to your guest OS, and it should just work.</p> <p>Don't bother with any of the advanced network settings in the options for the VM - they're useful in s...
8,629
<p>I use ASP.NET and WCF services in a load balanced web server environment, using Memcached in the service layer.</p> <p>I also wanted to replace the use of ASP.NET State Server (for Session State) with Memcached. Now I am afraid it is not a good thing, because from what i understand, Memcached is a cache server rath...
<p>Memcached doesn't support data mirroring at present, it only provides the ability to split your entries across multiples servers to try to prevent one from getting swamped. This works by either hashing your key with the address of the server, or by using the consistent hashing algorithm (libketama).</p> <p>In gener...
<p>In an ideal situation, the session data is only a single value, the internal numerical representation of the user id. It means that the user has passed the login page successfully with providing the correct password.</p> <p>But what about others like, take stackoverflow for example, the dynamic data on the page dep...
37,104
<p>For sure this question will not help anyone in a heavy way, but it can be useful somehow. In the beginning, all <strong>Orkut</strong> pages had the extension <code>*.aspx</code>, but now all pages are <strong>masqueraded</strong> under a <code>Main#page.aspx</code>.</p> <p>Sorry if this <code>Main#</code> is an AS...
<p>browsing around, it seems like a lot of the stuff ends up as <a href="http://help.orkut.com/support/bin/answer.py?answer=30993&amp;src=top5" rel="nofollow noreferrer">.py</a> (python) files. From what I remember, Orkut was created, and then bought out by Google, so they may be in the process of switching it over t...
<p>Originally written in ASP.NET, then moved to Java (keep .aspx extension for SEO compatibility, and probably the less deep back-end layer was still in ASP.NET and not Java). Main#page.aspx doesn't have anything with the backend language, but with javascript, this was just a front-end feature (implementend using JS) t...
27,156
<p>I am looking for any examples or guides to using Linq over WCF (n-tier application). Please specify if you are showing something for Linq-to-SQL or Linq-to-entities. I would like to see usage examples for both. </p> <p>I am wondering how things like deffered execution works over WCF (if it works at all)? Cyclic ref...
<p>There isn't any LINQ provider that I'm aware of for generic WCF-based queries. <a href="http://blogs.msdn.com/astoriateam/archive/2007/12/11/linq-to-ado-net-data-services.aspx" rel="nofollow noreferrer">LINQ to ADO.NET Data Services</a>, however, lets you query an Entity model over WCF/REST.</p> <p>From <a href="ht...
<p>ADO.NET Data services is probably your best bet. There was a codeplex project <a href="http://www.codeplex.com/interlinq" rel="nofollow noreferrer">interlinq</a> to be able to use arbitrary LINQ expressions with WCF which could then be processed by another LINQ provider, like LINQ to NHibernate or LINQ to SQL. Sadly...
19,204
<p>I have two entities Foo and Bar with a Many to Many relationship between them.</p> <p>Let's say there is no semantic argument for why Foo might be "responsible" for the many to many relationship, but we arbitrarily decide that Foo is responsible for the relation (I.e., in NHibernate we would mark Bar as Inverse)</p...
<p>See <a href="http://www.hibernate.org/hib_docs/v3/reference/en-US/html/tutorial-associations.html#tutorial-associations-bidirectional" rel="nofollow noreferrer">Working bi-directional links</a> in the Hibernate documentation.</p> <blockquote> <p>Many developers program defensively and create link management met...
<p>you could make it static</p> <pre><code>public class Foo { List&lt;Bar&gt; Bars = new List&lt;Bar&gt;(); public void AddBar(Bar bar) { Bars.Add(bar); Bar.AddFoo(bar,this); } } public class Bar { List&lt;Foo&gt; Foos = new List&lt;Foo&gt;(); // This shouldn't exist. pub...
40,159
<p>I am searching for a tutorial <code>(optimally with Zend Framework)</code> on how to use <code>PHPUnit</code>.</p> <p>I have found a couple on <code>google</code> but have not quiet understood it yet.</p>
<p>What your are looking for is the <a href="http://www.phpunit.de/manual/current/en/" rel="noreferrer">Pocket Guide</a>. It explaines how to work with PHPUnit from A to Z in several languages. You can read it online or offline, for free, and it's regularly updated.</p>
<p>A great tutorial (git-based, exercise based), on physically going through the motions of testing by Sebastian Marek: <a href="https://github.com/proofek/phpnw12-tutorial" rel="nofollow">https://github.com/proofek/phpnw12-tutorial</a></p> <p>Found it very helpful for very baseline beginners. The slides: <a href="htt...
13,603
<p>I'm pretty new to 3D printing, got my printer about 5 days ago and spent most of my time with it.</p> <p>First off, it is an Ender 3 Pro with everything stock, haven't made any upgrades except I run it with OctoPrint from a Raspberry Pi Zero but I have determined that's not the source of the problem as it's well wit...
<blockquote> <p>I have heard that it is best to use a raft</p> </blockquote> <p>Actually, it is not best to use a raft, a raft is an aid that can best be used in special cases, e.g. for filaments that shrink reasonably (PLA is not such a filament).</p> <p>A raft always caused a rough bottom of your print and is frequen...
<p>Rafts fuse with models because the filament gets overheated. To avoid this, keep the temperature in the room between between 23 and 28 °C. Malfunctioning extruder fans, a heater &amp; thermocouple, extruder printed circuit board (PCB), extruder cable, and motherboard can be also to blame.</p>
2,163
<p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ...
<p>The <a href="http://technet.microsoft.com/en-us/library/cc754891.aspx" rel="noreferrer"><code>timeout</code></a> command is available from Windows&nbsp;Vista onwards:</p> <pre><code>c:\&gt; timeout /? TIMEOUT [/T] timeout [/NOBREAK] Description: This utility accepts a timeout parameter to wait for the specifi...
<pre><code>ping -n X 127.0.0.1 &gt; nul </code></pre> <p>Replace X with the number of seconds + 1.</p> <p>For example, if you were to wait 10 seconds, replace X with 11. To wait 5 seconds, use 6.</p> <p>Read earlier answers for milliseconds.</p>
20,050
<p>In a code review, I stumbled over this (simplified) code fragment to unregister an event handler:</p> <pre><code> Fire -= new MyDelegate(OnFire); </code></pre> <p>I thought that this does not unregister the event handler because it creates a new delegate which had never been registered before. But searching MSDN I...
<p>The C# compiler's default implementation of adding an event handler calls <code>Delegate.Combine</code>, while removing an event handler calls <code>Delegate.Remove</code>:</p> <pre><code>Fire = (MyDelegate) Delegate.Remove(Fire, new MyDelegate(Program.OnFire)); </code></pre> <p>The Framework's implementation of <...
<p>You should always check whether a delegate has no targets (its value is null) before firing it. As said before, one way of doing this is to subscribe with a do-nothing anonymous method which won't be removed.</p> <pre><code>public event MyDelegate Fire = delegate {}; </code></pre> <p>However, this is just a hack t...
37,364
<p>My database application is going to be deployed at multiple sites in different time zones.</p> <p>I need a T-SQL function that will determine the UTC timestamp of midnight on January 1 of the current year for YTD calculations. All of the data is stored in UTC timestamps.</p> <p>For example, Chicago is UTC-6 with ...
<p>Check out this previous question and answer for related information:</p> <p><a href="https://stackoverflow.com/questions/24797/effectively-converting-dates-between-utc-and-local-ie-pst-time-in-sql-2005#25073">Effectively Converting dates between UTC and Local (ie. PST) time in SQL 2005</a></p> <p>(To summarize, yo...
<p>Hmm, I guess I'm not understanding the problem. If the database app is already storing UTC timestamps for all of it's transactions, and you want to sum up some values since the first of the year "local time", your condition would have to be something like:</p> <pre><code>(timestamp + (getutcdate() - getdate())) &g...
21,793
<p>We are trying to build a High-Volume Orders Record System. There are three primary tables: 1. Orders 2. OrderDetails 3. OrderShipment</p> <p>The Shipment table contains n record per order and any record shipment entry can be changed before the Customer accepts th order, after which it is frozen. (A business require...
<p>If you are having genuine issues with concurrent updates on the same data, then you might consider performing the entire operation in a transaction - i.e. getting the data <em>and</em> committing it. As long as you treat the get/update/commit as a short-lived, atomic operation (i.e. you don't pause for user-input in...
<p>For this kind of situations, i.e. where more than one user may want to make changes to the same record/customer/order/whatever it is better to build "locking" into the application logic rather than use database locks.</p> <p>Using DB locks to solve logical locking of data is going to present you with a heap of new ...
23,141
<p>I'm trying to find a source control for my own personal use that's as simple as possible. The main feature I need is being able to read/pull a past version of my code. I am the only developer. I've looked at a lot of different version control systems, but they all seem way more complicated than I need. I need on...
<p><a href="http://subversion.tigris.org/" rel="nofollow noreferrer">Subversion</a> is great -- you can run the server yourself or use something like assembla.com to host your code (although that exposes it to the network).</p> <p>There are numerous gui applications like <a href="http://tortoisesvn.tigris.org/" rel="n...
<p>You should check <a href="http://www.cvsnt.org/" rel="nofollow noreferrer">CVSNT</a> as server and use any of the clients you would like (standalone or integrated with your IDE). There are plenty of them.</p>
7,223
<p>I'm looking for a good tool to profile a java webapp. I'd like to get performance information and memory usage if possible. </p> <p>Any suggestions?</p>
<p><a href="http://www.ej-technologies.com/products/jprofiler/overview.html" rel="nofollow noreferrer">JProfiler</a> is a really good one. It integrates with all the major IDEs and application servers.</p>
<p><a href="http://www.gurock.com/products/smartinspect/" rel="nofollow noreferrer">SmartInspect</a> is a profiler and logger. Not specific to memory, but you might want to take a look. It works with a variety of languages too, including Delphi, Java and .NET. Includes other more advanced features.</p> <p><img src=...
6,880
<p>If you were to build a badge system similiar to how SO does it, would you put the logic/business layer in the database directly (via stored procedure, scheduled sql jobs) or put it in the server side?</p> <p>From what I can think of, you have to:</p> <ol> <li>list badges that pertain to the current user action</li...
<p>I would recommend putting all business logic in the business layer. I recommend this for a few reasons:</p> <ul> <li>Keep the business logic in one language / place</li> <li>Scalability - You can partition data, implement different caching mechanisms, etc.</li> <li>Seperation of concerns - let your DB do what it d...
<p>I would concentrate all business logic in a single language logically separated in namespaces or packages. All the work needed to be done by web interface for instance, would be exposed by the server using services. </p>
40,563
<p>What are all the C++ blogs that you follow?</p> <p><strong><em>Please add one url for one posting.</em></strong></p>
<p><a href="http://herbsutter.wordpress.com/" rel="nofollow noreferrer">Sutter's Mill</a></p>
<p><a href="http://www.codemaestro.com/" rel="nofollow noreferrer">http://www.codemaestro.com/</a></p>
18,323
<p>I have a multipart form that takes basic user information at the beginning with some jquery.validate error checking to see if the fields have been filled in and the email address is valid.</p> <p>Below that there is a series of check boxes (type_of_request) for new accounts, delete accounts, new software etc which ...
<p>Assuming that you are using the jQuery <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" rel="nofollow noreferrer">validation plugin</a>, you could set/clear the class of each of the controls in the required/not required sections based on the checkbox that was clicked. </p> <pre><code>$(docum...
<p>Assuming that you are using the jQuery <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" rel="nofollow noreferrer">validation plugin</a>, you could set/clear the class of each of the controls in the required/not required sections based on the checkbox that was clicked. </p> <pre><code>$(docum...
38,078
<p>I am using a DataGridView control in a Windows Forms application. When a user holds down control to select multiple items, it works fine. Now when the user releases control and clicks (and holds down the left mouse button) to start a drag operation, the selection changes. How can I stop the selection from clearing w...
<p>I found this answer in a <a href="http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3197591&amp;SiteID=1" rel="nofollow noreferrer">Microsoft Forum</a></p> <p>"In order to drag and drop multiple rows, Set DataGridView.MultiSelect to true and in the DataGridView.DragDrop event, remove and insert all the rows in ...
<p>I found one technique that works. Upon selecting the last cell (either with ctrl or shift) you start to drag before releasing the mouse button, the selection will not change. Then on the drop you can use the following method to get a list of the selected cells:</p> <pre><code> private SC.ArrayList selectedCells...
22,835
<p>If I have hundreds/thousands of client computers WCP'ing to my server, should I respond with a '200 OK' type message stating that I received the data and stored it in the db successfully?</p> <p>Is this already built-into WCF?</p>
<p>There are three messaging patterns mentioned here:</p> <ol> <li>Synchronous request-response </li> <li>Asynchronous send (fire and forget with one-way service)</li> <li>Asynchronous request-response (duplex service call with one-way service)</li> </ol> <p>All three display different messaging behaviour, and the...
<p>I think the question could use a little more elaboration in order to answer correctly. Primary, which type of binding are you currently using?</p> <p>If you're using a binding that supports reliability, and you just want to be sure, from the client side, that server did indeed receive the message, then just turn r...
28,071
<p>I have a WinForms application with a view where the user selects a single time span from a list of predefined time spans in a ComboBox, with it's DropDownStyle property set to DropDownList.</p> <p>Now, the requirements have changed. The users are going to need the ability to make multiple selections from the list o...
<p>I agree with @Thomas Owens on the usability aspect. If you are selecting multiple items then the user should be able to see all of the items that are selected. Maybe a checked list box will work for this.</p> <p>If you still have you heart set on using a drop down type of control take a look at the DevExpress edito...
<p>The Windows.Forms.ComboBox cannot provide multi-selection.</p>
20,099
<p>I have a prefix trie. What is the recommended schema for representing this structure in a relational database? I need substring matching to remain efficient.</p>
<p>How about the <a href="http://www.dbazine.com/oracle/or-articles/tropashko4" rel="noreferrer">Materialized Path</a> design?</p> <pre><code>CREATE TABLE trie ( path VARCHAR(&lt;maxdepth&gt;) PRIMARY KEY, ...other attributes of a tree node... ); </code></pre> <p>To store a word like "stackoverflow":</p> <pre><c...
<p>Does any of your entities have a relationship with any other? If not, that is, not relational, a hash table with a serialization would do it.</p>
46,271
<p>I have been given a DLL ("InfoLookup.dll") that internally allocates structures and returns pointers to them from a lookup function. The structures contain string pointers:</p> <pre><code>extern "C" { struct Info { int id; char* szName; }; Info* LookupInfo( int id ); } </code></pre> <p>In...
<p>Try the following layout. Code automatically generated using the <a href="http://www.codeplex.com/clrinterop/Release/ProjectReleases.aspx?ReleaseId=14120" rel="noreferrer">PInvoke Interop Assistant</a>. Hand coded LookpInfoWrapper()</p> <pre><code>[System.Runtime.InteropServices.StructLayoutAttribute(System.Runti...
<p>You need to implement the structure in C# as well, making sure to use the attributes in the Marshal class properly to ensure that the memory layout matches the unmanaged version.</p> <p>So, some variation of this:</p> <pre><code>using System.Runtime.InteropServices; [DllImport("mydll.dll")] public static extern I...
46,536
<p>The following code calls the builtin functions for clz/ctz in GCC and, on other systems, has C versions. Obviously, the C versions are a bit suboptimal if the system has a builtin clz/ctz instruction, like x86 and ARM.</p> <pre><code>#ifdef __GNUC__ #define clz(x) __builtin_clz(x) #define ctz(x) __builtin_ctz(x) #...
<p>Bouncing from sh0dan code, the implementation should be corrected like this :</p> <pre><code>#ifdef _MSC_VER #include &lt;intrin.h&gt; uint32_t __inline ctz( uint32_t value ) { DWORD trailing_zero = 0; if ( _BitScanForward( &amp;trailing_zero, value ) ) { return trailing_zero; } else ...
<p>There are two intrinsics "_BitScanForward" and "_BitScanReverse", which suits the same purpose for MSVC. Include . The functions are:</p> <pre><code>#ifdef _MSC_VER #include &lt;intrin.h&gt; static uint32_t __inline ctz( uint32_t x ) { int r = 0; _BitScanReverse(&amp;r, x); return r; } static uint32_t _...
46,409
<p>I forgot my password for Sql Server 2005. Windows Authentication is not enabled so I cannot login. How can I remove the current instance and create a new db instance? Or is there a better solution exists?</p>
<p>Assuming you are a member of the Windows Admininstrator group, you can put the server in Single User mode, you could try this -</p> <p><a href="http://blogs.msdn.com/raulga/archive/2007/07/12/disaster-recovery-what-to-do-when-the-sa-account-password-is-lost-in-sql-server-2005.aspx" rel="nofollow noreferrer">http://...
<p>Have you tried connecting when logged on as domain/server-local Administrator?</p>
3,932
<p>I have a problem. One of the datatable colums value is a string value '001200' for example. When the Excel document creats the value became '1200'. How can I keep a data format as is? I'm working with ASP.NET 1.1.</p> <p>The part of the code is:</p> <pre><code>private void lnkExport_Click( object sender, System.Ev...
<p>Add an apostrophe (single quote) to the start - that should fix it. It forces Excel to treat the cell as text instead of a number.</p> <p>Edit: just to be clear - the apostrophe thing is a built-in feature of an Excel, not just a random character I picked. Can't seem to find a link for it though.</p>
<p>Can you precede any that need to be kept as numbers with a single quote when exported to excel e.g.</p> <pre><code>'001200 </code></pre> <p>This should keep it as text</p>
45,243
<p>What graphics toolkit is used for the Window's Google Talk application?</p>
<p>There isn't much information on this out there but it seems to be their own customized controls plus an IE component (and not Qt like Google Earth). <a href="http://www.customizetalk.com/forums/viewtopic.php?t=841&amp;postdays=0&amp;postorder=asc&amp;start=0" rel="nofollow noreferrer">This forum thread</a> has a lit...
<p>I'm not positive but I believe it's QT. </p>
5,505
<p>For the sake of simplicity:</p> <p>There is a permission based system in place with different kinds of user levels and actions (think: UNIX file system permissions)</p> <p>What would be the best approach to visualize this in UML?</p>
<p>I typically have classes that represent Users, Roles, and Permissions. Users belong to Roles and Roles are granted Permissions. Permissions are required to access other objects. In UML I suppose that you would model Role as an abstract base class and have multiple different implementations, one for each role.</p>...
<p>I like to think of a file system object has having a number of standard methods, each of which has an associated permission.</p> <p>There are 9 methods/permissions that of usually of interest: the combinations of (User, Group, Other) * (Read, Write, Execute). Additionally, there are options like Sticky and SetUID....
29,381
<p>I'm trying to implement some hooks, both pre and post fail however. I get the same error message for both when I try to commit:</p> <pre> '*-commit' hook failed (did not exit cleanly: apr_exit_why_e was 2, exitcode was -1073741515). with no output. </pre> <p>Exitcode -1073741515 looks to be an odd one, and a quic...
<p>Normally the problem with commit hooks is that there is ABSOLUTELY no environment (thus no path), so all references have to be painfully explicit. I usually end up making a small batch file that changes directory to the proper directory and executes the command.</p> <p>Edit:</p> <p>TRY CHANGING DIRECTORY TO C:\Sub...
<p>Thanks for posting your answer. If you didn't I would have spent a lot more time trying to run this down and feeling even more stupid than I do now. Just blew out a box and did an install of VisualSVN and SubversionNotify and couldn't figure out why it wasn't working. </p>
39,331
<p>I have the following models.</p> <pre><code># app/models/domain/domain_object.rb class Domain::DomainObject &lt; ActiveRecord::Base has_many :links_from, :class_name =&gt; "Link", :as =&gt; :from, :dependent =&gt; :destroy end # app/models/link.rb class Link &lt; ActiveRecord::Base belongs_to :from, :polymorph...
<p>To fix this, I did a <code>include Domain</code> in the <code>DomainObject</code> model and set <code>ActiveRecord::Base.store_full_sti_class = true</code> in <code>config/environment.rb</code>.</p>
<p>hoyhoy's response is the solution. This solved my problem , too (I actually wanted the namespace to be stripped off).</p> <p>However, I'd recommend that <code>x.store_full_sti_class = true</code> be added to <code>config/environment.rb</code>, only if it is desired globally. I imagine it might not always be require...
27,707
<p>I'm looking for tips, suggestions, advice or examples of applications build using Google's Web Toolkit with Google AppEngine.</p>
<p>Here's a screencast on the subject: <a href="http://www.thescreencast.com/2008/04/using-java-gwt-with-google-app-engine.html" rel="nofollow noreferrer" title="Using Java (GWT) with Google App Engine">Using Java (GWT) with Google App Engine</a></p> <p>Functionality seems very limited though since GAE uses Python + J...
<p>Can you elaborate more on why using GWT with the Java version of GAE would necessarily be a good idea?</p> <p>I'm not arguing against it, and it seems obvious Java would be the way to go, but just wanted to hear the concrete reasons.</p> <p>To answer my own question: GWT provides an interface called "GWT RPC" that...
45,153
<p>Can this be done without MVC? Is there an easy way to abstract or encapsulate navigational logic? </p> <p>I currently have quite a lot of the following in my code behinds (and I know it's probably not the best thing to be doing):</p> <pre><code>protected void btnNext_Click(object sender, EventArgs e) { ... ...
<p>You may want to consider using the Web.sitemap file to hold your navigation information.</p> <p>You could also look into the Routing library that was built for MVC in one of the previews, they split those classes off into the System.Web.Routing namespace and from what I've heard, it can be used with WebForms now. I...
<p>Based on your example, I don't think that MVC makes much difference. That's pretty much the standard way to do multi-page workflows. MVC would just send it to a different view, presumably, but the underlying concept is the same. Unless you have a very large and complex workflow, that's the simplest way to handle it....
36,962
<p>This should a quick question for some easy rep.</p> <p>I'm doing some PHP Website development, decided to check out and play around with jQuery as well. I don't want to install and manage a local PHP server/service, but I would like a quick one click method for automatically uploading the PHP file I'm working on to...
<p>I have a setup that I use FileZilla as the FTP, and NotePad++ as my text editor.</p> <p>Within FileZilla, I set NotePad++ as the default text editor, and when I hit <kbd>Ctrl</kbd>-<kbd>S</kbd> within the file I am working on at that time, it automatically uploads those changes to the server.</p> <p>You will be able...
<p><a href="http://bluefish.openoffice.nl/" rel="nofollow noreferrer">Bluefish</a> can edit the file directly on the FTP server. I'm not sure if the <a href="http://code.google.com/p/bluefish-win/" rel="nofollow noreferrer">Win32</a> version can do that though.</p>
27,711
<p>As part of our databuild run a 3rd party program (3D Studio Max) to export a number of assets. Unfortunately if a user is not currently logged in, or the machine is locked, then Max does not run correctly.</p> <p>This can be solved for freshly booted machines by using a method such as TweakUI for automatic login. H...
<p>There is a separate terminal service connection available called the 'console' connection.</p> <p>You can connect to this space using mstsc /console /v:servername. Use mstsc /? for full command line options.</p> <p>This allows you to connect, open up the terminal services manager and boot the bad sessions.</p>
<p>You might want to look at using the "shadow" utility. This allows you to essentially proxy into an existing remote desktop session. You could log into the console of the machine with the account you need, then users could open non-console remote desktop sessions to the machine (or to another machine) then use shado...
3,927
<p>There are several types of objects in a system, and each has it's own table in the database. A user should be able to comment on any of them. How would you design the comments table(s)? I can think of a few options:</p> <ol> <li>One comments table, with a FK column for each object type (ObjectAID, ObjectBID, etc)</...
<p>@palmsey</p> <p>Pretty much, but the variation on that pattern that I've seen most often gets rid of <code>ObjectAID</code> et al. <code>ParentID</code> becomes both the PK and the FK to <code>Parents</code>. That gets you something like:</p> <ul> <li><p><code>Parents</code></p> <ul> <li><code>ParentID</code></li...
<p>@Hank Gay</p> <p>So something like:</p> <ol> <li>ObjectA <ul> <li>ObjectAID</li> <li>ParentID</li> </ul></li> <li>ObjectB <ul> <li>ObjectBID</li> <li>ParentID</li> </ul></li> <li>Comments <ul> <li>CommentID</li> <li>ParentID</li> </ul></li> <li>Parents <ul> <li>ParentID</li> </ul></li> </ol>
6,110
<p>I've seen <a href="http://msdn.microsoft.com/en-us/library/7tas5c80.aspx" rel="nofollow noreferrer">How to: Host Controls in Windows Forms DataGridView Cells</a> which explains how to host a control for editing a cell in a DataGridView. But how can I host a control for displaying a cell?</p> <p>I need to display a...
<p>As per your "UPDATE", creating a custom <code>DataGridViewCell</code> is the way this is done. I've done it, and it doesn't require that much modification from the example code available from the MSDN. In my case, I needed a bunch of custom editing controls, so I ended up inheriting from <code>DataGridViewTextBoxCel...
<p>Usually you should host controls in winfors forms datagridview cells as shown <a href="https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-host-controls-in-windows-forms-datagridview-cells?view=netframeworkdesktop-4.8&amp;redirectedfrom=MSDN" rel="nofollow noreferrer">here</a></p> <p>But if you...
27,936
<p>How can I move items from one list box control to another listbox control using JavaScript in ASP.NET?</p>
<p>If you're happy to use jQuery, it's very, very simple.</p> <pre><code>$('#firstSelect option:selected').appendTo('#secondSelect'); </code></pre> <p>Where #firstSelect is the ID of the select box.</p> <p>I've included a working example here:</p> <p><a href="http://jsbin.com/aluzu" rel="noreferrer">http://jsbin.co...
<p>A library-independent solution:</p> <pre><code>function Move(inputControl) { var left = document.getElementById("Left"); var right = document.getElementById("Right"); var from, to; var bAll = false; switch (inputControl.value) { case '&lt;&lt;': bAll = true; // Fall through case '&lt;': ...
24,974
<p>I work with quite a bit of multi-platform C/C++ code, separated by common #defines (#if WIN, #if UNIX, etc). It would be nice if I could have vim automatically fold the sections I'm currently not interested in when I open a file. I've searched through the vim script archives, but I haven't found anything useful. ...
<p>Just add a folding region to your syntax <a href="http://vim.wikia.com/wiki/Syntax_folding_of_Vim_scripts#Syntax_definitions" rel="noreferrer">http://vim.wikia.com/wiki/Syntax_folding_of_Vim_scripts#Syntax_definitions</a></p> <pre><code>:syn region myFold start="\#IF" end="\#ENDIF" transparent fold :syn sync fromst...
<p>A quick addition to Denton's addition: to use the new syntax rule with any C or C++ code, add it to a file at <code>$VIMRUNTIME/syntax/c.vim</code> and <code>cpp.vim</code>. (<code>$VIMRUNTIME</code> is where your local Vim code lives: <code>~/.vim</code> on Unix.) Also, the values for <code>start</code> and <code>e...
14,740
<p>In what cases is it necessary to synchronize access to instance members? I understand that access to static members of a class always needs to be synchronized- because they are shared across all object instances of the class.</p> <p>My question is when would I be incorrect if I do not synchronize instance members?...
<p>It depends on whether you want your class to be thread-safe. Most classes shouldn't be thread-safe (for simplicity) in which case you don't need synchronization. If you need it to be thread-safe, you should synchronize access <em>or</em> make the variable volatile. (It avoids other threads getting "stale" data.)</p>...
<p>In Java, operations on ints are atomic so no, in this case you don't need to synchronize if all you're doing is 1 write and 1 read at a time.</p> <p>If these were longs or doubles, you do need to synchronize because it's possible for part of the long/double to be updated, then have another thread read, then finally...
39,887
<p><strong>Introduction</strong></p> <p>I've always been searching for a way to make Visual Studio draw a line after a certain amount of characters.</p> <p>Below is a guide to enable these so called <em>guidelines</em> for various versions of Visual Studio.</p> <p><strong>Visual Studio 2013 or later</strong></p> <p>Ins...
<p>This is originally from Sara's <a href="https://web.archive.org/web/20160221095812/http://blogs.msdn.com:80/b/saraford/archive/2004/11/15/257953.aspx" rel="nofollow noreferrer">blog</a>.</p> <p>It also works with almost any version of Visual Studio, you just need to change the &quot;8.0&quot; in the registry key to ...
<p>You might be looking for rulers not guidelines.</p> <p>Go to settings &gt; editor &gt; rulers &gt; and give an array of character counts to provide lines at the specified values.</p>
10,975
<p>I need to track traffic between a specific set of web sites. I would then store the number of clicks in a database table with the fields <strong>fromSite</strong>, <strong>toSite</strong>, <strong>day</strong>, <strong>noOfClicks</strong>. The complete urls are unimportant - only web site identity is needed.</p> <p...
<p>The best way is to use an analytics program like Google Analytics, and to review the reports for each domain.</p>
<p>You could place an onclick event on to each link that goes between each site. the onclick would then call some javascript which could do a server call back to register the click.</p>
13,174