instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>Sometimes I notice that if I manually command a single axis movement (typically Z, when I want better access to the extruder), I observe that several channels move together (and they maybe move slower than I expect). After one 'coupled' movement, subsequent commands have the result I'm expecting.</p> <p>What happen...
<p>This is easily explained - it's the stepper motors getting powered up. Stepper motors even if not moving are constantly powered up and actively hold the position they are in exactly at the stepping point where they are.</p> <p>If you power down the machine or if the board disables the stepper drivers to save energy...
<p>This is easily explained - it's the stepper motors getting powered up. Stepper motors even if not moving are constantly powered up and actively hold the position they are in exactly at the stepping point where they are.</p> <p>If you power down the machine or if the board disables the stepper drivers to save energy...
624
<p>I'd like to have a python program alert me when it has completed its task by making a beep noise. Currently, I use <code>import os</code> and then use a command line speech program to say &quot;Process complete&quot;. I much rather it be a simple &quot;bell.&quot;</p> <p>I know that there's a function that can be...
<p>Have you tried :</p> <pre><code>import sys sys.stdout.write('\a') sys.stdout.flush() </code></pre> <p>That works for me here on Mac OS 10.5</p> <p>Actually, I think your original attempt works also with a little modification:</p> <pre><code>print('\a') </code></pre> <p>(You just need the single quotes around th...
<p>By the way: there is a module for that. ;-)</p> <p>Just install via pip:</p> <pre class="lang-py prettyprint-override"><code>pip3 install mac_alerts </code></pre> <p>run your sound:</p> <pre class="lang-py prettyprint-override"><code>from mac_alerts import alerts alerts.play_error() # plays an error sound </code></p...
3,485
<p>I am using the standard outputcache tag in my MVC app which works great but I need to force it to be dumped at certain times. How do I achieve this? The page that gets cached is built from a very simple route {Controller}/{PageName} - so most pages are something like this: /Pages/About-Us</p> <p>Here is the outpu...
<p>Be careful about using "None" vs. "".</p> <ul> <li>If you send "" then the HttpHeader for <a href="http://www.w3.org/Protocols/HTTP/Issues/vary-header.html" rel="nofollow noreferrer">Vary</a> is <em>not</em> sent.</li> <li>If you send "None" then the HttpHeader for <a href="http://www.w3.org/Protocols/HTTP/Issues/v...
<p>it seems that output cache doesn't put anything in HttpContent.Cache because when I loop through it the collection is empty:</p> <pre><code>For Each elem As DictionaryEntry In HttpContext.Cache HttpContext.Cache.Remove(elem.Key) Next </code></pre> <p>Here is my action attribute:</p> <pre><code>&lt;OutputCache(D...
49,337
<p>I have a file <code>test.txt</code> that is inside a zip archive <code>test.zip</code>. The permissions on <code>test.txt</code> are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell.</p> <p><strong>ED...
<p>I had a similar problem to you, so here is the code spinet from my stuff, this I believe should help here.</p> <pre><code># extract all of the zip for file in zf.filelist: name = file.filename perm = ((file.external_attr &gt;&gt; 16L) &amp; 0777) if name.endswith('/'): outfile = os.path.join(dir...
<p>Extract to stdout (unzip -p) and redirect to a file? If there's more than one file in the zip, you could list the zip contents, and then extract one at a time.</p> <pre><code>for n in `unzip -l test.zip | awk 'NR &gt; 3 &amp;&amp; NF == 4 { print $4 }'`; do unzip -p test.zip $n &gt; $n; done </code></pre> <p>(yea...
35,383
<p>I've tried to remix this model: <a href="https://www.thingiverse.com/thing:90933" rel="nofollow noreferrer">https://www.thingiverse.com/thing:90933</a> (Bauhaus chess set) by scaling it down and inserting little magnet holes into the pieces' underside. My SCAD file looks as follows:</p> <pre><code>difference() { ...
<p>It is interesting that the WTH line and the next line both should remove a cylinder of the same diameter from the same location. Only the height is different.</p> <p>It could be interesting to remove the first King/Queen line and see if there is a change.</p> <p>Have you checked the STL file with another tool, ot...
<p>It is interesting that the WTH line and the next line both should remove a cylinder of the same diameter from the same location. Only the height is different.</p> <p>It could be interesting to remove the first King/Queen line and see if there is a change.</p> <p>Have you checked the STL file with another tool, ot...
1,440
<p>I am using <a href="http://nant.sourceforge.net/release/0.85-rc2/help/fundamentals/listeners.html#MailLogger" rel="nofollow noreferrer">MailLogger</a> to send a message about a failed/successful release. I would like to make the mail body simple and easy to read. How can I suppress output for some particular tasks?<...
<p>Here's one way to do it that makes it explicit - size() is called only once.</p> <pre><code>for (size_t ii = 0, count = values.size(); ii &lt; count; ++ii) </code></pre> <p><strong>Edit:</strong> I've been asked to actually answer the question, so here's my best shot.</p> <p>A compiler generally won't optimize ...
<p>Most, maybe even all, standard implementations of size() will be inlined by the compiler to what would be the equivalent of a temporary or at most a pointer dereference.</p> <p>However, you can never be sure. Inlining is about as hidden as these things get, and 3rd party containers may have virtual function tables ...
20,130
<p>I have a list of numbers, say {2,4,5,6,7} I have a table, foos, with foos.ID, including say, {1,2,3,4,8,9}</p> <p>Id like to take my list of numbers, and find those without a counterpart in the ID field of my table.</p> <p>One way to achieve this would be to create a table bars, loaded with {2,4,5,6,7} in the ID f...
<p>This is a problem that is pretty common: generating a relation on the fly without creating a table. SQL solutions for this problem are pretty awkward. One example using a derived table:</p> <pre><code>SELECT n.id FROM (SELECT 2 AS id UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 ...
<p>Alnitak's (and yours) solution should work, and I can not thing about anything else which can work only in SQL language.</p> <p>But here comes the question - how do you pass the list of values? Isn't it better to handle this in the calling code - i.e. request the ID's and compare it in the colling code, which may b...
34,473
<p>What is the best/fastest way to sort Alphanumeric fields? </p>
<p>You don't specify your target language, but whatever it is, it should have reliable, built-in sorting methods, so use one of them! For PHP...</p> <p>Load into an array and sort($array);</p> <p><a href="http://ie.php.net/sort" rel="nofollow noreferrer">php sort</a>...</p> <pre><code>$fruits = array("lemon", "orang...
<p>You will find that most development libraries ship with an implementation of the quicksort algorithm, which is often the fastest sorting algorithm. Check out the <a href="http://en.wikipedia.org/wiki/Quicksort" rel="nofollow noreferrer">Wikipedia link here</a>.</p>
10,354
<p>I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted. </p> <p>Right now, I call <code>to_json</code> and my JSON is all on one line. At times this can be difficult to see if there is a problem in the JSON output stream.</p> <p>Is there way to configure to make my JSON "pretty" or nicely...
<p>Use the <code>pretty_generate()</code> function, built into later versions of JSON. For example:</p> <pre><code>require 'json' my_object = { :array =&gt; [1, 2, 3, { :sample =&gt; "hash"} ], :foo =&gt; "bar" } puts JSON.pretty_generate(my_object) </code></pre> <p>Which gets you:</p> <pre><code>{ "array": [ ...
<p>I had a JSON object in the rails console, and wanted to display it nicely in the console (as opposed to displaying like a massive concatenated string), it was as simple as:</p> <pre class="lang-rb prettyprint-override"><code>data.as_json </code></pre>
11,218
<p>I am writing a program in Python, and I realized that a problem I need to solve requires me, given a set <code>S</code> with <code>n</code> elements (|S|=n), to test a function on all possible subsets of a certain order <code>m</code> (i.e. with <em>m</em> number of elements). To use the answer to produce a partial ...
<p><a href="http://docs.python.org/library/itertools.html#itertools.combinations" rel="noreferrer">itertools.combinations</a> is your friend if you have Python 2.6 or greater. Otherwise, check the link for an implementation of an equivalent function.</p> <pre><code>import itertools def findsubsets(S,m): return se...
<p><code> $ python -c "import itertools; a=[2,3,5,7,11]; print sum([list(itertools.combinations(a, i)) for i in range(len(a)+1)], [])" [(), (2,), (3,), (5,), (7,), (11,), (2, 3), (2, 5), (2, 7), (2, 11), (3, 5), (3, 7), (3, 11), (5, 7), (5, 11), (7, 11), (2, 3, 5), (2, 3, 7), (2, 3, 11), (2, 5, 7), (2, 5, 11), (2, 7, 1...
49,000
<p>When I call GetForegroundWindow from c# I am getting the explorer parent process ID (I see this from process explorer) and not the process ID of the app that is in the foreground.</p> <p>Why is this and how do get the right process ID?</p> <p>Malcolm</p>
<p>The API function GetForegroundWindow gets you a handle to the top window, not the process ID. So what other functions do you use to get the process ID from the window handle you get from GetForegroundWindow?</p> <p>This will get you the WINDOW HANDLE of the foreground window:</p> <pre><code> [DllImport("user32...
<p>Not sure what's happening here, but have you tried running your app as Administrator? There are now lots of restrictions about what non-admin apps are able to see across the rest of the system.</p>
44,170
<p>Is there a built-in editor for a multi-line string in a <code>PropertyGrid</code>.</p>
<p>I found that <code>System.Design.dll</code> has <code>System.ComponentModel.Design.MultilineStringEditor</code> which can be used as follows:</p> <pre><code>public class Stuff { [Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))] public string MultiLineProperty { get; set; } } </code></pre>
<p>Yes. I don't quite remember how it is called, but look at the Items property editor for something like ComboBox</p> <p>Edited: As of @fryguybob, ComboBox.Items uses the System.Windows.Forms.Design.ListControlStringCollectionEditor</p>
15,793
<p>When using the app_offline.htm feature of ASP.NET, it only allows html, but no images. Is there a way to get images to display <strong>without having to point them to a different url on another site</strong>?</p>
<p>Yes, it just can't come from the site that has the app_offline.htm file. The image would have to be hosted elsewhere. </p>
<p>You could just convert your images to base64 and then display them:</p> <pre><code> &lt;html&gt; &lt;body&gt; &lt;h1&gt; Web under maintenance with image in base64 &lt;/h1&gt; &lt;img src=&quot;data:image/png;base64,iVBORw0K...=&quot;&gt; &lt;/bo...
5,270
<p>I'm developing a client/server app that will communicate via rest. Some custom request data will be stored in the header of the request. Both the server sending the request and the receiving server have an SSL certificate - will the headers be encrypted, or just the content?</p>
<p>SSL encrypts the entire communications path from the client to the server and back, so yes - the headers will be encrypted.</p> <p>By the way, if you develop networked applications and care about data security, the least you should do is read a book like Practical Cryptography, by Niels Ferguson and Bruce Schneier,...
<p>Not <em>everything</em> is encrypted: the request query string is not encrypted. Believe me, I've seen requests like this:</p> <p><a href="https://mydomain.com/authenticate?user=username&amp;password=MyStrongPasswordSentInTheClear" rel="nofollow">https://mydomain.com/authenticate?user=username&amp;password=MyStron...
9,927
<p>I have a web report that uses a Django form (new forms) for fields that control the query used to generate the report (start date, end date, ...). The issue I'm having is that the page should work using the form's initial values (unbound), but I can't access the cleaned_data field unless I call <code>is_valid()</cod...
<p>If you add this method to your form class:</p> <pre><code>def get_cleaned_or_initial(self, fieldname): if hasattr(self, 'cleaned_data'): return self.cleaned_data.get(fieldname) else: return self[fieldname].field.initial </code></pre> <p>you could then re-write your code as:<...
<p>You can pass a dictionary of initial values to your form:</p> <pre><code>if request.method == "GET": # calculate my_start_date and my_end_date here... form = MyForm( { 'start_date': my_start_date, 'end_date': my_end_date} ) ... </code></pre> <p>See the <a href="http://docs.djangoproject.com/en/dev/ref/form...
10,122
<p>I would like to open a small video file and map every frames in memory (to apply some custom filter). I don't want to handle the video codec, I would rather let the library handle that for me.</p> <p>I've tried to use Direct Show with the SampleGrabber filter (using this sample <a href="http://msdn.microsoft.com/en...
<p>Currently these are the most popular video frameworks available on Win32 platforms:</p> <ol> <li><p>Video for Windows: old windows framework coming from the age of Win95 but still widely used because it is very simple to use. Unfortunately it supports only AVI files for which the proper VFW codec has been installed...
<p>I would recommend FFMPEG or GStreamer. Try and stay away from openCV unless you plan to utilize some other functionality than just streaming video. The library is a beefy build and a pain to install from source to configure FFMPEG/+GStreamer options.</p>
5,880
<p>A friend of mine was recently asked in a job interview to tell the difference between a standard singleton and a mono singleton. I have never heard the term before and a simple google search does not return any meaningful results. </p> <p>My friend suggested that it is an object where the constructor is public but ...
<p>I imagine they actually meant "Monostate". I won't go into the details as they are now easily googleable (along with discussions of the difference to Singletons).</p> <p>However, I will say that Monostates tend to have at least all the same problems and Singletons and should be avoided as far as possible (consideri...
<p>I've never heard the term being used before, but I'd imagine that it's used to refer to a singleton that only allows for one instance being created. (A general singleton doesn't require that, it can also give out a limited number of instances).</p> <p>Either that, or it's a singleton done in mono...</p>
30,804
<p>Is there a simple way to tell what triggered Click event of a Button apart from setting multiple flags in Mouse/Key Up/Down event handlers? I'm currently only interested in distinguishing mouse from everything else, but it would be nice to handle Stylus and other input types if possible. Do I have to create my own b...
<pre><code>if (InputManager.Current.MostRecentInputDevice is KeyboardDevice) </code></pre>
<p>You should instead handle specifically the MouseXXX, StylusXXx, and KeyboardXXX events.</p>
45,146
<p>I would like to include CLR stored procedure deployment in our deployment script (powershell at the moment), however I can't figure out a nice way to do this automatically.</p> <p>I would have thought there would be a nice command line option to do the same as right-click deploy in Visual studio</p>
<p>Well, PowerShell itself won't give you much in the way of extra help. You don't mention which version of SQL, so I'll be a bit generic.</p> <p>Really, all you need to do is have your script file copy the necessary DLLs for your CLR stored procs - PowerShell can copy files like a maniac, so no problem there. Then yo...
<p>The SQL Server Publishing Wizard can script CLR stored procs as text. Looks like it converts the binary source of CLR stored procs as some kind of hex encoded text.</p>
46,031
<p>I would like to know How to create a fps-game with SDL lib? </p> <p>Are there any books that explain with examples? </p>
<p>this wins for most open ended question. You could literally write a book. But lets settle for pointing in the right direction...</p> <p>Step one, you will need good debugging skills for a project like this. Pick up Code Complete by Steve McConnell. Read the whole thing. The time invested will pay for itself more t...
<p>Pretty much anything that says in the TItle the "Tricks of the Game Programming Gurus" is going to show you how to make a FPS game. LeMothe loves them.</p> <p>Edit : forgot those titles.</p>
36,673
<p>I'm fully aware that set division can be accomplished through a series of other operations, so my question is: </p> <p>Is there a command for set division in SQL?</p>
<p><a href="http://vadimtropashko.files.wordpress.com/2007/02/ch3.pdf" rel="noreferrer">http://vadimtropashko.files.wordpress.com/2007/02/ch3.pdf</a></p> <p>From Page 32:</p> <blockquote> <p>Relational Division is not a fundamental operator. It can be expressed in terms of projection, Cartesian product, and set dif...
<p>Related question: <a href="https://stackoverflow.com/questions/48475/database-design-for-tagging">Database Design for Tagging</a></p> <p>And relevant part of answer is <a href="http://www.dbazine.com/ofinterest/oi-articles/celko1" rel="nofollow noreferrer">this article</a></p> <p>So in short, no, there is no set d...
13,534
<p>I've noticed that there seems to be quite a bit of hostility towards Linq To Entities particularly from the Alt.Net folks. I understand the resistance to more "drag and drop" programming, but from my understanding, Linq To Entities doesn't require it. </p> <p>We're currently using Linq to SQL, and we are using th...
<p>I don't think it's a hate for the <em>idea</em> of it per se. It's just that people don't like the <em>implementation</em> of it.</p> <p><a href="http://efvote.wufoo.com/forms/ado-net-entity-framework-vote-of-no-confidence/" rel="nofollow noreferrer">http://efvote.wufoo.com/forms/ado-net-entity-framework-vote-of-n...
<p>I would add that LTE implementation of TPT inheritance is nothing short of criminal. See my question <a href="https://stackoverflow.com/questions/4126668/when-quering-over-a-base-type-why-does-the-ef-provider-generate-all-those-union-a">here</a>.</p> <p>And while I'm at it, I believe that the many <a href="http://w...
7,890
<p>I am re-factoring some code and am wondering about the use of a <code>lock</code> in the instance constructor.</p> <pre><code>public class MyClass { private static Int32 counter = 0; private Int32 myCount; public MyClass() { lock(this) { counter++; myCount = counter; ...
<p>If you are only incrementing a number, there is a special class (Interlocked) for just that...</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.threading.interlocked.increment.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/system.threading.interlocked.increment.aspx</a></p> <blockquote>...
<p>I think if you modify the <a href="http://en.wikipedia.org/wiki/Singleton_pattern#C.23" rel="nofollow noreferrer">Singleton Pattern</a> to include a count (obviously using the thread-safe method), you will be fine :)</p> <h3>Edit</h3> <p>Crap I accidentally deleted!</p> <p>I am not sure if instance constructors <em>...
6,318
<p>Simple question: how do you reinsulate the MakerBot Smart Extruders? </p> <p>Backstory: I work at the library. We've recently replaced the MakerBot (extruder connection issues followed by software incompatibility) with a Prusa.</p> <p>As a new hire, I'm obsessed with the 3D printers. I'm trying to make it my missi...
<p>I recently wrapped a LOT of hot PLA around my print head and, as a result, had to remove the kapton tape and the fibreglass insulation that came with it.</p> <p>I was reluctant to use fibreglass because of the tissue embedding hazard and the lung hazard (especially on what is effectively an indoor appliance) and ka...
<p>Strictly speaking, you do not require the insulation to be there. It is supposed to keep some of the heat contained in the core to allow more heat to be available for the filament to melt (basically higher print speeds and less chance of burning your fingers :) ). </p> <p>If I go to the Makerbot website and look at...
934
<p>Is there any IL level debugger in form of a VS plugin or standalone application?</p> <p>Visual studio’s debugger is great, but it allows you to debug on either HLL code level or assembly language, you can’t debug IL. It seems that in some situations it would be useful to have an opportunity to debug at IL level. </...
<p>The best way to do this is to use ILDASM to disassemble the managed binary, which will generate the IL instructions. Then recompile that IL source code in debug mode using ILASM, when you fire up the Visual Studio debugger you will be able to step through the raw IL.</p> <ol> <li><code>ildasm foo.exe /OUT=foo.exe.i...
<p>ISTR there's a debugger plug-in for Reflector. </p> <p>Not used it myself, though I have used TestDriven.net to debug a 3rd-party assembly with the aid of Reflector:</p> <p><a href="http://weblogs.asp.net/nunitaddin/archive/2006/11/05/Debug-With-Reflector.aspx" rel="nofollow noreferrer">weblogs.asp.net/nunitaddin...
3,062
<p>I would like TortoiseSVN (1.5.3) to ignore certain folders, their contents and certain other files wherever they might appear in my directory hierarchy but I cannot get the global ignore string right.</p> <p>Whatever I do, it either adds to much or ignores too much</p> <p>What is the correct 'Global ignore pattern...
<p>Currently I have the following in my Global Ignore Pattern:<br></p> <pre><code>bin obj CVS .cvsignore *.user *.suo Debug Release *.pdb test.* Thumbs.db </code></pre> <p>Works really well to ignore several hidden or temp files/folders....</p> <p>So for your specific requirements:</p> <ul> <li>Folders: <code>bin o...
<p>This is one I use for .NET. Note that I use VB6 as well as other packages so there are extra entries. Also it is case sensitive. </p> <p>*.chm *.dat *.dll *.ini *.err *.exe *.DLL *.INI *.ERR *.EXE *.backup *.zip *.ZIP *.vbw *.scc *.vbg *.log *.exp *.lib <em>.vrs</em>.SCC *.PRF *.prf *.NIP *.NOP *.nip *.nop *.out *....
22,051
<p>I'm looking into a restful design and would like to use the HTTP methods (<code>POST</code>, <code>GET</code>, ...) and HTTP headers as much as possible. I already found out that the HTTP methods <code>PUT</code> and <code>DELETE</code> are not supported from the browser.</p> <p>Now I'm looking to get different rep...
<p>I would partially disagree with Milan's suggestion of embedding the requested representation in the URI.</p> <p>If anyhow possible, URIs should <b>only</b> be used for addressing resources and <b>not</b> for tunneling HTTP methods/verbs. Eventually, specific business action (edit, lock, etc.) could be embedded in t...
<p>Use some javascript!</p> <pre> xmlhttp=new XMLHttpRequest(); xmlhttp.open('PUT',http://www.mydomain.org/documents/standards/browsers/supportlist) xmlhttp.send("page content goes here"); </pre>
49,041
<p>Long time listener, first time caller.</p> <p>I'm a full time SE during the day and a full time data mining student at night. I've taken the courses, and heard what our professors think. Now, I come to you - the <strong>stackoverflowers</strong>, to bring out the real truth.</p> <p>What is your favorite data min...
<p>Most of my professional experience involved last-minute feature additions like, "Hey, we should add a recommendation system to this e-Commerce site." The solution was usually a quick and dirty nearest neighbor search - brute force, euclidean distance, doomed to fail if the site ever became popular. But hey, prematur...
<p>If you can be more specific about the task the data mining algorithm will perform, sure we can help you (classification, clustering, association rules detection, etc)</p>
43,174
<p>I need to make a WebCast presentation soon and need to do some "whiteboarding" during that WebCast. Does anyone have any stylus/tablet input device recommendations? Anyone ever used such an input device with WebEx's whiteboard feature?</p> <p>rp</p>
<p>Wacom <a href="http://www.wacom.com/index2.cfm" rel="nofollow noreferrer">http://www.wacom.com/index2.cfm</a><Br /> makes by far the best tablets I have ever used. They come in a variety of prices with associated features. If you want to be able to draw 'on-screen' they have the Cintiq, which is the most expensive...
<p>A lot of people recommend Wacom. I've tried one, and it is really nice to use. To some extent, it really depends if you want only a tablet (no video feedback on the device), or a 'screen' (having video feedback, which I find nice but is also a bit pricey...).</p>
4,424
<p>I'm trying to build a mapping table to associate the IDs of new rows in a table with those that they're copied from. The OUTPUT INTO clause seems perfect for that, but it doesn't seem to behave according to the documentation. </p> <p>My code:</p> <pre><code>DECLARE @Missing TABLE (SrcContentID INT PRIMARY KEY ) IN...
<p>I've verified that the problem is that you can only use <code>INSERTED</code> columns. The documentation seems to indicate that you can use <code>from_table_name</code>, but I can't seem to get it to work (The multi-part identifier "m.ContentID" could not be bound.):</p> <pre><code>TRUNCATE TABLE main SELECT * FR...
<p>I think I found a solution to this problem, it sadly involves a temporary table, but at least it'll prevent the creation of a dreaded cursor :) What you need to do is add an extra column to the table you're duplicating records from and give it a 'uniqueidentifer' type.</p> <p>then declare a temporary table:</p> <p...
18,783
<p>Do you know of any differences in handling HTML tags/properties in different browsers? For example, I once saw a page with a input tag with a maxlength field set to "2o". Firefox and Opera ignore the "o", and set the max length to 2, while Internet Explorer ignores the field altogether. Do you know of any more?</p> ...
<p>Check out <a href="http://www.quirksmode.org/" rel="nofollow noreferrer">http://www.quirksmode.org/</a></p>
<p>The one that really annoys me is IE's broken document.getElementById javascript function - in most browsers this will give you something that has the id you specify, IE is happy to give you something that has the value in the name attribute, even if there is something later in the document with the id you asked for....
3,454
<p>I have a very simple model. I want to add a send email routine to on of the methods for the model:</p> <pre><code>$this-&gt;Email-&gt;delivery = 'smtp'; $this-&gt;Email-&gt;template = 'default'; $this-&gt;Email-&gt;sendAs = 'text'; $this-&gt;Email-&gt;from = 'email'; $this-&gt;Email-&gt;to = 'email'; $...
<p>even if it is not best practice, you actually can use the EmailComponent in a model, but you need to instanciate it (in the Models there is no automatic Component loading) and you need to pass it a controller. The EmailComponent relies on the Controller because of the connection it needs to the view, for rendering e...
<p>I have an app where I add a single row to a model (model1). That model then triggers entries into another model (model2). model1 hasmany model2. I wanted to only send emails if model2 inserts successfully. So I was looking to have model1 send emails each time it inserts successfully into model2.</p> <p>Restructurin...
40,318
<p>I want to convert a number between 0 and 4096 ( 12-bits ) to its 3 character hexadecimal string representation in C#. </p> <p>Example:</p> <pre> 2748 to "ABC" </pre>
<p>try</p> <pre><code>2748.ToString("X") </code></pre>
<p>Note: This assumes that you're using a custom, 12-bit representation. If you're just using an int/uint, then Muxa's solution is the best.</p> <p>Every four bits corresponds to a hexadecimal digit.</p> <p>Therefore, just match the first four digits to a letter, then >> 4 the input, and repeat.</p>
17,256
<p>I'm running programs from Eclipse (on Windows) that eat a lot of CPU time. To avoid bogging down my whole machine, I set the priority to Low with the Task Manager. However, this is a cumbersome manual process. Is there a way Eclipse can set this priority automatically?</p> <p>EDIT: I realized that each particular l...
<p>I have the same problem on Windows--- launching subprocesses that use all the CPUs (thread-parallel jobs), yet I want good responsiveness in my Windows development environment. </p> <p><strong>Solution</strong>: after launching several jobs:</p> <p>DOS cmd>> <code>wmic process where name="javaw.exe" CALL setpr...
<p>If you need it only in development you can set the priority of all other processes to high...</p>
15,230
<p>I have a link that I dynamically create which looks something like the following:</p> <pre><code>&lt;a onclick="Edit('value from a text column here')" href="javascript:void(null);"&gt;Edit&lt;/a&gt; </code></pre> <p>with the Edit function then taking the passed in value and putting it into a Yahoo Rich Text Editor...
<p>Convert quote charaters to their HTML equivalents, <code>&amp;quot;</code> etc. before you insert them into the HTML. There's a <a href="http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references" rel="noreferrer">long list</a> of HTML/XML character codes on wikipedia. </p> <p>There may well be a...
<p>So it seems there was more going on, most of these would probably work under most circumstances, but in the interest of posterity here's what I had to do. </p> <p>The information being pulled into the Rich Text Editor was in a YUI datatable and I am creating a link using the custom formatter prototype for said cont...
18,606
<p>When editing an XML file in IntelliJ IDEA, if the document references a schema, IDEA will fetch the schema and use the information for auto-complete. It knows which tags are valid in which contexts, so when you hit CTRL-space, it suggests only those tags. It also highlights any tags that are invalid according to t...
<p>The closest thing that I've seen for Vim is the <a href="http://www.vim.org/scripts/script.php?script_id=1442" rel="noreferrer">XML Completion</a> script.</p> <p>It contains XML definition files for DocBook 4.[234], XSL FO 1.0, XSLT 1.0, Relax NG 1.0, XML Schemas 1.0, SVG 1.1, XHTML 1.1, XInclude 1.0 and OpenOffice...
<p>Reference: <a href="http://ricardianambivalence.com/2013/02/17/xml-validation-in-vim/" rel="nofollow noreferrer">http://ricardianambivalence.com/2013/02/17/xml-validation-in-vim/</a></p> <p>With the <code>bar.xml</code> open, you can easily validate against <code>foo.xsd</code>. First, save your changes and then hi...
41,741
<p>I'd like to create a subset of Users that don't have a login... basically as a way to add a photographer field to photos without having a full blown account associated with that person (since in many cases, they'll never actually log in to the site). A caveat is that I'd also like to be able to enable an account for...
<p>A <a href="http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users" rel="noreferrer">user profile</a> (as returned by <code>django.contrib.auth.models.User.get_profile</code>) doesn't extend the User table - the model you specify as the profile model with the <code>AUTH_PROFILE_M...
<p>From the documentation on <a href="http://docs.djangoproject.com/en/dev/topics/auth/" rel="nofollow noreferrer">django auth</a>, if you want to use the User model, it's mandatory to have a username and password, there are no "anonymous accounts". I guess you could create accounts with a default password and then giv...
20,739
<p>I need a way to bind POJO objects to an external entity, that could be XML, YAML, structured text or anything easy to write and maintain in order to create Mock data for unit testing and TDD. Below are some libraries I tried, but the main problems with them were that I am stuck (for at least more 3 months) to Java 1...
<p>If the objects to be populated are simple beans it may be a good idea to look at apache common's BeanUtils class. The populate() method might suit the described cases. Generally dependency injection frameworks like Spring can be very useful, but that might not be answer for the current problem. For input in form of ...
<p>Just use XStream (for XML or you could give a try to JSON).</p> <p>But...</p> <p>Man, I just can't avoid to think that put the test data outside the unit test itself will leads you to unreadable tests. You will need look two files when reading a test case, you will lose refactoring tools (when changing property's ...
23,770
<p>I'm working on a site with multiple subdomains, some of which should get their own session.</p> <p>I think I've got it worked out, but have noticed something about cookie handling that I don't understand. I don't see anything in the docs that explains it, so thought I would see if anyone here has some light to she...
<p>PHP's cookie functions automatically prefix the $domain with a dot. If you don't want this behavior you could use the <a href="http://us2.php.net/header" rel="noreferrer">header</a> function. For example:</p> <pre><code>header("Set-Cookie: cookiename=cookievalue; expires=Tue, 06-Jan-2009 23:39:49 GMT; path=/; dom...
<p>I was having a problem to set cookies on wordpress and this helped me, the domain value was the key to get it working in all the pages</p> <pre><code>$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; setcookie("cookie_name", 'cookie_value', 0, '/', $domain); </code></pre>
45,321
<p>Right now, I have code that looks something like this:</p> <pre><code>Private Sub ShowReport(ByVal reportName As String) Select Case reportName Case "Security" Me.ShowSecurityReport() Case "Configuration" Me.ShowConfigurationReport() Case "RoleUsers" M...
<pre><code>Type type = GetType(); MethodInfo method = type.GetMethod("Show"+reportName+"Report"); if (method != null) { method.Invoke(this, null); } </code></pre> <p>This is C#, should be easy enough to turn it into VB. If you need to pass parameter into the method, they can be added in the 2nd argument to Invoke...
<p>You can, using <a href="https://learn.microsoft.com/en-us/dotnet/api/system.reflection" rel="nofollow noreferrer">System.Reflection</a>. See <a href="http://www.codeproject.com/KB/codegen/Run-Time_Code_Generation2.aspx" rel="nofollow noreferrer">this code project article</a> for more information. </p> <pre class="l...
16,247
<ol> <li>How do I get a method's execution time? </li> <li>Is there a <code>Timer</code> utility class for things like timing how long a task takes, etc? </li> </ol> <p>Most of the searches on Google return results for timers that schedule threads and tasks, which is not what I want.</p>
<p>There is always the old-fashioned way:</p> <pre><code>long startTime = System.nanoTime(); methodToTime(); long endTime = System.nanoTime(); long duration = (endTime - startTime); //divide by 1000000 to get milliseconds. </code></pre>
<p><strong>Pure Java SE code</strong>, no need for adding dependency, using <code>TimeTracedExecuter</code> :</p> <pre><code>public static void main(String[] args) { Integer square = new TimeTracedExecutor&lt;&gt;(Main::calculateSquare) .executeWithInput("calculate square of num",5,logger); } pub...
21,733
<p>I need to store a url in a MySQL table. What's the best practice for defining a field that will hold a URL with an undetermined length?</p>
<blockquote> <ol> <li><a href="https://web.archive.org/web/20060217120846/http://www.boutell.com/newfaq/misc/urllength.html" rel="noreferrer">Lowest common denominator max URL length among popular web browsers: <strong>2,083</strong> (Internet Explorer)</a></li> </ol> </blockquote> <blockquote> <ol start="2"> <li><a hr...
<p>Most web servers have a URL length limit (which is why there is an error code for "URI too long"), meaning there is a practical upper size. Find the default length limit for the most popular web servers, and use the largest of them as the field's maximum size; it should be more than enough.</p>
27,029
<p>I have a C++ library and a C++ application trying to use functions and classes exported from the library. The library builds fine and the application compiles but fails to link. The errors I get follow this form:</p> <blockquote> <p>app-source-file.cpp:(.text+0x2fdb): undefined reference to `lib-namespace::GetSta...
<p>the U before _ZN3lib-namespace12GetStatusStrEi in the nm output shows that the symbol is <strong>undefined</strong> in the library.</p> <p>Maybe it's defined in the wrong namespace: it looks like you're calling it in lib-namepace but you might be defining it in another.</p>
<p>It's been a while, but if you specify a lib with the -l option, then don't you have the skip the lib prefix?</p> <p>(I changed the name from "lib-in-question.so" to "libfoobar.so" for easier reading for the example below)</p> <pre><code>g++ -fPIC -Wall -O3 -L~/project/lib/release -lfoobar </code></pre> <p>or</p>...
26,609
<p>I was planning to implememt owner-drawn of CListCtrl. I thought that drawing an item is after the item is inserted into the control. So my method is declare a class which is derived from CListCtrl and override its DrawItem() method. The problem is DrawItem is never invoked after inserting an item. Is there anything ...
<p>To get your DrawItem() override called in a CListCtrl derived class, you need to set the style <strong>LVS_OWNERDRAWFIXED</strong> and also set the control to "Report View" mode. As far as I know, ownerdraw only works in report mode.</p> <p>Also check that the variable is the correct type in your header file (eg. C...
<p>You need to set the LBS_OWNERDRAWFIXED style on the control. You can do that in the resource template or programmatically using the ModifyStyle() function.</p> <p>example:</p> <pre><code>m_myListbox.ModifyStyle(0, LBS_OWNERDRAWFIXED, 0); </code></pre>
28,739
<p>Should I always wrap external resource calls in a try-catch? (ie. calls to a database or file system) Is there a best practice for error handling when calling external resources?</p>
<p>Catch <strong>only exceptions</strong> that you <strong>can handle</strong>. So for example when using external resources, the best practice is to catch <strong>specific</strong> exceptions that you know you can handle. In case of files this can be (IOException, SecurityException, etc), in case of Database the excep...
<p>I think the absolute answer is completely conditional (how control do you have over the environment, what is the expected balance between performance and consistency and many others I'm sure), but generally speaking I always do, choosing the safety over the potentially slower performance.</p>
28,865
<p>What applications/modules/dlls do I need on the Window CE 5.0 device in order to be able to attach Visual Studio 2005 to process running on the device ?</p>
<p>In the Debug menu, select Attach to process...<br> In the dialog that pops up change Transport to Smart Device.<br> Hit the Browse button and pick the type of device.<br> It'll pop up a connecting dialog, when it disappears, you get a list of processes on the device.</p> <p>Pick the one you want to debug and the de...
<p>You need to ensure you have a CoreCon connection. This can be done via ActiveSync (which I don't recommend) or directly via Ethernet. It's a fiarly straightforward process, though a little to lengthy to post here clearly, but it entails running the CoreCon client on the device and setting Studio's Device Connectiv...
26,153
<p>I'm playing a bit with LINQ to SQL and overall it's a much better option than what Microsoft had before (DataSet), but it seems that object-oriented capabilities are still limited. Since we currently use a custom persistence framework that created a OO model on top of DataSet, I'm looking to port the framework to a ...
<p>For # 1, you may be looking for the newer Linq to Entity. Here's one place to start: <a href="http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx</a></p>
<p>Rob Conery is developing a new type of repository pattern in his <a href="http://blog.wekeroad.com/mvc-storefront/" rel="nofollow noreferrer">store front series</a>. AFAIK, it uses OO object over LINQ to SQL. It contains a lot of talk about MVC and TDD but it's still worth a watch to see what he's doing with LINQ to...
25,535
<p>I am evaluating several Javascript UI toolkits for building web applications that have a desktop-like feel, mainly because of dialogs and window management.</p> <p>I looked at several options - here are my evaluations so far:</p> <ul> <li><a href="http://extjs.com/" rel="nofollow noreferrer">ExtJS</a> - Great widg...
<p>In terms of a desktop look/feel the best of that bunch has to be ExtJS. In terms of the UI it really is leaps ahead of the rest. Of course there are licensing issues but they have their FLOSS exceptions and if you intend to make money from the project then a commercial license isn't exactly going to break the bank...
<p>ExtJS is probably the best choice. It's fast, it's lean and it's damn beautiful. Their support is also excellent.</p>
33,716
<p>This happened to me in Visual Studio 2008 pre and post 2008 sp1 on more than one computer and to someone else I know, so it can't be an isolated incident.</p> <p>Seemingly random, every so often I lose all syntax highlighting in my aspx page (the html) so that Visual Studio now looks like a really expensive version...
<p>it happened to me after an uninstall of visual studio using a removal tool at <a href="http://msdn.microsoft.com/en-us/vstudio/bb968856.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/vstudio/bb968856.aspx</a> I had to run this before upgrading sql server management studio to 2008 version syntax high...
<p>when this happens to me, i let it sit there for a minute. it will usually bring the syntax highlighting back.</p>
6,750
<p>What is the SQL command to copy a table from one database to another database? I am using MySQL and I have two databases x and y. Suppose I have a table in x called a and I need to copy that table to y database. Sorry if the question is too novice.</p> <p>Thanks.</p>
<p>If your two database are separated, the simplest thing to do would be to create a dump of your table and to load it into the second database. Refer to your database manual to see how a dump can be performed.</p> <p>Otherwise you can use the following syntax (for MySQL)</p> <pre><code>INSERT INTO database_b.table (...
<p>If you just want to copy the contents, you might be looking for <code>select into</code>: <a href="http://www.w3schools.com/Sql/sql_select_into.asp" rel="nofollow noreferrer">http://www.w3schools.com/Sql/sql_select_into.asp</a>. This will not create an identical copy though, it will just copy every row from one tabl...
15,988
<p>I am making a bed for my 3D printer. I have bought a silicon heater (31x31 cm) and I want to glue it to my custom aluminum bed. The tape that it had from factory was bad, so I removed it. I want to glue it to the aluminum and I don't know what type of adhesive to use, I was thinking gasket glue with silicon, but I t...
<p>Heat Transfer PAste will not work as a gluing agent. What you need is a high-temperature glue that bonds Aluminium and a silicone rubber. The benchmark temperature that the glue needs to withstand is about 100 °C or approximately 200 °F.</p> <p><a href="https://www.mcmaster.com/glue/for-use-on%7Ealuminum/for-joining...
<p>Heat Transfer PAste will not work as a gluing agent. What you need is a high-temperature glue that bonds Aluminium and a silicone rubber. The benchmark temperature that the glue needs to withstand is about 100 °C or approximately 200 °F.</p> <p><a href="https://www.mcmaster.com/glue/for-use-on%7Ealuminum/for-joining...
1,790
<p>What do you use to monitor the uptime / performance of your websites, specifically those based on a PHP/MySQL platform like Wordpress?</p> <p>I'm looking for something that alerts me if the site is down, or performing too slowly, and has some useful (not volumeous!) charts showing me any potential problems, and wha...
<p>Try looking at Zabbix</p> <p><a href="http://www.zabbix.com/" rel="nofollow noreferrer">http://www.zabbix.com/</a></p> <ul> <li>WEB performance monitoring </li> <li>WEB availability monitoring </li> <li>Support of POST and GET methods</li> </ul>
<p>Try out <a href="https://www.insping.com/" rel="nofollow">Insping</a> also</p> <ol> <li>performance monitoring</li> <li>availability monitoring</li> <li>e-mail and SMS alerts</li> </ol>
18,416
<p>Internet Explorer has a file download limit of 4GB (2 GB on IE6). Firefox does not have this problem (haven't tested safari yet) (More info here: <a href="http://support.microsoft.com/kb/298618" rel="nofollow noreferrer">http://support.microsoft.com/kb/298618</a>)</p> <p>I am working on a site that will allow the ...
<p><a href="http://www.bittorrent.com/" rel="nofollow noreferrer">bittorrent</a>?</p> <p>There have been a few web-based versions already (<a href="http://www.bitlet.org/" rel="nofollow noreferrer">bitlet</a>, <a href="http://torrentfreak.com/w3btorrent-a-bittorrent-client-for-your-web-server/" rel="nofollow noreferre...
<p>@travis</p> <p>Unfortunately It has to be over HTTP inside the users browser. I'll update the question to be more clear about that.</p>
5,570
<p>I am working on a legacy ASP application. I am attempting to insert a value (40.33) into a field in SQL Server 2000 that happens to be a float type. Every place I can see (via some logging) in the application is sending 40.33 to the Stored Procedure. When I run SQL Profiler against the database while the call is h...
<p>Yes, this is a weird, although <a href="http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems" rel="noreferrer">well-known</a>, side effect of using FLOAT.</p> <p>In Microsoft SQL Server, you should use exact numeric datatypes such as <a href="http://msdn.microsoft.com/en-us/library/ms187746(SQL.90).aspx" r...
<p>I think this is probably just a precision issue - the 0.33 part of the number can't be represented exactly in binary - this is probably the closest that you can get to.</p>
30,829
<p>Is it possible to build a good medium to full sized application using just silverlight as a host?</p> <p>A few things that would be needed: - dynamic pages (one silverlight "screen" can switch between screens, like a normal app. - similar to a java applet which launches from the browser</p> <p>I see that Telerik s...
<p>Although still a somewhat immature platform, Silverlight 2.0 supports many of the features that I would expect from a platform needed to create full sized applications.</p> <ul> <li>Data access through web services and local data/object query support with Linq</li> <li>Many feature rich controls such as datagrid, t...
<p>Absolutely. I've been looking into this and believe that it's as easy to do in Silverlight as it is in any other language. Remember that Silverlight 2 uses C# 3.0 and from that you can build anything that's not included in the Silverlight version of the CLR. Also, the fact that Microsoft gives you access to the .NET...
48,379
<p>What do you suggest for Data Access layer? Using ORMs like Entity Framework and Hibernate OR Code Generators like Subsonic, .netTiers, T4, etc.?</p>
<p>For me, this is a no-brainer, you <em>generate</em> the code. </p> <p>I'm going to go slightly off topic here because there's a bigger underlying fallacy at play. The fallacy is that these ORM frameworks <em>solve</em> the object/relational impedence mismatch. This claim is a barefaced lie.</p> <p>I find the best ...
<p>I've always preferred to go the code generator route, especially in C# where you can make use of extended classes to add functionality to the basic data objects.</p>
32,029
<p>I need to keep the files &amp; folders on two Windows-based, non-domain machines synchronized across a public network. </p> <p>I was thinking rsync over SSH - but I was wondering if there is a simpler solution? Any possibility of using the sync framework over SFTP/SCP/SSH? </p> <p>Or I'm open to better ideas?</...
<p>Figured I'd post what I finally went with - WinSCP - <a href="http://winscp.net" rel="nofollow noreferrer">http://winscp.net</a></p> <p>Connects via GUI to an SFTP server + supports Local/Remote/Both synchronization + scriptable with command-line/batch interface.</p>
<p>You could set up shared folders over a secure VPN with <a href="http://www.hamachi.cc" rel="nofollow noreferrer">Hamachi</a>, then use a folder syncing app to sync them up.</p>
4,516
<p>I have a <a href="http://en.wikipedia.org/wiki/Uniform_resource_locator" rel="noreferrer">URL</a>, and I'm trying to match it to a regular expression to pull out some groups. The problem I'm having is that the URL can either end <em>or</em> continue with a "/" and more URL text. I'd like to match URLs like this:</p>...
<pre class="lang-none prettyprint-override"><code>/(.+)/(\d{4}-\d{2}-\d{2})-(\d+)(/.*)?$ </code></pre> <p><strong>1st Capturing Group <code>(.+)</code></strong></p> <p><code>.+</code> matches any character (except for line terminators)</p> <ul> <li><code>+</code> <strong>Quantifier</strong> — Matches between <strong>on...
<p>In Ruby and Bash, you can use <code>$</code> inside parentheses.</p> <pre><code>/(\S+?)/(\d{4}-\d{2}-\d{2})-(\d+)(/|$) </code></pre> <p>(This solution is similar to Pete Boughton's, but preserves the usage of <code>$</code>, which means end of line, rather than using <code>\z</code>, which means end of string.)</p...
21,112
<p>I've created a few <code>autorun</code> script files on various USB devices that run <code>bash</code> scripts when they mount. These scripts run "in the background", how do I get them to run in a terminal window? (Like the "Application in Terminal" gnome Launcher type.)</p>
<p>Run them as a two stage process with your "autorun" script calling the second script in a new terminal eg</p> <pre><code>gnome-terminal -e top --title Testing </code></pre> <p>Would run the program "top" in a new gnome terminal window with the title "Testing" You can add additional arguments like setting the geome...
<pre><code>xterm -e shellscript.sh </code></pre> <p>or (if <code>xterm</code> isn't installed)</p> <pre><code>gnome-terminal -e shellscript.sh </code></pre> <p>or (if you're using kubuntu / kde)</p> <pre><code>konsole -e shellscript.sh </code></pre>
5,649
<p>I am using the Model-View-Presenter pattern for a web page. Should the presenter be aware of Session or should only the view be aware of it?</p> <p>I guess what I am getting at is that concepts like Session are very related to the architecture of the view so should they be limited to use by the view? Otherwise what...
<p>I am doing something like this in my MVP Implementation I inject an ICookieManager, ISessionManager, ICacheManager, IConfigurationManager, IRedirector into my presenter which are implemented by classes that wrap the functionality for this.</p> <p>This allows for a presenter where you can inject mocked versions of t...
<p>Depends which object you're trying to re-use or otherwise contains most of the business logic.</p> <p>I would assume only the presenter should know of the session as that object is the closest thing to a controller in MVP.</p>
32,245
<p>Is there an alternative to history.go(-1) for FireFox and Safari. Any Help would be greatly appreciated. </p>
<p>You can use <code>history.back()</code>.</p>
<pre><code>&lt;a href="javascript:history.go(-1)"&gt;Link&lt;/a&gt; </code></pre> <p>Should work though.</p> <p>Because, indeed, the following does not work in Firefox:</p> <pre><code>&lt;a href="#" onclick="Javascript:goback();"&gt;some Text&lt;/a&gt; function goback() { history.go(-1); } </code></pre> <p>Is t...
40,122
<p>Somebody used libapt or libept to list packages and get informations about package in a debian-like system?</p> <p>Libapt is not well-documented at all, and i've found few examples and tutorials about libept. Can someone explain me best methods to</p> <ol> <li>get a list of every packages in the apt-system</li> <l...
<p>In debian there is a package called <code>libapt-pkg-doc</code> which contains some documentation (like an API reference). Once installed, you can access it at file:///usr/share/doc/libapt-pkg-doc/html/index.xhtml.</p> <p>I only just had a look at libapt and here is what I have learned so far:</p> <p>How to list a...
<p>There is also DPKG::Parse from CPAN if you are using perl.</p>
44,393
<p>What is a Turing machine and why do people keep mentioning it? My IBM PC is all I need to do my computation! Why does anyone care about these machines?</p>
<p>The reason that Turing Machines are a big deal has to do with the study of classical Computing Science or Theory of Computation type stuff. It's basically about analyzing the general properties of a computer, such as what theoretical abilities and limitations a computer has, as well as what we mean when we talk abo...
<p>The amazing thing about a Turing Machine is that it is the most primary computing machine that exists and it can perform computations as powerful as any computer that exists today. There is no computing problem that you can do with your computer that you can't do with a Turing Machine. In fact, your computer is a TM...
29,205
<p>I work in a medium sized team and I run into these painfully large class files on a regular basis. My first tendency is to go at them with a knife, but that usually just makes matters worse and puts me into a bad state of mind.</p> <p>For example, imagine you were just given a windows service to work on. Now there ...
<p>Ouch! Sounds like the place I use to work.</p> <p>Take a look at <a href="https://rads.stackoverflow.com/amzn/click/com/0131177052" rel="noreferrer" rel="nofollow noreferrer">Working effectivly with legacy code</a>. It has some gems on how to deal with atrocious code. </p> <p>DotNetRocks recently did a <a href="ht...
<p>That reminds me of my current job and when I first joined. They didn't let me re-write anything because I had the same argument, "These classes are so big and poorly written! no one could possibly understand them let alone add new functionality to them."</p> <p>So the first thing I would do is to make sure there ...
47,232
<p>In regards to a part that I'm having printed remotely (by two processes:- stereolithography and laser sintering), I've been advised by the 3d printing company that 'the triangulation of the file is rather rough'. </p> <p>In this particular instance, it probably doesn't matter, but for the future, are there any tips...
<p>The phrase "triangulation of the file is rather rough" is somewhat vague, but one can interpret it to mean that the surface is what is considered "low poly" in the 3D modeling world.</p> <p><a href="https://i.stack.imgur.com/RarRO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RarRO.jpg" alt="lo...
<p><a href="https://forums.autodesk.com/t5/autocad-forum/stl-files-resolution/td-p/6591803" rel="nofollow noreferrer">This thread</a> and <a href="https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-Core/files/GUID-2DF46705-EE9E-409F-86B5-ED391CE207DC-htm.html" rel="no...
1,362
<p>I'm a c# developer but have a job that involves some jsp code. I've been using notepad++ which does a great job in highlighting but I'm missing the intellisense and find it difficult to find the methods I need.</p> <p>What is a good jsp IDE for someone coming for C# that has intellisense?</p> <p><strong>Update</s...
<p>You might want to check out <a href="http://www.netbeans.org/" rel="noreferrer">Netbeans</a>. From what I remember for Java applications, it had pretty good intellisense support. Although I've never used it for JSP. From just reading their site, it seems like they do have good intellisense like features for JSP an...
<p>Eclipse from IBM would appear to be one of the market leaders, but maybe to much of an entreprise application for what you are doing.</p>
39,229
<p>In Java, you can qualify local variables and method parameters with the final keyword.</p> <pre><code>public static void foo(final int x) { final String qwerty = "bar"; } </code></pre> <p>Doing so results in not being able to reassign x and qwerty in the body of the method.</p> <p>This practice nudges your cod...
<p>You should try to do this, whenever it is appropriate. Besides serving to warn you when you "accidentally" try to modify a value, it provides information to the compiler that can lead to better optimization of the class file. This is one of the points in the book, "Hardcore Java" by Robert Simmons, Jr. In fact, the ...
<p>Why would you want to? You wrote the method, so anyone modifying it could always remove the final keyword from qwerty and reassign it. As for the method signature, same reasoning, although I'm not sure what it would do to subclasses of your class... they may inherit the final parameter and even if they override the ...
40,846
<p>Currently we have a table that we use to track inivitations. We have an email field that is indexed but we also have three optional keys that the user can specify when adding new record emails. We don't allow duplicates so we have to query if the email plus the optional keys already exists. Currently the keys are on...
<p>Personally I would recommend this approach.</p> <p>Try the method with the single index that covers everything, if I recall correctly it will still perform well if you only query on the first of the included columns. Once you have the index in place, run the Index Advisor.</p> <p>Then try the other route and repe...
<p>I could be wrong, but I believe if you add:</p> <ul> <li>email, key1, key2, key3</li> </ul> <p>as an index, that most databases will use it if your query is using "email", "email/key1", "email/key1/key2", etc... without requiring you to specify Null values for the missing fields.</p>
25,731
<p>When performance testing a web site using the Load Web Test of Visual Studio one gets a summary of the results. Useful measures are shown, like the average response time, maximum response time etc. </p> <p>One thing that intrigues me is being able to drill down to specific requests if needed, answering questions li...
<p>AFAIK, Loadtests in VSTS 2008 doesn't allow you to capture request details at a granular level. I've read VSTS 2010(still in beta) has a feature which will allow you to do something similar. <a href="http://blogs.msdn.com/billbar/archive/2009/06/09/vsts-2010-load-test-feature-saving-test-logs.aspx" rel="nofollow nor...
<p>(this feature was new in VS 2008 or 2010, not sure which): select the query string parameter on your request, and in the Properties pane there is a property "Show Separate Request Results". Set this to True, and then Visual Studio will record separate page results for all variations of that query string parameter....
41,536
<p>A while ago, I had a discussion with a colleague about how to insert values in STL <a href="http://www.sgi.com/tech/stl/Map.html" rel="noreferrer">maps</a>. I preferred <code>map[key] = value;</code> because it feels natural and is clear to read whereas he preferred <code>map.insert(std::make_pair(key, value))</code...
<p>When you write</p> <pre><code>map[key] = value; </code></pre> <p>there's no way to tell if you <strong>replaced</strong> the <code>value</code> for <code>key</code>, or if you <strong>created</strong> a new <code>key</code> with <code>value</code>.</p> <p><a href="http://en.cppreference.com/w/cpp/container/map/in...
<p>The difference between <a href="https://en.cppreference.com/w/cpp/container/map/insert" rel="nofollow noreferrer"><code>insert()</code></a> and <a href="https://en.cppreference.com/w/cpp/container/map/operator_at" rel="nofollow noreferrer"><code>operator[]</code></a> has already been well explained in the other answ...
42,243
<p>I have an ASP.net Application that runs on the internal network (well, actually it's running on Sharepoint 2007). </p> <p>I just wonder:</p> <p>Can I somehow retrieve the name of the PC the Client is using? I would have access to Active Directory if that helps. The thing is, people use multiple PCs. So, I cannot ...
<p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.web.httprequest.userhostname?redirectedfrom=MSDN&amp;view=netframework-4.8#System_Web_HttpRequest_UserHostName" rel="nofollow noreferrer">System.Web.HttpRequest.UserHostname</a> as suggested in <a href="https://stackoverflow.com/a/17691/1011722">this answe...
<p>Does <a href="http://msdn.microsoft.com/en-us/library/system.web.httprequest.userhostname.aspx" rel="nofollow noreferrer">System.Web.HttpRequest.UserHostname</a> provide what you're looking for?</p>
3,824
<p>Does anyone know how I can get a format string to use <a href="http://en.wikipedia.org/wiki/Rounding#Round-to-even_method" rel="nofollow noreferrer">bankers rounding</a>? I have been using "{0:c}" but that doesn't round the same way that bankers rounding does. The <a href="http://msdn.microsoft.com/en-us/library/sys...
<p>Can't you simply call Math.Round() on the string input to get the behavior you want?</p> <p>Instead of:</p> <pre><code>string s = string.Format("{0:c}", 12345.6789); </code></pre> <p>Do:</p> <pre><code>string s = string.Format("{0:c}", Math.Round(12345.6789)); </code></pre>
<p>Its not possible, a regular expression doesn't have any concept of "numbers". You could use a <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchevaluator(VS.71).aspx" rel="nofollow noreferrer">match evaluator</a> but you'd be adding imperative c# code, and would stray from your reg...
15,627
<p>I am using git on a project, that generates lots of data-files (simulation-results). I am "forced" to version and track all those results in the same repository. (This is a hard requirement and can not be changed)</p> <p>However I don't need them. We have about 50 MB for the project and 5 GB results in the reposit...
<p>If you were to make a branch and delete the result files from the branch, then merging your branch back into master would also try to delete the results from master. A file delete is a change just like any other.</p> <p>Perhaps you could use the git submodule support to manage your code changes as a submodule of th...
<p>Besides git cherry-pick, another alternative is to run git-revert on the file delete change just before merging.</p>
9,680
<p>I have an object of class F. I want to output the contents of the object using Console.WriteLine for quick and dirty status updates like this:</p> <p>Console.WriteLine(objectF);</p> <p>This prints out only the name of the class to the console:</p> <pre><code>F </code></pre> <p>I want to overload this somehow so...
<p>Console.WriteLine(objectF)</p> <p>Should work, if you overloaded <code>ToString</code>. When the framework needs to convert an object to a string representation, it invokes <code>ToString</code>.</p> <pre><code>public override string ToString() { // replace the line below with your code return base.ToStrin...
<p>I would continue to use ToString(). That's its purpose for existing. Also, unless you have a format string, you can just write:</p> <pre><code>Console.WriteLine(objectF) </code></pre>
22,870
<p>The problem is simple:</p> <p>Using bash, I want to add a directory to my PYTHONPATH for ease of script execution. Unfortunately, the directory I want to use has a : in it. So I try each of the following</p> <pre><code>export PYTHONPATH=${PYTHONPATH}:/home/shane/mywebsite.com:3344/ export PYTHONPATH=${PYTHONPATH}:...
<p>The problem is not with bash. It should be setting your environment variable correctly, complete with the <code>:</code> character.</p> <p>The problem, instead, is with Python's parsing of the <code>PYTHONPATH</code> variable. Following the example set by the <a href="http://sourceware.org/cgi-bin/cvsweb.cgi/libc/p...
<p>The symlink hack is probably the only viable option, unless there is some heuristic to determine how to handle colons in PYTHONPATH.</p>
37,715
<p>I have all my entities in a seperate project in my edmx file and I expose them to my client application using a WCF service.</p> <p>That means I don't have to give my client app a direct link to the project that contains the edmx file. That would be bad because it contines the object to query the database with.</p>...
<p>If the WCF service doesn't use it, what would you want it for? A WCF service (itself) is purely for data transport - the "mex" approach for metadata doesn't share code, so your MyClass2 would be impotent. If you want, you can use assembly sharing at the client, but I <em>really</em> don't recommend this in this case...
<p>If you want to do it the "proper" way, you should be creating special classes for your messages that are going across the wire, rather than trying to reuse business entities or data objects as messages. The value in this is that you are then free to change your business entities and data objects without worrying abo...
27,225
<p>I frequently find myself with a folder open in Windows, wishing to have a command prompt open with the same working directory.</p> <p>I am aware of Power Toys "Command Prompt", but that only works as a context menu item on the folder, and not from inside the folder if you are already there. I know you can navigate...
<p>Hold <strong>Shift</strong> while <strong>Right-Clicking</strong> a blank space in the desired folder to bring up a more verbose context menu. One of the options is <code>Open Command Window Here</code>. This works in Windows Vista, 7, 8, and 10. Since Windows 10 Creators Update, the option has been replaced with <c...
<p>Use the following in command prompt to open your current location in windows explorer:</p> <p>C:\your-directory> explorer .</p>
49,548
<p>I've got a few Unix shell scripts where I need to check that certain environment variables are set before I start doing stuff, so I do this sort of thing:</p> <pre><code>if [ -z "$STATE" ]; then echo "Need to set STATE" exit 1 fi if [ -z "$DEST" ]; then echo "Need to set DEST" exit 1 fi </code></...
<h3>Parameter Expansion</h3> <p>The obvious answer is to use one of the special forms of parameter expansion:</p> <pre><code>: ${STATE?&quot;Need to set STATE&quot;} : ${DEST:?&quot;Need to set DEST non-empty&quot;} </code></pre> <p>Or, better (see section on 'Position of double quotes' below):</p> <pre><code>: &quot;$...
<p>The <code>$?</code> syntax is pretty neat:</p> <pre><code>if [ $?BLAH == 1 ]; then echo "Exists"; else echo "Does not exist"; fi </code></pre>
39,580
<p>I am using Oracle SQL (in SQLDeveloper, so I don't have access to SQLPLUS commands such as COLUMN) to execute a query that looks something like this:</p> <pre><code>select assigner_staff_id as staff_id, active_flag, assign_date, complete_date, mod_date from work where assigner_staff_id = '2096'; </code></pre> <p...
<p>What are you using to get the results? The output you pasted looks like it's coming from SQL*PLUS. It may be that whatever tool you are using to generate the results has some method of modifying the output. </p> <p>By default Oracle outputs columns based upon the width of the title or the width of the column data w...
<p>Nice question. I really had to think about it. </p> <p>One thing you could do is change your SQL so that it only returns the narrowest usable columns. </p> <p>e.g. (I'm not very hot on oracle syntax, but something similar should work): </p> <pre><code>select substring( convert(varchar(4), assigner_staff_id), 1...
17,387
<p>I'm interested in how much up front validation people do in the Python they write.</p> <p>Here are a few examples of simple functions:</p> <pre><code>def factorial(num): """Computes the factorial of num.""" def isPalindrome(inputStr): """Tests to see if inputStr is the same backwards and forwards.""" def...
<p>For calculations like sum, factorial etc, pythons built-in type checks will do fine. The calculations will end upp calling <strong>add</strong>, <strong>mul</strong> etc for the types, and if they break, they will throw the correct exception anyway. By enforcing your own checks, you may invalidate otherwise working ...
<p>Only bother to check if you have a failing unit-test that forces you to.</p> <p>Also consider "<a href="http://docs.python.org/glossary.html#term-eafp" rel="nofollow">EAFP</a>"... It's the Python way!</p>
47,972
<p>I have a web application that I'm writing (C#, MSSQL) and I need to store the timestamp when a record is stored in the system. Normally, I would just do this with SQL and the DATETIME function. However, the server is located in a different time zone than our company is located... AND we may change to another serve...
<p><strong><em>always store DATETIME data in Universal Time Coordinated (UTC aka GMT)</em></strong></p> <ul> <li>this avoids all timezone issues</li> <li>this avoids daylight-savings-time issues</li> <li>this allows simple date math to always work</li> <li>this allows transactions in different time zones to stay in sy...
<p>Store it as UTC time and then preform the time zone calculation on the client end in C# use .ToUniversalTime() on the DateTime object to get the UTC time, store that on the server and then use .ToLocalTime() to convert it back.</p>
27,143
<p>Assuming you have a suitable oven to maintain temperature at the filament melting point and a suitable mold that can handle the temperature, is a commodity 3D printer hotend and extruder, with large nozzle, suitable for injecting material into the mold? I'm thinking of a setup like having the hotend mounted through ...
<p>Injection molding requires two major components: pressure and heat. So your question can be broken down into those two halves: can your average extruder handle injection molding temperatures, and can it handle injection molding pressures?</p> <p><strong>Let's start with pressure.</strong> Per <a href="http://www.me....
<p>An injection molding injector melts all the plastic needed for the shot and pushes it into the mold and through the sprue very quickly. Perhaps that is why it is called a "shot".</p> <p>Injection molding machines do not heat the mold to plastic-melting temperatures. This works because the plastic is injected quic...
1,332
<p>I have a little program that I want to make open automatically when my mac is started up.</p> <p>Because this program accepts command line arguments, its not as simple as just going to System Prefs/Accounts/Login items and adding it there...</p> <p>From google, I read that I can create a .profile file in my user's...
<p>From here and into the future, look into <a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fdeveloper.apple.com%2Fmacosx%2Flaunchd.html&amp;ei=JKHjSLHbH5GMpwT2_tH4Cw&amp;usg=AFQjCNH84xt1QnHIRkhYtYJtGScdITegxQ&amp;sig2=xYVn27D-CXFP8IbLig9-qg" rel="nofollow noreferrer"><cod...
<p>You could always write a wrapper script that runs it with the arguments you want</p>
19,155
<p>I am working on a Windows application which needs to be able to update itself. When a button is pressed it starts the installer and then the parent application exits. At some point during the installer, the installer attempts to rename the directory that the parent application was running from and fails with "Access...
<p>I actually found a better way than what <a href="https://stackoverflow.com/users/3253/gowri">Gowri</a> suggested (after starting to implementing the jsp).</p> <p>There is actually a way to dump the threads from the jmx-console in the Server Info MBean, see <a href="http://www.jboss.org/community/docs/DOC-9804" rel=...
<p>You could just write a jsp that does <code>Thread.getAllStackTraces()</code> and print out the stacktracelements in an amenable format. Then hitting the URL of that jsp at any time would give you the stack dump of all threads at that time.</p>
39,755
<p>I just moved a project to the the beta release of <code>ASP.net MVC</code> framework and the only problem I am having is with <code>jQuery</code> and <code>jQueryUI</code>. </p> <p>Here's the deal:</p> <p>In <code>Site.Master</code> are the following script references:</p> <pre><code>&lt;script src="../../Scripts...
<p>does this help?</p> <p><a href="http://forums.asp.net/p/1334947/2690469.aspx" rel="nofollow noreferrer">http://forums.asp.net/p/1334947/2690469.aspx</a></p> <blockquote> <p>The reason for the inconstistency is very simple, though I admit it's not easy to figure out! When you have a &lt;link&gt; tag inside ...
<p>You need to change the links in jquery-ui-themeroller.css to point to the current location of the images. </p> <p>As in, you need to update the path of the images that the css file is looking for. </p> <pre><code>background: url(images/foo.gif) </code></pre> <p>Remove the 'images/' from your paths to make it look...
26,369
<p>Does there exist any way in .Net to check before opening if a file (on a local network drive) is already in use?</p>
<p>You should try to access it and if it failed, you either don't have required permissions (which you can check with GetAccessControl) or it's locked by another process.</p> <p>But I don't think there is any reliable measure to distinguish a lock and a permission failure (since you might be able to read the file, but...
<p>The following syntax will help:</p> <p>FileStream s2 = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read);</p>
48,929
<p>When trying to commit to a cvs branch after adding a new file I get this error</p> <pre><code>Assertion failed: key != NULL, file hash.c, line 317 </code></pre> <p>Any idea how to fix it so I can check my code in?<br> Both server and client are Linux and there are pre-commits involved.</p>
<blockquote> <p>sleep-er writes:</p> <blockquote> <p>Not sure what the issue was but I solved it by going onto the server and deleting the file Attic/newfile.v in the repository and adding it again.</p> </blockquote> </blockquote> <p>The "Attic" is the place where deleted files go in CVS. At some point in...
<p>Perhaps there is some kind of pre-commit check on your repository, see <a href="http://ximbiot.com/cvs/manual/cvs-1.12.13/cvs_18.html#SEC188" rel="nofollow noreferrer">here</a></p>
9,572
<p>I've been searching around and haven't found any reference to tools that can create Safari's webarchive format.</p> <p>Does anyone have pointers to code for creating this format, or at least a format reference documentation?</p> <p>Ideally I'd like to build a tool that takes a directory and splits out a webarchive...
<p>To expand on what Ben said: <a href="http://developer.apple.com/opensource/cflite.html" rel="noreferrer">CFLite</a> (the cross-platform open-source subset of Core Foundation) ships with a plist parser. If you can link against that, it should be quite simple to work with <code>.webarchive</code> files, which are simp...
<p>Webarchive creation is part of Webkit luckily, as such you can use the following for working with them on the Mac:</p> <p><a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/WebKit/Classes/WebArchive_Class/Reference/Reference.html" rel="nofollow noreferrer">http://developer.apple.com/DOCUMENTATION/Coc...
27,022
<p>On a page from a website (one of ours) I can enter in the url the following code:</p> <pre><code>javascript:createNewWindow('Something', 100, 100, 'Text') </code></pre> <p>Is there a way someone can exploit this?</p> <pre><code>function createNewWindow(url, widthIn, heightIn, title) { var str...
<p>Given that code, the createNewWindow() script isn't any more vulnerable than the raw javascript. </p>
<p>In general javascript running on your site is not the source of vulnerabilities. You should be worrying about the server side of the application.</p> <p>However! You can introduce vulnerabilities into your site using javascript. Its called <a href="http://www.owasp.org/index.php/DOM_Based_XSS" rel="nofollow noref...
28,029
<p>Does anyone know how to turn this string: "Smith, John R"<br> Into this string: "jsmith" ?</p> <p>I need to lowercase everything with lower()<br> Find where the comma is and track it's integer location value<br> Get the first character after that comma and put it in front of the string<br> Then get the entire last ...
<p>Start by writing your own INSTR function - call it my_instr for example. It will start at char 1 and loop until it finds a ','.</p> <p>Then use as you would INSTR.</p>
<p>instr() is not compatible with your version of what? Oracle? Are you using version 4 or something?</p>
48,549
<p>What Latex styles do you use and where do you find them?</p> <p>The reason I'm asking this is that it seems that some 99.9999% of all styles on the internet are copies of each other and of a <a href="http://www.tug.org/texshowcase/ps_s_1b.pdf" rel="noreferrer">physics exam paper</a></p> <p>However, when you try to...
<p>LaTeX was originally designed as a reasonably flexible system on which a few standard classes were distributed — that were themselves rather <em>in</em>flexible.</p> <p>In the current state of affairs, if you want a custom layout, you need to write a few amount of supporting code yourself. How else would it happen?...
<p>Well I think <a href="http://ctan.org/" rel="nofollow noreferrer">CTAN</a> is the best resource for LaTeX and TeX-related stuff. Also lots of scientific organizations provide their own styles, it makes sense to try tracing who was the author/publisher of the paper you like and check their websites.</p>
22,530
<p>The library should;</p> <ul> <li>Be easy to use and few lines of client code should accomplish much</li> <li>Be as platform independent as possible. (In case of future ports to other platforms)</li> <li>Have C++ bindings.</li> <li>Be mature and stable</li> </ul> <p>I would also like to be notified of most HID events...
<p>If libhid works for you, then perhaps the thing to do would be to write an application (which you would GPL), which uses libhid to talk to devices, then provides whatever you need via a TCP connection. Your real application would connect via TCP to do what it needs. This would obviously be a massive performance hit....
<p>HIDmaker software suite from Trace systems is an option.</p> <p>Pros:</p> <ul> <li>Easy to use (excellent for learning how to program for USB HID)</li> <li>Generates working applications source code in a various project formats (Visual Studio and <a href="https://en.wikipedia.org/wiki/Borland" rel="nofollow noreferr...
35,421
<p>I'm using a CListCtrl control to display information in my MFC app. At the moment I have LVS_EX_CHECKBOXES set in SetExtendedStyle so all rows in the control have a checkbox next to them. What I would like however is that only some of the rows in the control have checkboxes. Is this possible ? If it is how is this d...
<p>For each item which shouldn't have a checkbox:</p> <pre><code>LVITEM lvi; lvi.stateMask = LVIS_STATEIMAGEMASK; lvi.state = INDEXTOSTATEIMAGEMASK(0); ::SendMessage(m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)&amp;lvi); </code></pre> <p>To 'create' the check box for an item:</p> <pre><code>SetCheck(Item, true/false); ...
<p>Yes it is. What you would need to do is to create bitmaps of the check boxes and included those in the call back. One of your bit maps would be blank. </p> <p>Alternatively, you could do some owner drawing and call the DrawFrameControl function.</p> <p>You could also add code to test for mouse clicks and respon...
23,142
<p>From what I've seen in the past, StackOverflow seems to like programming challenges, such as the <a href="https://stackoverflow.com/questions/69115/char-to-hex-string-exercise">fast char to string exercise problem</a> which got dozens of responses. This is an optimization challenge: take a very simple function and ...
<p>Hmm...how about something like this?</p> <pre><code>#define likely(x) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0) while( likely(src &lt; end) ) { //Copy non-zero run int runlen = strlen( src ); if( unlikely(src+runlen &gt;= end) ) { memcpy( dest, src, end-src ); ...
<p>Mike F, thanks a lot for the "unlikely" suggestion: the following is about 10% faster than the original:</p> <pre><code>#define unlikely(x) __builtin_expect((x),0) while( src &lt; end ) { if( unlikely(i_count == 2) &amp;&amp; unlikely(*src &lt;= 0x03) ) { *dst++ = 0x03; i_count = 0; } ...
17,745
<p>My mission is to create a little app where you can upload a picture, and the app will turn it into ASCII art. I'm sure these exist already but I want to prove that I can do it myself.</p> <p>This would involve taking an image, making it greyscale and then matching each pixel with a character depending on how dark t...
<p>As pointed out by <a href="https://stackoverflow.com/users/9021/nickf">nickf</a> in his <a href="https://stackoverflow.com/questions/276780/making-an-image-greyscale-with-gd-library#276811">comment</a>, the simple formula <code>(pixel.r + pixel.g + pixel.b) / 3</code> is not correct. Use the GD-included function <co...
<p>Typically in a RGB color space, value of 128 for each color component(RG and B) will give a medium gray. You might as well put any value lower or greater than 128 to get different intensities(shades) of gray.</p> <p>-AD</p>
34,909
<p>I was looking for a pattern to model something I'm thinking of doing in a personal project and I was wondering if a modified version of the decorator patter would work.</p> <p>Basicly I'm thinking of creating a game where the characters attributes are modified by what items they have equiped. The way that the decor...
<p>To be honest, it sounds like you're really trying to fit a pattern where you don't really need one, just for the sake of using a pattern. Don't be that guy.</p> <p>Now, if the weapons gave the character some extra strength/stam/hp or whatever, then it might be worth considering. But it doesn't sound like you're goi...
<p>Are you looking for the Strategy pattern?</p>
22,568
<p>The topic says the most of it - what is the reason for the fact that static methods can't be declared in an interface?</p> <pre><code>public interface ITest { public static String test(); } </code></pre> <p>The code above gives me the following error (in Eclipse, at least): "Illegal modifier for the interface ...
<p>There are a few issues at play here. The first is the issue of declaring a static method without defining it. This is the difference between</p> <pre><code>public interface Foo { public static int bar(); } </code></pre> <p>and</p> <pre><code>public interface Foo { public static int bar() { ... } } </c...
<p>Perhaps a code example would help, I'm going to use C#, but you should be able to follow along.</p> <p>Lets pretend we have an interface called IPayable</p> <pre><code>public interface IPayable { public Pay(double amount); } </code></pre> <p>Now, we have two concrete classes that implement this interface:</p>...
4,188
<p>I'm looking for a good sample project, or web site reference, which gives a simple easy to understand overview of URL Rewriting and making Hackable URLs.</p> <p>I've read a good amount about the concept, but I'm specifically looking for a good implementation example for a programmer to use to get started.</p> <p>T...
<p>Pretty sure you mean for webforms, if so check out this post by phil haack <a href="http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx" rel="nofollow noreferrer">http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx</a></p> <p>If you meant asp.net MVC, check this out <a href="ht...
<p>After reading these very helpful responses, and spending a fair amount of time researching this topic, and working on code samples with framework 3.5 sp1, I have found myself successful.</p> <p>To me, the best approach was to first implement this super simple example, and play with it:</p> <p><a href="http://blogs....
43,529
<p>Is there a way to create register a handler that will be called exactly at the time when the last reference to a certain object is released?</p> <p>An example would be an object that is backed by a physical data file and once the object become unreferenced, the file should be closed and than renamed. It would be ni...
<p>In short, <strong>no.</strong></p> <p>The Java specification explicitly denies you the ability to know when the last reference is released. JVM implementations (and optimizations) depend on this. There is no hook.</p>
<p>You <em>could</em> override <code>finalize()</code> in your object, but that is problematic for reasons others have mentioned.</p> <p>For your specific example, you could take a look at using something like <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#deleteOnExit()" rel="nofollow noreferrer"...
25,589
<p>What are differences between declaring a method in a base type "<code>virtual</code>" and then overriding it in a child type using the "<code>override</code>" keyword as opposed to simply using the "<code>new</code>" keyword when declaring the matching method in the child type? </p>
<p>The "new" keyword doesn't override, it signifies a new method that has nothing to do with the base class method. </p> <pre><code>public class Foo { public bool DoSomething() { return false; } } public class Bar : Foo { public new bool DoSomething() { return true; } } public class Test { public stati...
<p>Not marking a method with anything means: Bind this method using the object's compile type, not runtime type (static binding). </p> <p>Marking a method with <code>virtual</code> means: Bind this method using the object's runtime type, not compile time type (dynamic binding). </p> <p>Marking a base class <code>vi...
19,346