instruction
stringlengths 21
27.8k
| chosen
stringlengths 18
28.2k
| rejected
stringlengths 18
33.6k
| __index_level_0__
int64 0
50k
|
|---|---|---|---|
<p>I've cached a value using the ASP.NET Cache, with the following code:</p>
<pre><code>Cache.Insert("TEST_VALUE", 150, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(120));
</code></pre>
<p>As I understand it, this should mean that if nothing accesses that object for 120 seconds, it will expire and return null.</p>
<p>However, if after 10 minutes I run a page which writes out that value from the cache, it's still there (and indeed still after a whole hour). I know there's nothing else accessing it, because this is all on a local server on my machine.</p>
<p>Can anyone tell me why these values aren't getting purged from the cache?</p>
<hr>
<p>Thanks, I see what you mean, but my HttpModule is checking the type of request before inserting anything into the cache, so it will only occur on form uploads.</p>
<p>I've tried what you suggested anyway, and the breakpoint never gets hit when I am refreshing the page that displays the cached value. </p>
<p>I am assuming that even reading from the cache should extend the lifespan of the object, so I am leaving it 5-10 minutes before refreshing the 'debugging' page, but the value is still there!</p>
|
<p>Just a debugging tip: Set the value of the cached object to DateTime.Now when you insert it in order to see when it was inserted. That way you can easily determine if it was re-inserted somehow or if something somewhere keeps accessing and thus forcing it to stay in the cache.</p>
<p>That combined with my suggestion about subscribing to the cache expiry event and writing to a log file should provide you with enough information to locate the problem.</p>
|
<p>Dupe of your original question here:</p>
<p><a href="https://stackoverflow.com/questions/337897/whats-the-reason-for-my-aspnet-cache-never-expiring-despite-having-a-sliding-ex">What's the reason for my ASP.NET Cache never expiring, despite having a sliding expiration time set?</a></p>
<p>Suggest you supply more info on the context of the caching.</p>
| 44,199
|
<p>The <a href="http://en.wikipedia.org/wiki/Effect_system" rel="noreferrer">Wikipedia article on <em>Effect system</em></a> is currently just a short stub and I've been wondering for a while as to what is an effect system. </p>
<ul>
<li>Are there any languages that have an effect system in addition to a type system? </li>
<li>What would a possible (hypothetical) notation in a <strong>mainstream</strong> language, that you're familiar, with look like with effects? </li>
</ul>
|
<p>A "type and effect system" describes not only the kinds of values in a program, but the changes in those values. "Typestate" checking is a related idea.</p>
<p>An example might be a type system that tracks file handles: instead of having a function <code>close</code> with return type <code>void</code>, the type system would record the <em>effect</em> of <code>close</code> as disposing of the file resource—any attempt to read from or write to the file after calling <code>close</code> would become a type error.</p>
<p>I'm not aware of any type and effect system appearing in a mainstream programming language. They have been used to define static analyses (for example, it's quite natural to define an analysis for proper locking/unlocking in terms of effects). As such, effect systems are usually defined using inference schemes rather than concrete syntax. You could imagine a syntax looking something like</p>
<pre><code>File open(String name) [+File]; // open creates a new file handle
void close(File f) [-f] ; // close destroys f
</code></pre>
<p>If you want to learn more, the following papers might be interesting (fair warning: the papers are quite theoretical).</p>
<ul>
<li><a href="http://slang.soe.ucsc.edu/cormac/papers/atomic-toplas.pdf" rel="noreferrer">Types for Atomicity: Static Checking and Inference for Java</a>. Flanagan, Freund, Lipshin, and Qadeer.</li>
<li><a href="http://research.microsoft.com/~maf/Papers/pldi01.pdf" rel="noreferrer">Enforcing High-Level Protocols in Low-Level Software</a>. Robert DeLine and Manuel Fändrich.</li>
<li><a href="http://www.cs.ucla.edu/~palsberg/tba/papers/nielson-nielson-csd99.pdf" rel="noreferrer">Type and Effect Systems</a>. Nielson and Nielson.</li>
</ul>
|
<p>(This is not an authoritative answer; just trying to trawl my memory.)</p>
<p>In a sense, any time you code a 'state monad' in a language, you're using the type system as a potential effect system. So "State" or "IO" in Haskell capture this notion (IO captures a whole lot of other effects as well). I vaguely remember reading papers about various languages that use advanced type systems including things like "dependent types" to control finer-grained management of effects, so that for instance the type/effect system could capture information about which memory locations would be modified in a given data type. This is useful, as it provides ways to make two functions that modify mutually exclusive bits of state be allowed to "commute" (monads don't typically commute, and different monads don't always compose well with one another, which often makes it hard to type (read: assign a static type to) 'reasonable' programs)...</p>
<p>An analogy at a <em>very</em> hand-wavy level is how Java has checked exceptions. You express extra information in the type system about certain effects (you can think of an exception as an 'effect' for the purpose of the analogy), but these 'effects' typically leak out all over your program and don't compose well in practice (you end up with a million 'throws' clauses or else resort to lots of unchecked runtime exception types).</p>
<p>I think a lot of research is being done in this area, both for research-y and mainstream-y languages, as the ability to annotate functions with effect information can unlock the compiler's ability to do a number of optimizations, can impact concurrency, and can do great things for various program analyses and tooling. I don't personally have high hopes for it any time soon, though, as I think lots of smart people have been working on it for a long time and there's still very little to show for it.</p>
| 23,864
|
<p>I'm working on an upgrade for an existing database that was designed without any of the code to implement the design being considered. Now I've hit a brick wall in terms of implementing the database design in code. I'm certain whether its a problem with the design of the database or if I'm simply not seeing the correct solution on how to what needs to be done. </p>
<p>The basic logic stipulates the following:</p>
<ol>
<li>Users access the online trainings by way of Seats. Users can have multiple Seats.</li>
<li>Seats are purchased by companies and have a many-to-many relationship with Products.</li>
<li>A Product has a many-to-many relationship with Modules.</li>
<li>A Module has a many-to-many relationship with Lessons.</li>
<li>Lessons are the end users access for their training.</li>
<li>To muddy the waters, for one reason or another some Users have multiple Seats that contain the same Products. </li>
<li>Certification takes place on a per Product basis, not on a per Seat basis.</li>
<li>Users have a many-to-many relationship with lessons that stores their current status or score for the lesson.</li>
<li>Users certify for a Product when they complete all of the Lessons in all of the Modules for the Product.</li>
<li>It is also significant to know when all Lessons for a particular Module are completed by a User.</li>
<li>Some Seats will be for ReCertification meaning that Users that previously certified for a Product can sign up and take a recertification exam.</li>
<li>Due to Rule 11, Users can and will have multiple Certification records.</li>
<li>Edit: When a User completes a Lesson (scores better than 80%) then the User has (according to the current business logic) completed the Lesson for all Products and all Seats that contain the Lesson.
</ol>
<p>The trouble that I keep running into with the current design and the business logic as I've more or less described it is that I can't find a way to effectively tie whether a user has certified for a particular product and seat vs when they have not. I keep hitting snags trying to establish which Products under which Seats have been certified for the User and which haven't. Part of the problem is because if they are currently registered for multiple of the same Product under different Seats, then I have to count the Product only once.</p>
<p>Below is a copy of the portion of the schema that's involved. Any suggestions on how to improve the design or draw the association in code would be appreciated. In case it matters, this site is built on the LAMPP stack.</p>
<p>You can view the relevant portion of the database schema here: <a href="http://lpsoftware.com/problem_db_structure.png" rel="nofollow noreferrer"><a href="http://lpsoftware.com/problem_db_structure.png" rel="nofollow noreferrer">http://lpsoftware.com/problem_db_structure.png</a></a></p>
|
<p>What you're looking for is <a href="http://www.dbazine.com/ofinterest/oi-articles/celko1" rel="nofollow noreferrer">relational division</a>
Not implemented directly in SQL, but it can be done. Search google for other examples.</p>
|
<p>After a quick look at the schema I think one of the things you can do is create a 'to_be_certified' table. Populate it with user_id, product_id and seat_id when a product is assigned to a seat (when product_seat_rtab is populated).</p>
<p>On adding a record to the certification_rtab table, delete the corresponding record in the 'to_be_certified' table. This will give you an easy access to all the products which are certified for a users and the ones that are not.</p>
<p>To get rid of duplicate product_ids, you can group by product_id.</p>
| 19,752
|
<p>I'm getting zits or blobs in lithophanes while printing on my Ender 3 and 10S Pro. I tried a suggestion: change resolution in mesh fixes of Cura to 0.5 (from 0.05 default). That removed the zits.</p>
<p>But now there are white patches as shown in the image. I reduced the resolution to 0.2 but to no avail.</p>
<p>Anyone else encountered this problem?</p>
<p><a href="https://i.stack.imgur.com/Xpqvz.jpg" rel="nofollow noreferrer" title="Example of white patches in a lithophane print"><img src="https://i.stack.imgur.com/Xpqvz.jpg" alt="Example of white patches in a lithophane print" title="Example of white patches in a lithophane print" /></a></p>
<p><a href="https://i.stack.imgur.com/tKl6c.jpg" rel="nofollow noreferrer" title="Example of zits/blobs in a lithophane print"><img src="https://i.stack.imgur.com/tKl6c.jpg" alt="Example of zits/blobs in a lithophane print" title="Example of zits/blobs in a lithophane print" /></a></p>
|
<p>In short, no. A 2D image has insufficient information to determine a 3D form.</p>
<p>If you want to do this yourself, what you could do is start with the 2D outline in a program like Blender (as 0scar mentioned in a comment), extrude it to make a thin "cardboard cutout", then begin shaping it into three dimensions from there. Imagine it like cutting a slab of Play-doh with a cookie cutter matching your 2D outline, then using the picture and your imagination as a guide to form it into 3D. I'm not sure whether something like that makes any more sense than just starting from scratch modeling it.</p>
<p>Alternatively, nowadays there <em>might</em> be some "AI" models to produce a reasonable guess at what 3D structure you want, with the knowledge that it's supposed to be a person, for a 2D image you provide. I'm not sure if there's anything yet of usable quality, but it's something you could look for.</p>
|
<p>If you only have a 2D photo then as others have already said its not really possible. However if you have the action figure itself you could try a technique called Photogrammetry where you use your phone to take multiple images of the object and then use software to build up a model. Search youtube for guides on Photogrammetry or 3D scanning with your phone. I've never done it but certainly something I'd like to try!</p>
| 2,009
|
<p>How do I alternate HTML table row colors using JSP?</p>
<p>My CSS looks something like:</p>
<pre><code>tr.odd {background-color: #EEDDEE}
tr.even {background-color: #EEEEDD}
</code></pre>
<p>I want to use <code><c:forEach></code> to iterate over a collection. </p>
<pre><code><c:forEach items="${element}" var="myCollection">
<tr>
<td><c:out value="${element.field}"/></td>
...
</tr>
</c:forEach>
</code></pre>
<p>I need an int count variable or boolean odd/even variable to track the row. Then my <code><tr></code> tag would look something like:</p>
<pre><code><tr class="odd or even depending on the row">
</code></pre>
|
<p>Use the <code>varStatus</code> attribute on your <code>forEach</code> tag and JSTL will manage an instance of a <a href="http://java.sun.com/products/jsp/jstl/1.1/docs/api/javax/servlet/jsp/jstl/core/LoopTagStatus.html" rel="noreferrer"><code>javax.servlet.jsp.jstl.core.LoopTagStatus</code></a> for you in the variable name you specify. </p>
<p>You can then use a ternary operator to easily output the appropriate class name:</p>
<pre><code><c:forEach items="${element}" var="myCollection" varStatus="loopStatus">
<tr class="${loopStatus.index % 2 == 0 ? 'even' : 'odd'}">
...
</tr>
</c:forEach>
</code></pre>
<p>This <a href="http://www.ibm.com/developerworks/java/library/j-jstl0318/" rel="noreferrer">JSTL primer</a> from IBM has more information about the <code>core</code> tag library and what it gives you.</p>
|
<p>I don't use JSP, so I can't give you an answer in your language, but here's what I do (using pseudo code)</p>
<pre><code>counter = 0
foreach (elements)
counter = counter + 1
output: <tr class="row{counter % 2}">...</tr>
</code></pre>
<p>Personally, I name the classes "row0" and "row1", which lets you alternate between them with a simple modulus calculation, also, if you decide to have rows alternating in triples or quads (instead of pairs), you can easily extend it to <code>row2</code>, <code>row3</code> and change your output code to be <code>counter % 4</code>, etc.</p>
| 29,944
|
<p>I have two Tronxy 2.0 V5 Marlin boards that reboot whenever heat is applied to the bed. The bed has been swapped (because I thought that was the problem) for a new shiny one. The thermistors, too, of course. The same boards (both) work when the beds remain unheated (setpoint = 0 °C).</p>
<p>Any ideas what might be causing this, or what I might do to figure it out?</p>
<p>Note: I really have no idea which Tronxy board this is; the "2.0" is stenciled on the board, so that's all I can figure out. I shamefully admit I tagged it with Tronxy x1 to see if I could generate any interest, and because a "Tronxy" tag is not available.</p>
|
<p>It sounds like a power-related problem. Always use an external MOSFET to drive a heated bed, and consider investing in a decent power supply. Inevitably, the Tronxy PSU will be barely adequate.</p>
<p>Edit: I've just noticed the <a href="/questions/tagged/tronxy-x1" class="post-tag" title="show questions tagged 'tronxy-x1'" rel="tag">tronxy-x1</a> tag. Be aware that the stock (60 Watt) PSU for the Tronxy X1 cannot power a heated bed (the printer does not have one). Trying to do so will overload the PSU and cause an immediate reset.</p>
|
<p>First, check the power supply. Although it may be specified to deliver the required power, it is possible that the power supply has failed in a way that it can not deliver the rated power. At lower load, the voltage may be correct, but under higher load, it either droops or cuts out completely.</p>
<p>To check this, use a voltmeter on the power as it enters the CPU board, not where it leaves the power supply. This accomplishes one additional check. If the voltage droops rather than cuts off, it may be that the connections have corroded and have a higher resistance.</p>
<p>If you have any kind of oscilloscope, I would recommend it over a simple voltmeter, because the power interruption or droop time may be very short. When the CPU resets it will switch off the load that causes the problem, and the power may quickly resume the correct value.</p>
<p>Second, check that there is not a short in the bed wiring. You might detect that with an ohm meter. You have used two different CPU boards, to it is unlikely to be a common fault on both boards, but you might be using the same wiring.</p>
<p>Third, check the routing of the bed heater wires to see that they are not near other wires which connect with the CPU, including thermistor wires and wires to the UI. High-current switching in the bed wires could be coupling into other wires and conducting a RESET signal to the CPU. Ideally, the heater wires will be twisted together with about 3 (or more) twists per inch, and not twisted together with other wires.</p>
| 1,330
|
<p>Looking for a good rss/feed reader for windows or if there are any good cross platforms one i would be really amazed, or good web services (dont like the google one).</p>
<p>I want something simplistic and minimalistic.</p>
|
<p>I like the NewsGator family of tools (<a href="http://newsgator.com" rel="nofollow noreferrer">http://newsgator.com</a>). I mostly use the Mac and web-based versions, but thought FeedDemon was good, too, for the Windows environment. All keep a common subscription list, so you can bounce back and forth as needed.</p>
|
<p>If you have a Google account already, seriously consider Google Reader. It's available everywhere, with Gears installed it is available offline and binds well to Firefox and Chrome. </p>
| 14,826
|
<p>What is the best way to go about upgrading TFS 2005 to 2008? Also, what about the Team Build scripts ("Build Types"), are those compatible with Team Build 2008 or do they need converted/migrated somehow?</p>
|
<p>First and foremost - backup everything! The databases, the machine itself... You can never be too careful.</p>
<p>I was able to upgrade the TFS installation at my company by using these resources:</p>
<p><a href="http://olausson.net/blog/CommentView,guid,6f97b619-a5ac-41af-a908-f099d49a3b16.aspx" rel="nofollow noreferrer">http://olausson.net/blog/CommentView,guid,6f97b619-a5ac-41af-a908-f099d49a3b16.aspx</a>
<a href="http://blogs.msdn.com/sudhir/archive/2007/05/31/upgrade-2005-with-wss2-0-to-orcas-wss3-0.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/sudhir/archive/2007/05/31/upgrade-2005-with-wss2-0-to-orcas-wss3-0.aspx</a>
<a href="http://weblogs.asp.net/dmckinstry/archive/2007/08/27/considerations-on-using-tfs-2008-with-visual-studio-2005.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/dmckinstry/archive/2007/08/27/considerations-on-using-tfs-2008-with-visual-studio-2005.aspx</a></p>
<p>It's not that hard and can in fact be done in a couple of hours, with better luck.</p>
|
<p>Simply, follow the guidance in the Install document for TFS 2008 - It has an upgrade section. It talks about backing up databases and so on already. The instructions are clear and layed out well. </p>
| 6,084
|
<p>I know I can compile individual source files, but sometimes -- say, when editing a header file used by many <code>.cpp</code> files -- multiple source files need to be recompiled. That's what Build is for.</p>
<p>Default behavior of the "Build" command in VC9 (Visual C++ 2008) is to attempt to compile all files that need it. Sometimes this just results in many failed compiles. I usually just watch for errors and hit ctrl-break to stop the build manually.</p>
<p>Is there a way to configure it such the build stops at the <strong>very first compile error</strong> (not the first failed project build) automatically?</p>
|
<p>I came up with a better macro guys. It stops immediately after the first error/s (soon as build window is updated).</p>
<p>Visual Studio -> Tools -> Macros -> Macro IDE... (or ALT+F11)</p>
<pre><code>Private Sub OutputWindowEvents_OnPaneUpdated(ByVal pPane As OutputWindowPane) Handles OutputWindowEvents.PaneUpdated
If Not (pPane.Name = "Build") Then Exit Sub
pPane.TextDocument.Selection.SelectAll()
Dim Context As String = pPane.TextDocument.Selection.Text
pPane.TextDocument.Selection.EndOfDocument()
Dim found As Integer = Context.IndexOf(": error ")
If found > 0 Then
DTE.ExecuteCommand("Build.Cancel")
End If
End Sub
</code></pre>
<p>Hope it works out for you guys.</p>
|
<p>There is <a href="http://old.stevenharman.net/blog/archive/2008/01/17/visual-studio-tip-kill-that-build.aspx" rel="nofollow noreferrer">this post</a> - not sure if it stops the build at the first error or the first failed project in a solution.</p>
<p>Ctrl-break will also stop it manually.</p>
<p>Now if there was some way to stop it spending 10mins rebuilding intelisense after a build failed!</p>
| 16,321
|
<p>I am trying to find a way to determine at run-time how much memory a given class is using in .NET. Using <code>Marshal.SizeOf()</code> is out, as it only works on value types. Is there a way to check exactly how much memory a class uses?</p>
|
<p>I've only recently started looking into this type of thing, but i have found that memory profilers can give quite detailed information regarding instances of objects within your application.</p>
<p>Here are a couple that are worth trying:</p>
<ul>
<li><a href="http://www.red-gate.com/Products/ants_profiler/index.htm" rel="noreferrer">ANTS Profiler</a></li>
<li><a href="http://memprofiler.com/" rel="noreferrer">.NET Memory Profiler</a></li>
</ul>
|
<p>I agree that a memory profiler is the easiest way to get the information you are looking for. In addition to the two previously mentioned, I recommend JetBrains <a href="http://www.jetbrains.com/profiler/index.html" rel="nofollow noreferrer">dotTrace</a>, which is both a performance profiler and a memory profiler.</p>
<p>If you want to do it yourself, and are willing to get pretty deep into the guts of the CLR, you can use the <a href="http://msdn.microsoft.com/en-us/library/ms404386.aspx" rel="nofollow noreferrer">.NET Profiling API</a>, which is an unmanaged API that (as Microsoft says): "enables a profiler to monitor a program's execution by the common language runtime (CLR)." It's not exactly intended for casual use, but it does have an enormous amount of functionality.</p>
| 7,464
|
<p>Is there an efficient way of detecting if a jpeg file is corrupted? </p>
<p>Background info:<br>
solutions needs to work from within a php script<br>
the jpeg files are on disk<br>
manual checking is no option (user uploaded data) </p>
<p>I know that <code>imagecreatefromjpeg(string $filename);</code> can do it. But it is quite slow at doing so.</p>
<p>Does anybody know a faster/more efficient solutions?</p>
|
<p>From the command line you can use jpeginfo to find out if a jpeg file is OK or not.</p>
<blockquote>
<p>$ jpeginfo -c test.jpeg</p>
<p>test.jpeg 260 x 264 24bit JFIF N 15332 [OK]</p>
</blockquote>
<p>It should be trivial to call jpeginfo from php.</p>
|
<p>You may also try to generate file hash based on MD5 and use it as checksum to validate JPEG data on various steps. For example, after read from file, then after transfer, etc.</p>
| 24,171
|
<p>I just re-read <a href="https://rads.stackoverflow.com/amzn/click/com/020161622X" rel="nofollow noreferrer" rel="nofollow noreferrer">The Pragmatic Programmer</a> (my third time reading it...I get something new every time, too). It seems like the tips that they mention are related to many of the various Agile methodologies. Is Pragmatic Programming just another form of Agile Development?</p>
|
<p>Much of what has been coined "Agile Development" are practices that have been used for years and you will find a lot of these ideas in "The Pragmatic Programmer" and "Code Complete", etc.. To some degree agile is a nice marketing spin that has been coined, but I do believe it has done us a lot of good to get some of these practices and ideeas into the mainstream.</p>
|
<p><strong>Yes, the pragprog way is being agile.</strong> Many elements of the agile manifesto can be found in the pragmatic programmer book. Great examples of this include "there are no final decisions" and "code that glows in the dark".</p>
<p>Andy Hunt and Dave Thomas (Ruby Dave) signed the agile manifesto.</p>
<p>The main point I'd like to make is that few really experienced agile people put much stock in how "agile" anything is. Kent Beck was interviewed just a few weeks ago on the FLOSS podcast ( <a href="http://twit.tv/floss87" rel="nofollow noreferrer">http://twit.tv/floss87</a> ) and it's clear from what he said and his tone of voice that the pioneer of extreme programming doesn't believe that the word "agile" carries much meaning these days in the industry.</p>
<p>I have done lots of extreme programming and have find that everybody says they're "agile" - even people who didn't know what it meant five minutes ago. IMHO the term has become meaningless. It's a lot more clear cut whether a project follows the scrum rules or the extreme programming rules... I'd say pick a specific style because <strong>the "agile" umbrella term seems to mean less and less as time goes on.</strong></p>
| 25,626
|
<p>I want to use <a href="http://alistapart.com/articles/sprites" rel="noreferrer">CSS sprites</a> on a web site instead of separate image files, for a large collection of small icons that are all the same size. How can I concatenate (tile) them into one big image using <a href="http://www.imagemagick.org/" rel="noreferrer">ImageMagick</a>?</p>
|
<p>From the page you linked, <a href="http://www.imagemagick.org/script/montage.php" rel="nofollow noreferrer">'montage'</a> is the tool you want. It'll take a bunch of images and concatenate/tile them into a single output. Here's an example image I've made before using the tool:
<a href="https://i.stack.imgur.com/8rCKY.png" rel="nofollow noreferrer" title="montage example"><img src="https://i.stack.imgur.com/8rCKY.png" alt="alt text" title="montage example"></a><br>
<sub>(source: <a href="http://davr.org/ds2/demos2/index.png" rel="nofollow noreferrer">davr.org</a>)</sub> </p>
|
<p>I like this script for automatical sprite/css generation.
"<a href="http://jaymz.eu/2010/05/building-css-sprites-with-bash-imagemagick/" rel="nofollow noreferrer">Building CSS sprites with Bash & Imagemagick</a>"</p>
<ul>
<li><p>article copy in Waybackmashine <a href="https://web.archive.org/web/20150529041037/http://jaymz.eu/blog/2010/05/building-css-sprites-with-bash-imagemagick" rel="nofollow noreferrer">https://web.archive.org/web/20150529041037/http://jaymz.eu/blog/2010/05/building-css-sprites-with-bash-imagemagick</a></p></li>
<li><p>script copy <a href="http://blog.kupriyanov.com/2011/01/solvedbuilding-css-sprites-with-bash.html" rel="nofollow noreferrer">http://blog.kupriyanov.com/2011/01/solvedbuilding-css-sprites-with-bash.html</a></p></li>
</ul>
| 11,437
|
<p>I'm porting an application from php to fastcgi (c). My host runs apache.</p>
<p>Since the fastcgi app would be running in a loop, I could open a mysql connection, and leave it open for all incoming requests. Is this recommended?</p>
<p>I think I've read about an equal number of opinions saying the connection is way more expensive than the request and it should be persistent, and on the other hand people claiming that the open connection is a resource hog and should be closed each time.</p>
<p>Which one of these is correct in my context?</p>
|
<p>I hate to say such an obvious answer, but...have you tried both ways and compared them? It's pretty easy to change a connect() to a pconnect() and just attempt it with both methods. Do some profiling, especially under load, and see what works best on your combination of hardware and software.</p>
<p>On high-traffic sites, sometimes you can't get your DB to accept enough connections to allow persistent to work, but in general, persistent connections tend to be more efficient.</p>
|
<p>I would say if you have atleast 10-20 people using ur site at all times than persistent connections work the best. anything less is overkill</p>
| 35,465
|
<p>Recently I wrote an extremely basic Java Swing program with a couple of text fields and buttons. The program works fine for me on Ubuntu with Java 1.5. But when I try to run it on OSX (10.4), the main window is displayed correctly but the program seems unresponsive. Nothing seems to happen, no matter which button I click on.</p>
<p>I know next to nothing about Mac OSX, so is there something I might be doing wrong?</p>
|
<p>Could it be that you are executing something off the Event-Dispatch Thread? For example, you might be creating, displaying and then modifying a <code>JTextArea</code> in the <code>main</code> thread.</p>
|
<p>Any chance you could put the code online somewhere so we could try it? I am actually using 10.4 as well so it would not be a problem.</p>
| 27,760
|
<p>I've got to write few words about C#, generally piece of cake? No! </p>
<p>I've searched through various internet resources and books and what i got is kind of headache. For example <strong>Garbage Collector</strong> some sources says that this is C# feature, other that CLR got this feature and C# along with all other .NET languages got it by default. Ofcourse, my vote on CLR but there are lot other things that bring confusion, like <strong>avoiding explicit code conversions</strong>. Maybe i've got bad books and resources... so maybe someone would suggest some place where in clear way is said about C#</p>
<p>Second thing are origins of C# syntax, again few choices and nothing clear, other language combo by each other author. C, c++, Java, that's ok but VB6 and Delphi, i have doubts. And again features origin from these languages is mixed up with c# but in fact it is not clear if it is C# or CLR feature</p>
<p>MTH</p>
|
<p>GC is provided by the CLR</p>
<p>C# is everything that the language spec states, and no more.</p>
<p>Some of the more-interesting things that are actually C# features:</p>
<ul>
<li>iterator blocks [yield return]</li>
<li>anonymous methods / closures / lambdas [the syntax, not to be confused with expression trees]</li>
</ul>
<p>But anything that relates to the code you type, but which isn't directly provided by either the CLR or the framework is a language feature. Other languages may implement them too, of course...</p>
<ul>
<li>using [try/finally/Dispose]</li>
<li>lock [Monitor.Enter/try/finally/Monitor.Exit]</li>
<li>foreach [GetEnumerator()/while/[Dispose]]</li>
<li>extension method resolution</li>
<li>query syntax ["where pred" to .Where(x=>pred) etc]</li>
</ul>
<p>(these are just a few examples of course; and again - other languages are at liberty to also provide these features!)</p>
|
<p>The CLR is a development platform, a runtime environment, supporting managed code written in one of the .NET languages, of which C# is one. Garbage collection is a CLR feature. As are Code Access Security and Just In Time compilation of your managed code.</p>
| 38,708
|
<p>I recently "needed" a zip function in Perl 5 (while I was thinking about <a href="https://stackoverflow.com/questions/11/how-do-i-calculate-relative-time">How do I calculate relative time?</a>), i.e. a function that takes two lists and "zips" them together to one list, interleaving the elements.</p>
<p>(Pseudo)example: </p>
<pre><code>@a=(1, 2, 3);
@b=('apple', 'orange', 'grape');
zip @a, @b; # (1, 'apple', 2, 'orange', 3, 'grape');
</code></pre>
<p><a href="http://www.haskell.org/onlinereport/standard-prelude.html" rel="nofollow noreferrer">Haskell has zip in the Prelude</a> and <a href="http://ferreira.nfshost.com/perl6/zip.html" rel="nofollow noreferrer">Perl 6 has a zip operator</a> built in, but how do you do it in an elegant way in Perl 5?</p>
|
<p>Assuming you have exactly two lists and they are exactly the same length, here is a solution originally by merlyn (Randal Schwartz), who called it perversely perlish:</p>
<pre><code>sub zip2 {
my $p = @_ / 2;
return @_[ map { $_, $_ + $p } 0 .. $p - 1 ];
}
</code></pre>
<p>What happens here is that for a 10-element list, first, we find the pivot point in the middle, in this case 5, and save it in <code>$p</code>. Then we make a list of indices up to that point, in this case 0 1 2 3 4. Next we use <code>map</code> to pair each index with another index that’s at the same distance from the pivot point as the first index is from the start, giving us (in this case) 0 5 1 6 2 7 3 8 4 9. Then we take a slice from <code>@_</code> using that as the list of indices. This means that if <code>'a', 'b', 'c', 1, 2, 3</code> is passed to <code>zip2</code>, it will return that list rearranged into <code>'a', 1, 'b', 2, 'c', 3</code>.</p>
<p>This can be written in a single expression along ysth’s lines like so:</p>
<pre><code>sub zip2 { @_[map { $_, $_ + @_/2 } 0..(@_/2 - 1)] }
</code></pre>
<p>Whether you’d want to use either variation depends on whether you can see yourself remembering how they work, but for me, it was a mind expander.</p>
|
<p>This is totally not an elegant solution, nor is it the best solution by any stretch of the imagination. But it's fun!</p>
<pre><code>package zip;
sub TIEARRAY {
my ($class, @self) = @_;
bless \@self, $class;
}
sub FETCH {
my ($self, $index) = @_;
$self->[$index % @$self][$index / @$self];
}
sub STORE {
my ($self, $index, $value) = @_;
$self->[$index % @$self][$index / @$self] = $value;
}
sub FETCHSIZE {
my ($self) = @_;
my $size = 0;
@$_ > $size and $size = @$_ for @$self;
$size * @$self;
}
sub CLEAR {
my ($self) = @_;
@$_ = () for @$self;
}
package main;
my @a = qw(a b c d e f g);
my @b = 1 .. 7;
tie my @c, zip => \@a, \@b;
print "@c\n"; # ==> a 1 b 2 c 3 d 4 e 5 f 6 g 7
</code></pre>
<p>How to handle <code>STORESIZE</code>/<code>PUSH</code>/<code>POP</code>/<code>SHIFT</code>/<code>UNSHIFT</code>/<code>SPLICE</code> is an exercise left to the reader.</p>
| 5,925
|
<p>In the process of learning <a href="https://en.wikipedia.org/wiki/TinyOS" rel="nofollow noreferrer">TinyOS</a> I have discovered that I am totally clueless about makefiles.</p>
<p>There are many optional compile time features that can be used by way of declaring preprocessor variables.</p>
<p>To use them you have to do things like:</p>
<p><code>CFLAGS="-DPACKET_LINK"</code> this enables a certain feature.</p>
<p>and</p>
<p><code>CFLAGS="-DPACKET_LINK" "-DLOW_POWER"</code> enables two features.</p>
<p>Can someone dissect these lines for me and tell me whats going on? Not in terms of TinyOS, but in terms of makefiles!</p>
|
<p>CFLAGS is a variable that is most commonly used to add arguments to the compiler. In this case, it define macros. </p>
<p>So the <code>-DPACKET_LINK</code> is the equivalent of putting <code>#define PACKET_LINK 1</code> at the top of all .c and .h files in your project. Most likely, you have code inside your project that looks if these macros are defined and does something depending on that:</p>
<pre><code>#ifdef PACKET_LINK
// This code will be ignored if PACKET_LINK is not defined
do_packet_link_stuff();
#endif
#ifdef LOW_POWER
// This code will be ignored if LOW_POWER is not defined
handle_powersaving_functions();
#endif
</code></pre>
<p>If you look further down in your makefile, you should see that <code>$(CFLAGS)</code> is probably used like:</p>
<pre><code>$(CC) $(CFLAGS) ...some-more-arguments...
</code></pre>
|
<p>-D stands for <em>define</em> (in gcc) at least, which lets you #define on the command line instead of a file somewhere. A common thing to see would be -DDEBUG or -DNDEBUG which respectively activate or disable debugging code.</p>
| 10,618
|
<p>I am writing a Time Sheeting web application that involves users entering their tasks for the week. I would like not to have the page refresh so I am exploring ways to add/delete/edit tasks using JavaScript on the client browser. </p>
<p>Currently I am using ASP.NET-MVC, Ajax, JQuery and LiveValidation and I am make steady (if slow) progress.</p>
<p>I am interested to see if this is a solved problem and the pros and cons of various approaches.</p>
<p>For example my current approach to adding a new task (Category/Activity/Hours) involves basic validation using LiveValidation with a web service call to check the Category/Activity. If all the fields validate I create a new table row to show the task and the hide it. Next I call the web service again to add the task to the DB and on success I show the new row and enable it for deletion/editing</p>
|
<p>I would suggest ExtJS. It is a library for more "application" like interfaces in web apps. Included is a <code>EditorGridPanel</code> class, which would be able to do what you're looking for fairly easily. And it looks GREAT.</p>
|
<p>Why don't you validate and add your data in a single request? If data doesn't validate, return false with error fields, if validates, return true with newly created task's id. You don't need to validate and add in seperate requests.</p>
| 22,008
|
<p>I would like to know if there is any way to add custom behaviour to the auto property get/set methods.</p>
<p>An obvious case I can think of is wanting every set property method to call on any <code>PropertyChanged</code> event handlers as part of a <code>System.ComponentModel.INotifyPropertyChanged</code> implementation. This would allow a class to have numerous properties that can be observed, where each property is defined using auto property syntax.</p>
<p>Basically I'm wondering if there is anything similar to either a get/set template or post get/set hook with class scope.</p>
<p>(I know the same end functionality can easily be achieved in slightly more verbose ways - I just hate duplication of a pattern)</p>
|
<p>No, you'll have to use "traditional" property definitions for custom behavior.</p>
|
<p>If it's a behavior you'll repeat a lot during development, you can create a custom code snippet for your special type of property.</p>
| 14,154
|
<p>If you had a 10 minute hands-on session to teach someone Emacs, what would you show them?</p>
<pre>
Start emacs: emacs
...
Quit emacs: C-x C-c
</pre>
<p>What else would you have them do between starting and quitting Emacs, while you stood behind them?</p>
|
<p>If I had only 10 minutes, I would not teach them any shortcuts at all. All the common shortcuts are available next to the corresponding commands in the menus; those the users can discover for themselves.</p>
<p>The most important things to teach are those that will enable the users to discover/learn by themselves:</p>
<ul>
<li><p>That one can quit Emacs with <code>C-x C-c</code>, or File->Quit. When stuck, one should type <code>C-g</code>, and, if that doesn't work, <code>ESC ESC ESC</code>. [This is probably the single most useful advice to prevent total frustration with Emacs, trust me.]</p></li>
<li><p>The tutorial: Help->Emacs Tutorial, or <code>C-h t</code>. [This is not a terribly useful shortcut to <em>remember</em>; given how few times one reads the tutorial over the course of one's life...]</p></li>
<li><p>The concept that every keystroke in Emacs is bound to a function, and all that Emacs does is execute functions one after another. That there are more functions than can possibly be bound to keys, and functions without a keystroke can be invoked with <code>M-x function-name</code>.</p></li>
<li><p>That one can discover what function a particular key invokes with <code>C-h k [keystroke]</code>. Make the user walk through a few of those (including the amusing fact that typing a letter is not special and just invokes <code>self-insert-command</code>, so if one wanted, one could bind the letter 'z' to send email instead :D)</p></li>
<li><p>That one can search for possibly useful functions with <code>C-h a</code> (or <code>M-x apropos-command</code>), e.g. <code>C-h a paragraph</code> shows all the commands to do with paragraphs, including what shortcuts will take one to the end/beginning of a paragraph. And that <code>C-h w command-name</code> will tell you if the command is bound to some keystroke or not. [Make them walk through this to discover what the key for <strong>undo</strong> is -- usually they'll try C-z and it does something annoying :)]</p></li>
<li><p>That you can read detailed documentation about what a function does with <code>M-x describe-function</code> (<code>C-h f</code>). That Emacs has great documentation about most things; and <code>M-x apropos-documentation</code> (<code>C-h d</code>) is a great way of discovering stuff.</p></li>
<li><p>That one's settings are stored in .emacs, and that one can glean some things by looking at that file even if one don't understand Emacs Lisp.</p></li>
<li><p>That one can usually find all keystrokes that "complete" a particular set of keys by typing <code>C-h</code> after it, e.g. 'C-x C-h' will show all the shortcuts starting with C-x; <code>C-h C-h</code> is particularly useful; <code>C-c C-h</code> is useful for mode-specific commands such as when in java-mode or c++-mode or LaTeX-mode, etc. (Hmm, "modes"...)</p></li>
<li><p>That when stuck, one can search on <a href="http://www.emacswiki.org/" rel="noreferrer"><a href="http://www.emacswiki.org/" rel="noreferrer">http://www.emacswiki.org/</a></a>. (Or ask a question in the #emacs IRC channel on Freenode, or post to <a href="http://groups.google.com/group/gnu.emacs.help/topics" rel="noreferrer">gnu.emacs.help</a>.)</p></li>
</ul>
<p>This should fit in 10 minutes, and it's the most important stuff, I think. I wouldn't overload with too many shortcuts to remember; that's pointless anyway -- if the users know how to discover shortcuts, they'll find out shortcuts for whatever they use most frequently. Do have them write down the names of these commands, though, and also about Emacswiki etc.</p>
<p>The important thing is to show them how powerful Emacs is and how universal its model is (all those jokes about it being an operating system are not just jokes). If you just show a bunch of arcane shortcuts to do things they can already do in other editors, Emacs won't seem worth all the trouble. In the same spirit, I also wholly support Anton Nazarov's answer of showing them what Emacs can do (AucTeX if they use LaTeX, etc.) for <em>their</em> specific purposes. Then they can judge for themselves whether Emacs is worth learning, and learn using all the above.</p>
|
<p>I think the first thing to ask before trying to teach them something is "what do they want to get out of learning Emacs?" AND, are you trying to sell them on the idea of learning Emacs or are they already committed.</p>
<p>If they are a programmer and are looking for a new development environment, show them ECB, how tags work, etc? If they are looking for a general text editor, show them <code>M-x re-builder</code>. If they are looking to write documents quickly and publish them eventually, show them <code>org-mode</code> with HTML and LaTeX exports.</p>
| 40,108
|
<p>I want to use lucene.net to index records in our database. The records are stored in several different tables and tied together through a records table. Would it be better to index each table separately and tie the search results together in code, or should I tie the records together coming out of the database and place them all in one index?</p>
<p>Any other suggestions would be helpful as well.</p>
|
<p>If you make a Lucene index that corresponds to each table, then 1) you're going to have to do the work of performing the search against each index and 2) merging the search results in some magical fashion. Lucene is already set up to search documents with multiple fields (see MultiFieldQueryParser), and give you a unified result set.</p>
<p>Even if you decide after making the index that you occasionally only want to search based on the data that came from a single table, you can just use the normal QueryParser to search only the corresponding field of your documents.</p>
|
<p>Lucene isn't tied to database tables, you select the information you want in a Lucene document. I would likely be better to let Lucene handle the merging and ranking of results rather than doing it yourself. </p>
| 33,348
|
<p>I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.</p>
<p>Say we have a linked list record defined so:</p>
<pre><code>typedef struct _record
{
char* value;
struct _record* next;
} record;
</code></pre>
<p>We need a function that inserts a new record so that the entire list remains sorted with respect to the value's in the records. The following implementation is simpler than anything I would have used, albeit less readable.</p>
<pre><code>void insert_sorted(record** r, const char* value)
{
record* newrec = NULL;
while(*r && strcmp(value, (*r)->value) > 0)
r = &((*r)->next); /* move r to point to the next field of the record */
newrec = malloc(sizeof(record));
newrec->value = strdup(value);
newrec->next = *r;
*r = newrec;
}
</code></pre>
<p>When the function is called, r points to the head pointer of the list. During the while loop, r is updated to point to the <code>next</code> field of the record that comes just before the point where we want to put the new record in. The last line of the function either updates the head pointer of the list (if the insertion happens at the beginning) or the <code>next</code> field of the previous record, which is quite cool.</p>
<p>A couple of questions:</p>
<ul>
<li><p>Does this idiom have a name or is it mentioned in any literature?</p></li>
<li><p>Are there others like it in the C language?</p></li>
</ul>
<p>I thought I knew C pretty well and had pointers and indirection pretty well figured out, but this one took me a while to fully understand.</p>
|
<p>I've used similar to this to insert into a binary tree. Because when iterating the tree, you usually stop when your pointer becomes <code>NULL</code> (you ran off the tree).</p>
<p>So to insert, you have 3 options, </p>
<p>1: use a variable which tracks the previous value of your iterating pointer.</p>
<p>2: stop when the pointer you would follow is NULL before you follow it, works but slightly less elegant in my opinion.</p>
<p>3: or a more elegant solution is simply use a pointer to a pointer, so you can just do: <code>*it = new_node();</code> and it'll add it where the <code>NULL</code> used to be in your tree.</p>
<p>For a linked list, while this code works nicely, I usually just use a doubly linked list which makes it trivial to insert at any location.</p>
|
<p>I have also come up with this use of a double pointer, I have used it, but I don't really like it. The code that I came up with has this kernel to search for certain objects and remove them from the list:</p>
<pre><code>Element** previous = &firstElement, *current;
while((current = *previous)) {
if(shouldRemove(current)) {
*previous = current->next; //delete
} else {
previous = &current->next; //point to next
}
}
</code></pre>
<p>The reason I don't like my code is the subtle difference between the two if clauses: the syntax is almost identical, but the effect is entirely different. I do not think, we should write code as subtle as this, but doing it differently makes the code really lengthy. So, either way is bad - you might go for brevity or for readability, it's your choice.</p>
| 43,065
|
<p>Let me describe the problem in details:</p>
<p>I want to show an absolute positioned div when hovering over an element. That's really simple with jQuery and works just fine. But when the mouse goes over one of the child elements, it triggers the mouseout event of the containing div. How do I keep javascript from triggering the mouseout event of the containing element when hovering a child element. </p>
<p>What's the best and shortest way to do that with jQuery?</p>
<p>Here is a simplified example to illustrate what I mean:</p>
<p>Html:</p>
<pre><code><a>Hover Me</a>
<div>
<input>Test</input>
<select>
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
</code></pre>
<p>Javascript/jQuery:</p>
<pre><code>$('a').hover( function() { $(this).next().show() }
function() { $(this).next().hide() } );
</code></pre>
|
<p>The question is a bit old, but I ran into this the other day.</p>
<p>The simplest way to do this with recent versions of jQuery is to use the <code>mouseenter</code> and <code>mouseleave</code> events rather than <code>mouseover</code> and <code>mouseout</code>.</p>
<p>You can test the behavior quickly with:</p>
<pre><code>$(".myClass").on( {
'mouseenter':function() { console.log("enter"); },
'mouseleave':function() { console.log("leave"); }
});
</code></pre>
|
<p>The way I've usually seen this handled is to have a delay of about 1/2 second between moving the mouse from the HoverMe element. When moving the mouse into the hovered element, you would want to set some variable which signals that you are hovering over element, and then basically stop the hovered part from hiding if this variable is set. You then have to add a similar hide function OnMouseOut from the hovered element to make it disappear when you remove the mouse. Sorry I can't give you any code, or something more concrete, but I hope this points you in the right direction.</p>
| 45,642
|
<p>What code analysis tools do you use on your Java projects?</p>
<p>I am interested in all kinds</p>
<ul>
<li>static code analysis tools (FindBugs, PMD, and any others)</li>
<li>code coverage tools (Cobertura, Emma, and any others)</li>
<li>any other instrumentation-based tools </li>
<li>anything else, if I'm missing something</li>
</ul>
<p>If applicable, also state what build tools you use and how well these tools integrate with both your IDEs and build tools. </p>
<p>If a tool is only available a specific way (as an IDE plugin, or, say, a build tool plugin) that information is also worth noting.</p>
|
<p>For static analysis tools I often use CPD, <a href="http://pmd.sourceforge.net" rel="noreferrer">PMD</a>, <a href="http://findbugs.sourceforge.net" rel="noreferrer">FindBugs</a>, and <a href="http://checkstyle.sourceforge.net" rel="noreferrer">Checkstyle</a>.</p>
<p><p>CPD is the PMD "Copy/Paste Detector" tool. I was using PMD for a little while before I noticed the <a href="http://pmd.sourceforge.net/cpd.html" rel="noreferrer">"Finding Duplicated Code" link</a> on the <a href="http://pmd.sourceforge.net" rel="noreferrer">PMD web page</a>.</p>
<p><p>I'd like to point out that these tools can sometimes be extended beyond their "out-of-the-box" set of rules. And not just because they're open source so that you can rewrite them. Some of these tools come with applications or "hooks" that allow them to be extended. For example, PMD comes with the <a href="http://pmd.sourceforge.net/howtowritearule.html" rel="noreferrer">"designer" tool</a> that allows you to create new rules. Also, Checkstyle has the <a href="http://checkstyle.sourceforge.net/config_misc.html#DescendantToken" rel="noreferrer">DescendantToken</a> check that has properties that allow for substantial customization.</p>
<p><p>I integrate these tools with <a href="http://virtualteamtls.svn.sourceforge.net/viewvc/virtualteamtls/trunk/scm/common.xml?view=markup" rel="noreferrer">an Ant-based build</a>. You can follow the link to see my commented configuration.</p>
<p><p>In addition to the simple integration into the build, I find it helpful to configure the tools to be somewhat "integrated" in a couple of other ways. Namely, report generation and warning suppression uniformity. I'd like to add these aspects to this discussion (which should probably have the "static-analysis" tag also): how are folks configuring these tools to create a "unified" solution? (I've asked this question separately <a href="https://stackoverflow.com/questions/79918/configuring-static-analysis-tools-for-uniformity">here</a>)</p>
<p><p>First, for warning reports, I transform the output so that each warning has the simple format:</p>
<pre><code>/absolute-path/filename:line-number:column-number: warning(tool-name): message</code></pre>
<p><p>This is often called the "Emacs format," but even if you aren't using Emacs, it's a reasonable format for homogenizing reports. For example:</p>
<pre><code>/project/src/com/example/Foo.java:425:9: warning(Checkstyle):Missing a Javadoc comment.</code></pre>
<p><p>My warning format transformations are done by my Ant script with Ant <a href="http://ant.apache.org/manual/Types/filterchain.html" rel="noreferrer">filterchains</a>.</p>
<p><p>The second "integration" that I do is for warning suppression. By default, each tool supports comments or an annotation (or both) that you can place in your code to silence a warning that you want to ignore. But these various warning suppression requests do not have a consistent look which seems somewhat silly. When you're suppressing a warning, you're suppressing a warning, so why not always write "<code>SuppressWarning</code>?"</p>
<p><p>For example, PMD's default configuration suppresses warning generation on lines of code with the string "<code>NOPMD</code>" in a comment. Also, PMD supports Java's <code>@SuppressWarnings</code> annotation. I configure PMD to use comments containing "<code>SuppressWarning(PMD.</code>" instead of <code>NOPMD</code> so that PMD suppressions look alike. I fill in the particular rule that is violated when using the comment style suppression:</p>
<pre><code>// SuppressWarnings(PMD.PreserveStackTrace) justification: (false positive) exceptions are chained</code></pre>
<p><p>Only the "<code>SuppressWarnings(PMD.</code>" part is significant for a comment, but it is consistent with PMD's support for the <code>@SuppressWarning</code> annotation which does recognize individual rule violations by name:</p>
<pre><code>@SuppressWarnings("PMD.CompareObjectsWithEquals") // justification: identity comparision intended</code></pre>
<p><p>Similarly, Checkstyle suppresses warning generation between pairs of comments (no annotation support is provided). By default, comments to turn Checkstyle off and on contain the strings <code>CHECKSTYLE:OFF</code> and <code>CHECKSTYLE:ON</code>, respectively. Changing this configuration (with Checkstyle's "SuppressionCommentFilter") to use the strings "<code>BEGIN SuppressWarnings(CheckStyle.</code>" and "<code>END SuppressWarnings(CheckStyle.</code>" makes the controls look more like PMD:</p>
<pre>
<code>// BEGIN SuppressWarnings(Checkstyle.HiddenField) justification: "Effective Java," 2nd ed., Bloch, Item 2</code>
<code>// END SuppressWarnings(Checkstyle.HiddenField)</code>
</pre>
<p><p>With Checkstyle comments, the particular check violation (<code>HiddenField</code>) <em>is</em> significant because each check has its own "<code>BEGIN/END</code>" comment pair.</p>
<p><p>FindBugs also supports warning generation suppression with a <code>@SuppressWarnings</code> annotation, so no further configuration is required to achieve some level of uniformity with other tools. Unfortunately, Findbugs has to support a custom <code>@SuppressWarnings</code> annotation because the built-in Java <code>@SuppressWarnings</code> annotation has a <code>SOURCE</code> retention policy which is not strong enough to retain the annotation in the class file where FindBugs needs it. I fully qualify FindBugs warnings suppressions to avoid clashing with Java's <code>@SuppressWarnings</code> annotation:</p>
<pre><code>@edu.umd.cs.findbugs.annotations.SuppressWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")</code></pre>
<p><p>These techniques makes things look reasonably consistent across tools. Note that having each warning suppression contain the string "<code>SuppressWarnings</code>" makes it easy to run a simple search to find all instances for all tools over an entire code base.</p>
|
<p>I am looking for many answers to learn about new tools and consolidate this knowledge in a one question/thread, so I doubt there will be 1 true answer to this question.</p>
<p>My answer to my own question is that we use:</p>
<ul>
<li>Findbugs to look for common errors bad/coding - run from maven, and also integrates easily into Eclipse</li>
<li>Cobertura for our coverage reports - run from maven</li>
</ul>
<p>Hudson also has a task-scanner plugin that will display a count of your TODO and FIXMEs, as well as show where they are in the source files.</p>
<p>All are integrated with Maven 1.x in our case and tied into Hudson, which runs our builds on check-in as well as extra things nightly and weekly. Hudson trend graphs our JUnit tests, coverage, findbugs, as well as open tasks. There is also a Hudson plugin that reports and graphs our compile warnings. We also have several performance tests with their own graphs of performance and memory use over time using the Hudson plots plugin as well.</p>
| 2,610
|
<p>Is it possible to change the natural order of columns in Postgres 8.1?</p>
<p>I know that you shouldn't rely on column order - it's not <em>essential</em> to what I am doing - I only need it to make some auto-generated stuff come out in a way that is more pleasing, so that the field order matches all the way from pgadmin through the back end and out to the front end.</p>
|
<p>You can actually just straight up change the column order, but I'd hardly recommend it, and you should be very careful if you decide to do it.</p>
<p>eg.</p>
<pre>
# CREATE TABLE test (a int, b int, c int);
# INSERT INTO test VALUES (1,2,3);
# SELECT * FROM test;
a | b | c
---+---+---
1 | 2 | 3
(1 row)
</pre>
<p>Now for the tricky bit, you need to connect to your database using the postgres user so you can modify the system tables.</p>
<pre>
# SELECT relname, relfilenode FROM pg_class WHERE relname='test';
relname | relfilenode
---------+-------------
test_t | 27666
(1 row)
# SELECT attrelid, attname, attnum FROM pg_attribute WHERE attrelid=27666;
attrelid | attname | attnum
----------+----------+--------
27666 | tableoid | -7
27666 | cmax | -6
27666 | xmax | -5
27666 | cmin | -4
27666 | xmin | -3
27666 | ctid | -1
27666 | b | 1
27666 | a | 2
27666 | c | 3
(9 rows)
</pre>
<p>attnum is a unique column, so you need to use a temporary value when you're modifying the column numbers as such:</p>
<pre>
# UPDATE pg_attribute SET attnum=4 WHERE attname='a' AND attrelid=27666;
UPDATE 1
# UPDATE pg_attribute SET attnum=1 WHERE attname='b' AND attrelid=27666;
UPDATE 1
# UPDATE pg_attribute SET attnum=2 WHERE attname='a' AND attrelid=27666;
UPDATE 1
# SELECT * FROM test;
b | a | c
---+---+---
1 | 2 | 3
(1 row)
</pre>
<p>Again, because this is playing around with database system tables, use extreme caution if you feel you really need to do this.</p>
<p>This is working as of postgres 8.3, with prior versions, your milage may vary.</p>
|
<p>Unfortunately, no, it's not. Column order is entirely up to Postgres.</p>
| 15,380
|
<p>What are the available libraries for creating pretty charts and graphs in a Python application?</p>
|
<p>I'm the one supporting CairoPlot and I'm very proud it came up here.
Surely matplotlib is great, but I believe CairoPlot is better looking.
So, for presentations and websites, it's a very good choice.</p>
<p>Today I released version 1.1. If interested, check it out at <a href="http://linil.wordpress.com/2008/09/16/cairoplot-11/" rel="nofollow noreferrer">CairoPlot v1.1</a></p>
<p>EDIT: After a long and cold winter, CairoPlot is being developed again. Check out the new version on <a href="https://github.com/rodrigoaraujo01/cairoplot" rel="nofollow noreferrer">GitHub</a>.</p>
|
<p>You could also consider <a href="http://code.google.com/apis/chart/" rel="nofollow noreferrer">google charts</a>.</p>
<p>Not technically a python API, but you can use it from python, it's reasonably fast to code for, and the results tend to look nice. If you happen to be using your plots online, then this would be an even better solution.</p>
| 7,589
|
<p>In Mootools, I'd just run <code>if ($('target')) { ... }</code>. Does <code>if ($('#target')) { ... }</code> in jQuery work the same way?</p>
|
<p>As the other commenters are suggesting the most efficient way to do it seems to be: </p>
<pre><code>if ($(selector).length ) {
// Do something
}
</code></pre>
<p>If you absolutely must have an exists() function - which will be slower- you can do:</p>
<pre><code>jQuery.fn.exists = function(){return this.length>0;}
</code></pre>
<p>Then in your code you can use</p>
<pre><code>if ($(selector).exists()) {
// Do something
}
</code></pre>
<p>As answered <a href="https://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery">here</a></p>
|
<p>For me <code>.exists</code> doesn't work, so I use the index :</p>
<pre><code>if ($("#elem").index() ! = -1) {}
</code></pre>
| 38,424
|
<p>Greetings.</p>
<p>I'm looking for a way to parse a number of XML files in a particular directory with ASP.NET (C#). I'd like to be able to return content from particular elements, but before that, need to find those that have a certain value between an element.</p>
<p>Example XML file 1:</p>
<pre><code><file>
<title>Title 1</title>
<someContent>Content</someContent>
<filter>filter</filter>
</file>
</code></pre>
<p>Example XML file 2:</p>
<pre><code><file>
<title>Title 2</title>
<someContent>Content</someContent>
<filter>filter, different filter</filter>
</file>
</code></pre>
<p>Example case 1:</p>
<p>Give me all XML that has a filter of 'filter'.</p>
<p>Example case 2:</p>
<p>Give me all XML that has a title of 'Title 1'.</p>
<p>Looking, it seems this should be possible with LINQ, but I've only seen examples on how to do this when there is one XML file, not when there are multiples, such as in this case.</p>
<p>I would prefer that this be done on the server-side, so that I can cache on that end.</p>
<p>Functionality from any version of the .NET Framework can be used.</p>
<p>Thanks!</p>
<p>~James</p>
|
<p>If you are using .Net 3.5, this is extremely easy with LINQ:</p>
<pre><code>//get the files
XElement xe1 = XElement.Load(string_file_path_1);
XElement xe2 = XElement.Load(string_file_path_2);
//Give me all XML that has a filter of 'filter'.
var filter_elements1 = from p in xe1.Descendants("filter") select p;
var filter_elements2 = from p in xe2.Descendants("filter") select p;
var filter_elements = filter_elements1.Union(filter_elements2);
//Give me all XML that has a title of 'Title 1'.
var title1 = from p in xe1.Descendants("title") where p.Value.Equals("Title 1") select p;
var title2 = from p in xe2.Descendants("title") where p.Value.Equals("Title 1") select p;
var titles = title1.Union(title2);
</code></pre>
<p>This can all be written shorthand and get you your results in just 4 lines total:</p>
<pre><code>XElement xe1 = XElement.Load(string_file_path_1);
XElement xe2 = XElement.Load(string_file_path_2);
var _filter_elements = (from p1 in xe1.Descendants("filter") select p1).Union(from p2 in xe2.Descendants("filter") select p2);
var _titles = (from p1 in xe1.Descendants("title") where p1.Value.Equals("Title 1") select p1).Union(from p2 in xe2.Descendants("title") where p2.Value.Equals("Title 1") select p2);
</code></pre>
<p>These will all be IEnumerable lists, so they are super easy to work with:</p>
<pre><code>foreach (var v in filter_elements)
Response.Write("value of filter element" + v.Value + "<br />");
</code></pre>
<p>LINQ rules!</p>
|
<p>Use XPath?<br>
<a href="http://www.w3schools.com/XPath/default.asp" rel="nofollow noreferrer">http://www.w3schools.com/XPath/default.asp</a></p>
| 13,340
|
<p>We recently lost a database and I want to recover the data from de Production.log.</p>
<p>Every request is logged like this:</p>
<p>Processing ChamadosController#create (for XXX.XXX.XXX.40 at 2008-07-30 11:07:30) [POST]
Session ID: 74c865cefa0fdd96b4e4422497b828f9
Parameters: {"commit"=>"Gravar", "action"=>"create", "funcionario"=>"6" ... (all other parameters go here).</p>
<p>But some stuff to post on de database were in the session. In the request I have the Session ID, and I also have all the session files from the server.</p>
<p>Is there anyway I can, from this Session ID, open de session file and get it's contents?</p>
|
<p>Have you tried using <a href="http://corelib.rubyonrails.org/classes/Marshal.html" rel="nofollow noreferrer">Marshal#load</a>? I'm not sure how you're generating those session files, but it's quite possible Rails just uses Marshal.</p>
|
<p>Have you tried using <a href="http://corelib.rubyonrails.org/classes/Marshal.html" rel="nofollow noreferrer">Marshal#load</a>? I'm not sure how you're generating those session files, but it's quite possible Rails just uses Marshal.</p>
| 6,280
|
<p>Would the following make the objects fulfil all characteristics that enums have in JavaScript? Something like:</p>
<pre class="lang-js prettyprint-override"><code>my.namespace.ColorEnum = {
RED : 0,
GREEN : 1,
BLUE : 2
}
// later on
if(currentColor == my.namespace.ColorEnum.RED) {
// whatever
}
</code></pre>
<p>Or is there some other way I can do this?</p>
|
<p>Since 1.8.5 it's possible to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze" rel="noreferrer">seal and freeze the object</a>, so define the above as:</p>
<pre><code>const DaysEnum = Object.freeze({"monday":1, "tuesday":2, "wednesday":3, ...})
</code></pre>
<p>or</p>
<pre><code>const DaysEnum = {"monday":1, "tuesday":2, "wednesday":3, ...}
Object.freeze(DaysEnum)
</code></pre>
<p>and voila! JS enums.</p>
<p>However, this doesn't prevent you from assigning an undesired value to a variable, which is often the main goal of enums:</p>
<pre><code>let day = DaysEnum.tuesday
day = 298832342 // goes through without any errors
</code></pre>
<p>One way to ensure a stronger degree of type safety (with enums or otherwise) is to use a tool like <a href="https://www.typescriptlang.org/" rel="noreferrer">TypeScript</a> or <a href="https://flow.org/" rel="noreferrer">Flow</a>.</p>
<p>Quotes aren't needed but I kept them for consistency.</p>
|
<pre><code>var DaysEnum = Object.freeze ({ monday: {}, tuesday: {}, ... });
</code></pre>
<p>You don't need to specify an <em>id</em>, you can just use an empty object to compare enums. </p>
<pre><code>if (incommingEnum === DaysEnum.monday) //incommingEnum is monday
</code></pre>
<p><strong>EDIT:</strong> If you are going to serialize the object (to JSON for instance) you'll the <em>id</em> again.</p>
<ul>
<li><a href="https://stackoverflow.com/questions/287903/enums-in-javascript#comment12864576_5040502">( taken from Gabriel Llamas comment )</a></li>
<li><a href="https://stackoverflow.com/questions/287903/enums-in-javascript/30045582?noredirect=1#comment71130974_30045582">( edit based on Stijn de Witt's comment )</a></li>
</ul>
| 36,635
|
<p>I want to create a list of methods to execute. Each method has the same signature.
I thought about putting delegates in a generic collection, but I keep getting this error:</p>
<blockquote>
<p>'method' is a 'variable' but is used like a 'method'</p>
</blockquote>
<p>In theory, here is what I would like to do:</p>
<pre><code>List<object> methodsToExecute;
int Add(int x, int y)
{ return x+y; }
int Subtract(int x, int y)
{ return x-y; }
delegate int BinaryOp(int x, int y);
methodsToExecute.add(new BinaryOp(add));
methodsToExecute.add(new BinaryOp(subtract));
foreach(object method in methodsToExecute)
{
method(1,2);
}
</code></pre>
<p>Any ideas on how to accomplish this?
Thanks!</p>
|
<p>You need to cast the <code>object</code> in the list to a <code>BinaryOp</code>, or, better, use a more specific type parameter for the list:</p>
<pre><code>delegate int BinaryOp(int x, int y);
List<BinaryOp> methodsToExecute = new List<BinaryOp>();
methodsToExecute.add(Add);
methodsToExecute.add(Subtract);
foreach(BinaryOp method in methodsToExecute)
{
method(1,2);
}
</code></pre>
|
<p>Have them all implement of common interface, say IExecuteable, and then have a List<IExecutable></p>
<p>Also, using delegates:</p>
<pre><code>class Example
{
public delegate int AddDelegate(int x, int y);
public List<AddDelegate> methods = new List<AddDelegate>();
int Execute()
{
int sum = 0;
foreach(AddDelegate method in methods)
{
sum+=method.Invoke(1, 2);
}
return sum;
}
}
</code></pre>
| 16,406
|
<p>How can we find out that how many applications are there in a database?</p>
|
<p>Not entirely sure what you're asking for here. I'm assuming you mean "Applications written using SQL Server 2005 as the database.".</p>
<p>If that's what you want to know, I don't know of any single place you could get that information by it's always a good idea to try starting <a href="http://en.wikipedia.org/wiki/Microsoft_SQL_Server" rel="nofollow noreferrer">here</a>.</p>
|
<p>Do you mean stored procedures? You can have multiple applications using the same login credentials accessing a given database from the same web server, so you can't simply count databases or tables to get that number.</p>
| 33,851
|
<p>I'm using a Flashforge Pro and attempting to print a wheel about 6mm thick to serve as a platform. In other words, the wheel doesn't have to be solid, but spokes won't do the job. I've experimented with different temperatures, but, because of ABS' thermal expansion, I don't think that will solve the problem. Also tried putting lots of 2mm holes in the wheel. I've considered other designs for the interior, but doubt that would be a solution. Has anyone tried using different print paths, i.e. actually altering the path that the slicer suggests? (grasping at straws)
Thanks for your suggestions.</p>
|
<p>If you can, set your slicer to do honeycomb fill. Depending on the weight requirement choose maybe 10% - 20% fill. That ought to do the trick. It won't be solid, but it should be strong enough.</p>
<p>What are you going to put on the platform?</p>
|
<p>So you just want a short, wide cylinder? Just print that, with low density infill (20-30%) and 6-8 solid top layers, three bottom, and three perimeters, and you'll be fine. For bed adhesion with something this wide, use a 10mm brim, one layer thick. And a heated chamber will help a lot.</p>
| 484
|
<p>Everyone remembers google browser sync right? I thought it was great. Unfortunately Google decided not to upgrade the service to Firefox 3.0. Mozilla is developing a replacement for google browser sync which will be a part of the Weave project. I have tried using Weave and found it to be very very slow or totally inoperable. Granted they are in a early development phase right now so I can not really complain. </p>
<p>This specific problem of browser sync got me to thinking though. What do all of you think of Mozilla or someone making a server/client package that we, the users, could run on your 'main' machine? Now you just have to know your own IP or have some way to announce it to your client browsers at work or wherever.</p>
<p>There are several problems I can think of with this: non static IPs, Opening up ports on your local comp etc. It just seems that Mozilla does not want to handle this traffic created by many people syncing their browsers. There is not a way for them to monetize this traffic since all the data uploaded must be encrypted. </p>
|
<p>Mozilla Weave is capable of running on personal servers. It uses WebDAV to communicate with HTTP servers and can be configured to connect to private servers. I've tried setting it up on my own servers but with no success (Mainly because I'm not very good at working with Apache to configure WebDAV)</p>
<p>I'm hoping Mozilla Weave eventually allows FTP access so I can easily use my server to host my firefox profile.</p>
<p>If you're interested in trying Mozilla Weave on a personal server, there's a tutorial here:<br>
<a href="http://marios.tziortzis.com/page/blog/article/setting-up-mozilla-weave-on-your-server/" rel="nofollow noreferrer">http://marios.tziortzis.com/page/blog/article/setting-up-mozilla-weave-on-your-server/</a></p>
|
<p>I've been using the Firefox Scrapbook extension, sync'd via FolderShare. It takes a little setup, but the nice thing is that Scrapbook grabs a local copy of each page so it works offline or if the site goes away.</p>
| 3,444
|
<p>OK, struggling to get a definitive answer to this one...</p>
<p>I have an application written in VB6 which requires MDAC (2.8 for this installation). MDAC is included in the installer for my application. When the software is removed and re-installed on the same machine MDAC seems to go awry and I receive the following error as soon as my application tries to connect to the database:</p>
<p>Run-time error '-2147024769 (8007007f)':</p>
<p>Automation error
The specified procedure could not be found.</p>
<p>I have tried reinstalling MDAC which completes successfully, but does not fix the problem. I have searched over much of the Internet and found many people with a similar problem in different environments (VS.NET, JAVA etc), in fact anything that relies on MDAC, but cannot find a clear answer. Anyone who has a clean solution would receive my most merrily given thanks and appreciation.</p>
<p>Yours in bated anticipation.</p>
|
<p>Have you tried the <a href="http://support.microsoft.com/kb/307255" rel="nofollow noreferrer">MDAC Component Checker</a> from Microsoft? It is a tool for diagnosing problems and reconfiguring MDAC installations.</p>
|
<p>I have found removing MDAC 2.8 to be all but impossible. However, having run the component checker, changing the registry entries and putting a different version of MSDART the problem has been fixed.</p>
<p>The MSDART I have put in place is not the one suggested by the component checker, but it works. The component checker also has a problem with the version of MSXML, but the software seems to work regardless, so I'll look into this at a later date. However my problem is solved. So very quickly. Thanks and praises to you Mitch, and Stackoverflow. Great!</p>
| 35,992
|
<p>It was a long holiday weekend, so I got the coding bug again and started playing around:</p>
<p><a href="http://gfilter.net/junk/tileengine.jpg" rel="nofollow noreferrer">Mario http://gfilter.net/junk/tileengine.jpg</a></p>
<p>I wrote a basic tile engine, but having never attempted this before, I am really struggling with handling sprite collision detection and implementing realistic physics for gravity.</p>
<p>For any other game hobby writers, can you point me towards some walkthroughs on the best way to approach this?</p>
<p><strong>Update:</strong></p>
<p>I thought I'd share a progress report:</p>
<p><a href="http://www.youtube.com/watch?v=-RKNQ2UiiLY" rel="nofollow noreferrer">http://www.youtube.com/watch?v=-RKNQ2UiiLY</a> <-- Game in Action</p>
<p>Its still really buggy, but collision detection is mostly working, I've started working on some other features (such as bumping the blocks (notice the bug) and interacting with the enemies).</p>
<p>Mario still walks like he is on the moon, I'm using these constants, any advice for tweaking them for more realism?</p>
<pre><code> const float AirDrag = 1.00f;
const float GroundFriction = .97f;
const float Gravity = 0.8f;
</code></pre>
|
<p>Download the FarseerPhysics engine, have a look at how it works <a href="http://www.codeplex.com/FarseerPhysics" rel="nofollow noreferrer">http://www.codeplex.com/FarseerPhysics</a> I think it's the best thing available for XNA/Silverlight!</p>
|
<p>Ever heard of <a href="http://gamemaker.nl" rel="nofollow noreferrer">GameMaker</a>?</p>
| 43,089
|
<p>UPDATED: I'm asking this from a <strong>development perspective</strong>, however to illustrate, a canoical <em>non-development</em> example that comes to mind is that if it costs, say, $10,000
to keep a uptime rate of 99%, then it theoretically can cost $100,000 to keep a rate
of 99.9%, and possibly $1,000,000 to keep a rate of 99.99%. </p>
<p>Somewhat like calculus in approaching 0, as we closely approach 100%,
the cost can increase exponentially. Therefore, as a developer or PM, where do you decide
that the deliverable is "good enough" given the time and monetary constraints, e.g.: are you getting a good ROI at 99%, 99.9%,
99.99%?</p>
<p>I'm using a non-development example because I'm not sure of a solid metric for development. Maybe in the above example "uptime" could be replaced with "function point to defect ratio", or some such reasonable measure rate of bugs vs. the complexity of code. I would also welcome input regarding all stages of a software development lifecycle.</p>
<p>Keep the classic <a href="http://en.wikipedia.org/wiki/Project_triangle" rel="nofollow noreferrer">Project Triangle</a> constraints in mind (quality vs. speed vs. cost). And let's assume that the customer wants <em>the best quality you can deliver</em> given the original budget.</p>
|
<p>There's no way to answer this without knowing <em>what happens when your application goes down</em>.</p>
<ul>
<li>If someone dies when your application goes down, uptime is worth spending millions or even billions of dollars on (aerospace, medical devices).</li>
<li>If someone may be injured if your software goes down, uptime is worth hundreds of thousands or millions of dollars (industrial control systems, auto safety devices)</li>
<li>If someone looses millions of dollars if your software goes down, uptime is worth spending millions on (financial services, large e-commerce apps).</li>
<li>If someone looses thousands of dollars if your software goes down, uptime is worth spending thousands on (retail, small e-commerce apps).</li>
<li>If someone will swear at the computer and looses productivity while it reboots when your software goes down, then uptime is worth spending thousands on (most internal software).</li>
<li>etc.</li>
</ul>
<p>Basically take (cost of going down) x (number of times the software will go down) and you know how much to spend on uptime.</p>
|
<p>To expand on what "17 of 26" said, the answer depends on value to the customer. In the case of critical software, like aircrafct controller applications, the value to the customer of a high quality rating by whatever measure they use is quite high. To the user of an RSS feed reader, the value of high quality is considerably lower.</p>
<p>It's all about the <em>customer</em> (notice I didn't say user - sometimes they're the same, and sometimes they're not).</p>
| 7,833
|
<p>Is there a way to check to see if an Microsoft Office process (i.e. Word, Excel) has hung when using Office Automation? Additionally, if the process is hung, is there a way to terminate it?</p>
|
<p>Let me start off saying that I don't recommend doing this in a service on a server, but I'll do my best to answer the questions.</p>
<p>Running as a service makes it difficult to clean up. For example with what you have running as a service survive killing a hung word or excel. You may be in a position to have to kill the service. Will your service stop if word or excel is in this state. </p>
<p>One problem with trying to test if it is hung, is that your test could cause a new instance of word to startup and work, while the one that the service is running would still be hung.</p>
<p>The best way to determine if it's hung is to ask it to do what it is supposed to be doing and check for the results. I would need to know more about what it is actually doing. </p>
<p>Here are some commands to use in a batch file for cleaning up (both should be in the path):</p>
<ul>
<li>sc stop servicename - stops service named servicename</li>
<li>sc start servicename - starts service named servicename</li>
<li><p>sc query servicename - Queries the status of servicename</p></li>
<li><p>taskkill /F /IM excel.exe - terminates all instances of excel.exe</p></li>
</ul>
|
<p>I can answer the latter half; if you have a reference to the application object in your code, you can simply call "Quit" on it:</p>
<pre><code>private Microsoft.Office.Interop.Excel.Application _excel;
// ... do some stuff ...
_excel.Quit();
</code></pre>
<p>For checking for a hung process, I'd guess you'd want to try to get some data from the application and see if you get results in a reasonable time frame (check in a timer or other thread or something). There's probably a better way though.</p>
| 3,122
|
<p>I have a number of code value tables that contain a code and a description with a Long id.</p>
<p>I now want to create an entry for an Account Type that references a number of codes, so I have something like this:</p>
<pre><code>insert into account_type_standard (account_type_Standard_id,
tax_status_id, recipient_id)
( select account_type_standard_seq.nextval,
ts.tax_status_id, r.recipient_id
from tax_status ts, recipient r
where ts.tax_status_code = ?
and r.recipient_code = ?)
</code></pre>
<p>This retrieves the appropriate values from the tax_status and recipient tables if a match is found for their respective codes. Unfortunately, recipient_code is nullable, and therefore the ? substitution value could be null. Of course, the implicit join doesn't return a row, so a row doesn't get inserted into my table.</p>
<p>I've tried using NVL on the ? and on the r.recipient_id. </p>
<p>I've tried to force an outer join on the r.recipient_code = ? by adding (+), but it's not an explicit join, so Oracle still didn't add another row.</p>
<p>Anyone know of a way of doing this?</p>
<p>I can obviously modify the statement so that I do the lookup of the recipient_id externally, and have a ? instead of r.recipient_id, and don't select from the recipient table at all, but I'd prefer to do all this in 1 SQL statement.</p>
|
<p>Outter joins don't work "as expected" in that case because you have explicitly told Oracle you only want data if that criteria on that table matches. In that scenario, the outter join is rendered useless.</p>
<p>A work-around</p>
<pre><code>INSERT INTO account_type_standard
(account_type_Standard_id, tax_status_id, recipient_id)
VALUES(
(SELECT account_type_standard_seq.nextval FROM DUAL),
(SELECT tax_status_id FROM tax_status WHERE tax_status_code = ?),
(SELECT recipient_id FROM recipient WHERE recipient_code = ?)
)
</code></pre>
<p>[Edit]
If you expect multiple rows from a sub-select, you can add ROWNUM=1 to each where clause OR use an aggregate such as MAX or MIN. This of course may not be the best solution for all cases.</p>
<p>[Edit] Per comment, </p>
<pre><code> (SELECT account_type_standard_seq.nextval FROM DUAL),
</code></pre>
<p>can be just</p>
<pre><code> account_type_standard_seq.nextval,
</code></pre>
|
<pre><code>insert into received_messages(id, content, status)
values (RECEIVED_MESSAGES_SEQ.NEXT_VAL, empty_blob(), '');
</code></pre>
| 15,929
|
<p>I would like to restrict access to my <code>/admin</code> URL to internal IP addresses only. Anyone on the open Internet should not be able to login to my web site. Since I'm using Lighttpd my first thought was to use <code>mod_rewrite</code> to redirect any outside request for the <code>/admin</code> URL back to my home page, but I don't know much about Lighty and the docs don't say much about detecting a 192.168.0.0 IP range.</p>
|
<p>Try this:</p>
<pre><code>$HTTP["remoteip"] == "192.168.0.0/16" {
/* your rules here */
}
</code></pre>
<p>Example from the <a href="http://redmine.lighttpd.net/wiki/lighttpd/Docs:Configuration" rel="nofollow noreferrer">docs</a>:</p>
<pre><code> # deny the access to www.example.org to all user which
# are not in the 10.0.0.0/8 network
$HTTP["host"] == "www.example.org" {
$HTTP["remoteip"] != "10.0.0.0/8" {
url.access-deny = ( "" )
}
}
</code></pre>
|
<p>This worked for me:</p>
<pre><code>$HTTP["remoteip"] != "192.168.1.1/254" {
$HTTP["url"] =~ "^/intranet/" {
url.access-deny = ( "" )
}
}
</code></pre>
<p><code>!=</code> worked over <code>==</code>.</p>
| 47,605
|
<p>This caught my attention last night.</p>
<p>On the latest <a href="http://altnetpodcast.com/episodes/10-oop-in-ruby" rel="nofollow noreferrer">ALT.NET Podcast</a> Scott Bellware discusses how as opposed to Ruby, languages like C#, Java et al. are not truly object oriented rather opting for the phrase "class-oriented". They talk about this distinction in very vague terms without going into much detail or discussing the pros and cons much.</p>
<p>What is the real difference here and how much does it matter? What are other languages then are "object-oriented"? It sounded pretty interesting but I don't want to have to learn Ruby just to know what if anything I am missing.</p>
<h2>Update</h2>
<p>After reading some of the answers below it seems like people generally agree that the reference is to duck-typing. What I'm not sure I understand still though is the claim that this ultimately changes all that much. Especially if you are already doing proper TDD with loose coupling etc. Can someone show me an example of a specific thing I could do with Ruby that I cannot do with C# and that exemplifies this different OOP approach?</p>
|
<p>The duck typing comments here are more attributing to the fact that Ruby and Python are more <em>dynamic</em> than C#. It doesn't really have anything to do with it's OO Nature.</p>
<p>What (I think) Bellware meant by that is that in Ruby, everything is an object. Even a class. A class definition is an instance of an object. As such, you can add/change/remove behavior to it at runtime.</p>
<p>Another good example is that NULL is an object as well. In ruby, everything is LITERALLY an object. Having such deep OO in it's entire being allows for some fun meta-programming techniques such as method_missing.</p>
|
<p>I'll take a stab at this.</p>
<p>Python and Ruby are duck-typed. To generate any maintainable code in these languages, you pretty much have to use test driven development. As such, it is very important for a developer to easily inject dependencies into their code without having to create a giant supporting framework. </p>
<p>Successful dependency-injection depends upon on having a pretty good object model. The two are sort of two sides of the same coin. If you really understand how to use OOP, then you should by default create designs where dependencies can be easily injected. </p>
<p>Because dependency injection is easier in dynamically typed languages, the Ruby/Python developers feel like their language understands the lessons of OO much better than other statically typed counterparts.</p>
| 7,533
|
<p>I've tried to apply a sharp blade (the one that came witht he printer) to scrape the model off like I usually do but this model seems overly robust. What method can I do to take this off safely? </p>
<p>See image <a href="https://i.stack.imgur.com/c9nIu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c9nIu.jpg" alt="at"></a></p>
|
<p>Unfortunately, you may have to destroy this part, or the build surface, just to get it off the plate. It looks really on there, and if you can't get under it even with a razor that further supports my gut instinct. It's happened to me before, just part of learning how to print with a particular material on a particular printer and build surface.</p>
<p>One thing to try before just hacking away at the part or replacing the build surface (which you may have to do anyway) would be to heat the plate back up to maybe 60-70*C, then hit the part with some freeze spray (or the poor man's version, turning a can of air duster upside-down). The rapid expansion-contraction may pop the part free. How effective this is depends on the plastic you used. PLA doesn't stretch and shrink much, but by the same token it's also very inflexible, so the stretching and shrinking it does do can stil pop the part off. This method's <em>really</em> effective for plastics like ABS that stretch/shrink a lot with heat. Remember to ventilate well; the principal component of these sprays is difluoroethane, which isn't great stuff to breathe in any significant concentration, and when spraying the liquid the resulting "steam" state of boiling liquid is much more flammable (so after the bed comes up to proper heat, I'd turn off the printer just in case).</p>
<p>EDIT: Per the comment to this answer, an alternate method would be to heat the plate even further, to about 80-90*C, which would heat the PLA beyond its glass transition temperature, softening it and reducing its adhesion. You would destroy the part, but parts can be reprinted, that's the beauty of owning a general-purpose computer-controlled additive plastic forming machine.</p>
<p>Your first layer including the brim looks a little close to the plate, which is part of the problem; you <em>really</em> squished that first layer down onto the bed. I would relevel the bed a bit further away, or (if you're happy with how actually level the bed is) set a Z-offset to increase first layer width. There's a very fine balance to be struck here; once you find it, printing (and removing said prints) becomes a lot easier.</p>
<p>In future, a build adhesive like Elmer's glue stick or hairspray (or a dedicated adhesive like 3DLAC or Bed Weld) also doubles as a release agent; the adhesive grabs the extruded plastic to keep it on the plate, but also prevents direct contact between two plastics and thus avoids any chemical bonding between the part and plate. Also consider upgrading to a flexible removable surface, like a magnetic BuildTak surface. Being able to take the bed off the printer and then flex the surface to help pull a corner free (at which point you can slip a scraper in to lift the rest of it off) is a real boon to these types of situations. </p>
|
<p>Some comments assume that this is a PLA print. IS it PLA, or something more exotic?</p>
<p>If PLA, then try softening the object by heating the print with a heat gun or hair drier. </p>
<p>I assume that the bed is not easily removed and that you can not flex the bed. If you can remove the bed by unscrewing it, it might flex enough to break away the print. It doesn't take a lot of flex to remove a part. The smallest opening concentrates force on the edge.</p>
<p>I have had some success using a wood chisel "upside down". Don't try to get the edge under the part, but instead embed the pointy edge into the object and then use the angle behind the edge as a fulcrum to focus upward force on the object. That might work better while the object is hot.</p>
| 1,556
|
<p>Suppose I have a method that takes an object of some kind as an argument. Now say that if this method is passed a null argument, it's a fatal error and an exception should be thrown. Is it worth it for me to code something like this (keeping in mind this is a trivial example):</p>
<pre><code>void someMethod(SomeClass x)
{
if (x == null){
throw new ArgumentNullException("someMethod received a null argument!");
}
x.doSomething();
}
</code></pre>
<p>Or is it safe for me to just rely on it throwing NullException when it calls x.doSomething()?</p>
<p>Secondly, suppose that someMethod is a constructor and x won't be used until another method is called. Should I throw the exception immediately or wait until x is needed and throw the exception then?</p>
|
<p>I prefer the <code>ArgumentNullException</code> over the <code>NullReferenceException</code> that not checking the argument would provide. In general, my preference is to always check for nullity before trying to invoke a method on a potentially null object.</p>
<p>If the method is a constructor, then it would depend on a couple of different factors: is there also a public setter for the property and how likely is it that the object will actually be used. If there is a public setter, then not providing a valid instance via the constructor would be reasonable and should not result in an exception.</p>
<p>If there is no public setter and it is possible to use the containing object without referencing the injected object, you may want to defer the checking/exception until its use is attempted. I would think that the general case, though, would be that injected object is essential to the functioning of the instance and thus an ArgumentNull exception is perfectly reasonable since the instance can't function without it.</p>
|
<p>You can use syntax like the following to not just throw an <code>ArgumentNullException</code> but have that exception name the parameter as part of its error text as well. E.g.;</p>
<pre><code>void SomeMethod(SomeObject someObject)
{
Throw.IfArgNull(() => someObject);
//... do more stuff
}
</code></pre>
<p>The class used to raise the exception is;</p>
<pre><code>public static class Throw
{
public static void IfArgNull<T>(Expression<Func<T>> arg)
{
if (arg == null)
{
throw new ArgumentNullException(nameof(arg), "There is no expression with which to test the object's value.");
}
// get the variable name of the argument
MemberExpression metaData = arg.Body as MemberExpression;
if (metaData == null)
{
throw new ArgumentException("Unable to retrieve the name of the object being tested.", nameof(arg));
}
// can the data type be null at all
string argName = metaData.Member.Name;
Type type = typeof(T);
if (type.IsValueType && Nullable.GetUnderlyingType(type) == null)
{
throw new ArgumentException("The expression does not specify a nullible type.", argName);
}
// get the value and check for null
if (arg.Compile()() == null)
{
throw new ArgumentNullException(argName);
}
}
}
</code></pre>
| 48,142
|
<p>In most modern IDEs, you can have Debug and Release build configurations, and you can quickly switch between them.</p>
<p>In Delphi 7, this does not seem to be possible. I have to go to Project Settings and toggle optimization and all the debug information stuff manually.</p>
<p>It would be great if there was a plugin or some such that handled this for me.</p>
<p>Does anyone know of one? Any other suggestions?</p>
<p><strong>Edit:</strong> I can't upgrade to Delphi 2007 or 2009 as we have a large Delphi 7 codebase which would have to be converted. I agree that would be the best solution in theory though :P</p>
|
<p>You can very easily add project configurations, similar to what other IDEs offer, using Andreas Hausladen's great <a href="http://andy.jgknet.de/blog/?page_id=10" rel="noreferrer">DDevExtensions</a> IDE expert. Just make sure to download the 1.6 version from the link I mentioned, since later versions only work with Delphi 2009. The 1.6 version works with any Delphi version between 5 and 2007, inclusive.</p>
<p>The expert adds a submenu under the Project menu, in case you can't find it at first.</p>
|
<p>This feature was added only in Delphi 2009.</p>
<p>For older versions of Delphi you can write two copies of .cfg file, one with debug options and one with release options, and compile your program calling <strong>dcc32.exe</strong> from within a batch file.</p>
<p>Something like this:</p>
<pre><code>rem release.bat
copy release.cfg myprog.cfg
dcc32 -B myprog.dpr
rem debug.bat
copy debug.cfg myprog.cfg
dcc32 -B myprog.dpr
</code></pre>
| 21,223
|
<p>Of course, there are a whole range of possible errors relating to document validity, but my immediate stumbling block occurs when changing a paragraph (<code>p</code>) into an <code>address</code> element. My current method is (more-or-less):</p>
<pre><code>var p = $('p#test');
p.replaceWith('<address>' + p.html() + '</address>');
</code></pre>
<p>but that fails for this specific case; it works perfectly for p -> blockquote or h2 -> h3. Firebug suggests that a self-closing element (<code><address/></code>) has been added to the document, for some reason.</p>
<p>Can anyone spot the bug or suggest an alternative method?</p>
|
<pre><code>var p = $('p#test');
var a = $('<address>').
append(p.contents());
p.replaceWith(a);
</code></pre>
<p>Your solution is subject to all sorts of horrible HTML escaping issues and possibly injection attacks.</p>
|
<p>You'll could use a placeholder around the title:</p>
<pre>
<span id="demo"><h1>Title</h1></span>
</pre>
<p>Then use JavaScript DOM to create new values for the innerHTML property.</p>
<pre>
<script type="javascript">
setTitle = function(id, tag, title) {
var container = document.getElementById(id);
container.innerHTML = '<' + tag + '>' + title + '</' + tag + '>';
}
setTitle('demo', 'h1', 'My Title');
</script>
</pre>
| 29,768
|
<p>I have an Ender 3 and I'm experiencing an issue where it won't print on the edges. Near the outside of the bed plastic just peels away. Bed is level - verified multiple times.</p>
<p>The nozzle appears to be dragging the freshly extruded filament away before it has a chance to cool. Straight lines and wide curves print well about 30 % of the time, and sharp corners and curves won't print at all.</p>
<p>The printer works fine in the center, but the outer 3 cm or so are unusable. Not sure what could cause this. I leveled the bed multiple times - even told the printer to move without touching it, just to eliminate incorrect leveling by slight play in the rollers. Head is the same distance from the plate in the center as it is along the edges. No irregular high or low areas - bed is perfectly flat.</p>
<p>Is this a known issue with the Ender 3? How can it be fixed?</p>
<p>I am using the stock fiberglass bed with the BuildTak surface.</p>
|
<p>I used to have the same problem. Put masking or scotch tape on the bed, it should help with adhesion. I think the problem is that the bed is very dirty with finger grease and other things.</p>
|
<p>It sounds like it may be due to uneven heating. Check with an IR thermometer to make sure. If you're sure the bed is clean and has even heating, you may want to try a different surface. G10 is cheap and almost always perfectly flat.</p>
| 2,038
|
<p>In what domains do each of these software architectures shine or fail?</p>
<p>Which key requirements would prompt you to choose one over the other?</p>
<p>Please assume that you have developers available who can do good object oriented code as well as good database development.</p>
<p>Also, please avoid holy wars :) all three technologies have pros and cons, I'm interested in where is most appropriate to use which.</p>
|
<p>Every one of these tools provides differing layers of abstraction, along with differing points to override behavior. These are architecture choices, and all architectural choices depend on trade-offs between technology, control, and organization, both of the application itself and the environment where it will be deployed.</p>
<ul>
<li><p>If you're dealing with a culture where DBAs 'rule the roost', then a stored-procedure-based architecture will be easier to deploy. On the other hand, it can be very difficult to manage and version stored procedures.</p></li>
<li><p>Code generators shine when you use statically-typed languages, because you can catch errors at compile-time instead of at run-time.</p></li>
<li><p>ORMs are ideal for integration tools, where you may need to deal with different RDBMSes and schemas on an installation-to-installation basis. Change one map and your application goes from working with PeopleSoft on Oracle to working with Microsoft Dynamics on SQL Server.</p></li>
</ul>
<p>I've seen applications where Generated Code is used to interface with Stored Procedures, because the stored procedures could be tweaked to get around limitations in the code generator.</p>
<p>Ultimately the only correct answer will depend upon the problem you're trying to solve and the environment where the solution needs to execute. Anything else is arguing the correct pronunciation of 'potato'.</p>
|
<p>ORMs and code generators are kind of on one side of the field, and stored procedures are on another. Typically, it's easier to use ORMs and code generators in greenfield projects, because you can tailor your database schema to match the domain model you create. It's much more difficult to use them with legacy projects, because once software is written with a "data-first" mindset, it's difficult to wrap it with a domain model.</p>
<p>That being said, all three of the approaches have value. Stored procedures can be easier to optimize, but it can be tempting to put business logic in them that may be repeated in the application itself. ORMs work well if your schema matches the concept of the ORM, but can be difficult to customize if not. Code generators can be a nice middle ground, because they provide some of the benefits of an ORM but allow customization of the generated code -- however, if you get into the habit of altering the generated code, you then have two problems, because you will have to alter it each time you re-generate it.</p>
<p>There is no one true answer, but I tend more towards the ORM side because I believe it makes more sense to think with an object-first mindset.</p>
| 10,201
|
<p>3-Tier design has been my standard design philosophy for years for database driven applications, and it has never failed me. For those who practice it, describe your layers.</p>
<p>I've found that many people muddle up the business tier and the data access tier, making it more like a 2.5-Tier design.</p>
<p>I prefer to move the data tier almost entirely into the database using stored procedures, and just have a very lightweight data tier in code that wraps sproc calls into business objects.</p>
<p>How do you approach it?</p>
<p>EDIT: If all you are going to do is define what 3-tier is, don't waste your time replying. I am looking for how specific people implemented it, did you use stored procedures or an ORM, how did you handle circular dependancies between the DAL and the BLL? Theres a lot of depth to this topic besides saying</p>
<ul>
<li>UI</li>
<li>Business</li>
<li>Data</li>
</ul>
|
<p>I've been doing primarly web apps for a while now and have been following 3-Tier as well:</p>
<p>UI: Pure ASPX pages. It is actually kind of hard to push your business layer down from here at times because doing a quick calculation or something seems so easy to do here. However, I've gotten disciplined enough to make sure the code behind pages are doing nothing but showing/hiding panels, updating user input, etc.</p>
<p>DAL: All data access layer stuff. I have really enjoyed using the XSD/DataTable/TableAdapter classes that are available. I also use stored procedure based CRUD methods, so hooking up the adapters to the stored procs is easy.</p>
<p>BLL: The business layer tends to be the lightest of the three layers in most of my apps here, since they are primarily CRUD type apps with some reporting built in.</p>
|
<p>We once approached it using the following:
- UI Layer (where all the UI is)
- Business layer (where all the business logic is)
- Data layer (where all the DB access is)</p>
| 16,253
|
<p>This is probably pretty basic... but I don't seem to get it:</p>
<p>How does </p>
<pre><code>(2 & 1) = 0
(3 & 1) = 1
(4 & 1) = 0
</code></pre>
<p>etc..</p>
<p>This pattern above seems to help find even numbers</p>
<p>or </p>
<pre><code>(0 | 1) = 1
(1 | 1) = 1
(2 | 1) = 3
(3 | 1) = 4
(4 | 1) = 5
(5 | 1) = 5
</code></pre>
<p>I know how boolean algebra works between bits. But I don't understand how Boolean algebra works with integers (in C# at the least).</p>
<p>thanks in advance.</p>
|
<p>It works the same way in C# as it does in binary. </p>
<p><code>2 | 1 = 3</code> and <code>4 | 1 = 5</code>. </p>
<p>To understand this, you need to think about the binary representation of 1,2,3,4,and 5:</p>
<p><code>010 | 001 = 011</code> and <code>100 | 001 = 101</code>.</p>
<p>Similarly: </p>
<p><code>010 & 001 = 000</code> and <code>011 & 001 = 001</code></p>
|
<p>It is doing bitwise operations on the integer. That it is doing a logical or/and of each bit in the first integer with the corresponding bit in the other integer. It then returns the result of all of these operations. For example, 4 = 0100 and 1 = 0001, a logical and of these would and bit the bits in order and get 0000 (since 0&0 = 0, 1&0 = 0, 0&0 = 0, and 0&1 = 0). For or, you would get 0101 (since 0|0 = 0, 1|0 = 1, 0|0 = 0, and 0|1 = 1). The trick is that these are bitwise operations, not logical operations which operate only on boolean values in C#.</p>
| 41,339
|
<p>I'm interested in using Functional MetaPost on Mac OS X:</p>
<p><a href="http://cryp.to/funcmp/" rel="nofollow noreferrer">http://cryp.to/funcmp/</a></p>
<p>I'm looking for a tutorial like:</p>
<p><a href="http://haskell.org/haskellwiki/Haskell_in_5_steps" rel="nofollow noreferrer">http://haskell.org/haskellwiki/Haskell_in_5_steps</a></p>
<p>but for a trivial FuncMP example, i.e. using GHC, I can compile something simple such as:</p>
<pre><code>import FMP
myPicture = text "blah"
main = generate "foo" 1 myPicture
</code></pre>
<p>but I can't figure out how to view this foo.1.mp output. (It gives a runtime error about not finding 'virmp'; my MetaPost binary is 'mpost'; I can't figure out how to override this Parameter or what my .FunMP file is or should be doing...) I can run mpost on that but the output (foo.1.1) is what, PostScript? EPS? How do I use this? (I imagine I just need a simple LaTeX file with an EPS figure in it or something...)</p>
<p>Preferably, I'd like to generate output (.ps or .pdf that I can view) so I an actually get somewhere <em>with Functional MetaPost</em>, learning it, playing with it, not banging my head against paths and binaries and shell commands.</p>
|
<p>the output of mpost is eps, which you can view in ghostview...</p>
|
<p>the output of mpost is eps, which you can view in ghostview...</p>
| 28,318
|
<p>This question intends to be technology-agnostic. Which kind of web framework do you prefer, and when: <em>Pure MVC or event-driven component-oriented?</em></p>
<p>Just to make the point in "technology-agnosticism", here I name a few MVC vs. component web frameworks, in diverse technologies / languages:</p>
<ul>
<li>Struts <strong>vs.</strong> Java Server Faces / Tapestry</li>
<li>The new ASP.NET MVC <strong>vs.</strong> "classic" ASP.NET</li>
<li>Cake PHP <strong>vs.</strong> PRADO</li>
</ul>
|
<p>I'm a php dev by day; however, I strongly prefer Wicket and/or Lift, especially the latter. The problem with Prado seems to be that the controller is tied to the page, rather than the logical controls on the page, otherwise, it still seems better than most other options in PHP land. I think all boils down to reusability, unless you have components that are backed by controllers, you can't separate the display all that well from the backing control logic.</p>
<p>MVC as implmented by all these 'MVC' frameworks seems to suck, you get a logical page with a tonne of controls and you have to handle all those on page controllers, wow, thanks, now I have MVC / n, where n is the number of controls. Most 'MVC' systems that I've seen so far, have been a mish-mash of brain-dead tag libraries, contorting request response into a single controller that has to be aware of everything on the page.</p>
<p>xhtml templates with js, and css wonderfully separated. Along with a few classes backing those components, and all of a sudden you're not busy wondering how complex pages are going to work, or if you want to take piece x, and drop it somewhere else.</p>
|
<p>I loosely follow these guidelines:</p>
<ul>
<li>Web Forms/SQLDataSource- Quick and dirty app for internal use to show reporting or some other such data.</li>
<li>MVC- Simple to complex business logic for a core product.</li>
<li>MVC/REST Web Services/jQuery- HTML/Whatever type of client RIA's (when user experience reigns supreme).</li>
<li>Flash/Flex RIA- Useful when an extremely rich client is needed (think multimedia manipulation here).</li>
</ul>
<p>There are a lot of gaps in this list of course but that just represents how complicated a question it is.</p>
| 12,518
|
<p>I have an Access 2003 file that contains 200 queries, and I want to print out their representation in SQL. I can use Design View to look at each query and cut and paste it to a file, but that's tedious. Also, I may have to do this again on other Access files, so I definitely want to write a program to do it.</p>
<p>Where are queries stored an Access db? I can't find anything saying how to get at them. I'm unfamiliar with Access, so I'd appreciate any pointers. Thanks!</p>
|
<p>Procedures are what you're looking for:</p>
<pre><code>OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
DataTable queries = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Procedures, null);
conn.Close();
</code></pre>
<p>This will give you a DataTable with the following columns in it (among others):</p>
<p>PROCEDURE_NAME: Name of the query</p>
<p>PROCEDURE_DEFINITION: SQL definition</p>
<p>So you can loop through the table like so:</p>
<pre><code>foreach(DataRow row in queries.Rows)
{
// Do what you want with the values here
queryName = row["PROCEDURE_NAME"].ToString();
sql = row["PROCEDURE_DEFINITION"].ToString();
}
</code></pre>
|
<p>Not in C#, but may be a good place to start:</p>
<p><a href="http://www.datastrat.com/Code/DocDatabase.txt" rel="nofollow noreferrer">http://www.datastrat.com/Code/DocDatabase.txt</a></p>
| 48,535
|
<p>How do I format a number in Java?<br />
What are the "Best Practices"?</p>
<p>Will I need to round a number before I format it?</p>
<blockquote>
<p><code>32.302342342342343</code> => <code>32.30</code></p>
<p><code>.7323</code> => <code>0.73</code></p>
</blockquote>
<p>etc.</p>
|
<p>From <a href="http://bytes.com/forum/thread16212.html" rel="noreferrer">this thread</a>, there are different ways to do this:</p>
<pre><code>double r = 5.1234;
System.out.println(r); // r is 5.1234
int decimalPlaces = 2;
BigDecimal bd = new BigDecimal(r);
// setScale is immutable
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
r = bd.doubleValue();
System.out.println(r); // r is 5.12
</code></pre>
<hr>
<pre><code>f = (float) (Math.round(n*100.0f)/100.0f);
</code></pre>
<hr>
<pre><code>DecimalFormat df2 = new DecimalFormat( "#,###,###,##0.00" );
double dd = 100.2397;
double dd2dec = new Double(df2.format(dd)).doubleValue();
// The value of dd2dec will be 100.24
</code></pre>
<p>The <a href="http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html" rel="noreferrer">DecimalFormat()</a> seems to be the most dynamic way to do it, and it is also very easy to understand when reading others code.</p>
|
<p>There are two approaches in the standard library. One is to use java.text.DecimalFormat. The other more cryptic methods (String.format, PrintStream.printf, etc) based around java.util.Formatter should keep C programmers happy(ish).</p>
| 7,332
|
<p>I'm interested in assigning the tag name of the root element in an xml document to an xslt variable. For instance, if the document looked like (minus the DTD):</p>
<pre><code><foo xmlns="http://.....">
<bar>1</bar>
</foo>
</code></pre>
<p>and I wanted to assign the string 'foo' to an xslt variable. Is there a way to reference that?</p>
<p>Thanks, Matt</p>
|
<p>I think you want to retrieve the name of the outermost XML element. This can be done like in the following XSL sample:</p>
<pre><code><?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="outermostElementName" select="name(/*)" />
<xsl:template match="/">
<xsl:value-of select="$outermostElementName"/>
</xsl:template>
</xsl:stylesheet>
</code></pre>
<p>Please note that there is a slight difference in XPath terminology:</p>
<blockquote>
<p>The top of the tree is a root node
(1.0 terminology) or document node
(2.0). This is what "/" refers to.
It's not an element: it's the parent
of the outermost element (and any
comments and processing instructions
that precede or follow the outermost
element). The root node has no name.</p>
</blockquote>
<p>See <a href="http://www.dpawson.co.uk/xsl/sect2/root.html#d9799e301" rel="noreferrer">http://www.dpawson.co.uk/xsl/sect2/root.html#d9799e301</a></p>
|
<p>you want <strong><a href="http://zvon.org/xxl/XSLTreference/Output/function_local-name.html" rel="nofollow noreferrer">local-name()</a></strong></p>
| 48,134
|
<p>How do you concatenate characters in java? Concatenating strings would only require a <code>+</code> between the strings, but concatenating chars using <code>+</code> will change the value of the char into ascii and hence giving a numerical output. I want to do <code>System.out.println(char1+char2+char3...</code> and create a String word like this.</p>
<p>I could do </p>
<pre><code>System.out.print(char1);
System.out.print(char2);
System.out.print(char3);
</code></pre>
<p>But, this will only get me the characters in 1 line. I need it as a string. Any help would be appreciated.</p>
<p>Thanks</p>
|
<p>Do you want to make a string out of them?</p>
<pre><code>String s = new StringBuilder().append(char1).append(char2).append(char3).toString();
</code></pre>
<p>Note that</p>
<pre><code>String b = "b";
String s = "a" + b + "c";
</code></pre>
<p>Actually compiles to</p>
<pre><code>String s = new StringBuilder("a").append(b).append("c").toString();
</code></pre>
<p><strong>Edit</strong>: as litb pointed out, you can also do this:</p>
<pre><code>"" + char1 + char2 + char3;
</code></pre>
<p>That compiles to the following:</p>
<pre><code>new StringBuilder().append("").append(c).append(c1).append(c2).toString();
</code></pre>
<p><strong>Edit (2)</strong>: Corrected string append comparison since, as cletus points out, a series of strings is handled by the compiler.</p>
<p>The purpose of the above is to illustrate what the compiler does, not to tell you what you should do.</p>
|
<pre><code>System.out.print(a + "" + b + "" + c);
</code></pre>
| 42,538
|
<p>My understanding is that in unix, when memory is freed, the memory doesn't get returned back to the operating system, it stays in the process to be used again for the next call to malloc.</p>
<p>On windows, I understand that the memory actually gets returned to the operating system.</p>
<p>Is there any big difference between these two ways of doing things or are they just two different ways of doing the same thing? And if there are any pros/cons to these two methods, what are they?</p>
<p><strong>EDIT:</strong> Thanks for the clarification. I had always thought this was an OS thing (since processes never seem to decrease in size in UNIX-like systems, but do in windows).</p>
|
<p>There isn't much difference between Windows and Unix with respect to that.</p>
<p>In both, there are two levels of allocation. The operating system allocates memory to the process in large chunks (one page or more; on x86, the page size is usually 4096 bytes). The runtime libraries, running within the process, subdivide this space and allocate parts of it to your code.</p>
<p>To return the memory to the operating system, first all the memory allocated from one of these large chunks has to be released to the runtime library. The runtime library then can, if it wants, tell the operating system to release that chunk of memory.</p>
<p>On Linux, you have <code>brk</code> and <code>mmap</code>. <code>brk</code> controls the size of of a large chunk of memory allocated to your process; you can expand or shrink it, but only at one end. <code>malloc</code> traditionally expands this chunk of memory when it needs more memory to allocate from, and shrinks it when possible. However, shrinking is not easy; it takes a single one-byte ill-timed allocation at the end to make it unable to shrink even if everything before that allocation has been freed. This is the source of the "Unix doesn't release memory back" meme.</p>
<p>However, there's also anonymous <code>mmap</code>. Anonymous <code>mmap</code> requests a chunk of memory from the operating system, which can be placed anywhere in the process memory space. This chunk can be returned easily when it's not needed anymore, even if there are later allocations which weren't released yet. <code>malloc</code> uses also <code>mmap</code> (particularly for large allocations, where a whole chunk of memory can be easily returned after being freed).</p>
<p>Of course, on both Windows and Linux if you do not like the behavior of the memory allocator (or allocators) from the runtime libraries, you can use your own, asking memory from the operating system and subdividing it the way you want (or sometimes asking memory from another allocator, but in larger blocks). One interesting use is to have an allocator for all the memory associated with a task (for instance, a web server request), which is completely discarded at the end of the task (with no need to free all the pieces individually); another interesting use is an allocator for fixed-size objects (for instance, five-byte objects), which avoids memory fragmentation.</p>
|
<p>The malloc function returns either a null pointer or a pointer to the allocated space."</p>
<p>This suggests that any call to malloc may fail. It seems that the intent of the Standard is that memory is not returned to the OS.</p>
| 29,206
|
<p>I'm just wondering if there's a better way of doing this in SQL Server 2005.</p>
<p>Effectively, I'm taking an originator_id (a number between 0 and 99) and a 'next_element' (it's really just a sequential counter between 1 and 999,999).
We are trying to create a 6-character 'code' from them. </p>
<p>The originator_id is multiplied up by a million, and then the counter added in, giving us a number between 0 and 99,999,999.</p>
<p>Then we convert this into a 'base 32' string - a fake base 32, where we're really just using 0-9 and A-Z but with a few of the more confusing alphanums removed for clarity (I, O, S, Z).</p>
<p>To do this, we just divide the number up by powers of 32, at each stage using the result we get for each power as an index for a character from our array of selected character.</p>
<pre>
Thus, an originator ID of 61 and NextCodeElement of 9 gives a code of '1T5JA9'
(61 * 1,000,000) + 9 = 61,000,009
61,000,009 div (5^32 = 33,554,432) = 1 = '1'
27,445,577 div (4^32 = 1,048,576) = 26 = 'T'
182,601 div (3^32 = 32,768) = 5 = '5'
18,761 div (2^32 = 1,024) = 18 = 'J'
329 div (1^32 = 32) = 10 = 'A'
9 div (0^32 = 1) = 9 = '9'
so my code is 1T5JA9
</pre>
<p>Previously I've had this algorithm working (in Delphi) but now I really need to be able to recreate it in SQL Server 2005. Obviously I don't quite have the same functions to hand that I have in Delphi, but this is my take on the routine. It works, and I can generate codes (or reconstruct codes back into their components) just fine.</p>
<p>But it looks a bit long-winded, and I'm not sure that the trick of selecting the result of a division into an int (ie casting it, really) is necessarily 'right' - is there a better SQLS approach to this kind of thing?</p>
<pre>
CREATE procedure dummy_RP_CREATE_CODE @NextCodeElement int, @OriginatorID int,
@code varchar(6) output
as
begin
declare @raw_num int;
declare @bcelems char(32);
declare @chr int;
select @bcelems='0123456789ABCDEFGHJKLMNPQRTUVWXY';
select @code='';
-- add in the originator_id, scaled into place
select @raw_num = (@OriginatorID * 1000000) + @NextCodeElement;
-- now to convert this to a 6-char code
-- 5^32
select @chr = @raw_num / 33554432;
select @raw_num = @raw_num - (@chr * 33554432);
select @code = @code + SUBSTRING(@bcelems, 1 + @chr, 1);
-- 4^32
select @chr = @raw_num / 1048576;
select @raw_num = @raw_num - (@chr * 1048576);
select @code = @code + SUBSTRING(@bcelems, 1 + @chr, 1);
-- 3^32
select @chr = @raw_num / 32768;
select @raw_num = @raw_num - (@chr * 32768);
select @code = @code + SUBSTRING(@bcelems, 1 + @chr, 1);
-- 2^32
select @chr = @raw_num / 1024;
select @raw_num = @raw_num - (@chr * 1024);
select @code = @code + SUBSTRING(@bcelems, 1 + @chr, 1);
-- 1^32
select @chr = @raw_num / 32;
select @raw_num = @raw_num - (@chr * 32);
select @code = @code + SUBSTRING(@bcelems, 1 + @chr, 1);
-- 0^32
select @code = @code + SUBSTRING(@bcelems, 1 + @raw_num, 1);
-- that's it!
end;
</pre>
<p>I'm not desperately concerned about optimisation unless this method is actually an order of magnitude (or so) worse than any alternative. </p>
<p>The code only ever gets executed in small bursts, maybe generating 20 or 30 codes every 10 minutes or so. Because of the large range of numbers I don't want to pre-calculate the codes into a huge table (only small pockets of the overall code range will be used in any given installation).</p>
<p>However, I'm sure there's probably a tidier way of achieving the same result - particularly those divisions and subtractions.</p>
<p>Any constructive criticism, observations or suggestions would be most welcome. </p>
|
<p>Seeing as it's SQL Server 2005, any reason not to use a CLR stored procedure? You could use your CLR language of choice then and it'd probably be a relatively direct port of your existing Delphi code.</p>
|
<p>Although it can clearly be done in SQL Server 2005, I think that it's of sufficient 'non-database-ness' that some kind of precompiled, high-level language routine makese sense.</p>
<p>I've written DLLs for Interbase/Firebird, and T-SQL sprocs for SQL Server, but never a CLR routine. It will be an interesting exercise!</p>
| 7,907
|
<p>How can you get a <strong>raw</strong> socket in Perl, and then what's the best way to built a packet for use with it?</p>
|
<p>Perhaps searching <a href="http://search.cpan.org" rel="nofollow noreferrer">CPAN</a> might help? <a href="http://search.cpan.org/dist/IO" rel="nofollow noreferrer">IO::Socket</a> comes to mind.</p>
|
<p>Be aware that if you're trying to use raw sockets to send a pile of SYN packets, and you just "use Socket;" that's going to fill up your ARP tables and bomb out with "No buffer space available" and a stack of "CLOSE_WAIT" entries in "netstat" (which stops your machine doing any more connections of any kind until some of them free up).</p>
<p>Or in other words - you do really need Net::RawIP - it makes a difference.</p>
| 24,244
|
<p>I have a web app with a web-based configuration UI. If the user accesses via HTTP, I want to alert the user that they should really use HTTPS and give them a link to click on to get to the HTTPS-prefixed URL.</p>
<p>Now, this is pretty straightforward if we're on the default ports, but often, we're not - for example, HTTP might be on 8080, with HTTPS on 8181. I can have some heuristics for figuring out which port to use, e.g. 80->443, 8080->8181, but is there any way to get a list of ports and protocols back from the web container? Ideally Java EE standard, but even container-specific would be a start...</p>
<p>EDIT - one clarification - this is for an 'off-the-shelf' application (<a href="http://opensso.org/" rel="nofollow noreferrer">OpenSSO</a>), so I'd really like to be able to (a) give the user the choice to go ahead and use an insecure port if they <em>really</em> want to (e.g. they're deploying on their laptop on some container without a secure port) and (b) not make the user edit server.xml.</p>
|
<p>You could transfer them automatically to https by using configuration only.</p>
<p>in your web.xml:</p>
<pre><code><user-data-constraint>
<transport-guarantee>
CONFIDENTIAL
</transport-guarantee>
</user-data-constraint>
</code></pre>
<p>and in your server.xml in the HTTPConnector:</p>
<pre><code>redirectPort="YOUR_SSL_PORT"
</code></pre>
|
<p>In case you have a load balancer, usually it can be configured to perform that kind of redirect automatically.</p>
| 43,500
|
<p>I'm using a Prusa i3 MK3S printer. After ~8 months of printing PLA, PET-G, ABS I decided to buy some HIPS and print something with it. I cannot print >1 filaments at once, so I'm not using it as a support for ABS, <strong>I want to create some high durability working models, like gears, robot parts etc.</strong> </p>
<p>While the quality of my models is perfect, unfortunately their <strong>strength is disappointingly low. They easily undergo plastic deformation or break.</strong> I've tried lots of settings, some yielding better or worse results, but the problem is present regardless.</p>
<p>My settings:</p>
<ul>
<li>Printer: Prusa i3 MK3S</li>
<li>Nozzle: Default 0.4 mm nozzle for Prusa</li>
<li>Layer Height: 0.2-0.3 mm</li>
<li>Temperature: 230-240 °C nozzle, 100-110 °C bed</li>
<li>Slicer: PrusaSlicer 2.0.0</li>
</ul>
<p>I've read lots of tutorials regarding HIPS printing and they did not give me the answer to my question...</p>
<p>Am I doing something wrong or is it normal for High Impact PolyStyrene? At this point, the <em>High Impact</em> Polystyrene seems less <em>High Impact</em> than generic PLA.</p>
|
<p>It might. If HIPS is a single material with consistent properties, it might have a narrower temperature range. Online references suggest up to 240 °C. Try that, then 245 and 250 °C. Maybe higher. </p>
|
<p>I've been using HIPS for nearly 2 years now to print the housings of EDF units for RC planes. They come out light and strong but have poor layer adhesion, especially on thin-wall parts.</p>
<p>Normally I print at with a 260 °C nozzle and 100 °C bed but will try higher temperature when I upgrade my Ender 5 to a 32-bit board. Thin cyanoacrylate painted on the surface solves most issues. Sometimes I use a solution of ASA dissolved in acetone to paint the surface and bind layers together.</p>
<p>The EDF rotors I print from Apollo X which is a modified ASA that is easy to print but not soluble in acetone.</p>
| 1,543
|
<p>I'm working with jQuery and looking to see if there is an easy way to determine if the element has a specific CSS class associated with it.</p>
<p>I have the id of the element, and the CSS class that I'm looking for. I just need to be able to, in an if statement, do a comparison based on the existence of that class on the element.</p>
|
<p>Use the <code>hasClass</code> method:</p>
<pre><code>jQueryCollection.hasClass(className);
</code></pre>
<p>or</p>
<pre><code>$(selector).hasClass(className);
</code></pre>
<p>The argument is (obviously) a string representing the class you are checking, and it returns a boolean (so it doesn't support chaining like most jQuery methods).</p>
<p><strong>Note:</strong> If you pass a <code>className</code> argument that contains whitespace, it will be matched literally against the collection's elements' <code>className</code> string. So if, for instance, you have an element,</p>
<pre><code><span class="foo bar" />
</code></pre>
<p>then this will return <code>true</code>:</p>
<pre><code>$('span').hasClass('foo bar')
</code></pre>
<p>and these will return <code>false</code>:</p>
<pre><code>$('span').hasClass('bar foo')
$('span').hasClass('foo bar')
</code></pre>
|
<p>Check the official jQuery FAQ page :</p>
<p><a href="http://learn.jquery.com/using-jquery-core/faq/how-do-i-test-whether-an-element-has-a-particular-class/" rel="nofollow">How do I test whether an element has perticular class or not</a></p>
| 32,951
|
<p>Namely, how does the following code:</p>
<pre><code>var sup = new Array(5);
sup[0] = 'z3ero';
sup[1] = 'o3ne';
sup[4] = 'f3our';
document.write(sup.length + "<br />");
</code></pre>
<p>output '5' for the length, when all you've done is set various elements?</p>
<p>My 'problem' with this code is that I don't understand how <code>length</code> changes without calling a <code>getLength()</code> or a <code>setLength()</code> method. When I do any of the following:</p>
<pre><code>a.length
a['length']
a.length = 4
a['length'] = 5
</code></pre>
<p>on a non-array object, it behaves like a dict / associative array. When I do this on the array object, it has special meaning. What mechanism in JavaScript allows this to happen? Does JavaScript have some type of property system which translates</p>
<pre><code>a.length
a['length']
</code></pre>
<p>into "get" methods and</p>
<pre><code>a.length = 4
a['length'] = 5
</code></pre>
<p>into "set" methods?</p>
|
<p>Everything in JavaScript is an object. In the case of an <code>Array</code>, the <code>length</code> property returns the size of the internal storage area for indexed items of the array. Some of the confusion may come into play in that the <code>[]</code> operator works for both numeric and string arguments. For an array, if you use it with a numeric index, it returns/sets the expected indexed item. If you use it with a string, it returns/sets the named property on the array object - unless the string corresponds to a numeric value, then it returns the indexed item. This is because in JavaScript array indexes are coerced to strings by an implicit <code>toString()</code> call. Frankly, this is just one more of those things that makes you scratch your head and say "JavaScript, this, this is why they laugh at you."</p>
<p>The actual underlying representation may differ between browsers (or it may not). I wouldn't rely on anything other than the interface that is supplied when working with it.</p>
<p>You can find out more about JavaScript arrays <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" rel="noreferrer">at MDN</a>.</p>
|
<p>A JavaScript array is an object just like any other object, but JavaScript gives it special syntax.</p>
<pre><code>arr[5] = "yo"
</code></pre>
<p>The above is <strong>syntactic sugar</strong> for</p>
<pre><code>arr.insert(5,"yo")
</code></pre>
<p>which is how you would add stuff to a regular object. It's what is inside the <em>insert</em> method that changes the value of arr.length</p>
<p>See my implementation of a customArray type here: <a href="http://jsfiddle.net/vfm3vkxy/4/" rel="nofollow">http://jsfiddle.net/vfm3vkxy/4/</a></p>
| 47,773
|
<p>So I've got a nice Java project, build with Ant to a /dist folder.<br>
The whole project is under version control, so I can deploy the latest version just by 'svn export' on the path to the dist folder.<br>
But my build keeps deleting the .svn folders inside my dist folder, and all its dependents, because it cleans out the folder when building instead of just overwriting. The precise culprit is JarBundler, the Ant task that builds my mac.app bundle - It deletes the whole bundle's folder before recreating it.<br>
This obviously craps up my svn, because all the .svn folders are now missing for that folder and so it says its in conflict. </p>
<p>Anyone have any ideas for how I could solve this? I can't figure out how to stop jarbundler from deleting everything, so im going to have to do something more hacky I fear. Im pretty new to Ant as well, just for reference.</p>
|
<p>To have dist in source control <em>can</em> be considered as good practice if you want your source control system to be a <strong><em>unique referential</em></strong> for all:</p>
<ul>
<li>developers</li>
<li>assemblers (unit-testing)</li>
<li>homologation testers (you query a bunch of dist on your integration platform and perfom there your non-regression tests, perfs tests, stress tests, and so on)</li>
<li>production release managers
...</li>
</ul>
<p>BUT you need to have a proper release process to pull this through.</p>
<p>In your case, the <strong>build</strong> must be in a <strong><em>separate and private directory</em></strong>, that is a directory not in subversion. When the build is ok, you <strong><em>import</em></strong> it into subversion if it is an <em>official</em> release, or you import it to a shared directory if it is a temporary build, just needed by the next team (thus avoiding to commit hundreds of builds into SCM, using space for nothing). </p>
<p>Note: the main advantage for having the delivery (dist) in your SCM is to allow <strong><em>dependent</em></strong> project to work not with your sources, but directly with your delivery (which is bound to go at one point or another into production): if they manage to make their code work, by compiling with your delivery, chances are their own dist, when deployed with your, will work.<br>
That way, the other teams access your delivery (your 'myProject.jar') as they access any of their sources: they can read through the SCM the version of your jar, its date, its history, its metadata, its label, and so on.</p>
<p>However, for one small monolithic (as in 'no other projects depend on it') project, it can be argued that dist (the final packaged delivery) <strong>could be re-build on demand and stored in an external referential system</strong>, as an external Maven repository for instance.<br>
BUT: Maven is no SCM repository, meaning you need to sign you jar ('MyProject-1.0.jar'), you have no history, and you need to report all your metadata on a separate text file along your delivery. Any other project accessing to that delivery in that Maven repo needs to adjust its scripts and classpaths accordingly to your version naming convention.<br>
Plus, Maven is another repository in your development architecture. Whenever you can keep the number of repos to a minimum (of '1' ;) ), it is better.</p>
|
<p>Simple. Don't check in /dist in to version control.</p>
<p>Version Control really should not have any generated code/binaries/jars/what-have-you.</p>
| 27,219
|
<p>I'm just getting into creating some WCF services, but I have a requirement to make them backward compatible for legacy (.NET 1.1 and 2.0) client applications. </p>
<p>I've managed to get the services to run correctly for 3.0 and greater clients, but when I publish the services using a basicHttpBinding endpoint (which I believe is required for the compatibility I need), the service refactors my method signatures. e.g.</p>
<pre><code>public bool MethodToReturnTrue(string seedValue);
</code></pre>
<p>appears to the client apps as</p>
<pre><code>public void MethodToReturnTrue(string seedValue, out bool result, out bool MethodToReturnTrueResultSpecified);
</code></pre>
<p>I've tried every configuration parameter I can think of in the app.config for my self-hosting console app, but I can't seem to make this function as expected. I suppose this might lead to the fact that my expectations are flawed, but I'd be surprised that a WCF service is incapable of handling a bool return type to a down-level client.</p>
<p>My current app.config looks like this.</p>
<pre><code><?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" Name="MyCompany.Services.CentreService.CentreService">
<clear />
<endpoint address="http://localhost:8080/CSMEX" binding="basicHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<endpoint address="http://localhost:8080/CentreService" binding="basicHttpBinding" bindingName="Compatible" name="basicEndpoint" contract="MyCompany.Services.CentreService.ICentreService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
</code></pre>
<p>Can anyone advise, please?</p>
|
<p>OK, we needed to resolve this issue in the short term, and so we came up with the idea of a "interop", or compatibility layer.</p>
<p>Baiscally, all we did was added a traditional ASMX web service to the project, and called the WCF service from that using native WCF calls. We were then able to return the appropriate types back to the client applications without a significant amount of re-factoring work. I know it was a hacky solution, but it was the best option we had with such a large legacy code-base. And the added bonus is that it actually works surprisingly well. :)</p>
|
<p>You do have to use the XmlSerializer. For example:</p>
<pre><code>[ServiceContract(Namespace="CentreServiceNamespace")]
[XmlSerializerFormat(Style=OperationFormatStyle.Document, SupportFaults=true, Use=OperationFormatUse.Literal)]
public interface ICentreService {
[OperationContract(Action="CentreServiceNamespace/MethodToReturnTrue")]
bool MethodToReturnTrue(string seedValue);
}
</code></pre>
<p>You have to manually set the operation action name because the auto-generated WCF name is constructed differently from the ASMX action name (WCF includes the interface name as well, ASMX does not).</p>
<p>Any data contracts you use should be decorated with <code>[XmlType]</code> rather than <code>[DataContract]</code>.</p>
<p>Your config file should not need to change.</p>
| 2,770
|
<p>I'd like to set a cookie via Django with that has several different values to it, similar to .NET's <a href="http://msdn.microsoft.com/en-us/library/system.web.httpcookie_members(VS.80).aspx" rel="nofollow noreferrer">HttpCookie.Values</a> property. Looking at the <a href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.set_cookie" rel="nofollow noreferrer">documentation</a>, I can't tell if this is possible. It looks like it just takes a string, so is there another way?</p>
<p>I've tried passing it an array (<code>[10, 20, 30]</code>) and dictionary (<code>{'name': 'Scott', 'id': 1}</code>) but they just get converted to their string format. My current solution is to just use an arbitrary separator and then parse it when reading it in, which feels icky. If multi-values aren't possible, is there a better way? I'd rather not use lots of cookies, because that would get annoying.</p>
|
<p>.NETs multi-value cookies work exactly the same way as what you're doing in django using a separator. They've just abstracted that away for you. What you're doing is fine and proper, and I don't think Django has anything specific to 'solve' this problem.</p>
<p>I will say that you're doing the right thing, in not using multiple cookies. Keep the over-the-wire overhead down by doing what you're doing.</p>
|
<p>Django does not support it. The best way would be to separate the values with arbitrary separator and then just split the string, like you already said.</p>
| 15,666
|
<p>I have an OpenGL ES game that I am hacking together. One part of it involves looking at a large "map-like" area and then double-tapping on one part to "zoom into" it. How would you use OpenGL ES to provide this effect (given that it may need to zoom in on different parts of the map). </p>
<p>I've heard of glScale and glOrtho, but I'm unclear on how they actually work since the whole openGL world is very new to me. </p>
|
<p>The 2-D zooming you describe might be better achieved using Core Animation. NSView (and its NDA'd iPhone counterpart) provide implicit animation when you change their frame. All you'd need to do in this case would be to set the frame's origin.x and origin.y and size.width and size.height to such values to make the view larger than the screen. If you did this and wrapped it in the appropriate calls to start and commit an animation, you'd get a zooming animation for free. Core Animation uses OpenGL behind the scenes for its animations.</p>
<p>If, however, you feel that you have to do this in OpenGL, may I suggest a little writeup I did at <a href="http://www.sunsetlakesoftware.com/2008/08/05/lessons-molecules-opengl-es" rel="nofollow noreferrer">http://www.sunsetlakesoftware.com/2008/08/05/lessons-molecules-opengl-es</a>? I'm the author of <a href="http://www.sunsetlakesoftware.com/molecules" rel="nofollow noreferrer">Molecules</a>, a free 3-D molecular visualizer for the iPhone, and I knew nothing about OpenGL ES before I started that project. 3 weeks later, it was in the App Store as it launched.</p>
<p>OpenGL calls are pretty simple, it's the math surrounding them that can give you headaches. Zooming in on objects is actually pretty simple, and can be done either by moving the camera or by actually physically scaling objects. For Molecules, I went the route of scaling the object using the glScalef(x,y,z) function, where x, y, and z are the scale factors you wish to apply to your model object. I do my scaling incrementally. That is, I don't reset the transformation matrix at the start of each rendered frame (using glLoadIdentity()), but just scale it a little bit based on user input. If the user moves their fingers apart by 5%, I increase the scale by 5%.</p>
<p>Again, I'd suggest Core Animation for the 2-D zooming you describe, but it isn't too hard to achieve the same results in OpenGL ES.</p>
|
<p>Respectfully, the answer is to take a few days to learn the basics of OpenGL, and there are much better places for that on the net than here.</p>
| 12,914
|
<p>Simple example: I want to have some items on a page (like divs or table rows), and I want to let the user click on them to select them. That seems easy enough in jQuery. To save which items a user clicks on with no server-side post backs, I was thinking a cookie would be a simple way to get this done.</p>
<ol>
<li>Is this assumption that a cookie is OK in this case, correct?</li>
<li>If it is correct, does the jQuery API have some way to read/write cookie information that is nicer than the default JavaScript APIs?</li>
</ol>
|
<p>The default JavaScript "API" for setting a cookie is as easy as:</p>
<pre><code>document.cookie = 'mycookie=valueOfCookie;expires=DateHere;path=/'
</code></pre>
<p>Use the jQuery cookie plugin like:</p>
<pre><code>$.cookie('mycookie', 'valueOfCookie')
</code></pre>
|
<p>It seems the jQuery cookie plugin is not available for download. However, you can download the same jQuery cookie plugin with some improvements described in <em><a href="http://jquery-howto.blogspot.com/2010/09/jquery-cookies-getsetdelete-plugin.html" rel="nofollow noreferrer">jQuery & Cookies (get/set/delete & a plugin)</a></em>.</p>
| 12,083
|
<p>We recently started using maven for dependency management. Our team uses eclipse as it's IDE. Is there an easy way to get eclipse to refresh the maven dependencies without running mvn eclipse:eclipse?</p>
<p>The dependencies are up to date in the local maven repository, but eclipse doesn't pick up the changes until we use the eclipse:eclipse command. This regenerates a lot of eclipse configuration files.</p>
|
<p>Have you tried using the <a href="http://m2eclipse.codehaus.org/" rel="noreferrer">m2eclipse</a> plugin? I use it with eclipse and it maintains the eclipse .classpath when I add dependencies. It'll also check for updated dependencies.</p>
|
<p>You generate the special eclipse files with <code>mvn eclipse:eclipse</code>, but once you've done that, you should let a <a href="http://maven.apache.org/eclipse-plugin.html" rel="nofollow noreferrer">plugin</a> handle the dependencies while inside eclipse.</p>
<p>That's how we do it at my work place, and it generally works well.</p>
| 16,499
|
<p>I want to make my .Net application display a notification in the system tray. So I want to show an icon for that, can anyone tell how to do that?</p>
|
<p>Open the main Form for your application, go to the Toolbox, open the All Windows Forms section and drop a NotifyIcon on your form. Then add the icon you want to the NotifyIcon.</p>
<p>You may also want to change the ShowInTaskbar property of your form to false when the form is minimized and handle the double click event of the NotifyIcon to restore your form and set ShowInTaskbar back to true.</p>
|
<p>In .Net apps you can specify the file to use as an icon - it can be a bitmap or png etc. so just use your favourite image editing program to create you icon.</p>
<p>This <a href="http://www.developer.com/net/csharp/article.php/3336751" rel="nofollow noreferrer">article</a> gives advice on getting your app to put an icon in the system tray.</p>
<p>Hope this helps.</p>
| 38,832
|
<p>In our product we have a big utilities file that we require (with <code>do</code>) at the beginning of a lot of our files. Is there a reason <em>not</em> to turn this into a module? For example, instead of doing this:</p>
<pre><code>do '../dbi_utilities.pl';
our ($db,$user,$pw,$attr);
my $Data = DBI->connect($db,$user,$pw,$attr) or die "Could not connect to database: $DBI::errstr";
</code></pre>
<p>Couldn't I just do this?:</p>
<pre><code>use AppUtil;
my $Data = AppUtil->connect();
</code></pre>
|
<p>The only reason not to do this is time.</p>
<p>That is, it'll take time to clean up your interface, as well as all calling apps to use the new interface.</p>
<p>What it'll cost you in time now will be more than made up when you start using proper tests ("make test" or "./Build test" or just "prove ...") and be able to check that your changes won't break anything before checking it in. So, by all means, convert. Just be aware that it's not a free gain.</p>
|
<p>You get all of the cool module stuff, encapsulation, module specific functions, and so on.</p>
<p>Notice though, by using <code>use</code> with your syntax. creating an object for the AppUtil namespace, and calling the connect subroutine. for your utilities.</p>
<p>Also you must have 1; at the end of your file.</p>
<hr>
<p>Sticking with the other method means you don't have to change any code, you don't have to add 1 at the end. </p>
<p>All "do", "use", and "require" import, but scope code that is within them (except named subroutines cause they can't be hidden).</p>
| 22,329
|
<p>How do I post a form to an external site using an ASP.NET MVC controller?</p>
<p><strong>EDIT:</strong> Ok... I have a view with some data on it. After the user completes the form I need to do a postback with a specified form format to an external site (like for paypal). After I posted the constructed form I need to redirect the action to a new view</p>
|
<p>You have to do the POST on the server-side..</p>
<p>of which this guy has written a helper class to do <a href="https://web.archive.org/web/20210123193021/http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx" rel="nofollow noreferrer">Http Post in C#</a> (<a href="https://pastebin.com/f15346568" rel="nofollow noreferrer">pastebin-ed</a>). Check it out.</p>
<p>Send the post with the PostSubmitter class and just render your view normally.</p>
<p>Basically, in situation like this one would create a HttpWebRequest, set Method to post and write the post data to the request stream. But the linked code already does that for you in a nice and cozy way.</p>
<p>So no need rewire anything.</p>
<pre><code></code></pre>
|
<p>How about sending a redirect to the browser.</p>
| 48,148
|
<p>Is there a way to convert a HTML string into a Image .tiff file?</p>
<p>I am using C# .NET 3.5. The requirement is to give the user an option to fact a confirmation. The confirmation is created with XML and a XSLT. Typically it is e-mailed. </p>
<p>Is there a way I can take the HTML string generated by the transformation HTML string and convert that to a <code>.tiff</code> or any image that can be faxed?</p>
<p>3rd party software is allowed, however the cheaper the better.</p>
<p>We are using a 3rd party fax library, that will only accept <code>.tiff</code> images, but if I can get the HTML to be any image I can covert it into a <code>.tiff</code>.</p>
|
<p>Here are some free-as-in-beer possibilities:</p>
<p>You can use the PDFCreator printer driver that comes with ghostscript and print
directly to a TIFF file or many other formats.</p>
<p>If you have MSOffice installed, the Microsoft Office Document Image Writer will produce
a file you can convert to other formats.</p>
<p>But in general, your best bet is to print to a driver that will produce and
image file of some kind or a windows meta-file format (.wmf) file.</p>
<p>Is there some reason why you can't just print-to-fax? Does the third-party software not support a printer driver? That's unusual these days.</p>
|
<p>A starting point might be the software of <a href="http://www.websupergoo.com" rel="nofollow noreferrer">WebSuperGoo</a>, which provide rich image editing products, cheap or for free.</p>
<p>I know for sure their PDF Writer can do basic HTML (<a href="http://www.websupergoo.com/helppdf6net/source/3-concepts/b-htmlstyles.htm" rel="nofollow noreferrer">http://www.websupergoo.com/helppdf6net/source/3-concepts/b-htmlstyles.htm</a>). This should not be too hard to convert to TIFF.</p>
<p>This does not include the full HTML subset or CSS. That might require using Microsofts IE ActiveX component.</p>
| 7,752
|
<p>What is the best or most concise method for returning a string repeated an arbitrary amount of times?</p>
<p>The following is my best shot so far:</p>
<pre><code>function repeat(s, n){
var a = [];
while(a.length < n){
a.push(s);
}
return a.join('');
}
</code></pre>
|
<blockquote>
<p><strong>Note to new readers:</strong> This answer is old and and not terribly practical - it's just "clever" because it uses Array stuff to get
String things done. When I wrote "less process" I definitely meant
"less code" because, as others have noted in subsequent answers, it
performs like a pig. So don't use it if speed matters to you.</p>
</blockquote>
<p>I'd put this function onto the String object directly. Instead of creating an array, filling it, and joining it with an empty char, just create an array of the proper length, and join it with your desired string. Same result, less process!</p>
<pre><code>String.prototype.repeat = function( num )
{
return new Array( num + 1 ).join( this );
}
alert( "string to repeat\n".repeat( 4 ) );
</code></pre>
|
<p>Recursive solution using divide and conquer:</p>
<pre><code>function repeat(n, s) {
if (n==0) return '';
if (n==1 || isNaN(n)) return s;
with(Math) { return repeat(floor(n/2), s)+repeat(ceil(n/2), s); }
}
</code></pre>
| 24,776
|
<p>How do I configure SSRS/Windows Server 2003, so that I can setup email delivery via a remote SMTP server that requires username and password.</p>
<p>I can configure SSRS with an SMTP address and other parameters, but nowhere is it possible to configure it with smtp username and password. </p>
<p>I have hunted around, but can only find vague reference to setting up some sort of relay, to cover up the bizarre lack of smtp functionality that SSRS has out of the box. </p>
<p>Any ideas?</p>
|
<p>Here are the steps to set this up using only Microsoft SSRS/Windows Server 2003 components.</p>
<p>1) Install SMTP server in Add/Remove programs / App Server / IIS<br>
<strong>In IIS Manager:</strong><br>
2) add the domain (as a remote type) you will be sending as such as <em>yourwebsite.com</em><br>
3) Under Default SMTP Virtual Server properties / delivery tab / advaced button, add your remote smtp server in the smart host field.<br>
4) Under Default SMTP Virtual Server properties / delivery tab / Outbound security button, choose Basic Authentication, user name = SMTP user name, password = SMTP password<br></p>
<p><strong>In the rsreportserver.config file</strong> (<i>sql drive</i>:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer):<br>
5) Populate <code><SMTPServer>x.x.x.x</SMTPServer></code> with the IP of the machine where you just setup the SMTP server.<br>
6) Populate <code><From>you@yourwebserver.com</From></code> <br>
7) Change this one to false <code><SendEmailToUserAlias>False</SendEmailToUserAlias></code> <br>
8) Lastly, make sure you setup the domain as a permitted host such as this:<br>
<code><PermittedHosts></code><br> <code><HostName>yourwebsite.com</HostName></code><br><code></PermittedHosts></code><br></p>
<p>As far as <em>why</em> SMTP basic authenication isn't supported directly in SSRS seems to be by design. The best explaination I could find was here on this <a href="http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/e8c388ef-a864-4ab6-804f-4da3ca73aaf7" rel="noreferrer">MSDN forum</a>:</p>
<p>As one poster here mentions, there is a <a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=332979" rel="noreferrer">Microsoft Connect ticket</a> open for people who are requesting this functionality.</p>
|
<p>This might help you a little: C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\rsreportserver.config contains all of the configurations settings in the . I don't see exactly what you want so you'll probably have to perform some relay tricks.</p>
| 29,488
|
<p>So let's say I have an eBay-type application where only the seller can edit his/her listing. How do I go about restricting access to the Edit action based on the Id of the item we're editing and the currently logged in user?</p>
<p>As far as I can tell, the Authorize attribute only allows you to restrict access to controller actions based on whether the user is authenticated or not and their role. Is this simply something that I need to handle manually within the controller?</p>
|
<p>A custom attribute deriving from IAuthorizeFilter.</p>
|
<p>This looks like a pretty good example of controlling actions based on users and roles.
<a href="http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/" rel="nofollow noreferrer">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/</a></p>
<p>I'm brand-spanking new at MVC though, so I could be wrong. Check it out and let us know if it helped.</p>
| 26,348
|
<p>Looking for advice (perhaps best practice).</p>
<p>We have a MS Word document (Office 2007) that we are extracting text from a cell.</p>
<p>We can use the following:</p>
<pre><code>string text = wordTable.cell(tablerow.index, 1).Range.Text;
</code></pre>
<p>The text is extracted; however we seem to get extra characters trailing, for example <code>\r\a</code>.</p>
<p>Now we could add the following:</p>
<pre><code>.... wordTable.cell(tablerow.index, 1).Range.Text.Replace("\r\a,"");
</code></pre>
<p>But this seems a little too lazy, and pretty much a waste of time that would most likely lead to problems down the road.</p>
<p>We could also have a method that receives the string to clean:</p>
<pre><code>private string cleanTextWordCellBreak(string wordTextToClean)
{
// Clean the text here
return cleanstring;
}
</code></pre>
<p>then we could use it:</p>
<pre><code>cleanTextWordCellBreak(wordTable.cell(tablerow.index, 1).Range.Text;
);
</code></pre>
<p>This seems closer to a better way of handling the issue. What would you do?</p>
|
<p>I would break it out into a separate method but use the replace implementation since it's the simplest solution. You could always change the implementation later if you run into problem (like the text contains more than one <code>\r\a</code> and needs to be preserved)</p>
<p>So:</p>
<pre><code>private string stripCellText(string text)
{
return text.Replace("\r\a", "");
}
string text = stripCellText(wordTable.cell(tablerow.index, 1).Range.Text);
</code></pre>
|
<p>I would definitely opt for breaking it out into a separate method personally. it helps with code readability and makes it a lot easier to change if needed in the future.</p>
| 49,532
|
<p>I'm working on an asp.net web site. We have to use com interop to interact with legacy vb6 activex components. The components in many cases rely on receiving a context object (which is itself a vb6 activex component) as a parameter. The context object is fairly costly to construct.</p>
<p>Therefore one idea is that a context object is constructed once and stored in asp.net session. However, if this object is just a .net wrapper around an activex component, is it wise or advisible to persist such an object in session?</p>
<p>Additionally the context object contains user specific information, so persisting using .net HttpRuntime Caching could be used, but would require a user specific key. </p>
<p>I understand the other limitations and things you need to be aware of with asp.net session, <a href="https://stackoverflow.com/questions/133236/aspnet-session">aspnet-session question</a>.</p>
<p>To ask the question a slightly different way: are their any issues or problems with storing an .net object that is just a wrapper around a com object? </p>
|
<p>I think you will very rapidly get problems with one request blocking another.</p>
<p>ASP.NET by default initialises COM on its threads to put the thread in a multi-threaded apartment. VB6 components were apartment-model at best. That means that when the MTA thread creates the component, it's put into the main STA if one already exists (which for ASP.NET worker processes, it won't) or a new thread is created specifically for the STA. It doesn't matter which MTA thread creates the component, the same STA is always used for the components that can't handle the MTA model. That means the same thread is used for every call to those components, so concurrent calls have to wait in line.</p>
<p>To tell ASP.NET to initialize COM for single-threaded components, which will at least cause the object to be created on the same thread as the executing page, add the <code>AspCompat</code> attribute to the <a href="http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx" rel="nofollow noreferrer">@Page</a> directive.</p>
<p>I would not cache the objects as they're very likely to have cross-thread issues when they're reused.</p>
|
<p>I'd persist it in the cache, that way its not constructed once per user, unless that's the desired effect.</p>
| 22,353
|
<p>I need to take in a Date Range from the UI, retrieve the records within that range and plot a graph. This is the relevant section in my Rails view.</p>
<pre><code><span>
<%= check_box_tag :applyRange, @params[:applyRange]%>
From
<%= select_date Time.now, :prefix=>"fromDate" %>
To
<%= select_date Time.now, :prefix=>"toDate" %>
</span>
</code></pre>
<p>Back on the controller/action side, this is what I had to do to reconstruct the date values back (hack hack puts hack puts hack...)</p>
<pre><code>fromDate = Date.civil params[:fromDate]["year"].to_i, params[:fromDate]["month"].to_i, params[:fromDate]["day"].to_i
</code></pre>
<p><strong>This just feels wrong</strong>. I'll probably have the fields have blanks too.. in which case to_i is bound to barf. This looks like something that must have been done a zillion times before.. So looking for a good recipe for this. I spent the better part of the last hour trying to figure out this quirky rails helper.</p>
|
<p>I don't know much about the appsettings architecture (I've never really used it), but you can define different values for constants using a bit of MSBuild magic.</p>
<p>Create two .cs files, Constants1.cs and Constants2.cs (or name them after your configurations).</p>
<p>In each file, define a class called Constants (or whatever) -- but do it as if each file were the only definition (ie. use the same class name). Typically, this should just define <code>public static readonly</code> fields -- do <strong>not</strong> use <code>const</code>, as that can get you into trouble with partial builds.</p>
<p>Now Unload your project file and Edit it. Find the entries that look like this:</p>
<pre>
<Compile Include="Constants1.cs" />
<Compile Include="Constants2.cs" />
</pre>
<p>and change them like so:</p>
<pre>
<Compile Include="Constants1.cs" Condition="'$(Configuration)'=='Debug'" />
<Compile Include="Constants2.cs" Condition="'$(Configuration)'=='Release'" />
</pre>
<p>Finally Save and Reload your project. Now only one of the files will actually be built at a time, depending on your build configuration.</p>
|
<p>You could add a prebuild or postbuild task to the proj, you have access to the ConfigurationName from there. Would be fairly easy to do something like "copy Web.config.debug Web.config"</p>
| 43,920
|
<p>Are there any IDE's for developing HLSL code? The three key features I want are:<br>
1) syntax highlighting<br>
2) auto-complete<br>
3) interaction debugging</p>
<p>Visual Studio doesn't do any of these things, and it doesn't seem that RenderMonkey or FX Composer do either.</p>
<p>Is there some IDE that I'm not aware of, or does one of these three IDE's actually support these features and I'm too clueless to figure out how to use them properly?</p>
|
<p>Have you actually tried ATI's RenderMoney or NVidia's FX Composer?</p>
<p>Both actually provide syntax highlighting. Futher more, NVidia's Cg toolkits actually allows you to enable syntaxhightling in Visual Studio with some custom setting.</p>
<p>As for auto-completion, I don't think it's much needed as compare to our normal programming. It's because you won't be writing a very long code for your shader programming. Shader is quite critical in that it is run on every frame generated, and every instruction require 1 to a few clock cycle to execute, thus there's always a physical limit to how long you can afford to write.</p>
<p>Interactive debugging is currently the limitation of GPU hardware. To actually do that, the GPU has to be emulated with our CPU, which is quite impossible considering that the REF (software rendering) device can never cop up with even obsolete GPU, what more to say about emulating shader.</p>
|
<p>Now with Visual Studio 11 there is a "real hlsl ide and debugger". It was detailed at <a href="http://blogs.msdn.com/b/vcblog/archive/2011/11/08/10235150.aspx" rel="nofollow">Game Debugging in Visual Studio 11</a> and is available at <a href="http://blogs.msdn.com/b/chuckw/archive/2012/02/29/visual-studio-11-beta.aspx" rel="nofollow">Visual Studio 11 Beta</a>.</p>
| 17,763
|
<p>I've trouble setting up Vim (7.1.xxx) for editing Python files (*.py).
Indenting seems to be broken (optimal 4 spaces).
I've followed some tutorials I found via Google. Still no effect :/
Please help.</p>
|
<p>I use this on my macbook:</p>
<pre><code>" configure expanding of tabs for various file types
au BufRead,BufNewFile *.py set expandtab
au BufRead,BufNewFile *.c set expandtab
au BufRead,BufNewFile *.h set expandtab
au BufRead,BufNewFile Makefile* set noexpandtab
" --------------------------------------------------------------------------------
" configure editor with tabs and nice stuff...
" --------------------------------------------------------------------------------
set expandtab " enter spaces when tab is pressed
set textwidth=120 " break lines when line length increases
set tabstop=4 " use 4 spaces to represent tab
set softtabstop=4
set shiftwidth=4 " number of spaces to use for auto indent
set autoindent " copy indent from current line when starting a new line
" make backspaces more powerfull
set backspace=indent,eol,start
set ruler " show line and column number
syntax on " syntax highlighting
set showcmd " show (partial) command in status line
</code></pre>
<p>(edited to only show stuff related to indent / tabs)</p>
|
<p>for more advanced python editing consider installing the <a href="http://eigenclass.org/hiki/simplefold" rel="nofollow noreferrer">simplefold</a> vim plugin. it allows you do advanced code folding using regular expressions. i use it to fold my class and method definitions for faster editing.</p>
| 9,081
|
<p>Is it possible to convert floating point exceptions (signals) into C++ exceptions on x86 Linux?</p>
<p>This is for debugging purposes, so nonportability and imperfection is okay (e.g., if it isn't 100% guaranteed that all destructors are called).</p>
|
<p>If your C++ standard library implementation supports the TR1 functions
<code>fetestexcept</code>, <code>feraiseexcept</code> and <code>feclearexcept</code> (mine doesn't yet so I can't test this) you can detect five kinds of floating point errors and then you can throw whatever exceptions you want.</p>
<p>See <a href="http://en.cppreference.com/w/cpp/numeric/fenv" rel="nofollow noreferrer">here</a> for a description of these functions.</p>
<p>I also recommend section 12.3, "Managing the Floating Point Environment," of the book <em>The C++ Standard Library Extensions: A Tutorial and Reference</em> by Pete Becker, ISBN-13: 9780321412997, for an excellent description of these functions with sample code.</p>
<p><img src="https://i.stack.imgur.com/WdOi2.gif" alt="alt text"></p>
|
<p>The basic idea will be for you to install the appropriate signal handlers for floating point exceptions. Inside your signal handler, you can throw an exception (or send a user-defined signal to another process which will raise the exception, or send a message to another thread for something similar, etc. etc. etc). There are any number of ways to actually throw the exception - the main thing is to handle the signal.</p>
| 11,126
|
<p>I want to wrap a piece of code that uses the Windows Impersonation API into a neat little helper class, and as usual, I'm looking for a way to go test-first. However, while WindowsIdentity is a managed class, the LogonUser call that is required to actually perform the logging in as another user is an unmanaged function in advapi32.dll. </p>
<p>I think I can work around this by introducing an interface for my helper class to use and hiding the P/Invoke calls in an implementation, but testing that implementation will still be a problem. And you can imagine actually performing the impersonation in the test can be a bit problematic, given that the user would actually need to exist on the system.</p>
|
<p><em>Guideline: Don't test code that you haven't written.</em><br>
You shouldn't be concerned with WinAPI implementation not working (most probably it works as expected).
Your concern should be testing the 'Wiring' i.e. if your code makes the right WinAPI call. In which case, all you need is to mock out the interface and let the mock framework tell if you the call was made with the right params. If yes, you're done.</p>
<ul>
<li>Create IWinAPIFacade (with relevant WinAPI methods) and implementation CWinAPIFacade.</li>
<li>Write a test which plugs in a mock of IWinAPIFacade and verify that the appropriate call is made</li>
<li>Write a test to ensure that CWinAPIFacade is created and plugged in as a default (in normal functioning)</li>
<li>Implement CWinAPIFacade which simply blind-delegates to Platform Invoke calls - no need to auto-test this layer. Just do a manual verification. Hopefully this won't change that often and nothing breaks. If you find that it <em>does</em> in the future, barricade it with some tests.</li>
</ul>
|
<p>I am not sure if I follow you.. You don't want to test the PInvoke yourself (you didn't write it) so you want to test that the wrapper class is performing as expected right?</p>
<p>So, just create your interface in the wrapper class and test against that?</p>
<p>In terms of needing to set up users etc, I think that would be a bullet you need to bite. It would seem odd to mock a wrapper PInvoke call, since you would simply just confirm and interface exists :)</p>
| 7,689
|
<p>I'm trying to configure Apache to allow read only access and ask for user to write to a SVN repository when you are coming from the local network (10.*) but not allow any access unless logged in when coming from external network.</p>
<p>I sort of understand how the Order, Deny, Allow, and Limit directives work but I do not know if it is possible/how to combine them to achieve the desired result.</p>
<pre><code><Location /svn>
# Set mod_dav_svn settings
DAV svn
SVNListParentPath on
SVNParentPath /mnt/svn
AuthzSVNAccessFile /mnt/svn/.authz
# Set Authentication
AuthType Basic
AuthName "Auth Realm"
AuthUserFile /mnt/svn/.htpasswd
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 10.0.0.0/8
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
Satisfy Any
</Location>
</code></pre>
<p>I know this will allow all access to any local traffic but ask for login when trying to write from external traffic. This is close to what I want. Any help or suggestions on what to read are greatly appreciated.</p>
|
<p>Yes, you can write:</p>
<pre><code><#if hot>
it's hot
<#else>
it's not
</#if>
</code></pre>
<p>And if you're doing lots of freemarker, I really can recommend IntelliJ IDEA 8, its freemarker support really helps...</p>
|
<p><em>iberck</em> had already pointed out the docs. But here is the exact documentation about <a href="http://freemarker.sourceforge.net/docs/ref_directive_if.html" rel="nofollow noreferrer">if-else in FreeMarker</a>. </p>
| 37,930
|
<p>I'm developing a SWT/JFace application using the libraries from Eclipse 3.4.1.
I encounter the following problem on Windows (Vista 32bit) and Ubuntu 8.10 32bit:</p>
<p>I create a menu bar in the createMenuManager method of the JFace ApplicationWindow. I add MenuManagers for file, edit and help.</p>
<p>I then add an ExitAction to the file MenuManager like so:</p>
<pre><code>filemenu.add(new ExitAction(this));
</code></pre>
<p>The ExitAction is defined this way:</p>
<pre><code>public class ExitAction extends Action {
final ApplicationWindow window;
public ExitAction(ApplicationWindow w) {
this.window = w;
setText("E&xit");
setToolTipText("Exit the application");
setAccelerator(SWT.MOD1 + 'Q');
}
}
</code></pre>
<p>Now when my application starts I want be able to press "CTRL+Q" to quit the application. This does however not work. Only AFTER I click on "File" in the menu bar and THEN clicking "CTRL+Q" the application will quit.</p>
<p>I've tried this with different accelerators- same behavior.</p>
<p>It does work however if I create a "MenuItem" instead of an "Action" to contribute to the menu bar.</p>
<p>Is this a SWT bug or do I miss something?</p>
<p>Torsten.</p>
|
<p>Update: There is a duplicate bug of mine which also contains a workaround.
The bug url is: <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=243758" rel="nofollow noreferrer">https://bugs.eclipse.org/bugs/show_bug.cgi?id=243758</a></p>
<p>Basically the workaround is to call <code>create()</code> on the <code>ApplicationWindow</code> and then <code>getMenuBarManager().updateAll(true);</code> which will force all menu items to get initialized.</p>
<p>Of course you have to call the above methods after you created the menu items.</p>
|
<p>AFAIK <code>setAccelerator(.)</code> does nothing else than adding the appropriate text to your <code>MenuItem</code>. You are responsible to register for an <code>KeyUp</code> event and react on it.</p>
<p>You can use <code>Display.addFilter(SWT.KeyUp, myListener)</code> to register your <code>Listener</code> independently of your widgets.</p>
| 29,673
|
<p>I want to mount some internal and external NTFS drives in CentOS 5.2, preferably automatically upon boot-up. Doesn't matter if it's read/write or read-only, but read/write would be preferred, if it's safe.</p>
<p>Edit: Thanks for all answers, I summarized them below =)</p>
|
<p>To answer my own question: PostMan and mgb led me to the right path, but their answers did not contain complete solution.</p>
<p>Note: A short manual/wiki on this question is here: <a href="http://wiki.centos.org/TipsAndTricks/NTFSPartitions" rel="noreferrer">http://wiki.centos.org/TipsAndTricks/NTFSPartitions</a></p>
<p>So, I am using a fresh, bare install of CentOS 5.2 with latest updates. First of all, I ran the <code>su</code> command to avoid any permission issues.</p>
<p>I created mount points for a couple of external NTFS drives:</p>
<pre><code>mkdir /mnt/iomega80
mkdir /mnt/iogear250
</code></pre>
<p>I had to use the fdisk command, but it wasn't in my system. Here's what installs it:</p>
<pre><code>yum install util-linux
</code></pre>
<p>Then I ran <code>/sbin/fdisk -l</code> and found the device names:</p>
<pre><code>Disk /dev/sdc: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
**/dev/sdc1** * 1 30401 244196001 7 HPFS/NTFS
Disk /dev/sdd: 82.3 GB, 82348278272 bytes
255 heads, 63 sectors/track, 10011 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
**/dev/sdd1** * 1 10011 80413326 7 HPFS/NTFS
</code></pre>
<p>For me, they are <code>/dev/sdc1</code> and <code>/dev/sdd1</code>.</p>
<p>I had to install NTFS-3G, a package that enables NTFS support on CentOS. To install NTFS-3G, I first had to include RPMFORGE in YUM repository list. </p>
<p>To include RPMFORGE in YUM repository list, I used these instructions: <a href="http://rpmrepo.org/RPMforge/Using" rel="noreferrer">http://rpmrepo.org/RPMforge/Using</a>. For my system, the two commands I had to run were:</p>
<pre><code>wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uhv rpmforge-release-0.3.6-1.el5.rf.i386.rpm
</code></pre>
<p>Finally, I installed NTFS-3G using this YUM command:</p>
<pre><code>yum install fuse fuse-ntfs-3g dkms dkms-fuse
</code></pre>
<p>At last, I could use the mount command to mount the filesystems:</p>
<pre><code>mount -t ntfs-3g /dev/sdc1 /mnt/iogear250
mount -t ntfs-3g /dev/sdd1 /mnt/iomega80
</code></pre>
<p>By adding these two lines to <code>/etc/fstab</code>, like previous answers suggested, I got the drives to mount upon boot-up:</p>
<pre><code>/dev/sdc1 /mnt/iogear250 ntfs-3g rw,umask=0000,defaults 0 0
/dev/sdd1 /mnt/iomega80 ntfs-3g rw,umask=0000,defaults 0 0
</code></pre>
|
<p>First enable the repository Epel</p>
<pre><code>yum install epel-release
</code></pre>
<p>Then install ntfs</p>
<pre><code>yum install ntfs-3g
</code></pre>
| 17,508
|
<p>I have a <code>T-Mobile G1</code> and I'm going to download the developer SDK and see if I can create a few simple apps for my phone. If you've done similar development, please answer below and tell me about your experience. Please share any links you found especially useful.</p>
|
<p>I started from here</p>
<p><a href="http://code.google.com/android/kb/commontasks.html" rel="noreferrer">http://code.google.com/android/kb/commontasks.html</a></p>
<p>I got my environment and emulator up and running within about 15 minutes.</p>
<p>First impressions are its fun to work with. </p>
<p>Paul</p>
|
<p>I'm also beginning to get my feet wet with android development. Honestly, I think some of the books out there do a pretty good job of explaining the development framework and getting you started with using the tools quickly. Some of the books I'm reading include "Teach Yourself Android Application Development in 24 Hours" (obviously the title is an exaggeration; the book is just organized into hours. Each hour will take some time for a beginner), "Hello, Android: Introducing Google's Mobile Development Platform (3rd edition)", and "Beginning Android 2." From my, so far, limited experience, developing using the SDK is accessible and enjoyable. That being said, you really need to commit the time/energy to get up to speed. </p>
| 34,899
|
<p>We mostly tend to following the above best practice.</p>
<p>Have a look at <a href="https://stackoverflow.com/questions/73883/string-vs-stringbuilder">String vs StringBuilder</a></p>
<p>But StringBuilder could throw <strong>OutOfMemoryException even when there is sufficient memory available</strong>. It throws OOM exception because it needs "continuous block of memory".</p>
<p>Some links for reference
<a href="http://bytes.com/groups/net-c/501231-stringbuilder-outofmemory" rel="nofollow noreferrer">StringBuilder OutOfMemoryException</a></p>
<p>and there are many more.....</p>
<p>How many of you faced this problem or aware and what did you do to resolve it?</p>
<p>Is there anything I am missing?</p>
<p><strong>P.S: I wasn't aware of this.</strong></p>
<p>I have rephrased the question.</p>
<p>*** The same thing worked with manual concatenation(I'll verify this and update SO). The other thing that caused me concern was that there is enough memory in the system. That's the reason I raised this question here to check whether any one faced this problem or there was something drastically wrong with the code. </p>
|
<p>The underyling string you create will also need a contiguous block of memory because it is represented as an array of chars (arrays require contiguous memory) . If the StringBuilder throws an OOM exception you woludn't be able to build the underlying without it.</p>
<p>If creating a string causes an OOM, there is likely a more serious issue in your application.</p>
<p>Edit in response to clarification:</p>
<p>There is a small subset of cases where building a string with a StringBuilder will fail when manual concatenation succeeds. Manual concatenation will use the exact length required in order to combine two strings while a StringBuilder has a different algorithmn for allocating memory. It's more aggressive and will likely allocate more memory than is actually needed for the string. </p>
<p>Using a StringBuilder will also result in a temporary doubling of the memory required since the string will be present in a System.String form and StringBuilder simultaneously for a short time. </p>
<p>But if one way is causing an OOM and the other is not, it still likely points to a more serious issue in your program. </p>
|
<p>I encountered this exception with very large strings built sucessively with different stringbuilders (which should not have caused a problem as they were declared within anonymous functions), and finally solved it by reusing a single StringBuilder, declared outside of the anonymous function.</p>
| 47,475
|
<p>What is the syntax and which namespace/class needs to be imported? Give me sample code if possible. It would be of great help.</p>
|
<p>Put the following where you need it:</p>
<pre><code>System.Diagnostics.Debugger.Break();
</code></pre>
|
<p>You can use <code>System.Diagnostics.Debugger.Break()</code> to break in a specific place. This can help in situations like debugging a service.</p>
| 12,980
|
<p>I have a collection of custom entity objects one property of which is an <code>ArrayList</code> of byte arrays.</p>
<p>The custom entity is serializable and the collection property is marked with the following attributes: <code>[XmlArray("Images"), XmlArrayItem("Image",typeof(byte[]))]</code></p>
<p>So I serialize a collection of these custom entities and pass them to a web service, as a string.</p>
<p>The web service receives the string and byte array in tact, </p>
<p>The following code then attempts to deserialize the collection - back into custom entities for processing...</p>
<pre><code>XmlSerializer ser = new XmlSerializer(typeof(List<myCustomEntity>));
StringReader reader = new StringReader(xmlStringPassedToWS);
List<myCustomEntity> entities = (List<myCustomEntity>)ser.Deserialize(reader);
foreach (myCustomEntity e in entities)
{
// ...do some stuff...
foreach (myChildCollection c in entities.ChildCollection
{
// .. do some more stuff....
}
}
</code></pre>
<p>I've checked the XML resulting from the initial serialization and it does contain byte array - the child collection, as does the StringReader built above.</p>
<p>After the deserialization process, the resulting collection of custom entites is fine, except that each object in the collection does not contain any items in its child collection. (i.e. it doesn't get to "...do some more stuff..." above.</p>
<p>Can someone please explain what I am doing wrong? Is it possible to serialize ArrayLists within a generic collection of custom entities?</p>
|
<p>Depending on exactly what you are doing, there are a variety of options... Investigate the Xml Attributes in System.Xml.Serialization namespace... In particular, check out </p>
<p>[XmlArrayItem(ElementName = "")] </p>
<p>This goes on the property of a class that is typed as a collection of some kind (I think it needs to implement IList) and will be populated by the XmlDeserializer with Xml elements named "ElementName"... </p>
<p>There are a whole bunch of Xml Attributes inm this namespace that you can use to exactly control how serialization and deserialization takes place. You can create just about any class structure you want, by the appropriate decoration with the right Xml*Atttributes</p>
|
<p>Properties of serializable classes, that are to be serialized, must be Read/Write.</p>
<p>In my case above, the ArrayList property to read only, It was returning byte arrays based on a separate function where file names were added to it.</p>
<p>Once a setter was written for ArrayList property and the logic tweaked a bit throughout the Add method, the serializing works.</p>
<p>Lesson: for serializable classes that you need to reconstruct based on the serialised stream, all serialized properties need to be writable - kinda obvious when you say it lke that.</p>
| 38,568
|
<p>I'm having trouble with this code:</p>
<pre><code>NSRect itemFrame;
id item;
// code to assign item goes here.
itemFrame.origin.y -= [item respondsToSelector:@selector(selectedHeight)] ? [item selectedHeight] : [self defaultSelectedHeight];
</code></pre>
<p>This is the problematic bit:</p>
<pre><code>[item selectedHeight]
</code></pre>
<p>The compiler is assuming that the return type is id. I though that adding a cast would fix this:</p>
<pre><code>(float)[item selectedHeight]
</code></pre>
<p>but it doesn't work. </p>
<p>What am I doing wrong? (I suspect the problem is to do with resolving pointers related to id but I can't find any relevant documentation).</p>
|
<p>you want <code>[[item selectedHeight] floatValue]</code>, assuming that the selectedHeight returns an <code>NSNumber</code>.</p>
|
<p>You need to look at the declaration of your <code>selectedHeight</code> method. The problem is either that the method is returning a pointer to an object (id), or you haven't imported the header file for <code>item</code> in the file that contains the code snippet, so Xcode assumes it's a pointer by default.</p>
<p>You can't cast a pointer to a float, since they're fundamentally incompatible types. Once you get your declarations straightened out though you should be okay.</p>
| 39,524
|
<p>I know that LDAP is used to provide some information and to help facilitate authorization. </p>
<p>But what are the other usages of LDAP? </p>
|
<p>I will focus on why using LDAP, not what is LDAP.</p>
<p>The use model is similar like how people use library cards or phonebooks. When you have a task that requires “write/update once, read/query many times”, you might consider using LDAP. LDAP is designed to provide extremely fast read/query performance for a large scale of dataset. Typically you want to store only a small piece of information for each entry. The add/delete/update performance is relatively slower compared with read/query because the assumption is that you don’t do “update” that often. </p>
<p>Imagine you have a website that has a million registered users with thousands of page requests per second. Without LDAP, every time users click a page, even for static page viewing, you will probably need to interact with your database to validate the user ID and its digital signature for this login session. Obviously, the query to your database for user-validation will become your bottleneck. By using LDAP, you can easily offload the user validation and gain significant performance improvement. Essentially, in this example, LDAP is another optimization layer outside your database to enhance performance, not replacing any database functions. </p>
<p>LDAP is not just for user validation, any task that has the following properties might be a good use case for LDAP:</p>
<ol>
<li><p>You need to locate ONE piece of data many times and you want it fast</p></li>
<li><p>You don’t care about the logic and relations between different data</p></li>
<li><p>You don’t update, add, or delete the data very often</p></li>
<li><p>The size of each data entry is small</p></li>
<li><p>You don’t mind having all these small pieces of data at a centralized place</p></li>
</ol>
|
<p>LDAP is also used to store your credentials in a network security system and retrieve it with your password and decrypted key giving you access to the services.</p>
| 29,617
|
<p>What do I need to do to save an image my program has generated (possibly from the camera, possibly not) to the system photo library on the iPhone?</p>
|
<p>You can use this function:</p>
<pre><code>UIImageWriteToSavedPhotosAlbum(UIImage *image,
id completionTarget,
SEL completionSelector,
void *contextInfo);
</code></pre>
<p>You only need <strong>completionTarget</strong>, <strong>completionSelector</strong> and <strong>contextInfo</strong> if you want to be notified when the <code>UIImage</code> is done saving, otherwise you can pass in <code>nil</code>.</p>
<p>See the <a href="https://developer.apple.com/documentation/uikit/1619125-uiimagewritetosavedphotosalbum?language=objc" rel="noreferrer">official documentation for <code>UIImageWriteToSavedPhotosAlbum()</code></a>.</p>
|
<p>You can use this</p>
<pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImageWriteToSavedPhotosAlbum(img.image, nil, nil, nil);
});
</code></pre>
| 21,573
|
<p>It seems as if making the clipboard ring appear in the VS2008 toolbox is pretty elusive. Does anyone know how to turn this on ? <kbd>Ctrl</kbd>-<kbd>Shift</kbd>-<kbd>V</kbd> works fine, but I'd like to see what on the ring.</p>
|
<p>You should give <a href="http://ditto-cp.sourceforge.net/" rel="nofollow noreferrer">Ditto</a> a try. It saves everything you put in your clipboard into an sqlite database. A shortcut pops it up and shows the history of your clippings. </p>
<p>The nice thing is that you can instantly search in this window through all your clippings. </p>
<p>I set it up to remeber everything in my clipboard for 60 days and made a habit of copying everything that might be usefull. That way I can quickly find that particular SQL statement, i did last week. Just dont search for "select" ;-)</p>
<p>Try it for some days and you will be amazed. There is also a <a href="http://prdownloads.sourceforge.net/ditto-cp/Ditto_Portable_3_15_4_0.zip?download" rel="nofollow noreferrer">portable Version</a></p>
|
<p>If you drag text to the toolbox doesn't it appear?</p>
| 10,023
|
<p>I've opened the <strong>cmd in windows</strong> and I've created a directory by using <code>md</code> command. After that I've opened a text file via <code>notepad <name></code>, wrote my program and gave <code>.c</code> extention while saving the file.</p>
<p>How can I compile and run my C program to get an output? I've also other programs in my directory: how can I create .exe files for all of them?</p>
|
<p>Free (beer-free, not necessarily speech-free) C compilers for Windows include (from memory so there may be others):</p>
<ul>
<li>MinGW (Minimalist GNU for Windows)</li>
<li>MSYS</li>
<li>Cygwin</li>
<li>Eclipse CDT (which uses GNU under the covers I think)</li>
<li>Borland C++ (from their BDN museum site)</li>
<li>Visual C++ Express</li>
</ul>
|
<p>I would recommend if there is no reason to use MS windows, try linux.</p>
<p><a href="http://www.ubuntu.com/testing/intrepid/beta" rel="nofollow noreferrer">http://www.ubuntu.com/testing/intrepid/beta</a></p>
<p>The development environment is free.</p>
| 28,325
|
<p>I have a Google Web Toolkit (GWT) application and when I link to it, I want to pass some arguments/parameters that it can use to dynamically retrieve data. E.g. if it were a stock chart application, I would want my link to contain the symbol and then have the GWT app read that and make a request to some stock service. E.g. <a href="http://myapp/gwt/StockChart?symbol=GOOG" rel="noreferrer">http://myapp/gwt/StockChart?symbol=GOOG</a> would be the link to my StockChart GWT app and it would make a request to my stock info web service for the GOOG stock. </p>
<p>So far, I've been using the server-side code to add Javascript variables to the page and then I've read those variables using JSNI (JavaScript Native Interface). </p>
<p>For example:</p>
<p>In the host HTML:</p>
<pre><code><script type="text/javascript">
var stockSymbol = '<%= request.getParameter("symbol") %>';
</script>
</code></pre>
<p>In the GWT code:</p>
<pre><code>public static native String getSymbol() /*-{
return $wnd.stockSymbol;
}-*/;
</code></pre>
<p>(Although this code is based on real code that works, I've modified it for this question so I might have goofed somewhere)</p>
<p>However, this doesn't always work well in hosted mode (especially with arrays) and since JSNI wasn't around in version 1.4 and previous, I'm guessing there's another/better way. </p>
|
<p>If you want to read query string parameters from the request you can use the <strong>com.google.gwt.user.client.Window</strong> class:</p>
<pre><code>// returns whole query string
public static String getQueryString()
{
return Window.Location.getQueryString();
}
// returns specific parameter
public static String getQueryString(String name)
{
return Window.Location.getParameter(name);
}
</code></pre>
|
<p>It is also a nice option to 'parameterize' a GWT application using hash values. </p>
<p>So, instead of</p>
<pre><code> http://myapp/gwt/StockChart?symbol=GOOG
</code></pre>
<p>use</p>
<pre><code> http://myapp/gwt/StockChart#symbol=GOOG
</code></pre>
<p>There is some nice tooling support for such 'parameters' through <a href="https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsHistory" rel="nofollow">GWT's History Mechanism</a>.</p>
| 14,838
|
<p>I'm trying to print a calibration cube from PLA using a 70 °C heated build platform on a Prusa i3 Pro W. This results in:</p>
<p><a href="https://i.stack.imgur.com/G00Um.jpg)" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G00Um.jpg)" alt="Calibration cube print failed"></a></p>
<p>Please explain why it prints like this.</p>
|
<p>There are multiple issues that cause this result.</p>
<p>First, your nozzle is to far from the bed. This can be seen by the curly deposited filament on the build plate (I guess that is the brim or the skirt). Please properly level the bed and position the nozzle at a distance of a plain A4 paper as best as possible (should be doable as you have a glass sheet that are usually very flat as a result of the production process to make glass).</p>
<p>The second problem you face is layer shift. You see that the squares are printed further and further to the left, the print head does not return to original position. Layer shift is usually caused by improper belt tension or a loose grub screw of the belt pulley. <a href="/a/8167/">This answer</a> describes layer shifting in more detail. <a href="/q/8166/">This question</a> may be helpful too, the answer contains some references to layer shifting.</p>
|
<p>The layer shift can also be caused by the stepper motor "skipping" when it hits an obstruction. The obstruction can be a loop or ridge of filament sticking up higher than it should be.</p>
<p>As Oscar suggests, the first step is always to make the first-layer-thickness be right. This is often called "bed leveling", but really it is making sure that the bed defines the z=0 plane that the firmware is expecting. If it isn't planar, if it isn't constant Z (ie., it tilts in any direction), or it isn't at zero, problems follow.</p>
<p>It seems to have mostly shifted in X, so start with that motor and belt. Have you adjusted the tension correctly? Is the motor current set correctly?</p>
<p>Other things can also cause trouble, such as:</p>
<ol>
<li>A poorly mounted extruder that favors one direction</li>
<li>Bad slicer parameters that command movement faster than the printer's ability</li>
<li>Bad configuration parameters which call for acceleration or velocities beyond the printer's ability.</li>
</ol>
<p>Are the slicer settings matched to the printer? If this is a commercial printer, are you using a profile from the manufacturer? If this is your design, or heavily modded, have you tried de-tuning the slicer parameters and/or the configuration parameters?</p>
<p>Any debugging proceeds from the first step, so adjust the Z=0 plane and see if you can print a uniform, single layer print covering the while bed. When that is good, you are most of the way to victory.</p>
| 1,252
|
<p>Can the GT2 belts lengthen themselves if they are tentioned too much?</p>
<p>I had them tensioned quite a bit until I saw the <a href="https://youtu.be/zoKmmT0a7jk" rel="nofollow noreferrer">video</a> from "Lost in Tech". I then decided to reduce the tension, but the dimensional precision was all over the place. So my guess is, that the belts are too long now?</p>
|
<p>First of all there are two methods to achieve the belt be tensioned.</p>
<p>First method is when both ends of the belt hard attached. In this case if there is a fluctuation in the mechanical system then it will be absorbed by the belt itself. And in this case with big tension it will result in stretching over time with tension disappearing.</p>
<p>The second method is to use spring at one end. The spring will absorb all the fluctuations with little or no effect on the belt.</p>
<p>But I had really bad problems with GT2 PU belts (including steel reinforced), under big tension they degrade suddenly with big change in the geometry at some position. When removed they look twisted. Looks like some reinforcing wires slipped inside the PU body of the belt.</p>
<p>Once switched to rubber GT2 belts (fibreglass reinforced) I never had problems connected to the belts. I can tell that rubber GT2 belts have no noticeable change in the geometry over many years of constant use under high tension with the spring.</p>
|
<p>As I've seen in todays video from Makers Muse, he also says that these belts can lengthen over time: <div class="youtube-embed"><div>
<iframe width="640px" height="395px" src="https://www.youtube.com/embed/-cm1vIER_bk?start=338"></iframe>
</div></div> (Link with time code)</p>
| 2,141
|
<p>What is the best (cleanest, most efficient) way to write saturating addition in C?</p>
<p>The function or macro should add two unsigned inputs (need both 16- and 32-bit versions) and return all-bits-one (0xFFFF or 0xFFFFFFFF) if the sum overflows.</p>
<p>Target is x86 and ARM using gcc (4.1.2) and Visual Studio (for simulation only, so a fallback implementation is OK there).</p>
|
<p>You probably want portable C code here, which your compiler will turn into proper ARM assembly. ARM has conditional moves, and these can be conditional on overflow. The algorithm then becomes: add and conditionally set the destination to unsigned(-1), if overflow was detected.</p>
<pre class="lang-c prettyprint-override"><code>uint16_t add16(uint16_t a, uint16_t b)
{
uint16_t c = a + b;
if (c < a) /* Can only happen due to overflow */
c = -1;
return c;
}
</code></pre>
<p>Note that this differs from the other algorithms in that it corrects overflow, instead of relying on another calculation to detect overflow.</p>
<p><a href="https://gcc.godbolt.org/#%7B%22version%22%3A3%2C%22filterAsm%22%3A%7B%22labels%22%3Atrue%2C%22directives%22%3Atrue%2C%22commentOnly%22%3Atrue%2C%22intel%22%3Atrue%7D%2C%22compilers%22%3A%5B%7B%22sourcez%22%3A%22MQSwdgxgNgrgJgUwAQB4DOAXO4MDoAWAfAFCgBmSAjEjQPS1IgQRICGAbgPYhxpIQBbTuyQB3EBnxJJCNMnBIBaVlAwIATmgDkSdhrQhOYUojLhkUEAGsEUAJ4AKAB4BKGu5oB9TwCMYIVXBPBCcABwQIDAcAQmjnFwAaKhcTBDMwZBgwSxt7eI8kbz8AjCCQ8MiYuNckgAYU4Fs5VPSLa1tHVwKaJxbzJCycjvyPXsawbDJiYnokAGVOdTU4RjAkRcR1dYooBFZMJB9WFaMkJwAOADYk8UkkAHNmAFZp%2FzAMSkvPDDY4Xk%2FPEoVGpNA43h8vj9WElwQCfj43ABvYg0WGQ%2FhIAC8bCQAGpDgBuFGMCgOCAoVhuWgAKiQAGFWGsjPYkPhWKFwms4DBkBhOOs9OoyFBOKIkNTaMSaCxsQBaShEmjqBAYGDqNYQIkAX2I4IAzAAmb6%2FXiGwHKVT6ME4M1QmE2o3wpHE%2FWOjHY1h4wnEkCk8mUpA0%2BmM9bZOys9mcpDc3n84QaYWi8WSjwypDyxVIZWq9X8bXTcjRtLmFYObwgPVXbxuAA%2BNaLrVL3guX0uABZqzMGAAVADyABFewAuJC7H4yficAShAIaJBWMBJySscf4ZCccLqRm8NjK1YgiBssD3PY%2BXbTWY8PZQFmHiJWQqeECXKueJBkRb8ITsJJ%2BVcrrQ%2BGZcNTBLd9PxDVhIhgFRGBfS5pFYdQTwwJJFx%2BBBcHuXAIzQURbCgXUHWNY5TSNFtPFCAArCBAWEa13ltNh7UYt0EWIRE6AYNB8EWEF%2BHUCQmBUWVQhXKQoBXBBIHDHxwyMZAIDsaBeSPaQ1yQNAfB8XR9EMYwPFdY0MGnLF0wVKVuis9xZk4gBBbsADJuw8esAEl3lsJAtRoNA7HeVgnDYS11RXEA9DQHCkG7DTOBkLZBQMIw%2BFuXiYFXEA%2BDEAIoEOZVWAfVL0wEfYBExHBbEs0qkAcAAiUiCk4gBSABtHwAF0Ela1h2vcetus6mhWo67yAB0wFGjBassgpasEYRIBoZqWp6rqWt4DBev69bME6gbvOm6ykBHHbNqQWrcXUWqapM0JEiQFbeouxyrpqykZo8E6Rtq%2B5rocBFAwYGA5HO9QBAQa6Py2T12x8CRdM0fSkgMSB5B%2BTAcoGOQ%2BENOH0ZAe4wFlEI1AmBAVhAARwewKSPpshhF34EVtP0OmaBcTMlRVNU1lu%2FMjKhP40DNCjqNorSfAYjAmOhAZiKdDiuM0kqbznCBOEQWUDAALwQX90tHIwTy2CBBNKCARLEu5JNJpSarbFhTgACX2fCbySPVHbWOyAFl%2BzYCYkAAIXUThjjdqBaDmKw7EkmwUnpzTtMYIDeY002hIt3KrfwGFsnaRRhHMqKJYDlZ5pEJDVOQZRwdHKSZNDYLcrpAAFABVNApVmUva71vvo04WQwC0eF8ofCdEE5RBG9OCdOCgFZ2BUHltmjA5TkZcMYPUQ8kBCCAEFCH5ff7SyBekadObYNABBq%2Bq%2FgKYbBoG8bJsO6zatLjxWo2l%2FTvam%2FKabNzqfifo9JIv9dofysidP%2B51MSvQcLde6j1zq4hen9d6R0vpPV%2BjVdiR0OaWWzDzS%2BoR%2BbyxNMLciVYxZPjAKESSh8pYyxYtLNiKROJKwtmsZUwNq6aVYHXeUWYED3EyiCfWPxeGjyQKEUO3JD7qWQMqNAMBVCrBxBkMUyoJGYA0FVW%2B98GpIGfpAx6QCYHdDmt%2BFgrVlCbQsT1axBQTo9XQZgt6CdrK4POvg%2F6qDHFPSQfKKkDB1YaJWAIgOoMBDXXVmATAW4cBNxasE6RhtjjgHuOZd8oc77gyEOocMmVowwAED4ZG%2FJMAbiZoyXJZACmaV4nFHJjAMByCgBQBQE4PxxRAcQjwpDcysHzOMSYrwkkEwyCsRxaopKeFIp4cEngbDsHAGCaZhNyZnDzgYHZKw7DOg8L6GqdhCDtzcgAOW7GaH2dkAAasougjLWFc259ynnXzeWcXEdhKHvDhEIv4AJlRCClsC2WaJjSEPcJxX5DhPSECQLUJwAAxTF6L0yHDcAAflRRirFx0cT4h8ASbyrwqHKD%2BGacFnBWFumhVQuFS0xE5jWEipAKK0VYr5di2UuKkAEt5fyzFJLPRkoJDqaYRFWLGhpXAOljKSLsKYgDbhswmlTiQAAJVwOfHA7YFVmSlsajALhWC4nJSQ7muZZQODQIQQghpaw1QFi4NA%2BY%2BgZBBXAT4SLfxuHdTgOELgHA1RVRapFLhcRRvDQiNwPKnBkFTRQEVKa00kocDGuNiaUgX0VWaDcUbmJy3lU6JACK7Wco9RGnN4JzXhspHGxtHZo2Ju5YStNPb03dt7am7NubAkuA5pSi8QMwBQ1VGAKSt4pwzl2HwPk0hRD8kSdgUoRhYI%2BC3JANcQETbflkL%2BCIrAYnq2nLOTQg8R4%2FHuKHCe%2BBMpyo4QqlcCy1BLNpUaOAJ53glNLcyitQrkSGWpRUsykrvSnNJI6yDKA2C1nrPBu%2BiHE1s1%2BQAPwbfLFw9Rr5NAQJhmtmkKnakDLSeZW4v2kUNMmV9wLqOLNIgCP90kMCAZhXactEJYUnPcNxsjd8PRehtbByN6i0NIaQHWGqUnUC4p8d0bDuGgWQnw0M9wRGSMcuExRoMzHaOgoQhKWVXZooHuQP%2BjQUlWSLEEmeRSGtkBDgcBZuYAB1OyuqkDnC0YaV9TE5grjsn8du2zZnnE8F5nzngwABDQKWpwaq3THKrS6alMySpoAfNiNF5xaiFeK7UTMF8MC1FNeGAAemcNwjlNLZf2FYMrVCPhVaQA1roDWDlgByy14kQVHLYiw71%2FrmZwzDaQKNpruXMxBVxNiAFxJ2s1mxBVzrZxMztexMg6gKBEOUDcIKvb3KUUAHYtOIqCrVirbqPiArfT8ELGAwtwAi718mZoEtQD4Ml1Lxp0tgd40xMbzWzIFdqFD6HpXMsgY27tmrdXNtg7m3Dp70hqCI8291xrhNxuDc6yN1HA2aCTeJ7N0nZw8RLe29QNb0hKtdbp6a9rB3kg4tO86pAeojuZmu0gW79RZOY%2B9RZz7cyP00f0sQLLhzPCKs8C7MAi44BUQQA4KhssWUuGBzQCDIm2DWuvlQ%2BMQoRRil20i6rUmXCOX%2Bjbipo7nW85%2BaRhwZvEyiAO7zlw1XUPc494KL3jlffEJlakkqmzdc6iAAAA%22%2C%22compiler%22%3A%22g530%22%2C%22options%22%3A%22-xc%20-Wall%20-fverbose-asm%20%20-O3%20-mtune%3Dhaswell%22%7D%5D%7D" rel="noreferrer">x86-64 clang 3.7 -O3 output for adds32</a>: significantly better than any other answer:</p>
<pre class="lang-asm prettyprint-override"><code>add edi, esi
mov eax, -1
cmovae eax, edi
ret
</code></pre>
<p><a href="https://gcc.godbolt.org/#%7B%22version%22%3A3%2C%22filterAsm%22%3A%7B%22labels%22%3Atrue%2C%22directives%22%3Atrue%2C%22commentOnly%22%3Atrue%7D%2C%22compilers%22%3A%5B%7B%22sourcez%22%3A%22MQSwdgxgNgrgJgUwAQB4DOAXO4MDoAWAfAFCgBmSAjEjQPS1IgQRICGAbgPYhxpIQBbTuyQB3EBnxJJCNMnBIBaVlAwIATmgDkSdhrQhOYUojLhkUEAGsEUAJ4AKAB4BKGu5oB9TwCMYIVXBPBCcABwQIDAcAQmjnFwAaKhcTBDMwZBgwSxt7eI8kbz8AjCCQ8MiYuNckgAYU4Fs5VPSLa1tHVwKaJxbzJCycjvyPXsawbDJiYnokAGVOdTU4RjAkRcR1dYooBFZMJB9WFaMkJwAOADYk8UkkAHNmAFZp%2FzAMSkvPDDY4Xk%2FPEoVGpNA43h8vj9WElwQCfj43ABvYg0WGQ%2FhIAC8bCQAGpDgBuFGMCgOCAoVhuWgAKiQAGFWGsjPYkPhWKFwms4DBkBhOOs9OoyFBOKIkNTaMSaCxsQBaShEmjqBAYGDqNYQIkAX2I4IAzAAmb6%2FXiGwHKVT6ME4M1QmE2o3wpHE%2FWOjHY1h4wnEkCk8mUpA0%2BmM9bZOys9mcpDc3n84QaYWi8WSjwypDyxVIZWq9X8bXTcjRtLmFYObwgPVXbxuAA%2BNaLrVL3guX0uABZqzMGAAVADyABFewAuJC7H4yficAShAIaJBWMBJySscf4ZCccLqRm8NjK1YgiBssD3PY%2BXbTWY8PZQFmHiJWQqeECXKueJBkRb8ITsJJ%2BVcrrQ%2BGZcNTBLd9PxDVhIhgFRGBfS5pFYdQTwwJJFx%2BBBcHuXAIzQURbCgXUHWNY5TSNFtPFCAArCBAWEa13ltNh7UYt0EWIRE6AYNB8EWEF%2BHUCQmBUWVQhXKQoBXBBIHDHxwyMZAIDsaBeSPaQ1yQNAfB8XR9EMYwPFdY0MGnLF0wVKVuis9xZk4gBBbsADJuw8esAEl3lsJAtRoNA7HeVgnDYS11RXEA9DQHCkG7DTOBkLZBQMIw%2BFuXiYFXEA%2BDEAIoEOZVWAfVL0wEfYBExHBbEs0qkAcAAiUiCk4gBSABtHwAF0Ela1h2vcetus6mhWo67yAB0wFGjBassgpasEYRIBoZqWp6rqWt4DBev69bME6gbvOm6ykBHHbNqQWrcXUWqapM0JEiQFbeouxyrpqykZo8E6Rtq%2B5rocBFAwYGA5HO9QBAQa6Py2T12x8CRdM0fSkgMSB5B%2BTAcoGOQ%2BENOH0ZAe4wFlEI1AmBAVhAARwewKSPpshhF34EVtP0OmaBcTMlRVNU1lu%2FMjKhP40DNCjqNorSfAYjAmOhAZiKdDiuM0kqbznCBOEQWUDAALwQX90tHIwTy2CBBNKCARLEu5JNJpSarbFhTgACX2fCbySPVHbWOyAFl%2BzYCYkAAIXUThjjdqBaDmKw7EkmwUnpzTtMYIDeY002hIt3KrfwGFsnaRRhHMqKJYDlZ5pEJDVOQZRwdHKSZNDYLcrpAAFABVNApVmUva71vvo04WQwC0eF8ofCdEE5RBG9OCdOCgFZ2BUHltmjA5TkZcMYPUQ8kBCCAEFCH5ff7SyBekadObYNABBq%2Bq%2FgKYbBoG8bJsO6zatLjxWo2l%2FTvam%2FKabNzqfifo9JIv9dofysidP%2B51MSvQcLde6j1zq4hen9d6R0vpPV%2BjVdiR0OaWWzDzS%2BoR%2BbyxNMLciVYxZPjAKESSh8pYyxYtLNiKROJKwtmsZUwNq6aVYHXeUWYED3EyiCfWPxeGjyQKEUO3JD7qWQMqNAMBVCrBxBkMUyoJGYA0FVW%2B98GpIGfpAx6QCYHdDmt%2BFgrVlCbQsT1axBQTo9XQZgt6CdrK4POvg%2F6qDHFPSQfKKkDB1YaJWAIgOoMBDXXVmATAW4cBNxasE6RhtjjgHuOZd8oc77gyEOocMmVowwAED4ZG%2FJMAbiZoyXJZACmaV4nFHJjAMByCgBQBQE4PxxRAcQjwpDcysHzOMSYrwkkEwyCsRxaopKeFIp4cEngbDsHAGCaZhNyZnDzgYHZKw7DOg8L6GqdhCDtzcgAOW7GaH2dkAAasougjLWFc259ynnXzeWcXEdhKHvDhEIv4AJlRCClsC2WaJjSEPcJxX5DhPSECQLUJwAAxTF6L0yHDcAAflRRirFx0cT4h8ASbyrwqHKD%2BGacFnBWFumhVQuFS0xE5jWEipAKK0VYr5di2UuKkAEt5fyzFJLPRkoJDqaYRFWLGhpXAOljKSLsKYgDbhswmlTiQAAJVwOfHA7YFVmSlsajALhWC4nJSQ7muZZQODQIQQghpaw1QFi4NA%2BY%2BgZBBXAT4SLfxuHdTgOELgHA1RVRapFLhcRRvDQiNwPKnBkFTRQEVKa00kocDGuNiaUgX0VWaDcUbmJy3lU6JACK7Wco9RGnN4JzXhspHGxtHZo2Ju5YStNPb03dt7am7NubAkuA5pSi8QMwBQ1VGAKSt4pwzl2HwPk0hRD8kSdgUoRhYI%2BC3JANcQETbflkL%2BCIrAYnq2nLOTQg8R4%2FHuKHCe%2BBMpyo4QqlcCy1BLNpUaOAJ53glNLcyitQrkSGWpRUsykrvSnNJI6yDKA2C1nrPBu%2BiHE1s1%2BQAPwbfLFw9Rr5NAQJhmtmkKnakDLSeZW4v2kUNMmV9wLqOLNIgCP90kMCAZhXactEJYUnPcNxsjd8PRehtbByN6i0NIaQHWGqUnUC4p8d0bDuGgWQnw0M9wRGSMcuExRoMzHaOgoQhKWVXZooHuQP%2BjQUlWSLEEmeRSGtkBDgcBZuYAB1OyuqkDnC0YaV9TE5grjsn8du2zZnnE8F5nzngwABDQKWpwaq3THKrS6alMySpoAfNiNF5xaiFeK7UTMF8MC1FNeGAAemcNwjlNLZf2FYMrVCPhVaQA1roDWDlgByy14kQVHLYiw71%2FrmZwzDaQKNpruXMxBVxNiAFxJ2s1mxBVzrZxMztexMg6gKBEOUDcIKvb3KUUAHYtOIqCrVirbqPiArfT8ELGAwtwAi718mZoEtQD4Ml1Lxp0tgd40xMbzWzIFdqFD6HpXMsgY27tmrdXNtg7m3Dp70hqCI8291xrhNxuDc6yN1HA2aCTeJ7N0nZw8RLe29QNb0hKtdbp6a9rB3kg4tO86pAeojuZmu0gW79RZOY%2B9RZz7cyP00f0sQLLhzPCKs8C7MAi44BUQQA4KhssWUuGBzQCDIm2DWuvlQ%2BMQoRRil20i6rUmXCOX%2Bjbipo7nW85%2BaRhwZvEyiAO7zlw1XUPc494KL3jlffEJlakkqmzdc6iAAAA%22%2C%22compiler%22%3A%22armhfg482%22%2C%22options%22%3A%22-xc%20-std%3Dgnu99%20-Wall%20-pedantic%20-Wextra%20-fverbose-asm%20%20-O3%20-march%3Darmv7%22%7D%5D%7D" rel="noreferrer">ARMv7: <code>gcc 4.8 -O3 -mcpu=cortex-a15 -fverbose-asm</code> output for adds32</a>:</p>
<pre class="lang-asm prettyprint-override"><code>adds r0, r0, r1 @ c, a, b
it cs
movcs r0, #-1 @ conditional-move
bx lr
</code></pre>
<p>16bit: still doesn't use ARM's unsigned-saturating add instruction (<code>UADD16</code>)</p>
<pre class="lang-asm prettyprint-override"><code>add r1, r1, r0 @ tmp114, a
movw r3, #65535 @ tmp116,
uxth r1, r1 @ c, tmp114
cmp r0, r1 @ a, c
ite ls @
movls r0, r1 @,, c
movhi r0, r3 @,, tmp116
bx lr @
</code></pre>
|
<p>Using C++ you could write a more flexible variant of <em>Remo.D</em>'s solution:</p>
<pre><code>template<typename T>
T sadd(T first, T second)
{
static_assert(std::is_integral<T>::value, "sadd is not defined for non-integral types");
return first > std::numeric_limits<T>::max() - second ? std::numeric_limits<T>::max() : first + second;
}
</code></pre>
<p>This can be easily translated to C - using the limits defined in <code>limits.h</code>. Please also note that the <a href="http://en.cppreference.com/w/cpp/types/integer" rel="nofollow">Fixed width integer types</a> might not been available on your system.</p>
| 14,747
|
<p>One of the things mentioned recently maybe in the SO podcast or Joel was that the best way to succeed at business when you start out is to start specialised and concentrate on one thing only.</p>
<p>If you say you're the jack of all trades; you're just another jack! If you say you're a specialist in - I think joels example was some type of faucets - then even though you think you've just removed most of your market; you've actually increased the odds of getting business in a specific marked as you'll stand out more against the rest; somebody somewhere will want what you more than if you just say you do everything.</p>
<p>So anyway, my question is; I'd like to specialise myself in something. I've been doing C/C++ for a long time but never really pegged myself as either win32, mfc, directx, wxWidgets, qt, boost, sdl, allegro, etc etc. I've tried everything and done different things in each; I've also started moving into actually writing for linux (and now osx) as apposed to just using it so my opportunities have grown even further.</p>
<p>My view was that the more I know the less likely I am to become stagnant and stuck; if I know bits of each I can get a job anywhere and then learn more as I need it.</p>
<p>Over the last couple years I also took on .NET and then PHP/LAMP; I feel quite comfortable in either but I guess in my heart I'm still a C++ guy (although I think I've learned more commercial things in PHP than I have done with c++).</p>
<p>The other issue I feel is that the world is becoming highly web-based, and technologies such as C++ are becoming less and less used (ignoring Google's new tool - can't remember the name) and other things like flash and flex are becoming more popular. I do agree that the tools we use to view the web are written in C++/like but in terms of market share I think all the bases are already covered.</p>
<p>I was wondering how people decide what peg to eventually pick and why; and is this for business reasons (i.e. it makes more money) or for selfish reasons (i.e. I feel complete by writing things in C++ as apposed to PHP).</p>
<p>Maybe i'm asking the wrong question; maybe I should by specialising in a specific product rather than a language as a service; Didn't think of that...</p>
<p>Cheers,
Chris</p>
|
<p>I'd guess that most people choose a reason (interest, money) to head in a particular direction at the beginning of their careers, and the rest is largely serendipitous.</p>
<p>I still try to keep a broad general knowledge across the technologies related to my current and imminent responsibilities (and those of my friends and coworkers, so I can understand our conversations). But I've specialized in those that are necessary to stay "ahead of the curve" in my specific domain, or are unrelated but interesting to me, and I've dabbled in still others by osmosis.</p>
<p>You noted that "the world is becoming highly web-based, and technologies such as C++ are becoming less and less used." So you can either "follow the herd" and chase the new tools and methods, or you can find a niche in the areas that are creating them. I've chosen the latter because, although there may be fewer positions available, I find them more challenging and rewarding both intellectually and financially. Oh, and there's less competition!</p>
<p>As you advance through your career, you'll find that many technologies are very similar, with a lot of overlap. Once you've covered the basics, it becomes less important to know any specific platform or language, and more important to understand the techniques and processes that lead to effective, robust, high-quality products.</p>
<p>Good luck!</p>
|
<p>For people just starting out in the business it probably makes sense to specialize, cause they need something in order to compete. </p>
<p>For more experienced developers I agree with what The Pragmatic Programmer book suggests, namely that as a professional developer, you should always try to add more useful tools to your toolbox. E.g. they suggest picking up new programming languages on a regular basis etc. </p>
<p>If you do that, you will obviously not become a black belt in all of these areas, but you will broaden your horizon and learn to look at problems from different angels, which is very useful imo.</p>
| 48,952
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.