input
stringlengths
51
42.3k
output
stringlengths
18
55k
How can I read raw (CF_HTML) clipboard data in a webpage or C#? <p>If I drag and drop a selection of a webpage from Firefox to HTML-Kit, HTML-Kit asks me whether I want to paste as text or HTML. If I select "text," I get this:</p> <pre><code>Version:0.9 StartHTML:00000147 EndHTML:00000516 StartFragment:00000181 EndFragment:00000480 SourceURL:http://en.wikipedia.org/wiki/Herodotus &lt;html&gt;&lt;body&gt; &lt;!--StartFragment--&gt;Additional details have been garnered from the &lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/Suda" title="Suda"&gt;Suda&lt;/a&gt;&lt;/i&gt;, an 11th-century encyclopaedia of the &lt;a href="http://en.wikipedia.org/wiki/Byzantium" title="Byzantium"&gt;Byzantium&lt;/a&gt; which likely took its information from traditional accounts.&lt;!--EndFragment--&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ms649015(VS.85).aspx" rel="nofollow">According to MSDN</a>, this is "CF_HTML" formatted clipboard data. Is it the same on OS X and Linux systems? </p> <p>Is there any way to access this kind of detailed information (as opposed to just the plain clip fragment) in a webpage-to-webpage drag and drop operation? What about to a C# WinForms desktop application?</p>
<p>It is Microsoft specific, don't expect to see the same information in other OSes.<br /> Note that you get the same format when you copy a fragment from IE.</p> <p>I am not sure what you mean by "webpage-to-webpage drag and drop operation". To drop where? A textarea?</p> <p>I don't know C#, but in C/C++ applications, you have to use OpenClipboard and related Win32 APIs to get this info. In particular, GetClipboardData(CF_HTML) allows you to get this info (can be obtained in plain text too, for example, or Unicode data, etc.).</p>
How do you make a generic memoize function in Haskell? <p>I've seen <a href="http://stackoverflow.com/questions/129877/how-do-i-write-a-generic-memoize-function">the other post about this</a>, but is there a clean way of doing this in Haskell?</p> <p>As a 2nd part, can it also be done without making the function monadic?</p>
<p>The package data-memocombinators on hackage provides lots of reusable memoization routines. The basic idea is:</p> <pre><code>type Memo a = forall r. (a -&gt; r) -&gt; (a -&gt; r) </code></pre> <p>I.e. it can memoize any function from a. The module then provides some primitives (like <code>unit :: Memo ()</code> and <code>integral :: Memo Int</code>), and combinators for building more complex memo tables (like <code>pair :: Memo a -&gt; Memo b -&gt; Memo (a,b)</code> and <code>list :: Memo a -&gt; Memo [a]</code>).</p>
How do you compare structs for equality in C? <p>How do you compare two instances of structs for equality in standard C?</p>
<p>C provides no language facilities to do this - you have to do it yourself and compare each structure member by member.</p>
KornShell (ksh) wraparound <p>Okay, I am sure this is simple but it is driving me nuts. I recently went to work on a program where I have had to step back in time a bit and use Redhat 9. When I'm typing on the command line from a standard xterm running KornShell (ksh), and I reach the end of the line the screen slides to the right (cutting off the left side of my command) instead of wrapping the text around to a new line. This makes things difficult for me because I can't easily copy and paste from the previous command straight from the command line. I have to look at the history and paste the command from there. In case you are wondering, I do a lot of command-line awk scripts that cause the line to get quite long. </p> <p>Is there a way to force the command line to wrap instead of shifting visibility to the right side of the command I am typing? </p> <p>I have poured through man page options with no luck. </p> <p>I'm running:</p> <ul> <li>XFree86 4.2.99.903(174)</li> <li>KSH 5.2.14. </li> </ul> <p>Thanks.</p>
<p>Did you do <code>man ksh</code>?</p> <p>You want to do a <code>set -o multiline</code>.</p> <p>Excerpt from <code>man ksh</code>:</p> <blockquote> <p>multiline: </p> <blockquote> <p>The built-in editors will use multiple lines on the screen for lines that are longer than the width of the screen. This may not work for all terminals.</p> </blockquote> </blockquote>
How can I programmatically repair (not merely compact) an Access .mdb file? <p>I have a corrupt database. If I open it in MS Access, MS Access offers to repair it, and it succeeds.</p> <p>How can I do that with code? On a machine where MS Access is not installed.</p> <p>I know from trying it that JRO.JetEngine.CompactDatabase does NOT work.</p> <p>In other words, I want to do what Access or JETCOMP.exe is doing, not what JRO.JetEngine.CompactDatabase is doing.</p>
<p>You need to go to <a href="http://support.microsoft.com" rel="nofollow">http://support.microsoft.com</a> and search for the JetComp.exe utility, which will attempt to repair and compact your MDB without opening the file. The reason none of the suggestions above work is because they have to open the MDB to do their work, whereas JetComp doesn't open the file, but operates on it structurally.</p> <p>If it can't recover your file (which does happen), then you'll have to go to a data recovery service. I recommend Peter Miller of PKSolutions.com.</p>
Which Haskell package contains given module <p>I know a Haskell module name, but I can't figure out in what package it is defined. This is bad because I can't compile without a package exposing this module.</p> <p>Specificaly it is Text.Regex that I can't locate, but I would like to know how to solve that problem in general.</p>
<p><a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/packages.html">http://www.haskell.org/ghc/docs/latest/html/users_guide/packages.html</a></p> <p>ghc-pkg find-module Text.Regex</p> <p>But that only works for (a) recent GHCs, and (b) packages installed on your system.</p> <p>You can also grep through the package file (e.g. /usr/lib/ghc-6.8.2/package.conf) to see what's installed.</p> <p>You can also use either the haskell API search engines <a href="http://www.haskell.org/hoogle/">hoogle</a> or the <a href="http://hackage.haskell.org/packages/hackage.html">hackage</a> search engine <a href="http://holumbus.fh-wedel.de/hayoo/hayoo.html">hayoo</a>.</p> <p>Text.Regex is in the package regex-base, and a few others built on top of it.</p>
class with valueTypes fields and boxing <p>I'm experimenting with generics and I'm trying to create structure similar to Dataset class.<br> I have following code</p> <pre><code>public struct Column&lt;T&gt; { T value; T originalValue; public bool HasChanges { get { return !value.Equals(originalValue); } } public void AcceptChanges() { originalValue = value; } } public class Record { Column&lt;int&gt; id; Column&lt;string&gt; name; Column&lt;DateTime?&gt; someDate; Column&lt;int?&gt; someInt; public bool HasChanges { get { return id.HasChanges | name.HasChanges | someDate.HasChanges | someInt.HasChanges; } } public void AcceptChanges() { id.AcceptChanges(); name.AcceptChanges(); someDate.AcceptChanges(); someInt.AcceptChanges(); } } </code></pre> <p>Problem I have is that when I add new column I need to add it also in HasChanges property and AcceptChanges() method. This just asks for some refactoring.<br> So first solution that cames to my mind was something like this:</p> <pre><code>public interface IColumn { bool HasChanges { get; } void AcceptChanges(); } public struct Column&lt;T&gt; : IColumn {...} public class Record { Column&lt;int&gt; id; Column&lt;string&gt; name; Column&lt;DateTime?&gt; someDate; Column&lt;int?&gt; someInt; IColumn[] Columns { get { return new IColumn[] {id, name, someDate, someInt}; }} public bool HasChanges { get { bool has = false; IColumn[] columns = Columns; //clone and boxing for (int i = 0; i &lt; columns.Length; i++) has |= columns[i].HasChanges; return has; } } public void AcceptChanges() { IColumn[] columns = Columns; //clone and boxing for (int i = 0; i &lt; columns.Length; i++) columns[i].AcceptChanges(); //Here we are changing clone } } </code></pre> <p>As you can see from comments we have few problems here with struct cloning. Simple solution to this is to change Column to class, but from my tests it seems that it increases memory usage by ~40% (because of each object metadata) which is not acceptable for me. <br> <br> So my question is: does anyone have any other ideas how to create methods that can work on different structured objects/records? Maybe someone from F# community can suggest how such problems are solved in functional languages and how it impacts performance and memory usage. <br> <br> <strong>Edit:</strong><br> sfg thanks for suggestion about macros.<br> In Visual Studio 2008 there is built-in (but not so known) template engine called T4. Tha whole point is to add '.tt' file to my project and create a template that will search all my classes, recognize somehow the ones that are records (for example by some interface they implement) and produce partial classes with HasChanges and AcceptChanges() that will call only Columns the class contain.<br><br> Some usefull links:<br> <a href="http://www.t4editor.net/" rel="nofollow" title="T4 Editor for VS">T4 Editor for VS</a><br> <a href="http://www.olegsych.com/2007/12/text-template-transformation-toolkit/" rel="nofollow" title="Blog with links and tutorials about T4">Blog with links and tutorials about T4</a><br> <a href="http://www.olegsych.com/2008/07/t4-template-for-generating-sql-view-from-csharp-enumeration/" rel="nofollow" title="Blog entry with example that uses EnvDTE to read project files">Blog entry with example that uses EnvDTE to read project files</a></p>
<p>As you asked for examples from functional languages; in lisp you could prevent the writing of all that code upon each addition of a column by using a macro to crank the code out for you. Sadly, I do not think that is possible in C#. </p> <p>In terms of performance: the macro would be evaluated at compile time (thus slowing compilation a tiny amount), but would cause no slow-down at run-time as the run-time code would be the same as what you would write manually.</p> <p>I think you might have to accept your original AcceptChanges() as you need to access the structs directly by their identifiers if you want to avoid writing to cloned versions.</p> <p>In other words: you need a program to write the program for you, and I do not know how to do that in C# without going to extraordinary lengths or losing more in performance than you ever would by switching the structs to classes (e.g. reflection).</p>
jQuery override form submit not working when submit called by javascript on a element <p>I've got a page with a normal form with a submit button and some jQuery which binds to the form submit event and overrides it with <code>e.preventDefault()</code> and runs an AJAX command. This works fine when the submit button is clicked but when a link with <code>onclick='document.formName.submit();'</code> is clicked, the event is not caught by the AJAX form submit event handler. Any ideas why not or how to get this working without binding to all the a elements?</p>
<p>A couple of suggestions:</p> <ul> <li>Overwrite the submit function to do your evil bidding</li> </ul> <pre><code> var oldSubmit = form.submit; form.submit = function() { $(form).trigger("submit"); oldSubmit.call(form, arguments); } </code></pre> <ul> <li>Why not bind to all the &lt;a&gt; tags? Then you don't have to do any monkey patching, and it could be as simple as (assuming all the links are inside the form tag):</li> </ul> <pre><code> $("form a").click(function() { $(this).parents().filter("form").trigger("submit"); }); </code></pre>
Can XPath do a foreign key lookup across two subtrees of an XML? <p>Say I have the following XML...</p> <pre><code>&lt;root&gt; &lt;base&gt; &lt;tent key="1" color="red"/&gt; &lt;tent key="2" color="yellow"/&gt; &lt;tent key="3" color="blue"/&gt; &lt;/base&gt; &lt;bucket&gt; &lt;tent key="1"/&gt; &lt;tent key="3"/&gt; &lt;/bucket&gt; &lt;/root&gt; </code></pre> <p>...what would the XPath be that returns that the "bucket" contains "red" and "blue"?</p>
<p>If you're using XSLT, I'd recommend setting up a key:</p> <pre><code>&lt;xsl:key name="tents" match="base/tent" use="@key" /&gt; </code></pre> <p>You can then get the <code>&lt;tent&gt;</code> within <code>&lt;base&gt;</code> with a particular <code>key</code> using</p> <pre><code>key('tents', $id) </code></pre> <p>Then you can do</p> <pre><code>key('tents', /root/bucket/tent/@key)/@color </code></pre> <p>or, if <code>$bucket</code> is a particular <code>&lt;bucket&gt;</code> element,</p> <pre><code>key('tents', $bucket/tent/@key)/@color </code></pre>
C# Lambda Expressions or Delegates as a Properties or Arguments <p>I'm looking to create an ValidationRule class that validates properties on an entity type object. I'd really like to set the name of the property to inspect, and then give the class a delegate or a lambda expression that will be evaluated at runtime when the object runs its IsValid() method. Does anyone have a snippet of something like this, or any ideas on how to pass an anonymous method as an argument or property?</p> <p>Also, I'm not sure if I'm explaining what I'm trying to accomplish so please ask questions if I'm not being clear.</p>
<p>Really, what you want to use is <code>Func&lt;T,bool&gt;</code> where T is the type of the item you want to validate. Then you would do something like this</p> <pre><code>validator.AddValidation(item =&gt; (item.HasEnoughInformation() || item.IsEmpty()); </code></pre> <p>you could store them in a <code>List&lt;Func&lt;T,bool&gt;&gt;</code>.</p>
VBScript Excel Formatting .xlsx files <p>Basically I want to know how to set center alignment for a cell using VBScript...</p> <p>I've been googling it and can't seem to find anything that helps.</p>
<pre><code>Set excel = CreateObject("Excel.Application") excel.Workbooks.Add() ' create blank workbook Set workbook = excel.Workbooks(1) ' set A1 to be centered. workbook.Sheets(1).Cells(1,1).HorizontalAlignment = -4108 ' xlCenter constant. workbook.SaveAs("C:\NewFile.xls") excel.Quit() set excel = nothing 'If the script errors, it'll give you an orphaned excel process, so be warned. </code></pre> <p>Save that as a .vbs and run it using the command prompt or double clicking.</p>
Explicit code parallelism in c++ <p>Out of order execution in CPUs means that a CPU can reorder instructions to gain better performance and it means the CPU is having to do some very nifty bookkeeping and such. There are other processor approaches too, such as hyper-threading.</p> <p>Some fancy compilers understand the (un)interrelatedness of instructions to a limited extent, and will automatically interleave instruction flows (probably over a longer window than the CPU sees) to better utilise the processor. Deliberate compile-time interleaving of floating and integer instructions is another example of this.</p> <p>Now I have highly-parallel task. And I typically have an ageing single-core x86 processor without hyper-threading.</p> <p>Is there a straight-forward way to get my the body of my 'for' loop for this highly-parallel task to be interleaved so that two (or more) iterations are being done together? (This is slightly different from 'loop unwinding' as I understand it.)</p> <p>My task is a 'virtual machine' running through a set of instructions, which I'll really simplify for illustration as:</p> <pre>void run(int num) { for(int n=0; n&lt;num; n++) { vm_t data(n); for(int i=0; i&lt;data.len(); i++) { data.insn(i).parse(); data.insn(i).eval(); } } }</pre> <p>So the execution trail might look like this:</p> <pre>data(1) insn(0) parse data(1) insn(0) eval data(1) insn(1) parse ... data(2) insn(1) eval data(2) insn(2) parse data(2) insn(2) eval</pre> <p>Now, what I'd like is to be able to do two (or more) iterations explicitly in parallel:</p> <pre>data(1) insn(0) parse data(2) insn(0) parse \ processor can do OOO as these two flow in data(1) insn(0) eval / data(2) insn(0) eval \ OOO opportunity here too data(1) insn(1) parse / data(2) insn(1) parse</pre> <p>I know, from profiling, (e.g. using Callgrind with --simulate-cache=yes), that parsing is about random memory accesses (cache missing) and eval is about doing ops in registers and then writing results back. Each step is several thousand instructions long. So if I can intermingle the two steps for two iterations at once, the processor will hopefully have something to do whilst the cache misses of the parse step are occurring...</p> <p>Is there some c++ template madness to get this kind of explicit parallelism generated?</p> <p>Of course I can do the interleaving - and even staggering - myself in code, but it makes for much less readable code. And if I really want unreadable, I can go so far as assembler! But surely there is some pattern for this kind of thing?</p>
<p>Given optimizing compilers and pipelined processors, I would suggest you just write clear, readable code.</p>
Setting up our new Dev server What is the easiest way to assign multiple IP addresses <p>I'm setting up our new Dev server, what is the easiest way to assign multiple IP addresses to Windows 2008 Server Network Adapter?</p> <p>I'm setting up our development machine, running IIS 7 and want to have the range between 192.168.1.200 - .254 available when I'm setting up a new website in IIS 7.</p>
<pre><code>&gt; netsh interface ipv4 add address "Local Area Connection" 192.168.1.201 255.255.255.0 </code></pre> <p>Wrap in a cmd.exe "for" loop to add multiple IPs.</p> <p>EDIT: (from Brian) "Local Area Connection" above is a placeholder, make sure you use the actual network adapter name on your system.</p>
How do you version your projects? <p>I understand that Microsoft uses this template when versioning their products: Major.Minor.Build.Revision. </p> <p>Major is changed when the "developers" want to show that there is a big change in the software and backward compatibility cannot be assumed. Maybe a major rewrite of the code is done. </p> <p>Minor number represents a significant enhancement with the intention of backward compatibility. </p> <p>Build number is a small change, for example a recompilation of the same source. </p> <p>Revision is used to fix a security hole and should be fully interchangeable. Both Build and Revision are optional. This information is based on <a href="http://msdn.microsoft.com/en-us/library/system.version.aspx">MSDN Version Class</a>. </p> <p>How do you version your projects and why do you version them this way?</p>
<p>See this: <a href="http://stackoverflow.com/questions/65718/what-do-the-numbers-in-a-version-typically-represent-ie-v1901">SO version number question</a></p>
What's the best way to format 24 hour time in XSLT 1.0? <p>I've had a hard time finding good ways of taking a time format and easily determining if it's valid then producing a resulting element that has some formatting using XSLT 1.0.</p> <p>Given the following xml:</p> <pre><code>&lt;root&gt; &lt;srcTime&gt;2300&lt;/srcTime&gt; &lt;/root&gt; </code></pre> <p>It would be great to produce the resulting xml:</p> <pre><code>&lt;root&gt; &lt;dstTime&gt;23:00&lt;/dstTime&gt; &lt;/root&gt; </code></pre> <p>However, if the source xml contains an invalid 24 hour time format, the resulting <em>dstTime</em> element should be blank.</p> <p>For example, when the invalid source xml is the following:</p> <pre><code>&lt;root&gt; &lt;srcTime&gt;NOON&lt;/srcTime&gt; &lt;/root&gt; </code></pre> <p>The resulting xml should be:</p> <pre><code>&lt;root&gt; &lt;dstTime&gt;&lt;/dstTime&gt; &lt;/root&gt; </code></pre> <p>The question is, what's the <strong>best XSLT 1.0</strong> fragment that could be written to produce the desired results? The hope would be to keep it quite simple and not have to parse the every piece of the time (i.e. pattern matching would be sweet if possible).</p>
<p>There aren't any regular expressions in XSLT 1.0, so I'm afraid that pattern matching isn't going to be possible.</p> <p>I'm not clear if <code>&lt;srcTime&gt;23:00&lt;/srcTime&gt;</code> is supposed to be legal or not? If it is, try:</p> <pre><code>&lt;dstTime&gt; &lt;xsl:if test="string-length(srcTime) = 4 or string-length(srcTime) = 5"&gt; &lt;xsl:variable name="hour" select="substring(srcTime, 1, 2)" /&gt; &lt;xsl:if test="$hour &gt;= 0 and 24 &gt; $hour"&gt; &lt;xsl:variable name="minute"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="string-length(srcTime) = 5 and substring(srcTime, 3, 1) = ':'"&gt; &lt;xsl:value-of select="substring(srcTime, 4, 2)" /&gt; &lt;/xsl:when&gt; &lt;xsl:when test="string-length(srcTime) = 4"&gt; &lt;xsl:value-of select="substring(srcTime, 3, 2)" /&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable&gt; &lt;xsl:if test="$minute &gt;= 0 and 60 &gt; $minute"&gt; &lt;xsl:value-of select="concat($hour, ':', $minute)" /&gt; &lt;/xsl:if&gt; &lt;/xsl:if&gt; &lt;/xsl:if&gt; &lt;/dstTime&gt; </code></pre> <p>If it isn't, and four digits is the only thing that's legal then:</p> <pre><code>&lt;dstTime&gt; &lt;xsl:if test="string-length(srcTime) = 4"&gt; &lt;xsl:variable name="hour" select="substring(srcTime, 1, 2)" /&gt; &lt;xsl:if test="$hour &gt;= 0 and 24 &gt; $hour"&gt; &lt;xsl:variable name="minute" select="substring(srcTime, 3, 2)" /&gt; &lt;xsl:if test="$minute &gt;= 0 and 60 &gt; $minute"&gt; &lt;xsl:value-of select="concat($hour, ':', $minute)" /&gt; &lt;/xsl:if&gt; &lt;/xsl:if&gt; &lt;/xsl:if&gt; &lt;/dstTime&gt; </code></pre>
Java: Enum parameter in method <p>I have a method lets say:</p> <pre><code>private static String drawCellValue( int maxCellLength, String cellValue, String align) { } </code></pre> <p>and as you can notice, I have a parameter called align. Inside this method I'm going to have some if condition on whether the value is a 'left' or 'right'.. setting the parameter as String, obviously I can pass any string value.. I would like to know if it's possible to have an Enum value as a method parameter, and if so, how?</p> <p>Just in case someone thinks about this; I thought about using a Boolean value but I don't really fancy it. First, how to associate true/false with left/right ? (Ok, I can use comments but I still find it dirty) and secondly, I might decide to add a new value, like 'justify', so if I have more than 2 possible values, Boolean type is definitely not possible to use.</p> <p>Any ideas?</p>
<p>This should do it:</p> <pre><code>private enum Alignment { LEFT, RIGHT }; String drawCellValue (int maxCellLength, String cellValue, Alignment align){ if (align == Alignment.LEFT) { //Process it... } } </code></pre>
What are the main differences between the popular web frameworks? <p>There are <a href="http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks">lots of web application frameworks</a> available these days, for pretty much every language out there. In your experience, what are their strengths, weaknesses, and unique features? Assuming the luxury of choice, what factors would lead you to consider one over another other?</p> <p>I'm most interested in people's direct experience with one or more frameworks, rather than an exhaustive comparison of everything out there. Hopefully the SO community has programmers who have good and bad experiences with things like <a href="http://www.rubyonrails.org/">Rails</a>, <a href="http://www.asp.net">ASP.NET</a>, <a href="http://www.djangoproject.com/">Django</a>, <a href="http://turbogears.org/">TurboGears</a>, or <a href="http://java.sun.com/javaee/javaserverfaces/">JSF</a>. It would also be great to hear if anyone is using one of the less mainstream frameworks like <a href="http://www.seaside.st/">Seaside</a> or <a href="http://common-lisp.net/project/cl-weblocks/">Weblocks</a>.</p> <p>Programming language is an obvious difference, but a Java vs Ruby flamewar won't be much fun, and most of these frameworks seem to be at least as much an investment in technology, tools and complexity as their language of choice; so I'm more interested in things like:</p> <ul> <li>Development speed and convenience</li> <li>Barriers to entry - both in terms of developer training, and of infrastructure needed</li> <li>Lock-in - how much code could you keep if you had to switch frameworks?</li> <li>Flexibility - does the framework dictate your architecture or design? (Whether that would be a good or bad thing is probably best left to a separate discussion.)</li> <li>Performance, scalability, and stability - obviously depending on the developers!</li> </ul>
<p>I am going to briefly address each area for three popular Python frameworks. This is only based on my personal experiences and observations.</p> <h2>Development speed and convenience</h2> <p>For <strong>TurboGears</strong>, <strong>Pylons</strong>, and <strong>Django</strong>, development speed is roughly equal. Being modern frameworks, it's easy to get started on a new site and start throwing together pages. Python is famously fast to develop and debug and I would put any Python framework as having a shorter development time than any other setup I've worked with (including PHP, Perl, Embedded Perl, and C#/ASP.Net).</p> <h2>Barriers to entry - developer training and infrastructure</h2> <p>If you know Python and are willing to watch a <a href="http://files.turbogears.org/video/20MinuteWiki2nd.mov" rel="nofollow">20 minute video tutorial</a>, you can create a fairly complete wiki-type site from scratch. Or you can walk through a <a href="http://aymanh.com/turbogears-tutorial-social-bookmarking-application" rel="nofollow">social-bookmarking site tutorial</a> in 30 minutes (including installation). These are TurboGears examples but the other two frameworks have nearly identical tutorials as well.</p> <p>The test/development infrastructure that comes out of the box with these frameworks is generally enough to complete most sites. At any point, you can swap out components to meet your production environment requirements. For example, SQLite is fine for setting up your models and loading test data, but you will want to install MySQL (for example) before going live or storing large amounts of data.</p> <p>In all cases, the requirements are very low and dictated entirely by your scalability requirements and not any peculiarities of the framework. If you are comfortable with a certain template language or ORM, it will probably plug right in.</p> <h2>Lock-in</h2> <p>This is a generalized problem across all frameworks. When you select a language, you limit your code-reuse options. When you select a templater, you are again locked in (although that's easier to change, in general, than other things). The same goes for your ORM, database, and so on. There is nothing these frameworks do specifically that will help or hinder lock-in.</p> <h2>Flexibility</h2> <p>It's all about MVC with these three frameworks. As you said, that's a very different discussion!</p> <h2>Performance, scalability, and stability</h2> <p>Well, if you write good code, your site will perform well! Again, this is a problem across all frameworks addressed by <a href="http://agilemanifesto.org/principles.html" rel="nofollow">different development techniques</a> and is probably way outside the scope of this answer.</p>
Calling Reporting services rdl in Java application <p>I have developed my reports in SQL REporting services and deployed in my server. I need to display the reports in my java application page. I want to know is there any control (like .net report viewer control) to display this</p> <p>Thanks balaweblog</p>
<p>I don't know about a control, but if you just need to display reports and not provide much interaction you could use the report server web service and call it's render method. This would allow you to execute and return the report output in a number of formats. So you could have java code accepting parameters which you then pass to the Render method and you get back a byte array of a pdf that displays the report.</p> <p>Render method... <a href="http://msdn.microsoft.com/en-us/library/aa258532" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa258532</a>(SQL.80).aspx</p> <p>Reporting Services Webservice... <a href="http://msdn.microsoft.com/en-us/library/aa274396" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa274396</a>(SQL.80).aspx</p>
Can I implement a cooperative multi-tasking system in VxWorks? <p>A legacy embedded system is implemented using a cooperative multi-tasking scheduler. </p> <p>The system essentially works along the following lines:</p> <ul> <li>Task A does work</li> <li>When Task A is done, it yields the processor.</li> <li>Task B gets the processor and does work.</li> <li>Task B yields<br /> ... </li> <li>Task n yields</li> <li>Task A gets scheduled and does work</li> </ul> <p>One big Circular Queue: A -> B -> C -> ... -> n -> A</p> <p>We are porting the system to a new platform and want to minimize system redesign.</p> <p>Is there a way to implement that type of cooperative multi-tasking in vxWorks?</p>
<p>While VxWorks is a priority based OS, it is possible to implement this type of cooperative multi-tasking.</p> <p>Simply put all the tasks at the <strong>same</strong> priority.<br /> In your code, where you do your <em>yield</em>, simply insert a 'taskDelay(0);'</p> <p>Note that you have to make sure the kernel time slicing is disabled (kernelTimeSlice(0)).</p> <p>All tasks at the same priority are in a Queue. When a task yields, it gets put at the end of the queue. This would implement the type of algorithm described.</p>
How do you acess a property of a bean for reading in a spring xml config file? <p>I want to do something like the following in spring:</p> <pre><code>&lt;beans&gt; ... &lt;bean id="bean1" ... /&gt; &lt;bean id="bean2"&gt; &lt;property name="propName" value="bean1.foo" /&gt; ... </code></pre> <p>I would think that this would access the getFoo() method of bean1 and call the setPropName() method of bean2, but this doesn't seem to work.</p>
<p>You need to use <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPathFactoryBean.html">PropertyPathFactoryBean</a>:</p> <pre> &lt;bean id="bean2" depends-on="bean1"&gt; &lt;property name="propName"&gt; &lt;bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean"&gt; &lt;property name="targetBeanName" value="bean1"/&gt; &lt;property name="propertyPath" value="foo"/&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; </pre>
How to get CreateProcess/CreateProcessW to execute a process in a path > MAX_PATH characters <p>I'm trying to get either CreateProcess or CreateProcessW to execute a process with a name &lt; MAX&#95;PATH characters but in a path that's greater than MAX&#95;PATH characters. According to the docs at: <a href="http://msdn.microsoft.com/en-us/library/ms682425.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms682425.aspx</a>, I need to make sure lpApplicationName isn't NULL and then lpCommandLine can be up to 32,768 characters.</p> <p>I tried that, but I get ERROR&#95;PATH&#95;NOT&#95;FOUND.</p> <p>I changed to CreateProcessW, but still get the same error. When I prefix lpApplicationName with \\?\ as described in <a href="http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx</a> when calling CreateProcessW I get a different error that makes me think I'm a bit closer: ERROR&#95;SXS&#95;CANT&#95;GEN&#95;ACTCTX.</p> <p>My call to CreateProcessW is:</p> <p><code> CreateProcessW(w&#95;argv0,arg_string,NULL,NULL,0,NULL,NULL,&amp;si,&amp;ipi); </code></p> <p>where w_argv0 is <code>\\?\&lt;long absolute path&gt;\foo.exe.</code></p> <p>arg_string contains "&lt;long absolute path&gt;\foo.exe" foo </p> <p>si is set as follows:</p> <pre> memset(&si,0,sizeof(si)); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE;> </pre> <p>and pi is empty, as in:</p> <pre> memset(&pi,0,sizeof(pi)); </pre> <p>I looked in the system event log and there's a new entry each time I try this with event id 59, source SideBySide: Generate Activation Context failed for .Manifest. Reference error message: The operation completed successfully.</p> <p>The file I'm trying to execute runs fine in a path &lt; MAX_PATH characters.</p> <p>To clarify, no one component of &lt;long absolute path&gt; is greater than MAX&#95;PATH characters. The name of the executable itself certainly isn't, even with .manifest on the end. But, the entire path together is greater than MAX&#95;PATH characters long.</p> <p>I get the same error whether I embed its manifest or not. The manifest is named foo.exe.manifest and lives in the same directory as the executable when it's not embedded. It contains:</p> <pre> &lt;?xml version='1.0' encoding='UTF-8' standalone='yes'?> &lt;assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> &lt;dependency> &lt;dependentAssembly> &lt;assemblyIdentity type='win32' name='Microsoft.VC80.DebugCRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' /> &lt;/dependentAssembly> &lt;/dependency> &lt;/assembly> </pre> <p>Anyone know how to get this to work? Possibly:</p> <ul> <li><p>some other way to call CreateProcess or CreateProcessW to execute a process in a path > MAX_PATH characters</p></li> <li><p>something I can do in the manifest file</p></li> </ul> <p>I'm building with Visual Studio 2005 on XP SP2 and running native.</p> <p>Thanks for your help.</p>
<p>Embedding the manifest and using GetShortPathNameW did it for me. One or the other on their own wasn't enough.</p> <p>Before calling CreateProcessW using the \\?-prefixed absolute path name of the process to execute as the first argument, I check:</p> <pre> wchar&#95;t *w_argv0; wchar&#95;t *w_short_argv0; ... if (wcslen(w&#95;argv0) >= MAX&#95;PATH) { num&#95;chars = GetShortPathNameW(w&#95;argv0,NULL,0); if (num&#95;chars == 0) { syslog(LOG&#95;ERR,"GetShortPathName(%S) to get size failed (%d)",<br/> w&#95;argv0,GetLastError()); /* ** Might as well keep going and try with the long name */ } else { w&#95;short&#95;argv0 = malloc(num&#95;chars * sizeof(wchar&#95;t)); memset(w&#95;short&#95;argv0,0,num&#95;chars * sizeof(wchar&#95;t)); if (GetShortPathNameW(w&#95;argv0,w&#95;short&#95;argv0,num&#95;chars) == 0) { syslog(LOG&#95;ERR,"GetShortPathName(%S) failed (%d)",w&#95;argv0,<br/> GetLastError()); free(w&#95;short&#95;argv0); w&#95;short&#95;argv0 = NULL; } else { syslog(LOG_DEBUG,"using short name %S for %S",w&#95;short&#95;argv0,<br/> w&#95;argv0); } } } </pre> <p>and then call CreateProcessW(w&#95;short&#95;argv0 ? w&#95;short&#95;argv0 : w&#95;argv0...);</p> <p>remembering to free(w&#95;short&#95;argv0); afterwards.</p> <p>This may not solve every case, but it lets me spawn more child processes than I could before.</p>
Design Time viewing for User Control events <p>I've create a WinForms control that inherits from System.Windows.Forms.UserControl...I've got some custom events on the control that I would like the consumer of my control to be able to see. I'm unable to actually get my events to show up in the Events tab of the Properties window during design time. This means the only way to assign the events is to programmatically write </p> <pre><code>myUserControl.MyCustomEvent += new MyUserControl.MyCustomEventHandler(EventHandlerFunction); </code></pre> <p>this is fine for me I guess but when someone else comes to use my UserControl they are not going to know that these events exist (unless they read the library doco...yeah right). I know the event will show up using Intellisense but it would be great if it could show in the properties window too.</p>
<p>Make sure your events are exposed as public. For example...</p> <pre><code>[Browsable(true)] public event EventHandler MyCustomEvent; </code></pre>
What are your "hard rules" about commenting your code? <p>I have seen the other questions <em>but I am still not satisfied with the way this subject is covered</em>.</p> <p><strong>I would like to extract a distiled list of things to check on comments at a code inspection.</strong> </p> <p>I am sure people will say things that will just cancel each other. But hey, maybe we can build a list for each camp. For the guys who don't comment at all the list will just be very short :)</p>
<p>I have one simple rule about commenting: Your code should tell the story of what you are doing; your comments should tell the story of why you are doing it.</p> <p>This way, I make sure that whoever inherits my code will be able to understand the intent behind the code.</p>
Is the PageAction.Details route necessary in the default Dynamic Data template? <p>In the default Visual Studio template for a dynamic data web application, Global.asax includes the following two sample routes.</p> <pre><code>// route #1 routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") { Action = PageAction.List, ViewName = "ListDetails", Model = model }); // route #2 routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") { Action = PageAction.Details, ViewName = "ListDetails", Model = model }); </code></pre> <p>They only differ by the Action property. The comments in Global.asax indicate the two routes are used to configure a single page that handles all CRUD behaviors.</p> <p>Why is route #2 is necessary? Does it do anything? ListDetails.aspx does not look at the Action property of the route. It seems that everything runs fine when I comment out route #2 and I only have route #1 in Global.asax. Route #2 looks like its not used.</p>
<p>You're right, route #2 isn't going to be used in this instance. The only time route #2 would come into play is if you were requesting a details page URL from the route engine. Because the ListDetails.aspx page template handles both the list and details views, it never requests a details template URL.</p>
mathematical optimization library for Java --- free or open source recommendations? <p>Does anyone know of such a library that performs mathematical optimization (linear programming, convex optimization, or more general types of problems)? I'm looking for something like MATLAB, but with the ability to handle larger problems. Do I have to write my own implementations, or buy one of those commercial products (CPLEX and the like)?</p>
<p>A good answer is dependent on what you mean by "convex" and "more general" If you are trying to solve large or challenging linear or convex-quadratic optimization problems (especially with a discrete component to them), then it's hard to beat the main commercial solvers, <a href="http://www.gurobi.com">gurobi</a>, <a href="http://www.ilog.com/products/cplex">cplex</a> and <a href="http://www.dashoptimization.com/home/cgi-bin/example.pl#bcl_java">Dash</a> unless money is a big issue for you. They all have clean JNI interfaces and are available on most major platforms. There's an interesting java-based modeling environment called <a href="http://www.ateji.com/optimj.html">optimj</a>, that allows you to hook into several optimizers, but it requires a license for itself and whatever solvers you get (but there are some free solvers).</p> <p>The <a href="http://www.coin-or.org">coin-or</a> project has several optimizers and have a project for JNI interface. It is totally free (<a href="http://www.eclipse.org/legal/eplfaq.php">EPL</a> license), but will take more work to set-up and probably not give you the same performance.</p>
How to synchronize two Subversion repositories? <p>My company has a subsidiary with a slow Internet connection. Our developers there suffer to interact with our central <a href="http://en.wikipedia.org/wiki/Subversion%5F%28software%29">Subversion</a> server. Is it possible to configure a slave/mirror for them? They would interact locally with the server and all the commits would be automatically synchronized to the master server. </p> <p>This should work as transparently as possible for the developers. Usability is a must.</p> <p>Please, no suggestions to change our version control system.</p>
<p>It is possible but not necessarily simple: the problem you are trying to solve is dangerously close to setting up a distributed development environment which is not exactly what SVN is designed for.</p> <p><strong>The SVN-mirror way</strong></p> <p>You can use <code>svn mirror</code> as explained in the SVN book documentation to create a <em>read-only</em> mirror of your master repository. Your developers each interact with the mirror closest to them. However users of the slave repository will have to use </p> <p>svn switch --relocate master_url</p> <p>before they can commit and they will have to remember to relocate back on the slave once they are done. This could be automated using a wrapper script around the repository modifying commands on SVN if you use the command line client. Keep in mind that the relocate operation while fast adds a bit of overhead. (And be careful to duplicate the repository uuid - see <a href="http://svnbook.red-bean.com/en/1.5/svn.reposadmin.maint.html#svn.reposadmin.maint.replication">the SVN documentation</a>.)</p> <p>[Edit - Checking the <a href="http://en.wikipedia.org/wiki/TortoiseSVN">TortoiseSVN</a> documentation it seems that you can have TortoiseSVN <a href="http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-settings.html#tsvn-dug-settings-hooks">execute hook scripts client side</a>. You may be able to create a pre/post commit script at this point. Either that or try to see if you can use the <a href="http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-automation.html">TortoiseSVN automation interface</a> to do it].</p> <p><strong>The SVK way</strong></p> <p><a href="http://svk.bestpractical.com/view/HomePage">svk</a> is a set of Perl scripts which emulate a distributed mirroring service over SVN. You can set it up so that the local branch (the mirror) is shared by multiple developers. Then basic usage for the developers will be completely transparent. You will have to use the svk client for cherry picking, merging and starmerging. It is doable if you can get your head around the distributed concepts. </p> <p><strong>The git-svn way</strong></p> <p>While I never used that myself, you could also have distant developers use git locally and use the <a href="http://git-scm.com/docs/git-svn">git-svn</a> gateway for synchronization. </p> <p><strong>Final words</strong></p> <p>It all depends on your development environment and the level of integration you require. Depending on your IDE (and if you can change <a href="http://en.wikipedia.org/wiki/Source_Code_Management">SCM</a>) you might want to have a look at other fully distributed SCMs (think <a href="http://en.wikipedia.org/wiki/Mercurial">Mercurial</a>/<a href="http://en.wikipedia.org/wiki/Bazaar_%28software%29">Bazaar</a>/<a href="http://en.wikipedia.org/wiki/Git_%28software%29">Git</a>/...) which support distributed development out of the box.</p>
Bron-Kerbosch algorithm for clique finding <p>Can anyone tell me, where on the web I can find an explanation for Bron-Kerbosch algorithm for clique finding or explain here how it works?</p> <p>I know it was published in "Algorithm 457: finding all cliques of an undirected graph" book, but I can't find free source that will describe the algorithm.</p> <p>I don't need a source code for the algorithm, I need an explanation of how it works.</p>
<p>i find the explanation of the algorithm here: <a href="http://www.dfki.de/~neumann/ie-seminar/presentations/finding_cliques.pdf">http://www.dfki.de/~neumann/ie-seminar/presentations/finding_cliques.pdf</a> it's a good explanation... but i need a library or implementation in C# -.-'</p>
Create cronjob with Zend Framework <p>I am trying to write a cronjob controller, so I can call one website and have all modules cronjob.php executed. Now my problem is how do I do that?</p> <p>Would curl be an option, so I also can count the errors and successes?</p> <p>[Update]</p> <p>I guess I have not explained it enough. </p> <p>What I want to do is have one file which I can call like from <a href="http://server/cronjob">http://server/cronjob</a> and then make it execute every /application/modules/*/controller/CronjobController.php or have another way of doing it so all the cronjobs aren't at one place but at the same place the module is located. This would offer me the advantage, that if a module does not exist it does not try to run its cronjob.</p> <p>Now my question is how would you execute all the modules CronjobController or would you do it a completly different way so it still stays modular?</p> <p>And I want to be able to giveout how many cronjobs ran successfully and how many didn't</p>
<p>After some research and a lot procrastination I came to the simple conclusion that a ZF-ized cron script should contain all the functionality of you zend framework app - without all the view stuff. I accomplished this by creating a new cronjobfoo.php file in my application directory. Then I took the bare minimum from: -my front controller (index.php) -my bootstrap.php</p> <p>I took out all the view stuff and focused on keeping the environment setup, db setup, autoloader, &amp; registry setup. I had to take a little time to correct the document root variable and remove some of the OO functionality copied from my bootstrap.</p> <p>After that I just coded away.. in my case it was compiling and emailing out nightly reports. It was great to use Zend_Mail. When I was confident that my script was working the way I wanted, I just added it my crontab.</p> <p>good luck!</p>
Java: Text to Speech engines overview <p>I'm now in search for a Java Text to Speech (TTS) framework. During my investigations I've found several JSAPI1.0-(partially)-compatible frameworks listed on <a href="http://java.sun.com/products/java-media/speech/reference/codesamples/index.html">JSAPI Implementations page</a>, as well as a pair of Java TTS frameworks which do not appear to follow JSAPI spec (<a href="http://mary.dfki.de/">Mary</a>, <a href="http://www.say-it-now.com/mainsite.htm">Say-It-Now</a>). I've also noted that currently no reference implementation exists for JSAPI.</p> <p>Brief tests I've done for FreeTTS (first one listed in JSAPI impls page) show that it is far from reading simple and obvious words (examples: ABC, blackboard). Other tests are currently in progress.</p> <p>And here goes the question (6, actually):</p> <ol> <li>Which of the Java-based TTS frameworks have you used?</li> <li>Which ones, by your opinion, are capable of reading the largest wordbase?</li> <li>What about their voice quality?</li> <li>What about their performance?</li> <li>Which non-Java frameworks with Java bindings are there on the scene?</li> <li>Which of them would you recommend?</li> </ol> <p>Thank you in advance for your comments and suggestions.</p>
<p>I've actually had pretty good luck with <a href="http://freetts.sourceforge.net/">FreeTTS</a></p>
How can I modify a saved Microsoft Access 2007 or 2010 Import Specification? <p>Does anyone know how to modify an existing import specification in Microsoft Access 2007 or 2010? In older versions there used to be an Advanced button presented during the import wizard that allowed you to select and edit an existing specification. I no longer see this feature but hope that it still exists and has just been moved somewhere else.</p>
<p>I am able to use this feature on my machine using MS Access 2007.</p> <ul> <li>On the Ribbon, select External Data </li> <li>Select the "Text File" option </li> <li>This displays the Get External Data Wizard </li> <li>Specify the location of the file you wish to import </li> <li>Click OK. This displays the "Import Text Wizard" </li> <li>On the bottom of this dialog screen is the Advanced button you referenced </li> <li>Clicking on this button should display the Import Specification screen and allow you to select and modify an existing import spec. </li> </ul> <p>For what its worth, I'm using Access 2007 SP1</p>
linker woes - undefined reference <p>I'm having a problem with my compiler telling me there is an 'undefined reference to' a function I want to use in a library. Let me share some info on the problem:</p> <ul> <li>I'm cross compiling with gcc for C.</li> <li>I am calling a library function which is accessed through an included header which includes another header, which contains the prototype.</li> <li>I have included the headers directory using -I and i'm sure it's being found.</li> <li>I'm first creating the .o files then linking them in a separate command.</li> </ul> <p>So my thought is it might be the order in which I include the library files, but i'm not sure what is the correct way to order them. I tried with including the headers folder both before and after the .o file.</p> <p>Some suggests would be great, and maybe and explanation of how the linker does its thing.</p> <p>Thanks!</p> <p><hr /></p> <p>Response to answers</p> <ul> <li>there is no .a library file, just .h and .c in the library, so -l isn't appropriate</li> <li>my understanding of a library file is that it is just a collection of header and source files, but maybe it's a collection of .o files created from the source?!</li> <li>there is no library object file being created, maybe there should be?? Yes seems I don't understand the difference between includes and libraries...i'll work on that :-)</li> </ul> <p>Thanks for all the responses! I learned a lot about libraries. I'd like to put all the responses as the accepted answer :-)</p>
<p>It sounds like you are not compiling the .c file in the library to produce a .o file. The linker would look for the prototype's implementation in the .o file produced by compiling the library </p> <p>Does your build process compile the library .c file?</p> <p>Why do you call it a "library" if it's actually just source code?</p>
Where can I find open source 2d bin packing algorithms? <p>I'm looking for open source (preferably c++) algorithms for 2d bin packing of rectangular and or irregular shapes. I've found several papers on the subject but no code.</p>
<p>Here is the best to my knowledge about rectangular bin packing:</p> <p><a href="http://clb.demon.fi/projects/rectangle-bin-packing" rel="nofollow">http://clb.demon.fi/projects/rectangle-bin-packing</a></p>
What's the best system for installing a Perl web app? <p>It seems that most of the installers for Perl are centered around installing Perl modules, not applications. Things like ExtUtils::MakeMaker and Module::Build are very well suited for modules, but require some additional work for Web Apps.</p> <p>Ideally it would be nice to be able to do the following after checking out the source from the repository:</p> <ul> <li>Have missing dependencies detected</li> <li>Download and install dependencies from CPAN</li> <li>Run a command to "Build" the source into a final state (perform any source parsing or configuration necessary for the local environment).</li> <li>Run a command to install the built files into the appropriate locations. Not only the perl modules, but also things like template (.tt) files, and CGI scripts, JS and image files that should be web-accessible.</li> <li>Make sure proper permissions are set on installed files (and SELinux context if necessary).</li> </ul> <p>Right now we have a system based on <strong>Module::Build</strong> that does most of this. The work was done by done by my co-worker who was learning to use <strong>Module::Build</strong> at the time, and we'd like some advice on generalizing our solution, since it's fairly app-specific right now. In particular, our system requires us to install dependencies by hand (although it does detect them).</p> <p>Is there any particular system you've used that's been particularly successful? Do you have to write an installer based on <strong>Module::Build</strong> or <strong>ExtUtils::MakeMaker</strong> that's particular to your application, or is something more general available?</p> <p><strong>EDIT:</strong> To answer brian's questions below:</p> <ul> <li>We can log into the machines</li> <li>We do not have root access to the machines</li> <li>The machines are all (ostensibly) identical builds of RHEL5 with SELinux enabled</li> <li>Currently, the people installing the machines are only programmers from our group, and our source is not available to the general public. However, it's conceivable our source could eventually be installed on someone else's machines in our organization, to be installed by their programmers or systems people.</li> <li>We install by checking out from the repository, though we'd like to have the option of using a distributed archive (see above).</li> </ul>
<p>The answer suggesting RPM is definitely a good one. Using your system's package manager can definitely make your life easier. However, it might mean you also need to package up a bunch of other Perl modules.</p> <p>You might also take a look at <a href="http://search.cpan.org/dist/Shipwright/" rel="nofollow">Shipwright</a>. This is a Perl-based tool for packaging up an app and all its Perl module dependencies. It's early days yet, but it looks promising.</p> <p>As far as installing dependencies, it wouldn't be hard to simply package up a bunch of tarballs and then have you Module::Build-based solution install them. You should take a look at <a href="http://search.cpan.org/dist/pip/" rel="nofollow">pip</a>, which makes installing a module from a tarball quite trivial. You could package this with your code base and simply call it from your own installer to handle the deps.</p> <p>I question whether relying on CPAN is a good idea. The CPAN shell always fetches the latest version of a distro, rather than a specific version. If you're interested in ensuring repeatable installs, it's not the right tool.</p>
MySQL and data file encryption <p>Is there a way to encrypt the data file that mysql uses? I have a mysql server on an open machine, and I would like to encrypt the data file so even if someone copies the data files, they cannot read the data.</p> <p>Thanks</p>
<p>To anyone researching a transparent MySQL encryption solution <strong>for Linux</strong>, there's a relatively new product on the block that we've been working with: <a href="http://www.gazzang.com/" rel="nofollow">http://www.gazzang.com/</a></p> <p>I am not affiliated with Gazzang... just a happy customer.</p>
What books should I read to have an undergraduate education in Computer Science? <p>I've always been a largely independent learner gleaning what I can from Wikipedia and various books. However, I fear that I may have biased my self-education by inadvertent omission of topics and concepts. My goal is to teach myself the equivalent of an undergraduate degree in Computer Science from a top university (doesn't matter which one). </p> <p>To that end, I've purchased and started reading a few academic textbooks:</p> <ul> <li><a href="http://rads.stackoverflow.com/amzn/click/0262011530" rel="nofollow">Structure and Interpretation of Computer Programs</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0262032937" rel="nofollow">Introduction to Algorithms</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0137903952" rel="nofollow">Artificial Intelligence: A Modern Approach</a></li> </ul> <p>As well as a few textbooks I have left over from classes I've taken at a mediocre-at-best state university:</p> <ul> <li><a href="http://rads.stackoverflow.com/amzn/click/0805377581" rel="nofollow">An Introduction to Computer Simulation Methods</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/007330929X" rel="nofollow">Calculus: Concepts and Connections</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0131856448" rel="nofollow">Computer Organization and Architecture</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0471694665" rel="nofollow">Operating System Concepts</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/013600637X" rel="nofollow">A First Course in Database Systems</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0763737984" rel="nofollow">Formal Languages and Automata</a></li> </ul> <p>My questions are:</p> <ul> <li>What topics aren't covered by this collection?</li> <li>Are there any books that are more rigorous or thorough (or even easier to read) than a book listed here?</li> <li>Are there any books that are a waste of my time?</li> <li>In what order should I read the books?</li> <li>What does an MIT or Stanford (or UCB or CMU ...) undergrad learn that I might miss?</li> </ul> <p><em>Software engineering books are welcome, but in the context of academic study only please. I'm aware of Code Complete and the Pragmatic Programmer, but I'm looking for a more theoretical approach. Thanks!</em> </p>
<p>Biggest two omissions I see:</p> <ul> <li><a href="http://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools" rel="nofollow">The Dragon Book</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0130661023" rel="nofollow">Computer Networks</a></li> </ul> <p>For operating systems I prefer the Tanenbaum instead of the Silberschatz but both are good:</p> <ul> <li><a href="http://rads.stackoverflow.com/amzn/click/0136374069" rel="nofollow">Operating Systems</a></li> </ul> <p>And about the order, that would depend on your interests. There aren't many prerequisites, automata for compilers is the most obvious one. First read the automata book and then the dragon one.</p> <p>I don't know all the books you have, but the ones I know are good enough so that may mean the others are decent as well. </p> <p>You are missing some <a href="http://www.cs.rice.edu/~vardi/comp409/index.html" rel="nofollow">logic</a> and <a href="http://rads.stackoverflow.com/amzn/click/0387941150" rel="nofollow">discrete math</a> books as well.</p> <p>And let's not forget some <a href="http://oreilly.com/catalog/9780596100124/" rel="nofollow">database theory</a> books!</p>
How does Multiple C++ Threads execute on a class method <p>let's say we have a c++ class like:</p> <pre><code>class MyClass { void processArray( &lt;an array of 255 integers&gt; ) { int i ; for (i=0;i&lt;255;i++) { // do something with values in the array } } } </code></pre> <p>and one instance of the class like: </p> <pre><code>MyClass myInstance ; </code></pre> <p>and 2 threads which call the processArray method of that instance (depending on how system executes threads, probably in a completely irregular order). There is no mutex lock used in that scope so both threads can enter.</p> <p><strong>My question is what happens to the i ? Does each thread scope has it's own "i" or would each entering thread modify i in the for loop, causing i to be changing weirdly all the time.</strong> </p>
<p><code>i</code> is allocated on the stack. Since each thread has its own separate stack, each thread gets its own copy of <code>i</code>.</p>
Database Design <p>I need to create a database to store simulation results. What resources are out there to help me design this?</p> <p>EDIT: For those who want more details...</p> <p>We work with a discrete event simulation used by the military. Important simulation events are thus when weapons are fired, when kills occur, and also when weapons fail to kill a target. Other important events are when targets are detected or when they are no longer tracked. We keep pretty detailed log files that we then mine to calculate averages and other statistics. It's mainly the statistics that I'm concerned with storing in the database. </p> <p>Another thing I want to include is the case ID. We identify different cases using an alphanumeric case ID string that corresponds to a particular combination of systems and important input parameters. For example, suppose a sensor could detect a target at 3 different ranges depending on mode, there would be a character in the case ID that corresponds to each level of detection range, labeled 0, 1, or 2. If there are enough levels of a given case, the case ID characters switch to letters after 9. This case ID would definitely be an important key in the database. Once we have stored the data, we need to retrieve certain numbers to make charts comparing different cases. We currently make the charts in Excel, but I've been adding more MATLAB recently.</p> <p>As for the database technology, I thought I'd do the table design in Access to prototype things, then implement it in MS SQL Server. I'm planning to use Ruby to create HTML reports with data tables and graphs.</p>
<p>Provide the following and you'll get a helpful answer</p> <ol> <li>Database type (MsSQL, MySQL etc)</li> <li>Any other languages you are using with this (C#, PHP)</li> <li>The data you want to store</li> <li>What you plan to do with the data (it may affect how best to store and query it), this step is very optional</li> </ol>
How do I deploy an ADF business component? <p>How do I deploy an ADF business component to the middle tier and call it using <a href="http://en.wikipedia.org/wiki/Java_remote_method_invocation" rel="nofollow">RMI</a>?</p> <p>I just cannot find any good documentation on this!</p>
<p>Select the ADF BC application module and use your right button to create a business components deployment and select <a href="http://en.wikipedia.org/wiki/Enterprise_JavaBean" rel="nofollow">EJB</a> session bean. This will create different <a href="https://en.wikipedia.org/wiki/EAR_%28file_format%29" rel="nofollow">EAR</a> files which you can deploy. That's all.</p>
How can I be sure the whole MySQL DB is loaded in memory? <p>I am running a mysql server. I would like to somehow make sure that the whole DB is loaded into the ram as I heard it would be alot faster.</p> <p>Is this true? and how do I vertify it?</p>
<p>If you are using InnoDB, then you can set innodb_buffer_pool_size to be at least as large as your data and indexes. Then as you access data, it will be cached into memory and all subsequent accesses will occur via memory.</p> <p>If you wanted to pre-cache the data, you could do some of your common queries, or full table/index scans to force it to load all of the data into memory.</p> <p>There is an init-file option for mysqld which can have the server automatically execute some commands on startup, where you could include the pre-caching queries to execute.</p> <p>Keep in mind you don't want to run out of memory, so be careful with setting innodb_buffer_pool_size too large.</p>
How to get the RGB values for a pixel on an image on the iphone <p>I am writing an iPhone application and need to essentially implement something equivalent to the 'eyedropper' tool in photoshop, where you can touch a point on the image and capture the RGB values for the pixel in question to determine and match its color. Getting the UIImage is the easy part, but is there a way to convert the UIImage data into a bitmap representation in which I could extract this information for a given pixel? A working code sample would be most appreciated, and note that I am not concerned with the alpha value.</p>
<h2>A little more detail...</h2> <p>I posted earlier this evening with a consolidation and small addition to what had been said on this page - that can be found at the bottom of this post. I am editing the post at this point, however, to post what I propose is (at least for my requirements, which include modifying pixel data) a better method, as it provides writable data (whereas, as I understand it, the method provided by previous posts and at the bottom of this post provides a read-only reference to data). </p> <p>Method 1: Writable Pixel Information</p> <ol> <li><p>I defined constants</p> <pre><code>#define RGBA 4 #define RGBA_8_BIT 8 </code></pre></li> <li><p>In my UIImage subclass I declared instance variables:</p> <pre><code>size_t bytesPerRow; size_t byteCount; size_t pixelCount; CGContextRef context; CGColorSpaceRef colorSpace; UInt8 *pixelByteData; // A pointer to an array of RGBA bytes in memory RPVW_RGBAPixel *pixelData; </code></pre></li> <li><p>The pixel struct (with alpha in this version)</p> <pre><code>typedef struct RGBAPixel { byte red; byte green; byte blue; byte alpha; } RGBAPixel; </code></pre></li> <li><p>Bitmap function (returns pre-calculated RGBA; divide RGB by A to get unmodified RGB):</p> <pre><code>-(RGBAPixel*) bitmap { NSLog( @"Returning bitmap representation of UIImage." ); // 8 bits each of red, green, blue, and alpha. [self setBytesPerRow:self.size.width * RGBA]; [self setByteCount:bytesPerRow * self.size.height]; [self setPixelCount:self.size.width * self.size.height]; // Create RGB color space [self setColorSpace:CGColorSpaceCreateDeviceRGB()]; if (!colorSpace) { NSLog(@"Error allocating color space."); return nil; } [self setPixelData:malloc(byteCount)]; if (!pixelData) { NSLog(@"Error allocating bitmap memory. Releasing color space."); CGColorSpaceRelease(colorSpace); return nil; } // Create the bitmap context. // Pre-multiplied RGBA, 8-bits per component. // The source image format will be converted to the format specified here by CGBitmapContextCreate. [self setContext:CGBitmapContextCreate( (void*)pixelData, self.size.width, self.size.height, RGBA_8_BIT, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast )]; // Make sure we have our context if (!context) { free(pixelData); NSLog(@"Context not created!"); } // Draw the image to the bitmap context. // The memory allocated for the context for rendering will then contain the raw image pixelData in the specified color space. CGRect rect = { { 0 , 0 }, { self.size.width, self.size.height } }; CGContextDrawImage( context, rect, self.CGImage ); // Now we can get a pointer to the image pixelData associated with the bitmap context. pixelData = (RGBAPixel*) CGBitmapContextGetData(context); return pixelData; } </code></pre></li> </ol> <hr> <h2>Read-Only Data (Previous information) - method 2:</h2> <hr> <h2>Step 1. I declared a type for byte:</h2> <pre><code>typedef unsigned char byte; </code></pre> <h2>Step 2. I declared a struct to correspond to a pixel:</h2> <pre><code>typedef struct RGBPixel { byte red; byte green; byte blue; } RGBPixel; </code></pre> <h2>Step 3. I subclassed UIImageView and declared (with corresponding synthesized properties):</h2> <pre><code>// Reference to Quartz CGImage for receiver (self) CFDataRef bitmapData; // Buffer holding raw pixel data copied from Quartz CGImage held in receiver (self) UInt8* pixelByteData; // A pointer to the first pixel element in an array RGBPixel* pixelData; </code></pre> <h2>Step 4. Subclass code I put in a method named bitmap (to return the bitmap pixel data):</h2> <pre><code>// Get the bitmap data from the receiver's CGImage (see UIImage docs) [self setBitmapData: CGDataProviderCopyData( CGImageGetDataProvider( [self CGImage] ) )]; // Create a buffer to store bitmap data (unitialized memory as long as the data) [self setPixelBitData: malloc( CFDataGetLength( bitmapData ) )]; // Copy image data into allocated buffer CFDataGetBytes( bitmapData, CFRangeMake( 0, CFDataGetLength( bitmapData ) ), pixelByteData ); // Cast a pointer to the first element of pixelByteData // Essentially what we're doing is making a second pointer that divides the byteData's units differently - instead of dividing each unit as 1 byte we will divide each unit as 3 bytes (1 pixel). pixelData = (RGBPixel*) pixelByteData; // Now you can access pixels by index: pixelData[ index ] NSLog( @"Pixel data one red (%i), green (%i), blue (%i).", pixelData[0].red, pixelData[0].green, pixelData[0].blue ); // You can determine the desired index by multiplying row * column. return pixelData; </code></pre> <h2>Step 5. I made an accessor method:</h2> <pre><code>- (RGBPixel*) pixelDataForRow: (int) row column: (int) column { // Return a pointer to the pixel data return &amp;pixelData[ row * column ]; } </code></pre>
Simple basic explanation of a Distributed Hash Table (DHT) <p>Could any one give an explanation on how a DHT works?</p> <p>Nothing too heavy, just the basics.</p>
<p>Ok, they're fundamentally a pretty simple idea. A DHT gives you a dictionary-like interface, but the nodes are distributed across the network. The trick with DHTs is that the node that gets to store a particular key is found by hashing that key, so in effect your hash-table buckets are now independent nodes in a network.</p> <p>This gives a lot of fault-tolerance and reliability, and possibly some performance benefit, but it also throws up a lot of headaches. For example, what happens when a node leaves the network, by failing or otherwise? And how do you redistribute keys when a node joins so that the load is roughly balanced. Come to think of it, how do you evenly distribute keys anyhow? And when a node joins, how do you avoid rehashing everything? (Remember you'd have to do this in a normal hash table if you increase the number of buckets).</p> <p>One example DHT that tackles some of these problems is a logical ring of n nodes, each taking responsibility for 1/n of the keyspace. Once you add a node to the network, it finds a place on the ring to sit between two other nodes, and takes responsibility for some of the keys in its sibling nodes. The beauty of this approach is that none of the other nodes in the ring are affected; only the two sibling nodes have to redistribute keys.</p> <p>For example, say in a three node ring the first node has keys 0-10, the second 11-20 and the third 21-30. If a fourth node comes along and inserts itself between nodes 3 and 0 (remember, they're in a ring), it can take responsibility for say half of 3's keyspace, so now it deals with 26-30 and node 3 deals with 21-25. </p> <p>There are many other overlay structures such as this that use content-based routing to find the right node on which to store a key. Locating a key in a ring requires searching round the ring one node at a time (unless you keep a local look-up table, problematic in a DHT of thousands of nodes), which is O(n)-hop routing. Other structures - including augmented rings - guarantee O(log n)-hop routing, and some claim to O(1)-hop routing at the cost of more maintenance. </p> <p>Read the wikipedia page, and if you really want to know in a bit of depth, check out this <a href="http://www.eecs.harvard.edu/~mema/courses/cs264/cs264.html">coursepage</a> at Harvard which has a pretty comprehensive reading list.</p>
Ruby: How to break a potentially unicode string into bytes <p>I'm writing a game which is taking user input and rendering it on-screen. The engine I'm using for this is entirely unicode-friendly, so I'd like to keep that if at all possible. The problem is that the rendering loop looks like this:</p> <pre><code>"string".each_byte do |c| render_this_letter(c) end </code></pre> <p>I don't know a whole lot about i18n, but I know enough to know the above code is only ever going to work for me and people who speak my language. I'd prefer something like:</p> <pre><code>"unicode string".each_unicode_letter do |u| render_unicode_letter(u) end </code></pre> <p>Does this exist in the core distribution? I'm somewhat averse to adding additional requirements to the install, but if it's the only way to do it, I'll live.</p> <p>For extra fun, I have no way of knowing if the string is, in fact, a unicode string.</p> <p>EDIT: The library I'm using can indeed render entire strings, however I'm letting the user edit what comes up on the fly - if they hit 'backspace', essentially, I need to know how many bytes to chop off the end.</p>
<p>Unfortunately ruby 1.8.x has poor unicode support. It's being addressed in 1.9. But in the mean time, libraries like this one (<a href="http://snippets.dzone.com/posts/show/4527" rel="nofollow">http://snippets.dzone.com/posts/show/4527</a>) are a good solution. Using the linked library, your code would look something like this:</p> <pre><code>"unicode_string".each_utf8_char do |u| render_unicode_letter(u) end </code></pre>
== or .Equals() <p>Why use one over the other?</p>
<p>== is the identity test. It will return true if the two objects being tested are in fact the same object. <code>Equals()</code> performs an equality test, and will return true if the two objects consider themselves equal.</p> <p>Identity testing is faster, so you can use it when there's no need for more expensive equality tests. For example, comparing against <code>null</code> or the empty string.</p> <p>It's possible to overload either of these to provide different behavior -- like identity testing for <code>Equals()</code> --, but for the sake of anybody reading your code, please don't.</p> <hr> <p>Pointed out below: some types like <code>String</code> or <code>DateTime</code> provide overloads for the <code>==</code> operator that give it equality semantics. So the exact behavior will depend on the types of the objects you are comparing.</p> <hr> <p>See also:</p> <ul> <li><a href="http://blogs.msdn.com/csharpfaq/archive/2004/03/29/102224.aspx">http://blogs.msdn.com/csharpfaq/archive/2004/03/29/102224.aspx</a></li> </ul>
SQL Server: Dynamic where-clause <p><strong>Problem:</strong></p> <p>Ajax suggest-search on [<em>n</em>] ingredients in recipes. That is: match recipes against multiple ingredients.</p> <p>For instance: <code>SELECT Recipes using "flower", "salt"</code> would produce: <code>"Pizza", "Bread", "Saltwater"</code> and so forth.</p> <p><strong>Tables:</strong></p> <pre><code>Ingredients [ IngredientsID INT [PK], IngredientsName VARCHAR ] Recipes [ RecipesID INT [PK], RecipesName VARCHAR ] IngredientsRecipes [ IngredientsRecipesID INT [PK], IngredientsID INT, RecipesID INT ] </code></pre> <p><strong>Query:</strong></p> <pre><code>SELECT Recipes.RecipesID, Recipes.RecipesName, Ingredients.IngredientsID, Ingredients.IngredientsName FROM IngredientsRecipes INNER JOIN Ingredients ON IngredientsRecipes.IngredientsID = Ingredients.IngredientsID INNER JOIN Recipes ON IngredientsRecipes.RecipesID = Recipes.RecipesID WHERE Ingredients.IngredientsName IN ('salt', 'water', 'flower') </code></pre> <p>I am currently constructing my query using ASP.NET C# because of the dynamic nature of the <code>WHERE</code> clause.</p> <p>I bites that I have to construct the query in my code-layer instead of using a stored procedure/pure SQL, which in theory should be much faster.</p> <p>Have you guys got any thoughts on how I would move all of the logic from my code-layer to pure SQL, or at least how I can optimize the performance of what I'm doing?</p> <p>I am thinking along the lines of temporary tables:</p> <p><strong>Step one</strong>: <code>SELECT IngredientsID FROM Ingredients</code> and <code>INSERT INTO temp-table</code></p> <p><strong>Step two</strong>: <code>SELECT RecipesName FROM Recipes</code> joined with <code>IngredientsRecipes</code> joined with <code>temp-table.IngredientsID</code></p>
<p>You have two options. If you're using SQL Server 2008 (or Oracle) you can pass in a <a href="http://www.sqlteam.com/article/sql-server-2008-table-valued-parameters" rel="nofollow">table value parameter</a>. </p> <p>If you're using SQL Server 2005, you can use <a href="http://weblogs.asp.net/jgalloway/archive/2007/02/16/passing-lists-to-sql-server-2005-with-xml-parameters.aspx" rel="nofollow">XML to simulate this capability</a></p> <p>If you're using something earlier than 2005, you need to concatenate the ids in a single string and create a UDF to parse them.</p>
Specifying the type of ArrayList's elements <p>I thought that there was some way in .net 3.0 to give an array list a type so that it didnt just return Object's but I'm having trouble doing so. Is it possible? If so, how?</p>
<p><code>List&lt;T&gt;</code> was introduced with generics in .NET 2.0:</p> <pre><code>using System.Collections.Generic; var list = new List&lt;int&gt;(); list.Add(1); list.Add("string"); //compile-time error! int i = list[0]; </code></pre>
Robust and easy to implement serial bus (automotive application) <p>What serial communication bus would you use in a automotive embedded system if your main selection criteria were: </p> <ul> <li>Electrically robust </li> <li>Slow speed (32 kb/s) </li> <li>Easy to program </li> <li>Easy to interface with microcontrollers </li> </ul> <p>It won't be transferring much data, but it will need to be transferred periodically at high speed (100 - 500 Hz). I find that RS-232 is just not reliable enough if you have noise in your ground line. CAN-bus seems interesting, but I have no experience with it. </p> <p>We are currently interested in a combination of AVR AT90CAN128 microcontrollers.</p>
<p>You've already chosen the AT90CAN128, whose standout feature compared to other AVR processors is support for the CAN bus. There really is not a better choice than CAN for an automotive application with your data rate and noise immunity requirements. If you march in to an automotive customer with anything other than CAN, you'll end up spending all your time defending the decision not to use it.</p> <p>With that said, for noise immunity in a hostile environment like a car you'll need a bus using differential signaling. That rules out i2c or SPI, which is unfortunate because they meet your other requirements. RS-485 would be workable as @Andrew Edgecombe points out.</p> <p>If you're not building a commercial product but instead building something for your own use to put in the engine compartment, you can probably get by with USB. USB will make it easy to interface with a laptop in the passenger compartment, and though it isn't designed for high-noise environments it is differentially signaled at a reasonably high voltage.</p>
How do I allow a user to use their own domain name for a hosted service? <p>I am working on an ASP.NET MVC web app that allows people to publish content, but other than publish the content to a remote server, I want to allow people to use their domain name directly. For example, the user "Tom" can have his domain name TomSite.com point to <a href="http://www.mywebapp.com/user/tom" rel="nofollow">http://www.mywebapp.com/user/tom</a>, but the sub path will also be mapped. For example, TomSite.com/path will be mapped to www.mywebapp.com/user/tom/path, and this is transparent to the web visitor. The visitor will never see "mywebapp.com" anywhere on TomSite.com.</p> <p>I think Smugmug.com provides such service, to allow people to use their own domain name for the photo portfolio. I want to achieve the same result.</p> <p>How can I do this? Thanks!</p>
<p>This require multiple steps.</p> <p>First you have to find out how your users will configure their domain to have a CNAME record for you site. You can archieve this in a number of ways where the best is education. Making partnerships with hosting providers requires a great deal of volume.</p> <p>In IIS this will require you to either add each host name manually (however this could also be archieved through scripting) or have a dedicated IP address only for you site.</p> <p>There is also a need for the domain to be associated with an account. The user has to add this themselves and you would probably add a check in the interface which confirms the domain is pointed at your server. The code for this would look like (remember to include the System.Net namespace).</p> <pre><code>if (Dns.GetHostEntry("www.user.example.com").HostName == "www.example.com") { // www.user.example.com is a CNAME for www.example.com } </code></pre> <p>In you ASP.NET MVC project you need to implement routes for this particular purpose. Create a custom class inheriting from Route which also takes the domain into account.</p>
Teaching: Field, Class & Package Relationships <p>In general I think I can convey most programming related concepts quite well.<br /> Yet, I still find it hard to summarise the relationship between Fields, Classes and Packages.</p> <p><br> <strong>How do You summarise "Fields", "Classes" and "Packages" and "Their Relationship" ?</strong></p>
<p>I've faced a similar problem since I taught C, C++, and Java. Here is what I do:</p> <p>First, I keep packages separately and explain them in the end.</p> <p>Ideally, in my opinion, students should first learn about ADTs, preferably in C. They have the struct, they have the separate operations on it. Fields are then simply the "slots" in the struct and you can even show the memory layout to demonstrate it. Functions are separate entities that operate on those structs. </p> <p>You then make the transition to classes, methods, and fields and show that in essence (barring inheritance and some anecdotes) they are in many ways syntactic sugar for ADTs.</p> <p>If you need, you can then teach object layouts, inheritance, and virtual tables (in my experience it helps students understand inheritance better to see the memory layout).</p> <p>Finally you get to the topic of how to organize classes together. If you teach C++, you don't really have packages but you can explain namespaces and discuss organization and separate compilation.</p> <p>If you are in Java, then you just explain that these are collections of classes in the same namespace, that have special access rules and show them. The package system in Java is kind of broken anyway so I usually go through patterns (e.g., separating a UI package from the C). </p> <p>So in summary: Classes form the basis for objects that are a memory arrangement of several fields and associated methods that operate on them. Packages are collections of classes that have one more access restriction mechanism.</p>
Things to consider when writing for touch screen? <p>I'm starting a new project which involves developing an interface for a machine that measures wedge and roundness of lenses and stores the information in a database and reports on it. There's a decent chance we're going to be putting a touch screen on this machine so that it doesn't need to have a mouse or keyboard... </p> <p>I don't have any experience developing for full size touch screens, so I'm looking for advice/tips/info from you guys...</p> <p>I can imagine you want to make the elements a little larger than normal... space buttons out a bit more.... things like that... anyone have anything else to add?</p>
<p>A few things to consider:</p> <ul> <li><p>You need to account for parallax error when touching controls. Basically, the user may touch the screen above or below your actual control and therefore miss the control. This is a combination of the size of the control (eg you can have the active area larger than visual control to allow the user to miss and still activate the control), the viewing angle of the user (which you may or may not be able to predict/control) and the type of touch screen you're using. If you know where the user will be placed relative to the screen when using it, you can usually accommodate this with appropriate calibration.</p></li> <li><p>Depending on the type of touch screen, you may need to ensure that your users aren't wearing gloves or using an implement other than their fingers (eg the end of a pen) to touch the screen. Some screens (eg those depending on conductance) don't respond well to anything other than flesh and blood.</p></li> <li><p>Avoid using double clicks because it can be very hard for users to reliably double click a control. This can be partly mitigated if you've got experienced/trained users working in a fairly controlled environment where they're used to the screens.</p></li> <li><p>Linked to the above, if you are using double clicks, you may find the double click activated when the user only wants to single click. This is because it's very easy for the user's finger to bounce slightly on touching the screen and, depending on how sensitive the double click settings are, trigger a double rather than a single click. For this and the previous reason, we always disable double clicks and only use single clicks (or similar single activation controls).</p></li> <li><p>However big you think you need to make the controls to allow for touch activation, they almost certainly need to be bigger still. Make sure you test the interface with real users in the real deployment environment (or as close to it as you can get). For example, we deployed some screens with nice big buttons you couldn't miss only to find that the control room was unheated and that the users were wearing thick gloves in the middle of winter, making their fingers way bigger than we had allowed for.</p></li> <li><p>Don't put any controls near the edges of the screen - it's very hard to get your finger into the edges (particularly if the screen has a deep bezel) and a slight calibration problem can easily shift the control too close to the edge to use. Standard menus and scroll bars are a good example of controls that can be very tricky to use on a touch screen and you should either avoid them (which is preferable - they're not good for touch screens) or replicate them with jumbo equivalents.</p></li> <li><p>Remember that the user's hand will be over the screen, obscuring some of the screen and controls (typically those below where the user is touching, but it depends on the position of the user relative to the screen). Don't put instructions or indicators where the user's hand or arm will obscure them when trying to use the control they relate to (eg typically put them above rather than below the control).</p></li> <li><p>Depending on the environment, make sure your touch screen is suitably proofed against dust, damp, grease etc and make sure it's easy to clean without damaging it. You wouldn't believe the slime that can quickly accumulate on a touch screen in an industrial or public setting.</p></li> </ul>
jQuery get textarea text <p>Recently I have started playing with jQuery, and have been following a couple of tutorials. Now I feel slightly competent with using it (it's pretty easy), and I thought it would be cool if I were able to make a 'console' on my webpage (as in, you press the ` key like you do in <a href="http://en.wiktionary.org/wiki/first-person_shooter">FPS</a> games, etc.), and then have it Ajax itself back to the server in-order to do stuff.</p> <p>I originally thought the best way would be to just get the text inside the textarea, and then split it, or should I use the keyup event, convert the keycode returned to an ASCII character, append the character to a string and send the string to the server (then empty the string).</p> <p>I couldn't find any information on getting text from a textarea, all I got was keyup information. Also, how can I convert the keycode returned to an ASCII character?</p>
<p>Why would you want to convert key strokes to text? Add a button that sends the text inside the textarea to the server when clicked. You can get the text using the value attribute as the poster before has pointed out, or using jQuery's API:</p> <pre><code>$('input#mybutton').click(function() { var text = $('textarea#mytextarea').val(); //send to server and process response }); </code></pre>
How to judge the strength of a directed acyclic graph? <p>Curious what is recognized as a solid algorithm/approach for judging the strength of a directed acyclic graph - particularly the strength of certain nodes. The main question I have about this can be boiled down to the following two graphs:</p> <p> (if graph doesn't show up, click here or visit this link: <a href="http://www.flickr.com/photos/86396568@N00/2893003041/" rel="nofollow">http://www.flickr.com/photos/86396568@N00/2893003041/</a></p> <p>To my eyes, A is in a stronger position than a. I am judging strength by how strong a node can remain if a link is knocked out. I'd call the first a thin "stilt", and the second a thick "stalk".</p> <p>Here are the approaches I've considered so far for judging the strength of a node:</p> <p>1) Counting the number of nodes below, subtracting the number of nodes above.</p> <ul> <li>A=7, a=7, B=5, b=1</li> </ul> <p>2) Counting the number of complete paths (to termination) for each node, summing their lengths.</p> <ul> <li>A=17 (1+5+5+5+1), B=12 (4+4+4), a=9 (3+3+3), b=2</li> <li>This make the stilt stronger, rather than the stalk.</li> </ul> <p>3) Counting every possible path, treating every node as a destination.</p> <ul> <li>A=9 (A->B, A->C, A->D, A->E, A->G, 2xA->F, 2xA->H), B=6, a=9, b=2</li> </ul> <p>3 seems like the best option so far, but is there one that is better, generalized for DAGs? Is this something that has a known best approach? The principles are to use as much information in the graph as possible, and for the solution to be explainable in an intuitive way.</p>
<p>This really depends on what you mean by strength. Because of the versatility of the DAG in representing information, you could be discussing anything from a multiple-outcome control flow to argument clauses of non-adverbial discourse connectives or even the full set of dependencies between different words in a sentence.</p> <p>All of these would view node strength in a different way. For instance, a control flow may consider the node with the most amount of outcomes (therefore the most outward arcs) as the strongest, because it has the most power over the eventual outcome of the diagram. In discourse, the strongest node is the discourse connective, but it is found in speech and text after the first connective and before the third. Selection of the lexical "head" of a sentence is not directly related to the amount of arcs directly interacting with it.</p> <p>What I'm getting at is that there is no real panacea for computing "strength" in this data type because of the polysemous character of the term "strength" and the kind of data a DAG fits. I would say that in a machine learning problem, all three of these approaches would be very informative in selecting particular types of nodes for a classification or ranking problem, but in the end, the answer depends upon the data type's practical application.</p>
Can I get the current page sourcecode from a firefox extension? <p>Can this be done? How?</p> <p><hr /></p> <p>I want to write my own extension. Can Get the current page sorcecode in my own extension?</p>
<p>As Rich says, adding <code>view-source</code> in front of the URL will give you the current page's source code. A keyboard shortcut for this is <code>Ctrl+U</code>.</p> <blockquote> <p>I want to write my own extension.</p> </blockquote> <p>There are a number of existing Firefox extensions that fetch a page's source code and apply some action to it (colour-coding, syntax-checking, etc). Downloading them and looking at how they handle it may be a good place to start!</p> <ul> <li><p><a href="http://www.searchenginejournal.com/7-firefox-extensions-to-explore-page-source-code/7375/" rel="nofollow">7 Firefox extensions to explore source code</a></p></li> <li><p><a href="https://addons.mozilla.org/en-US/firefox/addon/697" rel="nofollow">View Formatted Source extension</a></p></li> </ul> <p>If you're new to Firefox extension development, <a href="http://lifehacker.com/software/programming/how-to-build-a-firefox-extension-264490.php" rel="nofollow">this article at Lifehacker</a> is an excellent primer in how to start, and will give you an idea of where to look in the above linked extensions for tasks that may be similar to your own.</p>
Implementing multithreading in C# (code review) <p>Greetings.</p> <p>I'm trying to implement some multithreaded code in an application. The purpose of this code is to validate items that the database gives it. Validation can take quite a while (a few hundred ms to a few seconds), so this process needs to be forked off into its own thread for each item.</p> <p>The database may give it 20 or 30 items a second in the beginning, but that begins to decline rapidly, eventually reaching about 65K items over 24 hours, at which point the application exits.</p> <p>I'd like it if anyone more knowledgeable could take a peek at my code and see if there's any obvious problems. No one I work with knows multithreading, so I'm really just on my own, on this one.</p> <p>Here's the code. It's kinda long but should be pretty clear. Let me know if you have any feedback or advice. Thanks!</p> <pre><code>public class ItemValidationService { /// &lt;summary&gt; /// The object to lock on in this class, for multithreading purposes. /// &lt;/summary&gt; private static object locker = new object(); /// &lt;summary&gt;Items that have been validated.&lt;/summary&gt; private HashSet&lt;int&gt; validatedItems; /// &lt;summary&gt;Items that are currently being validated.&lt;/summary&gt; private HashSet&lt;int&gt; validatingItems; /// &lt;summary&gt;Remove an item from the index if its links are bad.&lt;/summary&gt; /// &lt;param name="id"&gt;The ID of the item.&lt;/param&gt; public void ValidateItem(int id) { lock (locker) { if ( !this.validatedItems.Contains(id) &amp;&amp; !this.validatingItems.Contains(id) ){ ThreadPool.QueueUserWorkItem(sender =&gt; { this.Validate(id); }); } } } // method private void Validate(int itemId) { lock (locker) { this.validatingItems.Add(itemId); } // ********************************************* // Time-consuming routine to validate an item... // ********************************************* lock (locker) { this.validatingItems.Remove(itemId); this.validatedItems.Add(itemId); } } // method } // class </code></pre>
<p>The thread pool is a convenient choice if you have <em>light weight</em> sporadic processing that isn't time sensitive. However, I recall reading on MSDN that it's not appropriate for large scale processing of this nature.</p> <p>I used it for something quite similar to this and regret it. I took a worker-thread approach in subsequent apps and am much happier with the level of control I have.</p> <p>My favorite pattern in the worker-thread model is to create a master thread which holds a queue of tasks items. Then fork a bunch of workers that pop items off that queue to process. I use a blocking queue so that when there are no items the process, the workers just block until something is pushed onto the queue. In this model, the master thread produces work items from some source (db, etc.) and the worker threads consume them.</p>
What's the future of the web? XHTML 2, HTML 5, or something else? <p>I'm confused by the discussion and advancement both of a new version of HTML and a new version of XHTML. Are they competitors? If so, what is likeliest to be the adopted future of the web? If not, what is the differing non-competing purpose for each?</p> <p>Are we due to have a BluRay/HDVD battle here? Is there ultimately any clear decision? I fear a future where browsers pick and choose among the easiest and/or flashiest features of each to implement, leaving web developers trying to sort out the lowest common denominator for any new web app.</p>
<p>HTML 5 is meant for web applications whereas XHTML2 is meant for documents. From the <a href="http://www.w3.org/TR/html5/introduction.html#relationship0" rel="nofollow">HTML 5 working draft</a>:</p> <blockquote> <p>XHTML2 defines a new HTML vocabulary with better features for hyperlinks, multimedia content, annotating document edits, rich metadata, declarative interactive forms, and describing the semantics of human literary works such as poems and scientific papers. </p> <p>However, it lacks elements to express the semantics of many of the non-document types of content often seen on the Web. For instance, forum sites, auction sites, search engines, online shops, and the like, do not fit the document metaphor well, and are not covered by XHTML2. </p> <p>[HTML5] aims to extend HTML so that it is also suitable in these contexts. </p> <p>XHTML2 and [HTML5] use different namespaces and therefore can both be implemented in the same XML processor. </p> </blockquote>
Distributing iPhone applications 2.1 vs 2.0 <p>Can iPhone applications compiled against 2.1 be successfully installed via iTunes on a 2.0 device?</p> <p>I know iPhone applications compiled with 2.1 can <em>run</em> on a 2.0 device (assuming they're not using anything new from 2.1). But am not sure if iTunes will let the install take place.</p> <p>Does anyone have concrete information on this?</p> <p>I have not seen any apps on the AppStore that are 2.1+ only.</p>
<p>I believe apps that are compiled against 2.1 will be marked as "Requires iPhone 2.1 Softwar Update" when viewed through iTunes. (but not when viewed from an iPhone - the iPhone's App Store app only displays a subset of an app's metadata.)</p> <p>One example: <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=289310044&amp;mt=8" rel="nofollow">Caliper</a> (it's under "Application Description->Requirements")</p> <p>I don't know if this "requirement" is actually enforced, however.</p>
C++ performance vs. Java/C# <p>My understanding is that C/C++ produces native code to run on a particular machine architecture. Conversely, languages like Java and C# run on top of a virtual machine which abstracts away the native architecture. Logically it would seem impossible for Java or C# to match the speed of C++ because of this intermediate step, however I've been told that the latest compilers ("hot spot") can attain this speed or even exceed it.</p> <p>Perhaps this is more of a compiler question than a language question, but can anyone explain in plain English how it is possible for one of these virtual machine languages to perform better than a native language?</p>
<h2>JIT vs. Static Compiler</h2> <p>As already said in the previous posts, JIT can compile IL/bytecode into native code at runtime. The cost of that was mentionned, but not to its conclusion:</p> <p>JIT has one massive problem is that it can't compile everything: JIT compiling takes time, so the JIT will compile only some parts of the code, whereas a static compiler will produce a full native binary: For some kind of programs, the static compiler will simply easily outperform the JIT.</p> <p>Of course, C# (or Java, or VB) is usually faster to produce viable and robust solution than is C++ (if only because C++ has complex semantics, and C++ standard library, while interesting and powerful, is quite poor when compared with the full scope of the standard library from .NET or Java), so usually, the difference between C++ and .NET or Java JIT won't be visible to most users, and for those binaries that are critical, well, you can still call C++ processing from C# or Java (even if this kind of native calls can be quite costly in themselves)...</p> <h2>C++ metaprograming</h2> <p>Note that usually, you are comparing C++ runtime code with its equivalent in C# or Java. But C++ has one feature that can outperform Java/C# out of the box, that is template metaprograming: The code processing will be done at compilation time (thus, increasing vastly compilation time), resulting into zero (or almost zero) runtime.</p> <p><s>I have yet so see a real life effect on this (I played only with concepts, but by then, the difference was seconds of execution for JIT, and <strong>zero</strong> for C++), but this is worth mentioning, alongside the fact template metaprograming is not trivial...</s></p> <blockquote> <p><i><b>Edit 2011-06-10:</b> In C++, playing with types is done at compile time, meaning producing generic code which calls non-generic code (e.g. a generic parser from string to type T, calling standard library API for types T it recognizes, and making the parser easily extensible by its user) is very easy and very efficient, whereas the equivalent in Java or C# is painful at best to write, and will always be slower and resolved at runtime even when the types are known at compile time, meaning your only </i>hope<i> is for the JIT to inline the whole thing.</i></p> </blockquote> <p>...</p> <blockquote> <p><i><b>Edit 2011-09-20:</b> The team behind Blitz++ (<a href="http://www.oonumerics.org/blitz/whatis.html" rel="nofollow">Homepage</a>, <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Blitz%2B%2B" rel="nofollow">Wikipedia</a>) went that way, and apparently, their goal is to reach FORTRAN's performance on scientific calculations by moving as much as possible from runtime execution to compilation time, via C++ template metaprogramming. So the "</i>I have yet so see a real life effect on this<i>" part I wrote above apparently <b>does</b> exist in real life.</i></p> </blockquote> <h2>Native C++ Memory Usage</h2> <p>C++ has a memory usage different from Java/C#, and thus, has different advantages/flaws.</p> <p>No matter the JIT optimization, nothing will go has fast as direct pointer access to memory (let's ignore for a moment processor caches, etc.). So, if you have contiguous data in memory, accessing it through C++ pointers (i.e. C pointers... Let's give Caesar its due) will goes times faster than in Java/C#. And C++ has RAII, which makes a lot of processing a lot easier than in C# or even in Java. C++ does not need <code>using</code> to scope the existence of its objects. And C++ does not have a <code>finally</code> clause. This is not an error.</p> <p>:-)</p> <p>And despite C# primitive-like structs, C++ "on the stack" objects will cost nothing at allocation and destruction, and will need no GC to work in an independent thread to do the cleaning.</p> <p>As for memory fragmentation, memory allocators in 2008 are not the old memory allocators from 1980 that are usually compared with a GC: C++ allocation can't be moved in memory, true, but then, like on a Linux filesystem: Who needs hard disk defragmenting when fragmentation does not happen? Using the right allocator for the right task should be part of the C++ developer toolkit. Now, writing allocators is not easy, and then, most of us have better things to do, and for the most of use, RAII or GC is more than good enough.</p> <blockquote> <p><i><b>Edit 2011-10-04:</b> For examples about efficient allocators: On Windows platforms, since Vista, the <a href="http://msdn.microsoft.com/en-us/library/aa366750.aspx" rel="nofollow">Low Fragmentation Heap</a> is enabled by default. For previous versions, the LFH can be activated by calling the WinAPI function <a href="http://msdn.microsoft.com/en-us/library/aa366705.aspx" rel="nofollow">HeapSetInformation</a>). On other OSes, alternative allocators are provided (see <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Malloc" rel="nofollow">https://secure.wikimedia.org/wikipedia/en/wiki/Malloc</a> for a list)</i></p> </blockquote> <p>Now, the memory model is somewhat becoming more complicated with the rise of multicore and multithreading technology. In this field, I guess .NET has the advantage, and Java, I was told, held the upper ground. It's easy for some "on the bare metal" hacker to praise his "near the machine" code. But now, it is quite more difficult to produce better assembly by hand than letting the compiler to its job. For C++, the compiler became usually better than the hacker since a decade. For C# and Java, this is even easier.</p> <p>Still, the new standard C++0x will impose a simple memory model to C++ compilers, which will standardize (and thus simplify) effective multiprocessing/parallel/threading code in C++, and make optimizations easier and safer for compilers. But then, we'll see in some couple of years if its promises are held true.</p> <h2>C++/CLI vs. C#/VB.NET</h2> <p><i>Note: In this section, I am talking about C++/CLI, that is, the C++ hosted by .NET, not the native C++.</i></p> <p>Last week, I had a training on .NET optimization, and discovered that the static compiler is very important anyway. As important than JIT.</p> <p>The very same code compiled in C++/CLI (or its ancestor, Managed C++) could be times faster than the same code produced in C# (or VB.NET, whose compiler produces the same IL than C#).</p> <p>Because the C++ static compiler was a lot better to produce already optimized code than C#'s.</p> <p>For example, function inlining in .NET is limited to functions whose bytecode is less or equal than 32 bytes in length. So, some code in C# will produce a 40 bytes accessor, which won't be ever inlined by the JIT. The same code in C++/CLI will produce a 20 bytes accessor, which will be inlined by the JIT.</p> <p>Another example is temporary variables, that are simply compiled away by the C++ compiler while still being mentioned in the IL produced by the C# compiler. C++ static compilation optimization will result in less code, thus authorizes a more aggressive JIT optimization, again.</p> <p>The reason for this was speculated to be the fact C++/CLI compiler profited from the vast optimization techniques from C++ native compiler.</p> <h2>Conclusion</h2> <p>I love C++.</p> <p>But as far as I see it, C# or Java are all in all a better bet. Not because they are faster than C++, but because when you add up their qualities, they end up being more productive, needing less training, and having more complete standard libraries than C++. And as for most of programs, their speed differences (in one way or another) will be negligible...</p> <h2>Edit (2011-06-06)</h2> <h3>My experience on C#/.NET</h3> <p>I have now 5 months of almost exclusive professional C# coding (which adds up to my CV already full of C++ and Java, and a touch of C++/CLI).</p> <p>I played with WinForms (Ahem...) and WCF (cool!), and WPF (Cool!!!! Both through XAML and raw C#. WPF is so easy I believe Swing just cannot compare to it), and C# 4.0.</p> <p>The conclusion is that while it's easier/faster to produce a code that works in C#/Java than in C++, it's a lot harder to produce a strong, safe and robust code in C# (and even harder in Java) than in C++. Reasons abound, but it can be summarized by:</p> <ol> <li><b>Generics are not as powerful as templates</b> (<i>try to write an efficient generic Parse method (from string to T), or an efficient equivalent of boost::lexical_cast in C# to understand the problem</i>)</li> <li><b>RAII remains unmatched</b> (<i>GC still can leak (yes, I had to handle that problem) and will only handle memory. Even C#'s <code>using</code> is not as easy and powerful because writing a correct Dispose implementations is difficult</i>)</li> <li><b>C# <code>readonly</code> and Java <code>final</code> are nowhere as useful as C++'s <code>const</code></b> (<i>There's no way you can expose readonly complex data (a Tree of Nodes, for example) in C# without tremendous work, while it's a built-in feature of C++. Immutable data is an interesting solution, but not everything can be made immutable, so it's not even enough, by far</i>).</li> </ol> <p>So, C# remains an pleasant language as long as you want something that works, but a frustrating language the moment you want something that <i>always and safely</i> works.</p> <p>Java is even more frustrating, as it has the same problems than C#, and more: Lacking the equivalent of C#'s <code>using</code> keyword, a very skilled colleague of mine spent too much time making sure its resources where correctly freed, whereas the equivalent in C++ would have been easy (using destructors and smart pointers).</p> <p>So I guess C#/Java's productivity gain is visible for most code... until the day you need the code to be as perfect as possible. That day, you'll know pain. (you won't believe what's asked from our server and GUI apps...).</p> <h3>About Server-side Java and C++</h3> <p>I kept contact with the server teams (I worked 2 years among them, before getting back to the GUI team), at the other side of the building, and I learned something interesting.</p> <p>Last years, the trend was to have the Java server apps be destined to replace the old C++ server apps, as Java has a lot of frameworks/tools, and is easy to maintain, deploy, etc. etc..</p> <p>...Until the problem of low-latency reared its ugly head the last months. Then, the Java server apps, no matter the optimization attempted by our skilled Java team, simply and cleanly lost the race against the old, not really optimized C++ server.</p> <p>Currently, the decision is to keep the Java servers for common use where performance while still important, is not concerned by the low-latency target, and aggressively optimize the already faster C++ server applications for low-latency and ultra-low-latency needs.</p> <h3>Conclusion</h3> <p>Nothing is as simple as expected.</p> <p>Java, and even more C#, are cool languages, with extensive standard libraries and frameworks, where you can code fast, and have result very soon.</p> <p>But when you need raw power, powerful and systematic optimizations, strong compiler support, powerful language features and absolute safety, Java and C# make it difficult to win the last missing but critical percents of quality you need to remain above the competition.</p> <p>It's as if you needed less time and less experienced developers in C#/Java than in C++ to produce average quality code, but in the other hand, the moment you needed excellent to perfect quality code, it was suddenly easier and faster to get the results right in C++.</p> <p>Of course, this is my own perception, perhaps limited to our specific needs.</p> <p>But still, it is what happens today, both in the GUI teams and the server-side teams.</p> <p>Of course, I'll update this post if something new happens.</p> <h2>Edit (2011-06-22)</h2> <blockquote> <p>"We find that in regards to performance, C++ wins out by a large margin. However, it also required the most extensive tuning efforts, many of which were done at a level of sophistication that would not be available to the average programmer.</p> <p>[...] The Java version was probably the simplest to implement, but the hardest to analyze for performance. Specifically the effects around garbage collection were complicated and very hard to tune."</p> </blockquote> <p>Sources:</p> <ul> <li><a href="https://days2011.scala-lang.org/sites/days2011/files/ws3-1-Hundt.pdf" rel="nofollow">https://days2011.scala-lang.org/sites/days2011/files/ws3-1-Hundt.pdf</a></li> <li><a href="http://www.computing.co.uk/ctg/news/2076322/-winner-google-language-tests" rel="nofollow">http://www.computing.co.uk/ctg/news/2076322/-winner-google-language-tests</a></li> </ul> <h2>Edit (2011-09-20)</h2> <blockquote> <p>"The going word at Facebook is that '<b>reasonably written C++ code just runs fast,</b>' which underscores the enormous effort spent at optimizing PHP and Java code. Paradoxically, C++ code is more difficult to write than in other languages, but <b>efficient code is a lot easier [to write in C++ than in other languages].</b>"</p> <p>– <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Herb_Sutter" rel="nofollow">Herb Sutter</a> at <a href="http://www.buildwindows.com/" rel="nofollow">//build/</a>, quoting <b><a href="https://secure.wikimedia.org/wikipedia/en/wiki/Andrei_Alexandrescu" rel="nofollow">Andrei Alexandrescu</a></b></p> </blockquote> <p>Sources:</p> <ul> <li><a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-835T" rel="nofollow">http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-835T</a></li> <li><a href="http://video.ch9.ms/build/2011/slides/TOOL-835T_Sutter.pptx" rel="nofollow">http://video.ch9.ms/build/2011/slides/TOOL-835T_Sutter.pptx</a></li> </ul>
Algorithm to estimate number of English translation words from Japanese source <p>I'm trying to come up with a way to estimate the number of English words a translation from Japanese will turn into. Japanese has three main scripts -- <a href="http://en.wikipedia.org/wiki/Kanji" rel="nofollow">Kanji</a>, <a href="http://en.wikipedia.org/wiki/Hiragana" rel="nofollow">Hiragana</a>, and <a href="http://en.wikipedia.org/wiki/Katakana" rel="nofollow">Katakana</a> -- and each has a different average character-to-word ratio (Kanji being the lowest, Katakana the highest).</p> <p><strong>Examples:</strong></p> <ul> <li>computer: コンピュータ (Katakana - 6 characters); 計算機 (Kanji: 3 characters)</li> <li>whale: くじら (Hiragana -- 3 characters); 鯨 (Kanji: 1 character)</li> </ul> <p>As data, I have a large glossary of Japanese words and their English translations, and a fairly large corpus of matched Japanese source documents and their English translations. I want to come up with a formula that will count numbers of Kanji, Hiragana, and Katakana characters in a source text, and estimate the number of English words this is likely to turn into.</p>
<p>Here's what Borland (now Embarcadero) thinks about English to non-English:</p> <p><a href="http://www.podgoretsky.com/ftp/Docs/Delphi/D5/dg/intapps.html" rel="nofollow">Length of English string (in characters)</a></p> <pre><code>Expected increase 1-5 100% 6-12 80% 13-20 60% 21-30 40% 31-50 20% over 50 10% </code></pre> <p>I think you can sort of apply this (with some modification) for Japanese to non-Japanese. </p> <p>Another element you might want to consider is the tone of the language. In English, instructions are phrased as an imperative as in "Press OK." But in Japanese language, imperatives are considered rude, and you must phrase instructions in honorific (or keigo) as in "OKボタンを押してください。"</p> <p>Watch out for three-letter kanji combos. Many of the big words translate into three- or four- letter kanji combo such as 国際化(internationalization: 20 chars), 高可用性(high availability: 17 chars).</p>
Calling C/C++ from python? <p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
<p>I like <a href="http://docs.python.org/2/library/ctypes.html">ctypes</a> a lot, <a href="http://www.swig.org/">swig</a> always tended to give me <a href="http://groups.google.com/group/comp.lang.python/browse_thread/thread/d94badd9847fe43a?pli=1">problems</a>. Also ctypes has the advantage that you don't need to satisfy any compile time dependency on python, and your binding will work on any python that has ctypes, not just the one it was compiled against.</p> <p>Suppose you have a simple C++ example class you want to talk to in a file called foo.cpp:</p> <pre><code>#include &lt;iostream&gt; class Foo{ public: void bar(){ std::cout &lt;&lt; "Hello" &lt;&lt; std::endl; } }; </code></pre> <p>Since ctypes can only talk to C functions, you need to provide those declaring them as extern "C"</p> <pre><code>extern "C" { Foo* Foo_new(){ return new Foo(); } void Foo_bar(Foo* foo){ foo-&gt;bar(); } } </code></pre> <p>Next you have to compile this to a shared library</p> <pre><code>g++ -c -fPIC foo.cpp -o foo.o g++ -shared -Wl,-soname,libfoo.so -o libfoo.so foo.o </code></pre> <p>And finally you have to write your python wrapper (e.g. in fooWrapper.py)</p> <pre><code>from ctypes import cdll lib = cdll.LoadLibrary('./libfoo.so') class Foo(object): def __init__(self): self.obj = lib.Foo_new() def bar(self): lib.Foo_bar(self.obj) </code></pre> <p>Once you have that you can call it like</p> <pre><code>f = Foo() f.bar() #and you will see "Hello" on the screen </code></pre>
Wide exec for C/C++ <p>Is there a <code>wchar_t</code> version of <code>exec[lv][pe]</code> (i.e. an <code>exec</code> that uses <code>wchar_t</code> as path and <code>wchar_t</code> as arguments)? In <code>Windows</code>, I can just do <code>CreateProcessW(process, cmdline)</code>, but in <code>*nix</code>, I'm stuck (i.e. no pure <code>POSIX</code> equivalent). I'm trying to add <code>UTF-16</code> support to my program (an autorun).</p>
<p>There is not. In UNIX, it's customary to use UTF-8 when interacting with the environment.</p>
How do I dictate the destination folder of a clickOnce application? <p>How do I dictate the destination folder of a clickOnce application?</p>
<p>This is not possible with ClickOnce. ClickOnce applications are always installed in the <code>Apps</code> subdirectory of local application data.</p>
Is there any performance difference in using .resx file and satellite assembly? <p>Which is the best way to go forward while building a localized aspx web application, .resx files of satellite assemblies? Is there any performance comparisons available any where on web?</p>
<p>Well I don't know if the comparison is valid.. </p> <p>ResX is a storage format for storing resources in XML. It gets compiled to a binary form (.resources) with the resgen tool before it gets embedded (if so specified) into the assembly.</p> <p>Satellite assembly is a diff/delta of your main assembly resources and your localized resources. So if you have a Strings.resx with 100 strings in MainAssembly.dll of which 10 change in French Canadian Culture, you should have a MainAssembly.resources.dll (satellite assembly) containing just those 10 strings in the fr-CA subdirectory of the DLL folder. When you query for a string resource using a ResourceManager, it takes into account current culture. If fr-CA, it will first look for the string in the satellite assembly in the fr-CA folder, if not found it will fall back to the resources in the DLL itself and return that. The mechanism is to search for it in the following order always.</p> <pre><code> - [fr-CA subfolder]\MyAssembly.resources.dll - [fr subfolder]\MyAssembly.resources.dll - DLL itself </code></pre> <p>For more details, check out <a href="https://web.archive.org/web/20090211132440/http://dotneti18n.com/" rel="nofollow">http://www.dotneti18n.com/</a> or the Resources chapter of 'Programming WPF'</p>
Deploy a Desktop Shortcut to a Device running Windows CE 4.2 (VS2005) <p>I have an application written using VS2005 in C# targeting the Compact Framework 2.0 SP2. As part of the solution, I have CAB deploy project which deploys to the device without a problem. What I can't do is create a shortcut to my application on the devices desktop.</p> <p>I have spent several hours reading various bits of documentation (why is the search at the MSDN site so bad?), followed the instructions but no joy. </p> <p>What I've done is:</p> <ul> <li>Add the "Windows Folder" node to the File System</li> <li>Created a folder underneath that named "Desktop"</li> <li>Created a shortcut to the Applications Primary Output and placed that in the "Desktop" folder</li> </ul> <p>What am I missing?</p>
<p>A bit late but maybe this will help somebody like me who searched for this issue, I solved the problem like this:</p> <p>I added a custom folder on the root node (File System on Local Machine) and called it %CE3%. That is the shortcut for \Windows\Desktop. I added my shortcut (right click create new shortcut) and gave it a name. That's it, then I build!</p> <p>When analysing the Shortcuts section in the inf generated, it looked good.</p> <pre><code>[Shortcuts] "ShortCutName",0,"MyApp.exe","%CE3%" </code></pre> <p>And when I deployed and it worked perfectly!</p> <p>I'm using VS2008 and deploy on windows CE 5.0</p> <p>Here is a list of shortcuts: <a href="http://www.cabextract.org.uk/wince_cab_format/#app_b">windows CE shortcuts</a></p>
Why Stackoverflow binds user actions dynamically with javascript? <p>Checking the HTML source of a question I see for instance:</p> <pre><code>&lt;a id="comments-link-xxxxx" class="comments-link"&gt;add comment&lt;/a&gt;&lt;noscript&gt;&amp;nbsp;JavaScript is needed to access comments.&lt;/noscript&gt; </code></pre> <p>And then in the javascript source:</p> <pre><code>// Setup our click events.. $().ready(function() { $("a[id^='comments-link-']").click(function() { comments.show($(this).attr("id").substr("comments-link-".length)); }); }); </code></pre> <p>It seems that all the user click events are binded this way.</p> <p>The downsides of this approach are obvious for people browsing the site with no javascript but, what are the advantages of adding events dynamically whith javascript over declaring them directly?</p>
<ul> <li>You don't have to type the same string over and over again in the HTML (which if nothing else would increase the number of typos to debug)</li> <li>You can hand over the HTML/CSS to a designer who need not have any javascript skills</li> <li>You have programmatic control over what callbacks are called and when</li> <li>It's more elegant because it fits the conceptual separation between layout and behaviour</li> <li>It's easier to modify and refactor</li> </ul> <p>On the last point, imagine if you wanted to add a "show comments" icon somewhere else in the template. It'd be very easy to bind the same callback to the icon.</p>
Best way to sandbox Apache on Linux <p>I have Apache running on a public-facing Debian server, and am a bit worried about the security of the installation. This is a machine that hosts several free-time hobby projects, so none of us who use the machine really have the time to constantly watch for upstream patches, stay aware of security issues, etc. But I would like to keep the bad guys out, or if they get in, keep them in a sandbox.</p> <p>So what's the best, easy to set up, easy to maintain solution here? Is it easy to set up a user-mode linux sandbox on Debian? Or maybe a chroot jail? I'd like to have easy access to files inside the sadbox from the outside. This is one of those times where it becomes very clear to me that I'm a programmer, not a sysadmin. Any help would be much appreciated!</p>
<p>Chroot jails can be really insecure when you are running a complete sandbox environment. Attackers have complete access to kernel functionality and for example may mount drives to access the "host" system.</p> <p>I would suggest that you use linux-vserver. You can see linux-vserver as an improved chroot jail with a complete debian installation inside. It is really fast since it is running within one single kernel, and all code execution is one natively. </p> <p>I personally use linux-vserver for seperation of all my services and there are only barely noticeable performance differences. </p> <p>Have a look at the <a href="http://linux-vserver.org/Installation_on_Debian">linux-vserver wiki</a> for installation instructions.</p> <p>regards, Dennis</p>
Existing Standard Style and Coding standard documents <p>The following have been proposed for an upcoming C++ project.</p> <ul> <li>C++ Coding Standards, by Sutter and Alexandrescu</li> <li>JSF Air Vehicle C++ coding standards</li> <li>The Elements of C++ Style</li> <li>Effective C++ 3rd Edition, by Scott Meyers</li> </ul> <p>Are there other choices? Or is the list above what be should used on a C++ project?</p> <p>Some related links</p> <ul> <li><a href="http://stackoverflow.com/questions/145508/do-you-think-a-software-company-should-impose-developers-a-coding-style">http://stackoverflow.com/questions/145508/do-you-think-a-software-company-should-impose-developers-a-coding-style</a></li> <li><a href="http://stackoverflow.com/questions/66268/what-is-the-best-cc-coding-style-closed">http://stackoverflow.com/questions/66268/what-is-the-best-cc-coding-style-closed</a></li> </ul>
<p><a href="http://rads.stackoverflow.com/amzn/click/0321113586">C++ Coding Standards: 101 Rules, Guidelines, and Best Practices</a> (C++ In-Depth Series) by Herb Sutter and, Andrei Alexandrescu.</p>
What techniques do you use to maximise code reuse? <p>Some years ago I was told about a study into code reuse. Apparently it was found that, on average, programmers have a 7 minute window when searching for code to reuse. If they don't find code that suits their needs within that window they'll write their own.</p> <p>This was presented in the context of needing to carefully manage your code for reuse to ensure that you can find what you need within the window.</p> <p>How do you (individuals and organisations) manage your source to make it easier to reuse? Do you specifically maintain a reuse library? And if so, how do you index it to maximise your hit rate?</p>
<p>A complex question:</p> <ul> <li><p>Some parts of the code can be generalized as libraries or APIs. We have a common library which is kept up to date with solutions to common problems. Typically: validation, caching, data access classes, logging, etc...</p></li> <li><p>Some parts are application specific. They cannot be generalized easily. We convert them in HowTos and give internal presentations. Code is also recycled by use of an easily browsable SCM (in our case SVN).</p></li> <li><p>We also have tools that generate code that one one hand cannot be recycled, on the other it's always similar (think calling a stored procedure).</p></li> <li><p>Pair programming is also a useful way to spread knowledge of existing solutions. We use that when possible or appropriate.</p></li> <li><p>The last technique is tuition. Each coder has a tutor to refer to. Since the tutors are few, there is a lot of sharing between them and this knowledge can be diffused in a top down manner.</p></li> </ul>
Firefox Sidebar and Document object of DOM <p>There is a webpage loaded in the firefox sidebar and another webpage loaded in the main document. Now, how do I ask access the main document object through the Firefox sidebar? An example to do this through Javascript code in the firefox sidebar document to access the main document would be helpful.</p> <p>Thanks for the answers. I have to refine my question however. The main window has some webpage loaded and the sidebar has a webpage. I want the sidebar window to know what text the user has selected on the main window when a link on the sidebar window is clicked. I know how to get the selected text from a window. Only that the sidebar element adds complexity to the problem that I am not able to surpass.</p> <p>@PConory:</p> <p>I like your answer, but when I try it there is an error: Error: Permission denied to create wrapper for object of class UnnamedClass.</p> <p>Thanks.</p>
<p>As far as I can tell, you are actually loading a web site in the sidebar (checked the 'Load this bookmark in Sidebar'). If this is the case, AND if the sidebar is opening the main window page. You can use the window.postMessage to communicate between them. But like I said, the sidebar page has to open the main page because you need the window reference in order to post the message.</p> <p>sidebar.js</p> <pre><code>var newwin = window.open('http://otherpage') newwin.onload = function() { newwin.postMessage('Hey newwin', 'http://sidebar'); }; mainpage.js window.addEventListener('message',function(e) { if(message.origin == 'http://sidebar') alert('message from sidebar'); },false); </code></pre> <p>Using this you still do not have access to the document, but can communicate between them and script out any changes you want to do.</p> <p>EDIT: Putting some more thought into it, if you opened the window from the side bar, you would have the DOM for it. var newwin = window.open('blah'); newwin.document making the hole postMessage thing pretty pointless.</p>
Favorite image file format for 2d sprites <p>What is your favorite, lossless image format for games (namely 2d games)? And why?</p> <p>Some things to take into consideration are size on disk, overhead for converting to a usable format, and features of the format (ie alpha support).</p> <p>There is no best answer, but be sure to back yours up the best you can!</p>
<p>I'd suggest PNG. Most software supports writing it, most libraries support reading it, it's lossless and supports alpha transparency. And it's a standard format.</p> <p>And, maybe important for hobbyist 2D games, very small images also result in very small files (i.e. a 16x16 icon can be 1KB or less).</p>
How do I get a stack trace in OCaml? <p>The Objective Caml language will only produce stack traces if you ask for them just right - what are the requirements for both bytecode and native code?</p>
<p>Compile with -g and set environment variable OCAMLRUNPARAM=b</p>
How can I determine that Windows Installer is performing an upgrade rather than a first time install? <p>I have an install that upgrades a previous version of an app if it exits. I'd like to skip certain actions when the install is upgrade mode. How can I determine if the install is running in upgrade mode vs. first time install mode?</p> <p>I'm using Wise Installer, but I don't think that matters. I'm assuming that Windows Installer has a property that is set when the installer is in upgrade mode. I just can't seem to find it. If the property exists, I'm assuming I could use it in a conditional statement.</p>
<p>Can you elaborate what kind of tools are you using to create this installer?</p> <p>I use Windows Installer XML(<a href="http://wix.sourceforge.net/" rel="nofollow">WIX</a>). In WIX you could do something like this:</p> <pre><code> &lt;!-- Property definitions --&gt; &lt;?define SkuName = "MyCoolApp"?&gt; &lt;?define ProductName="My Cool Application"?&gt; &lt;?define Manufacturer="Acme Inc."?&gt; &lt;?define Copyright="Copyright © Acme Inc. All rights reserved."?&gt; &lt;?define ProductVersion="1.1.0.0"?&gt; &lt;?define RTMProductVersion="1.0.0.0" ?&gt; &lt;?define UpgradeCode="{EF9D543D-9BDA-47F9-A6B4-D1845A2EBD49}"?&gt; &lt;?define ProductCode="{27EA5747-9CE3-3F83-96C3-B2F5212CD1A6}"?&gt; &lt;?define Language="1033"?&gt; &lt;?define CodePage="1252"?&gt; &lt;?define InstallerVersion="200"?&gt; </code></pre> <p>And define upgrade options: </p> <pre><code>&lt;Upgrade Id="$(var.UpgradeCode)"&gt; &lt;UpgradeVersion Minimum="$(var.ProductVersion)" IncludeMinimum="no" OnlyDetect="yes" Language="$(var.Language)" Property="NEWPRODUCTFOUND" /&gt; &lt;UpgradeVersion Minimum="$(var.RTMProductVersion)" IncludeMinimum="yes" Maximum="$(var.ProductVersion)" IgnoreRemoveFailure="no" IncludeMaximum="no" Language="$(var.Language)" Property="OLDIEFOUND" /&gt; &lt;/Upgrade&gt; </code></pre> <p>Then further you could use <code>OLDIEFOUND</code> and <code>NEWPRODUCTFOUND</code> properties depending on what you want to do:</p> <pre><code>&lt;!-- Define custom actions --&gt; &lt;CustomAction Id="ActivateProduct" Directory='MyCoolAppFolder' ExeCommand='"[MyCoolAppFolder]activateme.exe"' Return='asyncNoWait' Execute='deferred'/&gt; &lt;CustomAction Id="NoUpgrade4U" Error="A newer version of MyCoolApp is already installed."/&gt; </code></pre> <p>The above defined actions have to be define in <code>InstallExcecuteSequence</code> </p> <pre><code>&lt;InstallExecuteSequence&gt; &lt;Custom Action="NoUpgrade4U" After="FindRelatedProducts"&gt;NEWPRODUCTFOUND&lt;/Custom&gt; &lt;Custom Action="ActivateProduct" OnExit='success'&gt;NOT OLDIEFOUND&lt;/Custom&gt; &lt;/InstallExecuteSequence&gt; </code></pre>
Making Eclipse behave like Visual Studio <p>I'm doing some Android dev, and I much prefer Visual Studio, but I'll have to use <em>Eclipse</em> for this.</p> <p>Has anyone made a tool that switches <em>Eclipse</em> to look and behave more like visual studio? I mainly can't stand its <strong>clippyesqe</strong> suggestions on how I should program (Yes, I know I have not yet used that private field! Thanks Eclipse!), or its incredibly lousy <strong>intellisense</strong>.</p> <p>For example, in eclipse, if I don't type <code>this</code> first, its <strong>intellisense</strong> won't realize I want to look for locally scoped members. Also, the TAB to complete VS convention is drilled into my head, and <em>Eclipse</em> is ENTER to complete, I could switch everything by hand but that would take hours, and I was hoping someone had some sort of theme or something that has already done it :)</p>
<p>Have you tried using the Visual Studio keybindings available in Eclipse Ganymede (3.4)?</p> <p>(You may want to know that "IntelliSense" is a Visual Studio-term, an probably unknown to anyone without Visual Studio-experience. "Autocompletion" is probably a more widely used term.)</p>
Is it possible to programmatically change a user's screen saver and/or desktop background? <p>I have been asked to standardize the screen saver and desktop background used by everyone in my company and, aside from going around to each PC individually, I'm looking for a programmatic way to accomplish this. I am not a systems admin, so have never crossed this bridge before. It is also worth noting that most PCs are running Windows XP, however some are Windows Server 2003 and a few are Vista.</p>
<p>Why not just use <a href="http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/prork/prdb_cdk_ugxd.mspx?mfr=true">Group Policies</a>?</p>
OpenGL: How to do RGBA->RGBA blitting without changing destination alpha <p>I have an OpenGL RGBA texture and I blit another RGBA texture onto it using a framebuffer object. The problem is that if I use the usual blend functions with <code>glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), </code> the resulting blit causes the destination texture alpha to change, making it slightly transparent for places where alpha previously was 1. I would like the destination surface alpha never to change, but otherwise the effect on RGB values should be exactly like with <code>GL_SRC_ALPHA</code> and <code>GL_ONE_MINUS_SRC_ALPHA</code>. So the blend factor functions should be (As,As,As,0) and (1-As,1-As,1-As,1). How can I achieve that?</p>
<p>You can set the blend-modes for RGB and alpha to different equations:</p> <pre><code>void glBlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); </code></pre> <p>In your case you want to use the following enums:</p> <pre><code> glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE); </code></pre> <p>Note that you may have to import the glBlendFuncSeparate function as an extension. It's safe to do so though. The function is around for a very long time. It's part of OpenGL 1.4</p> <p>Another way to do the same is to disable writing to the alpha-channel using glColorMask:</p> <pre><code>void glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ) </code></pre> <p>It <strong>could</strong> be a lot slower than glBlendFuncSeparate because OpenGL-drivers optimize the most commonly used functions and glColorMask is one of the rarely used OpenGL-functions. </p> <p>If you're unlucky you may even end up with software-rendering emulation by calling oddball functions :-)</p>
nant: Can I extract the last directory in a path? <p>In Nant, I would like to be able to extract the last name of the directory in a path.<br /> For example, we have the path 'c:\my_proj\source\test.my_dll\'</p> <p>I would like to pass in that path and extract 'test.my_dll'</p> <p>Is there a way to easily do this?</p>
<p>You can actually do it with existing NAnt string functions. Just a bit ugly...</p> <pre><code>${string::substring(path, string::last-index-of(path, '\') + 1, string::get-length(path) - string::last-index-of(path, '\') - 1)} </code></pre>
Push or Pull? Turning keypresses into velocity for in-game vehicles <p>Should I push keypresses to vehicles when they're pressed, or should vehicles pull keys pressed from the engine?</p> <p>I have a vehicle object, which has location, velocity and accelleration members (among other things) and an update method, during which it updates its location based on its velocity, and its vevlocity based on its accelleration.</p> <p>I have a game object which contains the game loop, which calls the update method on the vehicle.</p> <p>If the player controls the vehicle with the arrow keys, should a keypress set the accelleration (push) and a key-release clear the velocity, or should the vehicle ask the game-engine if the accellerate key is pressed (pull)? I think a push would mean that the keyboard control module would need to know about vehicles, whereas pull would mean a vehicle needs to know specific keyboard controls.</p> <p>I think a related question would be something like: should all objects know about all other objects, or should there be a strict hierarchy, so objects can ask things / tell things to other objects up the tree, but not down (or vice-versa)?</p>
<p>You should try and follow an <a href="http://en.wikipedia.org/wiki/Observer_pattern" rel="nofollow">Subscribing/Observer</a> pattern. You put all the key capture code into one <a href="http://en.wikipedia.org/wiki/Singleton_pattern" rel="nofollow">singleton</a> InputManager and then each object that requires reaction to input registers with the manager.</p> <p>The manager holds the list of subscribed objects and sends events to them when the keys are pressed/depressed. Just don't forget to unsubscribe when the object is deleted or 'loses focus'.</p> <p>This avoids the polling problem. There are very few exceptions where a polling solution is desirable.</p>
Enhancing Performance in Real-Time Systems <p>First, I'd like to establish the acceptable end-to-end latency for a real-time system in the financial world is less than 200ms. Okay, here's what I'm after. In the design of real-time systems, there are "design patterns" (or techniques) that will increase the performance (i.e. reduce processing time, improve scalability, etc).</p> <p>An example of what I'm after is, the use of GUIDs instead of sequential numbers for allocation of primary keys. Rationale for GUIDs is that handlers have their own primary key generators without "consulting" each other. This allows for parallel processing to occur and permits scaling.</p> <p>Here're some more. I'll try and add to the list when able to.</p> <ul> <li>The use of <a href="http://en.wikipedia.org/wiki/Event_Driven_Architecture" rel="nofollow">event driven architecture (EDA)</a>.</li> <li>Use of messaging queues to support EDA.</li> </ul> <p>I bow to the collective wisdom of the community. Thanks heaps!</p>
<p>For general real-time system work, the classic rule is to go after variability and kill it. Real hard real-time means using static schedules, streamlined operating systems, efficient device drivers, and rock-hard priorities. No dynamic or adaptive stuff is feasible, if you really want computation X to end within a known time-bound T. </p> <p>I guess what you mean here is not really real-time in that respect, and I guess the system is a bit more complicated than reading sensors, computing control loop, activating actuators. Some more details would be nice to know waht the constraints are here.</p>
Java printf functionality for collections or arrays <p>In python you can use a tuple in a formatted print statement and the tuple values are used at the indicated positions in the formatted string. For example:</p> <pre><code>&gt;&gt;&gt; a = (1,"Hello",7.2) &gt;&gt;&gt; print "these are the values %d, %s, %f" % a these are the values 1, Hello, 7.200000 </code></pre> <p>Is there some way to use any array or collection in a java printf statement in a similar way?</p> <p>I've looked at the <a href="http://java.sun.com/javase/6/docs/api/java/util/Formatter.html#syntax" rel="nofollow">documentation</a> and it appears to have built in support for some types like Calendar, but I don't see anything for collections. </p> <p>If this isn't provided in java, is there any java idiom that would be used in a case like this where you are populating collections and then printing the values from many collections using one format string (other than just nested looping)?</p>
<p>printf will have a declaration along the lines of:</p> <pre><code>public PrintString printf(String format, Object... args); </code></pre> <p>... means much the same as <code>[]</code>. The difference is <code>...</code> allows the caller to omit explicitly creating an array. So consider:</p> <pre><code> out.printf("%s:%s", a, b); </code></pre> <p>That is the equivalent of:</p> <pre><code> out.printf("%s:%s", new Object[] { a, b }); </code></pre> <p>So, getting back to your question, for an array, you can just write:</p> <pre><code> out.printf("%s:%s", things); </code></pre> <p>For a collection:</p> <pre><code> out.printf("%s:%s", things.toArray()); </code></pre>
How do I get the resolution of the main monitor in Mac OS X in C++? <p>I have a graphical app that needs to test the resolution of the display it is starting up on in Mac OS X to ensure it is not larger than the resolution. This is done before the window itself is initialized. </p> <p>If there is more than one display, it needs to be the primary display. This is the display that hardware accelerated (OpenGL) apps will start up on in Full Screen, and is typically the display that has the menu bar at the top.</p> <p>In Windows, I can successfully use GetSystemMetrics(). How can I do this on OS X?</p>
<p>Using CoreGraphics:</p> <pre><code>CGRect mainMonitor = CGDisplayBounds(CGMainDisplayID()); CGFloat monitorHeight = CGRectGetHeight(mainMonitor); CGFloat monitorWidth = CGRectGetWidth(mainMonitor); </code></pre> <p>More information at Apple's <a href="http://developer.apple.com/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html">Quartz Display Services Reference</a>.</p>
How to programmatically simulate XP's "Windows Security" start menu option on Windows 2000 <p>I'm trying to find a way to invoke the Ctrl+Alt+Delete dialog on a Windows 2000 computer that I'm connected to via Remote Desktop. Windows XP and 2003 include a new start menu command called "Windows Security" that does this, but Windows 2000 has no such option.</p> <p>It appears that Ctrl+Alt+End will do this, but it only goes to the outermost RDP window, so if you're several connections deep, it doesn't help. In this scenario, I'm on computer A, connected to computer B. From computer B, I connect to computer C. Pressing Ctrl+Alt+End opens the Ctrl+Alt+Delete dialog on computer B, not computer C.</p> <p>The goal here is to allow users connecting to computer C to change their own passwords. The users are not administrators on the computer, so they can't access the various tools that an admin might use to accomplish this.</p> <p>[edit] I forgot to make this a programming question; my intent was to figure out how to do this from code (although a non-code method would be useful as well).</p>
<p>My coworker found the way to accomplish this directly: Start | Settings | Windows Security. If it's not present, it may have been disabled via Group Policy (<a href="http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/gp/1.mspx?mfr=true" rel="nofollow">Technet</a>).</p>
Glassfish: Deploying application in domain failed; Error loading deployment descriptors - invalid bit length repeat <p>I'm trying to deploy a .war trough the server's web interface. Getting the same error when deploying it as an exploded directory with IDEA. What is the solution to this problem?</p>
<p>The message points to an exception in java.util.zip thus implicating a corrupted packed file. Maybe you could try rebuilding the war file.</p>
Development with a tablet, not a mouse <p>Lifehacker had a post a couple days ago asking people about <a href="http://lifehacker.com/5054519/" rel="nofollow">the best mouse you've ever had</a> and it appears some people have traded their mouse for a tablet.</p> <p>I'm curious if anyone here has traded their mouse in for a tablet? Does it work well for development? Looking for pros and cons from people who have tried it or are using it.</p> <p>Thanks.</p>
<p>For development, I tend to switch between the keyboard for typing and shortcuts, and the mouse for pointing at things. Given that context:</p> <p>I've heard no end of praise for this approach from everyone who's used it. They say it's easier on the wrist, it feels more natural, and once you're used to it, it's impossible to go back without missing it. Strong enough praise that I'm planning on switching within the next two paycheques.</p>
Any reason to have SQL Server 2005 and 2008 installed on same machine? <p>I'm setting up a new development server and want to install the latest version of SQL Server 2008 Express.</p> <p>Will our existing sql2005 databases work with 2008 without modification? If so is there any reason to install both versions on the same server?</p>
<p>I haven't actually tried migrating a 2005 database to 2008, but generally SQL handles this cleanly and without difficulty. The simplest way to do it would be to make a backup of your database from SQL 2005 and then restore that backup with SQL 2008.</p> <p>If you want to keep the SQL 2005 copy around and online until you know that the 2008 copy is working, you might need to move the data/log files for your database when restoring the backup onto 2008, since the old data files will be in use by 2005. You can do this using the <code>with move</code> option of <code>restore database</code>, for example:</p> <p><code>RESTORE DATABASE mydb FROM disk = 'c:\backupfile.bak'<br /> WITH MOVE 'maindatafile' to 'c:\newdatalocation.mdf',<br /> MOVE 'mainlogfile' to 'c:\newloglocation.ldf'</code></p> <p>As to having both installed at the same time, one reason you might decide to do this would be to simplify the job of testing code against both versions, if you were intending to have your software support talking to both versions.</p>
C++ versus D <p>Is the <a href="http://www.digitalmars.com/d/">D language</a> a credible alternative to Java and C++? What will it take to become a credible alternative? Should I bother learning it? Does it deserve evangelizing?</p> <p>The main reason I ask is that with the new c++ standard (c++0x) almost here, its clear to me that the language has gone well past the point of no return with respect to anyone ever understanding it. I know that c/c++ will never die but at some point we need to move on. Even COBOL had its day and Java has in many respects undone c++. So what's next? Does D fill the bill?</p>
<p>What determines the success and popularity of a programming language for real-world software development is only partially related to the quality of the language itself. As a pure language, D arguably has many advantages over C++ and Java. At the very least it is a credible alternative as a pure language, all other things being equal.</p> <p>However, other things matter for software development - almost more than the language itself: portability (how many platforms does it run on), debugger support, IDE support, standard library quality, dynamic library support, bindings for common APIs, documentation, the developer community, momentum, and commercial support, just to name a few. In every one of those regards, D is hopelessly behind Java, C++, and C#. In fact, I'd argue it's even behind so-called "scripting" languages like Python, Perl, PHP, Ruby, and even JavaScript in these regards.</p> <p>To be blunt, you simply can't build a large-scale, cross-platform application using D. With an immature standard library, <s>no support in any modern IDEs</s> (there are plugins for both Visual Studio and Xamarin Studio/MonoDevelop), limited dynamic/shared library support, and few bindings to other languages, D is simply not an option today.</p> <p>If you like what you see of D, by all means, learn it - it shouldn't take long if you already know Java and C++. I don't think evangelism would be helpful - at this point if D is going to succeed, what it really needs is more people quietly using it and addressing its major shortcomings like standard library and IDE support.</p> <p>Finally, as for C++, while most agree the language is too complex, thousands of companies are successfully using C++ as part of a healthy mix of languages by allowing only a smaller, well-defined subset of the language. It's still hard to beat C++ when both raw performance and small memory usage are required.</p>
Anyone successfully using Commission Junction API? <p>Is anyone successfully using the CJ web services? I just keep getting <code>java.lang.NullPointerException</code>s even though my app is .net (clearly their errors). CJ support doesn't even know what a web service is. I googled and found many people getting this or other errors. Question is: is it a temporary problem or am I doomed to parse manually downloaded reports for eternity?</p> <p>The specific API I'm trying to use is the <a href="http://help.cj.com/en/web_services/Publisher_Commission_Service.htm" rel="nofollow">daily publisher commission service</a>. <a href="https://pubcommission.api.cj.com/wsdl/version2/publisherCommissionService.wsdl" rel="nofollow">Here</a> is the WSDL.</p> <p>Links:</p> <ul> <li><a href="http://webservices.cj.com/" rel="nofollow">CJ web services home</a></li> <li><a href="http://help.cj.com/en/web_services/web_services.htm" rel="nofollow">API Reference</a></li> </ul>
<p>After a spending many days, this code is working for me.</p> <pre><code>$client = new SoapClient($cjCommissionUrl, array('trace' =&gt; 1, 'soap_version' =&gt; SOAP_1_1, 'style' =&gt; SOAP_DOCUMENT, 'encoding' =&gt; SOAP_LITERAL )); $date = '06/23/2010'; $results = $client-&gt;findPublisherCommissions(array( "developerKey" =&gt; $cjDeveloperKey, "date" =&gt; $date, "dateType" =&gt; 'posting', "countries" =&gt; 'all', )); </code></pre>
Can SQLExpress 2005 and 2008 be installed on same machine without issue? <p>I would like to install SQLExpress2005 as an instance "SQLExpress" and install SQLExpresss2008 as "SQLExpress2008" instance.</p> <p>Is there any problem with doing this on the same machine?</p>
<p>As Long as you give them distinct names, there shouldn't be any problems. The binaries are stored in directories based on version, and you can (and should) point their filegroups at different locations. This should also apply to the Full versions.</p>
Search Engines Inexact Counting (about xxx results) <p>When you search in Google (i'm almost sure that Altavista did the same thing) it says "Results 1-10 of about xxxx"...</p> <p>This has always amazed me... What does it mean "about"?<br /> How can they count roughly?<br /> I do understand why they can't come up with a precise figure in a reasonable time, but how do they even reach this "approximate" one?</p> <p>I'm sure there's a lot of theory behind this one that I missed...</p>
<p>Most likely it's similar to the sort of estimated row counts used by most SQL systems in their query planning; a number of rows in the table (known exactly as of the last time statistics were collected, but generally not up-to-date), multiplied by an estimated selectivity (usually based on a sort of statistical distribution model calculated by sampling some small subset of rows).</p> <p>The PostgreSQL manual has a section on <a href="http://www.postgresql.org/docs/8.3/interactive/planner-stats.html" rel="nofollow">statistics used by the planner</a> that is fairly informative, at least if you follow the links out to pg_stats and various other sections. I'm sure that doesn't really describe what google does, but it at least shows one model where you could get the first N rows and an estimate of how many more there might be.</p>
Automatically adding specified text at beginning of files in VS 2008 <p>Is there a way to have Visual Studio 2008 automatically add heading information to files? For example, "Copyright 2008" or something along those lines. I've been digging through the options, but nothing seems to be jumping out at me.</p>
<p>I assume you'd like to modify the class file templates. They're in:</p> <pre><code>%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033 </code></pre> <p><a href="http://blogs.southworks.net/jpgarcia/2008/09/01/visual-studio-2008-templates-compliant-with-microsoft-stylecop/" rel="nofollow">More specific details here</a></p>
Are there any free ways to turn an html page into an image with .net <p>I want to take html, including the text and images and turn it into one image containing everything. Is there a free way to do it?</p> <p>This is using .net 3.5.</p> <h3>See also:</h3> <p><a href="http://stackoverflow.com/questions/119116/server-generated-web-screenshots">Server Generated web screenshots?</a><br /> <a href="http://stackoverflow.com/questions/65078/what-is-the-best-way-to-create-a-web-page-thumbnail">What is the best way to create a web page thumbnail?</a></p>
<p>You might check out <a href="http://www.codeproject.com/KB/graphics/IECapture.aspx" rel="nofollow">this project</a> or <a href="http://www.developerfusion.co.uk/show/4712/" rel="nofollow">this page</a>.</p> <p>Hope that helps.</p>
Why doesn't C++ have a garbage collector? <p>I'm not asking this question because of the merits of garbage collection first of all. My main reason for asking this is that I do know that Bjarne Stroustrup has said that C++ will have a garbage collector at some point in time.</p> <p>With that said, why hasn't it been added? There are already some garbage collectors for C++. Is this just one of those "easier said than done" type things? Or are there other reasons it hasn't been added (and won't be added in C++11)?</p> <p>Cross links:</p> <ul> <li><a href="http://stackoverflow.com/questions/81062/garbage-collectors-for-c">Garbage collectors for C++</a></li> </ul> <p><strong>EDIT:</strong> Just to clarify, I understand the reasons why C++ didn't have a garbage collector when it was first created. I'm wondering why the collector can't be added in.</p>
<p>To add to the debate here.</p> <p>There are known issues with garbage collection, and understanding them helps understanding why there is none in C++.</p> <p><strong>1. Performance ?</strong></p> <p>The first complaint is often about performance, but most people don't really realize what they are talking about. As illustrated by <code>Martin Beckett</code> the problem may not be performance per se, but the predictability of performance.</p> <p>There are currently 2 families of GC that are widely deployed:</p> <ul> <li>Mark-And-Sweep kind</li> <li>Reference-Counting kind</li> </ul> <p>The <code>Mark And Sweep</code> is faster (less impact on overall performance) but it suffers from a "freeze the world" syndrom: ie when the GC kicks in, everything else is stopped until the GC has made its cleanup. If you wish to build a server that answers in a few milliseconds... some transactions will not live up to your expectations :)</p> <p>The problem of <code>Reference Counting</code> is different: reference-counting adds overhead, especially in Multi-Threading environments because you need to have an atomic count. Furthermore there is the problem of reference cycles so you need a clever algorithm to detect those cycles and eliminate them (generally implement by a "freeze the world" too, though less frequent). In general, as of today, this kind (even though normally more responsive or rather, freezing less often) is slower than the <code>Mark And Sweep</code>.</p> <p>I have a seen a paper by Eiffel implementers that were trying to implement a <code>Reference Counting</code> Garbage Collector that would have a similar global performance to <code>Mark And Sweep</code> without the "Freeze The World" aspect. It required a separate thread for the GC (typical). The algorithm was a bit frightening (at the end) but the paper made a good job of introducing the concepts one at a time and showing the evolution of the algorithm from the "simple" version to the full-fledged one. Recommended reading if only I could put my hands back on the PDF file...</p> <p><strong>2. Resources Acquisition Is Initialization</strong></p> <p>It's a common idiom in <code>C++</code> that you will wrap the ownership of resources within an object to ensure that they are properly released. It's mostly used for memory since we don't have garbage collection, but it's also useful nonetheless for many other situations:</p> <ul> <li>locks (multi-thread, file handle, ...)</li> <li>connections (to a database, another server, ...)</li> </ul> <p>The idea is to properly control the lifetime of the object:</p> <ul> <li>it should be alive as long as you need it</li> <li>it should be killed when you're done with it</li> </ul> <p>The problem of GC is that if it helps with the former and ultimately guarantees that later... this "ultimate" may not be sufficient. If you release a lock, you'd really like that it be released now, so that it does not block any further calls!</p> <p>Languages with GC have two work arounds:</p> <ul> <li>don't use GC when stack allocation is sufficient: it's normally for performance issues, but in our case it really helps since the scope defines the lifetime</li> <li><code>using</code> construct... but it's explicit (weak) RAII while in C++ RAII is implicit so that the user CANNOT unwittingly make the error (by omitting the <code>using</code> keyword)</li> </ul> <p><strong>3. Smart Pointers</strong></p> <p>Smart pointers often appear as a silver bullet to handle memory in <code>C++</code>. Often times I have heard: we don't need GC after all, since we have smart pointers.</p> <p>One could not be more wrong.</p> <p>Smart pointers do help: <code>auto_ptr</code> and <code>unique_ptr</code> use RAII concepts, extremely useful indeed. They are so simple that you can write them by yourself quite easily.</p> <p>When one need to share ownership however it gets more difficult: you might share among multiple threads and there are a few subtle issues with the handling of the count. Therefore, one naturally goes toward <code>shared_ptr</code>.</p> <p>It's great, that's what Boost for after all, but it's not a silver bullet. In fact, the main issue with <code>shared_ptr</code> is that it emulates a GC implemented by <code>Reference Counting</code> but you need to implement the cycle detection all by yourself... Urg</p> <p>Of course there is this <code>weak_ptr</code> thingy, but I have unfortunately already seen memory leaks despite the use of <code>shared_ptr</code> because of those cycles... and when you are in a Multi Threaded environment, it's extremely difficult to detect!</p> <p><strong>4. What's the solution ?</strong></p> <p>There is no silver bullet, but as always, it's definitely feasible. In the absence of GC one need to be clear on ownership:</p> <ul> <li>prefer having a single owner at one given time, if possible</li> <li>if not, make sure that your class diagram does not have any cycle pertaining to ownership and break them with subtle application of <code>weak_ptr</code></li> </ul> <p>So indeed, it would be great to have a GC... however it's no trivial issue. And in the mean time, we just need to roll up our sleeves.</p>
How can I reseed an identity column in a T-SQL table variable? <p>I have a T-SQL <strong>table variable</strong> (not a table) which has an auto incrementing identity column. I want to clear all data from this variable and reset the identity column value to 1. How can this be done?</p>
<p>Truncating the table will dump ALL the data, and reset the identity seed.</p> <p>Otherwise, you can use this call to reset the identity while retaining any of the data:</p> <pre><code>DBCC CHECKIDENT (yourtableName, reseed, @NewStartSeedValue) </code></pre>
Ruby isPrime Method <pre><code>('1' * N) !~ /^1?$|^(11+?)\1+$/ </code></pre> <p>On the net, I found this piece of Ruby code that works for N >= 0 that determines whether or not N is a prime. From what I can tell, it looks like play with regex but I have no idea how it works. Could someone tell me how it works?</p>
<p>You can find a lengthy explanation of this code here: <a href="http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/">http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/</a></p>
Can I have non-measure codes mixed with measures in my fact table? <p>We're doing a complex bit of data accumulation. Our customer sends us some stuff that includes two dimensions (time and a business unit). Time is mostly year-month. The business unit dimension has just a few attributes: a name, and a few categories to which BU's can belong for reporting and analysis purposes.</p> <p>The stuff they send us includes some current state information (dates and codes). These seem fact-like. They also send some information that characterizes the relationship with the business unit (mostly additional codes). Again, these are unique to the business unit and time period.</p> <p>Finally, they send us stuff that is clearly additive facts. It includes currency and counts that have proper units.</p> <p>Should I commingle this qualitative information in a single fact table with the additive facts? Or should I separate the qualitative stuff (which can only be used with counts) from the quantitative stuff (which can be used with sum)?</p>
<p>If the data is both directly related to the additive fact and is not something you want to be grouping/sorting/search on, then putting it in the fact table is okay.</p> <p>Be aware, though, that non-additive data in the fact table will either prevent roll-ups or will become a lossy operation.</p>
What is the best way to set-up authentication in a tomcat webapp? <p>I have a self built JSP webapp and at the moment I'm using tomcats built in admin pannel to manage user accounts (that are stored in tomcats config xml files) but this is limited because i can not create new accounts from within the web-app (eg. I can not have a sign up website) and need to manually create the accounts. </p> <p>What is the most straight forward way of implementing accounts in a tomcat environment?</p> <p>dennis</p>
<p>Set up a <a href="http://tomcat.apache.org/tomcat-5.5-doc/realm-howto.html" rel="nofollow">database realm in Tomcat</a>, either a simple JDBC realm or a DataSource realm that will allow for connection pooling. Then adding users is a very simple CRUD web application, possibly combined with some confirmation emails.</p>
Can you recommend a .cvsignore file for a Visual C#.NET solution? <p>I've developed a Visual C#.NET 2008 Express Edition solution containing three projects. I am cleaning it up to commit it into a CVS repository.</p> <p>There are several files that are created during the build process that are not necessary to be placed in the repository since they will be regenerated automatically.</p> <p>The question: Can anyone suggest a list of patterns to be placed into a .cvsignore file so that these generated files and folders are ignored?</p>
<p>Typically these are the only things that you <em>have</em> to commit:</p> <ul> <li>.sln files</li> <li>.cs files</li> <li>.csproj files</li> <li>.config files</li> <li>External DLLs and corresponding XML/config files that you are referencing</li> <li>other non-generated files that your application uses</li> </ul> <p>All the rest are to be ignored, including:</p> <ul> <li>.suo files</li> <li>.csproj.user files</li> <li>/bin folder and contents</li> <li>/obj folder and contents</li> <li>practically everything else</li> </ul>
Is it possible to include one CSS file in another? <p>Is it possible to include one CSS file in another?</p>
<p>Yes:</p> <pre><code>@import url("base.css"); </code></pre> <p>Note:</p> <ul> <li>The <code>@import</code> rule must <a href="http://www.w3.org/TR/CSS2/cascade.html#at-import">precede</a> all other rules (except the <code>@charset</code> rule); and</li> <li>Additional <code>@import</code> statements require additional server requests.</li> </ul> <p>Aggregate CSS into one file to avoid multiple HTTP requests. That is, copy the contents of <code>base.css</code> and <code>special.css</code> into <code>base-special.css</code> and reference only <code>base-special.css</code>).</p> <p>In 2008, not all browsers supported <code>@import</code> (see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@import#Browser_compatibility">Browser Compatibility</a>).</p>
Real HLSL IDE/debugger <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>
Debug Pylons application through Eclipse <p>I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?</p>
<p>Create a new launch configuration (Python Run)</p> <p><strong>Main tab</strong></p> <p>Use paster-script.py as main module (you can find it in the Scripts sub-directory in your python installation directory)</p> <p>Don't forget to add the root folder of your application in the PYTHONPATH zone</p> <p><strong>Arguments</strong> Set the base directory to the root folder also.</p> <p>As Program Arguments use "serve development.ini" (or whatever you use to debug your app")</p> <p><strong>Common Tab</strong></p> <p>Check allocate console and launch in background</p>
Get list of available servers in SQL server group <p>How can I extract the list of available SQL servers in an SQL server group? I'm planning to put that list in a combo box in VB.NET.</p>
<p>The only way I knew to do it was using the command line:</p> <pre><code>osql -L </code></pre> <p>But I found the below article which seems to solve your specific goal filling a combobox:</p> <p><a href="http://www.sqldbatips.com/showarticle.asp?ID=45" rel="nofollow">http://www.sqldbatips.com/showarticle.asp?ID=45</a></p>
When using ANT, how can I define a task only if I have some specific java version? <p>I have the problem that an specific step in Ant can only be executed when we have Java 1.5 installed in the build computer. The task definition uses uses a jar file that was compiled using 1.5, so running with a 1.4 virtual machine will throw an IncompatibleClassVersion exception.</p> <p>I have to find a solution meanwhile to have this task working for this specific project that requires 1.4, but a question came to me. How can I avoid defining this task and executing this optional step if I don't have a specific java version?</p> <p>I could use the "if" or "unless" tags on the target tag, but those only check if a property is set or not. I also would like to have a solution that doesn't require extra libraries, but I don't know if the build-in functionality in standard is enough to perform such a task.</p>
<p>The Java version is exposed via the <em>ant.java.version</em> property. Use a <em>condition</em> to set a property and execute the task only if it is true.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;project name="project" default="default"&gt; &lt;target name="default" depends="javaCheck" if="isJava6"&gt; &lt;echo message="Hello, World!" /&gt; &lt;/target&gt; &lt;target name="javaCheck"&gt; &lt;echo message="ant.java.version=${ant.java.version}" /&gt; &lt;condition property="isJava6"&gt; &lt;equals arg1="${ant.java.version}" arg2="1.6" /&gt; &lt;/condition&gt; &lt;/target&gt; &lt;/project&gt; </code></pre>
How to check the overall health of database using Toad? <p>Anyone have any idea? And any open source sofware which also seens to perform this kind of functionality?</p>
<p>The DBA version of Toad has such a feature. In my version, it is under the DBA menu, and is called "Health Check".<br /> Screenshot <a href="http://toadsoft.com/get2know96/Web/" rel="nofollow">http://toadsoft.com/get2know96/Web/</a></p>