Sei sulla pagina 1di 30

<p>I too get explorer crashes in Vista (I'm not in the 64Bit version though).

I' m using Vista Super Saijen (or whatever they are calling the most expensive vers ion). I'm not having any bugs with Tortoise.</p> <p>My explorer does, however, crash about every other day (sometimes multiple ti mes a day if it's having an "off" day). I'm not positive it's being caused by To rtoiseSVN though. From what I hear, the explorer just crashes a lot in Vista...< /p> <p>Have you tried uninstalling Tortoise and using Windows for a day or two and s eeing if it still crashes? Do you restart your computer at least once a day (It seems the longer I go between restarts, the worse the crashes get)?</p> ---------<p>I may be old fashioned, but I prefer my text editor. </p> <p>I use emacs, and it has a fairly decent xml mode. </p> <p>Most good text editors will have decent syntax hi-lighting and tag matching f acilities. Your IDE might already do it (IntelliJ idea does, and I believe Ecli pse does as well). Good text editors will be able to deal with <em>huge</em> fi les, but some text editors may not be able to handle them. How big are we talki ng about?</p> ---------<p>I have a Ruby on Rails Website that makes HTTP calls to an external Web Servi ce.</p> <p>About once a day I get a SystemExit (stacktrace below) error email where a ca ll to the service has failed. If I then try the exact same query on my site mom ents later it works fine. It's been happening since the site went live and I've had no luck tracking down what causes it.</p> <p>Ruby is version 1.8.6 and rails is version 1.2.6.</p> <p>Anyone else have this problem?</p> <p>This is the error and stacktrace.</p> <pre> A SystemExit occurred /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.6/lib/fcgi_handler.rb:116:in `exit' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.6/lib/fcgi_handler.rb:116:in `exit_n ow_handler' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/inflect or.rb:250:in `to_proc' /usr/local/lib/ruby/1.8/net/protocol.rb:133:in `call' /usr/local/lib/ruby/1.8/net/protocol.rb:133:in `sysread' /usr/local/lib/ruby/1.8/net/protocol.rb:133:in `rbuf_fill' /usr/local/lib/ruby/1.8/timeout.rb:56:in `timeout' /usr/local/lib/ruby/1.8/timeout.rb:76:in `timeout' /usr/local/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill' /usr/local/lib/ruby/1.8/net/protocol.rb:116:in `readuntil' /usr/local/lib/ruby/1.8/net/protocol.rb:126:in `readline' /usr/local/lib/ruby/1.8/net/http.rb:2017:in `read_status_line' /usr/local/lib/ruby/1.8/net/http.rb:2006:in `read_new' /usr/local/lib/ruby/1.8/net/http.rb:1047:in `request'

/usr/local/lib/ruby/1.8/net/http.rb:945:in /usr/local/lib/ruby/1.8/net/http.rb:380:in /usr/local/lib/ruby/1.8/net/http.rb:543:in /usr/local/lib/ruby/1.8/net/http.rb:379:in </pre> ----------

`request_get' `get_response' `start' `get_response'

<p><a href="http://jens-schaller.de/sonictools/sonicfilefinder/" rel="nofollow"> Sonic File Finder</a> for when you have loads of files in your solutions and sea rching for them in the solution explorer becomes a pain in the wrist.</p> <p>You might also find <a href="http://www.usysware.com/dpack/" rel="nofollow">D Pack</a> interesting. Several tools and enhancements rolled into one neat packag e.</p> ---------<p>You should look into DBUnit, or try to find a PHP equivalent (there must be o ne out there). You can use it to prepare the database with a specific set of da ta which represents your test data, and thus each test will no longer depend on the database and some existing state. This way, each test is self contained and will not break during further database usage.</p> <p>Update: A quick google search showed a <a href="http://www.ds-o.com/archives/ 63-PHPUnit-Database-Extension-DBUnit-Port.html" rel="nofollow">DB unit extension </a> for PHPUnit.</p> ---------<p>I'm looking for a good editor for both HTML and CSS. I currently use the Fire bug Firefox extension, and this is a great tool, but I'm looking for something I can use without necessarily firing up a browser. Ideally it would have a live p review of what I'm coding.</p> <p>Edit: As a student, I have access to MSDN. also, i have access to Windows, Ma c, and Linux. So any platform will do.</p> ---------<p>You're better off using prepared statements with placeholders. Are you using PHP, .NET...either way, prepared statements will provide more security, but I co uld provide a sample.</p> ---------<p>Many years ago, to provide an <a href="http://cloud9.hedgee.com/age">age calc ulator gimmick</a> on my website, I wrote a function to calculate age to a fract ion. This is a quick port of that function to C# (from <a href="http://hedgee.sv n.sourceforge.net/viewvc/hedgee/trunk/chris/ckwww/ckage.php3">the PHP version</a >). I'm afraid I haven't been able to test the C# version, but hope you enjoy al l the same!</p> <p>(Admittedly this is a bit gimmicky for the purposes of showing user profiles on Stack Overflow, but maybe readers will find some use for it. :-))</p> <pre><code>double AgeDiff(DateTime date1, DateTime date2) {<br> double years = date2.Year - date1.Year;<br><br> /*<br> * If date2 and date1 + round(da

te2 - date1) are on different sides<br> * of 29 February, then our partial y ear is considered to have 366<br> * days total, otherwise it's 365. Note tha t 59 is the day number<br> * of 29 Feb.<br> */<br> double fraction = 365<br> + (DateTime.IsLeapYear(date2.Year) &amp;&amp; date2.DayOfYear &gt;= 59<br> &amp;&amp; (date1.DayOfYear &lt; 59 || date1.DayOfYear &gt; date2.DayOfYear)<br> ? 1 : 0);<br><br> /*<br> * The only really nontrivial case is if date1 is in a leap year,<br> * and date2 is not . So let's handle the others first.<br> */<br> if (DateTime.IsLeapYear(da te2.Year) == DateTime.IsLeapYear(date1.Year))<br> return years + (date2.D ayOfYear - date1.DayOfYear) / fraction;<br><br> /*<br> * If date2 is in a leap year, but date1 is not and is March or<br> * beyond, shift up by a day .<br> */<br> if (DateTime.IsLeapYear(date2.Year)) {<br> return yea rs + (date2.DayOfYear - date1.DayOfYear<br> - (date1.DayOfYear &g t;= 59 ? 1 : 0)) / fraction;<br> }<br><br> /*<br> * If date1 is not on 29 February, shift down date1 by a day if<br> * March or later. Proceed nor mally.<br> */<br> if (date1.DayOfYear != 59) {<br> return years + (date2.DayOfYear - date1.DayOfYear<br> + (date1.DayOfYear &gt; 59 ? 1 : 0)) / fraction;<br> }<br><br> /*<br> * Okay, here date1 is on 2 9 February, and date2 is not on a leap<br> * year. What to do now? On 28 Feb in date2's year, the ``age''<br> * should be just shy of a whole number, an d on 1 Mar should be<br> * just over. Perhaps the easiest way is to a point halfway<br> * between those two: 58.5.<br> */<br> return years + (dat e2.DayOfYear - 58.5) / fraction;<br>}<br></code></pre> ---------<p>The way I typically go about coding permission systems is having 6 tables.</p > <ul> <li>Users - this is pretty straight forward it is your typical users table</li> <li>Groups - this would be synonymous to your departments</li> <li>Roles - this is a table with all permissions generally also including a huma n readable name and a description</li> <li>Users_have_Groups - this is a many-to-many table of what groups a user belon gs to</li> <li>Users_have_Roles - another many-to-many table of what roles are assigned to an individual user</li> <li>Groups_have_Roles - the final many-to-many table of what roles each group ha s</li> </ul> <p>At the beginning of a users session you would run some logic that pulls out e very role they have assigned, either directory or through a group. Then you code against those roles as your security permissions.</p> <p>Like I said this is what I typically do but your millage may vary.</p> ---------<p>Even though I have a robust and fast computer (Pentium Dual Core 2.0 with 2Gb RAM), I'm always searching for lightweight software to have on it, so it runs f ast even when many apps are up and running simultaneously.</p> <p>On the last few weeks I've been migrating gradually to Linux and want to inst all a free lightweight yet useful IDE to program on C++ and PHP. Sintax highlig hting and code completition tips are must-haves.</p> <p>So, I'd like to receive some suggestions from you, guys.</p>

---------<p>Right-click on the Source view of an HTML / ASP page and select "Formatting a nd Validation".</p> <ol> <li>Click "Tag Specific Options".</li> <li>Expand "Client HTML Tags" and select the heading.</li> <li>Click "New Tag...".</li> <li>And just fill it in!</li> </ol> <p>I wish that I could add custom CSS values as well.</p> ---------<p>Should you set all the objects to <code>null</code> (<code>Nothing</code> in VB.NET) once you have finished with them? </p> <p>I understand that in .NET it is essential to dispose of any instances of obje cts that implement the <code>IDisposable</code> interface to release some resour ces although the object can still be something after it is disposed (hence the < code>isDisposed</code> property in forms), so I assume it can still reside in me mory or at least in part?</p> <p>I also know that when an object goes out of scope it is then marked for colle ction ready for the next pass of the garbage collector (although this may take t ime).</p> <p>So with this in mind will setting it to <code>null</code> speed up the system releasing the memory as it does not have to work out that it is no longer in sc ope and are they any bad side effects?</p> <p>MSDN articles never do this in examples and currently I do this as I cannot see the harm. However I have come across a mixture of opinions so any comments a re useful.</p> ---------<p>Your <code>CAST</code>-<code>FLOOR</code>-<code>CAST</code> already seems to be the optimum way, at least on MS SQL Server 2005.</p> <p>Some other solutions I've seen have a string-conversion, like <code>Select Co nvert(varchar(11), getdate(),101)</code> in them, which is slower by a factor of 10.</p> ---------<p><a href="http://stackoverflow.com/questions/180/function-for-creating-color-w heels" rel="nofollow">Original Question</a></p> <p>If you are given N maximally distant colors (and some associated distance met ric), can you come up with a way to sort those colors into some order such that the first M are also reasonably close to being a maximally distinct set?</p> <p>In other words, given a bunch of distinct colors, come up with an ordering so I can use as many colors as I need starting at the beginning and be reasonably

assured that they are all distinct and that nearby colors are also very distinct (e.g., bluish red isn't next to reddish blue).</p> <p>Randomizing is OK but certainly not optimal.</p> <p><em>Clarification: Given some large and visually distinct set of colors (say 256, or 1024), I want to sort them such that when I use the first, say, 16 of th em that I get a relatively visually distinct subset of colors. This is equivalen t, roughly, to saying I want to sort this list of 1024 so that the closer indivi dual colors are visually, the farther apart they are on the list.</em></p> ---------<p>Don't forget you can pipe things to the more command which will give you a si ngle page of output and prompt you to continue. I use this most often with ls -l a | more (emulates the standard dir command) and I also sometimes pipe (|) grep searches to more.</p> ---------<p>Check out the <a href="http://www.telerik.com/products/aspnet-ajax/controls/a jax/overview.aspx" rel="nofollow">RadAjax</a> control from Telerik - it allows y ou to avoid using UpdatePanels, and limit the amount of info passed back and for th between server and client by declaring direct relationships between calling c ontrols, and controls that should be "Ajaxified" when the calling controls submi t postbacks. </p> ---------<p>First you will need some GUI library with Python bindings and then (if you wa nt) some program that will convert your python scripts into standalone executabl es.</p> <p><strong>Cross-platform GUI libraries with Python bindings (Windows, Linux, Ma c)</strong></p> <p>Of course, there are many, but the most popular that I've seen in wild are:</ p> <ul> <li><a href="http://wiki.python.org/moin/TkInter">Tkinter</a> - based on <a hre f="http://www.tcl.tk/">Tk GUI toolkit</a> (de-facto standard GUI library for pyt hon, free for commercial projects)</li> <li><a href="http://www.wxpython.org/">WxPython</a> - based on <a href="http://w ww.wxwidgets.org/">WxWidgets</a> (very popular, free for commercial projects)</l i> <li><a href="http://www.riverbankcomputing.co.uk/news">PyQt</a> - based on <a hr ef="http://trolltech.com/products/qt/">Qt</a> (also very popular and more stable than WxWidgets but costly license for commercial projects)</li> </ul> <p>Complete list is at <a href="http://wiki.python.org/moin/GuiProgramming">http ://wiki.python.org/moin/GuiProgramming</a></p> <p><strong>Single executable (Windows)</strong></p> <ul> <li><a href="http://www.py2exe.org/">py2exe</a> - Probably the most popular out there (<a href="http://stackoverflow.com/questions/2933/an-executable-python-app /31859#31859">PyInstaller</a> is also gaining in popularity)</li>

</ul> <p><strong>Single executable (Linux)</strong></p> <ul> <li><a href="http://wiki.python.org/moin/Freeze">Freeze</a> - works the same way like py2exe but targets Linux platform</li> </ul> <p><strong>Single executable (Mac)</strong></p> <ul> <li><a href="http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html">py2app </a> - again, works like py2exe but targets Mac OS</li> </ul> ---------<p>Oh, in WinForms you definitely should be able to get it to work. The only thi ng you have to watch out for is things happening on different threads.</p> <p>I have an old CodeProject article here which should help:</p> <p><a href="http://www.codeproject.com/KB/exception/ExceptionHandling.aspx">http ://www.codeproject.com/KB/exception/ExceptionHandling.aspx</a></p> ---------<p>As far as I know the LINQ library is only available since the framework 3.0. If you want to use something similar in the framework 2.0, you would need to rew ritte it yourself :) or find a similar third-party library. I only found a bit o f information <a href="http://weblogs.asp.net/fmarguerie/archive/2007/09/05/linq -support-on-net-2-0.aspx" rel="nofollow">here</a> but it didn't convinced me eit her.</p> ---------<p>SciTE http://www.scintilla.org/SciTE.html</p> ---------<p>In many places,(1,2,3) and [1,2,3] can be used interchangably.</p> <p>When should I use one or the other, and why? </p> ---------<p>I've got a menu in Python. That part was easy. I'm using <code>raw_input()</c ode> to get the selection from the user. </p> <p>The problem is that <code>raw_input</code> (and input) require the user to pr ess Enter after they make a selection. Is there any way to make the program act immediately upon a keystroke? Here's what I've got so far:</p> <pre><code>import sys print """Menu 1) Say Foo

2) Say Bar""" answer = raw_input("Make a selection&gt; ") if "1" in answer: print "foo" elif "2" in answer: print "bar" </code></pre> <p>It would be great to have something like</p> <pre><code>print menu while lastKey = "": lastKey = check_for_recent_keystrokes() if "1" in lastKey: #do stuff... </code></pre> ---------<p>Not efficient at all, but you can use a regular expression to test for prime numbers.</p> <pre><code>/^1?$|^(11+?)\1+$/ </code></pre> <p>This tests if, for a string consisting of <em>k</em> <code>1</code>s, <em>k</em > is <em>not prime</em> (i.e. whether the string consists of one <code>1</code> or any number of <code>1</code>s that can be expressed as an <em>n</em>-ary product) .</p> ---------<p>How often do you need to check for changes and how large (in terms of row siz e) are the tables in the database? If you use the <code>CHECKSUM_AGG(BINARY_CHE CKSUM(*))</code> method suggested by John, it will scan every row of the specifi ed table. The <code>NOLOCK</code> hint helps, but on a large database, you are still hitting every row. You will also need to store the checksum for every row so that you tell one has changed.</p> <p>Have you considered going at this from a different angle? If you do not want to modify the schema to add triggers, (which makes a sense, it's not your datab ase), have you considered working with the application vendor that does make the database? </p> <p>They could implement an API that provides a mechanism for notifying accessory apps that data has changed. It could be as simple as writing to a notification table that lists what table and which row were modified. That could be impleme nted through triggers or application code. From your side, ti wouldn't matter, your only concern would be scanning the notification table on a periodic basis. The performance hit on the database would be far less than scanning every row f or changes.</p> <p>The hard part would be convincing the application vendor to implement this fe ature. Since this can be handles entirely through SQL via triggers, you could d o the bulk of the work for them by writing and testing the triggers and then bri nging the code to the application vendor. By having the vendor support the trig gers, it prevent the situation where your adding a trigger inadvertently replace s a trigger supplied by the vendor.</p>

---------<P>The only time you should set a variable to null is when the variable does not go out of scope and you no longer need the data associated with it. Otherwise t here is no need. </P> ---------<P>As always, Google is your friend:</P> <P><A href="http://nixbit.com/cat/programming/libraries/c-generic-library/" rel= "nofollow">http://nixbit.com/cat/programming/libraries/c-generic-library/</A></P > <P>specifically:</P> <P><A href="http://nixbit.com/cat/programming/libraries/generic-data-structureslibrary/" rel="nofollow">http://nixbit.com/cat/programming/libraries/generic-dat a-structures-library/</A></P> ---------<p>I've written a database generation script in sql, and want to execute it in m y Adobe air application:</p> <pre><code>Create Table tRole ( roleID integer Primary Key ,roleName varchar(40) ); Create Table tFile ( fileID integer Primary Key ,fileName varchar(50) ,fileDescription varchar(500) ,thumbnailID integer ,fileFormatID integer ,categoryID integer ,isFavorite boolean ,dateAdded date ,globalAccessCount integer ,lastAccessTime date ,downloadComplete boolean ,isNew boolean ,isSpotlight boolean ,duration varchar(30) ); Create Table tCategory ( categoryID integer Primary Key ,categoryName varchar(50) ,parent_categoryID integer ); ... </code></pre> <p>I execute this in Air using the following methods:</p> <pre><code> public static function RunSqlFromFile(fileName:String):void { var file:File = File.applicationDirectory.resolvePath(fileName); var stream:FileStream = new FileStream(); stream.open(file, FileMode.READ) var strSql:String = stream.readUTFBytes(stream.bytesAvailable); NonQuery(strSql); }

public static function NonQuery(strSQL:String):void { var sqlConnection:SQLConnection = new SQLConnection(); sqlConnection.open(File.applicationStorageDirectory.resolvePath(DBPATH); var sqlStatement:SQLStatement = new SQLStatement(); sqlStatement.text = strSQL; sqlStatement.sqlConnection = sqlConnection; try { sqlStatement.execute(); } catch (error:SQLError) { Alert.show(error.toString()); } } </code></pre> <p>No errors are generated, however only <code>tRole</code> exists. It seems tha t it only looks at the first query (up to the semicolon- if I remove it, the que ry fails). Is there anyway to call multiple queries in one statement?</p> ---------<p>Actually, PyDev plugin for Eclipse has a full support for code completion (tr y PyDev Extensions too). You can easily try it <a href="http://easyeclipse.org/s ite/distributions/python.html">here</a>. Another editor worth mentioning is <a h ref="http://www.wingware.com/">WingIDE</a>, which is really powerful. For more o n Python editors check <a href="http://wiki.python.org/moin/PythonEditors">this page</a>.</p> <p>I use <a href="http://aquamacs.org/">Aquamacs</a> with <a href="http://rope.s ourceforge.net/ropemacs.html">ropemacs</a> on my Mac, but that's an ultra geeky setup :)</p> ---------<p>I need the name of the current logged in user in my Air/Flex application. The application will only be deployed on Windows machines. I think I could attain t his by regexing the User directory, but am open to other ways.</p> ---------<p>try <a href="http://www.pcre.org/">libpcre</a></p> <p>If you're stuck on windows they have a windows port which should work. I know <a href="http://e-texteditor.com">e-texteditor</a> uses it, so at least that's proof it works :-)</p> ---------<p>XML/SWF Charts does Chart off XML:</p> <p><a href="http://www.maani.us/xml_charts/" rel="nofollow">http://www.maani.us/ xml_charts/</a></p> ---------<P>Definately the best tool I have ever used.</P>

<P>It is the natural progression of the industry that the tools improve. It's no t 'magic'! It's just like a JCB digger instead of a shovel. I can go dig a hole manually with a shovel if I have to - but it hurts!</P> ---------<p>Brad's list is pretty good. I also listen to:</p> <ul> <li><a href="http://www.sparklingclient.com/" rel="nofollow">Sparkling Client</a > (Silverlight specific)</li> <li>Jon Udell's <a href="http://perspectives.on10.net/" rel="nofollow">Perspecti ves</a> series</li> <li><a href="http://herdingcode.com" rel="nofollow">Herding Code</a> (shameless plug for a podcast I put on with Kevin Dente, Scott "lazycoder" Koon, and K. Scott Allen. We recently <a href="http://herdingcode.com/?p=36" rel="nofollow">intervi ewed Jeff Atwood about Stack Overflow</a>, discussing both how the site is designed and the technology behind it.</li> </ul> ---------<p><strong>My Goal</strong></p> <p>I would like to have a main processing thread (non GUI), and be able to spin off GUIs in their own background threads as needed, and having my main non GUI t hread keep working. Put another way, I want my main non GUI-thread to be the own er of the GUI-thread and not vice versa. I'm not sure this is even possible with Windows Forms(?)</p> <p>(Sorry for the big post here. I've had complaints about previous shorter vers ions of this question just isn't comprehensible. I'm a lousy writer)</p> <p><strong>Background</strong></p> <p>I have a component based system in which a controller dynamically load assemb lies and instantiates and run classes implementing a common <em>IComponent</em> interface with a single method <em>DoStuff()</em> .</p> <p>Which components that gets loaded is configured via a xml configuration file and by adding new assemblies containing different implementations of <em>ICompon ent</em> . The components provides utility functions to the main application. Wh ile the main program is doing it's thing, e.g. controlling a nuclear plant, the components might be performing utility tasks (in their own threads), e.g. cleani ng the database, sending emails, printing funny jokes on the printer, what have you. What I would like, is to have one of these components be able to display a GUI, e.g. with status information for the said email sending component.</p> <p>The lifetime of the complete system looks like this</p> <ol> <li>Application starts.</li> <li>Check configuration file for components to load. Load them.</li> <li><strong>For each component, run DoStuff() to initialize it and make it live its own life in their own threads.</strong></li> <li>Continue to do main application-thingy king of work, forever.</li> </ol>

<p>I have not yet been able to successfully perform point 3 if the component fir es up a GUI in <em>DoStuff()</em> . It simply just halts until the GUI is closed . And not until the GUI is closed does the program progress to point 4.</p> <p>It would be great if these components were allowed to start up their own Wind ows Forms GUIs.</p> <p><strong>Problem</strong></p> <p>When a component tries to fire up a GUI in <em>DoStuff()</em> (the exact line of code is when the component runs Application.Run(theForm)) , the component an d hence our system "hangs" at the Application.Run() line until the GUI is closed . Well, the just fired up GUI works fine, as expected.</p> <p>Example of components. One hasn't nothing to do with GUI, whilst the second f ires up a cute windows with pink fluffy bunnies in them.</p> <pre><code>public class MyComponent1: IComponent<br>{<br> public string DoStu ff(...) { // write something to the database }<br>}<br><br>public class MyCompo nent2: IComponent<br> public void DoStuff()<br> {<br> Application.E nableVisualStyles();<br> Application.SetCompatibleTextRenderingDefault(fa lse);<br> Application.Run(new Form());<br><br> // I want the threa d to immediately return after the GUI <br> // is fired up, so that my mai n thread can continue to work.<br> }<br>}<br></code></pre> <p>I have tried this with no luck. Even when I try to fire up the GUI in it's ow n thread, the execution halts until the GUI as closed.</p> <pre><code> public void DoStuff()<br> {<br> new Thread(ThreadedI nitialize).Start()<br> }<br><br> private void ThreadedInitialize()<br> {<br> Application.EnableVisualStyles();<br> Application.SetCompati bleTextRenderingDefault(false);<br> Application.Run(new Form());<br> } <br></code></pre> <p>Is it possible to spin off a GUI and return after Application.Run()?</p> ---------<p>What are some guidelines for maintaining responsible session security with PH P? There's information all over the web and it's about time it all landed in on e place!</p> ---------<p>I have to agree with the OP 'wrong' dates really jar with my DD/MM/YYYY upbri nging and I find ISO 8601 dates and times extremely easy to work with. For once the standard got it right and <a href="http://stackoverflow.com/questions/761/# 770" rel="nofollow">engtech</a> has the obvious answer that doesn't require loca lisation.</p> <p>I was going to report the birthday input form on stack overflow as a bug beca use of how much of a sore thumb it is to the majority of the world.</p> ---------<p>In the vein of portability, I'd use relational. Moving a website from one ho st to another would be a nightmare with some niche DBMS. Almost all hosting pro viders offer MSSQL and MySQL these days. </p>

---------<p>When I was first learning Java we had to make Yahtzee and I thought it would be cool to create custom Swing components and containers instead of just drawing everything on one JPanel. The benefit of extending Swing components, of course , is to have the ability to add support for keyboard shortcuts and other accessi bility features that you can't do just by having a paint() method print a pretty picture. It may not be done the best way however, but it may be a good startin g point for you.</p> <p>Edit 8/6 - If it wasn't apparent from the images, each Die is a button you ca n click. This will move it to the DiceContainer below. Looking at the source co de you can see that each Die button is drawn dynamically, based on its value.</p > <p><img src="http://i.stack.imgur.com/pgyQp.jpg" alt="alt text"><br> <img src="http://i.stack.imgur.com/jkYRd.jpg" alt="alt text"><br> <img src="http://i.stack.imgur.com/9BI34.jpg" alt="alt text"></p> <p>Here are the basic steps:</p> <ol> <li>Create a class that extends JComponent</li> <li>Call parent constructor super() in your constructors</li> <li>Make sure you class implements MouseListener</li> <li><p>Put this in the constructor:</p> <pre><code>enableInputMethods(true); addMouseListener(this); </code></pre></li> <li><p>Override these methods:</p> <pre><code>public Dimension getPreferredSize() public Dimension getMinimumSize() public Dimension getMaximumSize() </code></pre></li> <li><p>Override this method:</p> <pre><code>public void paintComponent(Graphics g) </code></pre></li> </ol> <p>The amount of space you have to work with when drawing your button is defined by getPreferredSize(), assuming getMinimumSize() and getMaximumSize() return th e same value. I haven't experimented too much with this but, depending on the l ayout you use for your GUI your button could look completely different.</p> <p>And finally, the <a href="https://github.com/kdeloach/labs/blob/master/java/y ahtzee/src/Dice.java">source code</a>. In case I missed anything. </p> ---------<p>SVN has 3 main advantages over CVS</p> <ul> <li>it's faster</li> <li>supports versioning of binary files</li> <li>and adds transactional commit (all or nothing)</li>

</ul> ---------<p><strong>High Resolution, Low Overhead Timing for Intel Processors</strong></p > <p>If you're on Intel hardware, here's how to read the CPU real-time instruction counter. It will tell you the number of CPU cycles executed since the processo r was booted. This is probably the finest-grained counter you can get for perfo rmance measurement.</p> <p>Note that this is the number of CPU cycles. On linux you can get the CPU spe ed from /proc/cpuinfo and divide to get the number of seconds. Converting this to a double is quite handy.</p> <p>When I run this on my box, I get</p> <pre><code>11867927879484732 11867927879692217 it took this long to call printf: 207485 </code></pre> <p>Here's the <a href="http://cs.smu.ca/~jamuir/rdtscpm1.pdf">Intel developer's guide</a> that gives tons of detail.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdint.h&gt; inline uint64_t rdtsc() { uint32_t lo, hi; __asm__ __volatile__ ( "xorl %%eax, %%eax\n" "cpuid\n" "rdtsc\n" : "=a" (lo), "=d" (hi) : : "%ebx", "%ecx"); return (uint64_t)hi &lt;&lt; 32 | lo; } main() { unsigned long long x; unsigned long long y; x = rdtsc(); printf("%lld\n",x); y = rdtsc(); printf("%lld\n",y); printf("it took this long to call printf: %lld\n",y-x); } </code></pre> ---------<p>@rictic</p> <p>You're right. My math was wrong. (2n+3n+4n+...nn)=(2+3+4+..n)n= (.5n(n+1))n =.5n^3 +.5n^2 simplified to n^3. Serves me right for doing calculus in my head.

</p> ---------<p>I would be wary of automatically upcasing all whitespace-preceded-words in sc enarios where I would run the risk of attracting the fury of nitpickers.</p> <p>I would at least consider implementing a dictionary for exception cases like articles and conjunctions. Behold: </p> <blockquote> <p>"Beauty and the Beast"</p> </blockquote> <p>And when it comes to proper nouns, the thing gets much uglier.</p> ---------<p>@Bernard:</p> <blockquote> <p>I have to admit, most of your example went straight over my head. It does c ompile, and seems to work, though. Is this safe for SMP systems or SpeedStep?</p > </blockquote> <p>That's a good question... I think the code's ok. From a practical standpoint, we use it in my company every day, and we run on a pretty wide array of boxes, everything from 2-8 cores. Of course, YMMV, etc, but it seems to be a reliable and low-overhead (because it doesn't make a context switch into system-space) method of timing.</p> <p>Generally how it works is:</p> <ul> <li>declare the block of code to be assembler (and volatile, so the optimizer will leave it alone).</li> <li>execute the CPUID instruction. In addition to getting some CPU information (which we don't do anything with) it synchronizes the CPU's execution buffer so that the timings aren't affected by out-of-order execution.</li> <li>execute the rdtsc (read timestamp) execution. This fetches the number of machine cycles executed since the processor was reset. This is a 64-bit value, so with current CPU speeds it will wrap around every 194 years or so. Interestingly, in the original Pentium reference, they note it wraps around ever y 5800 years or so.</li> <li>the last couple of lines store the values from the registers into the variables hi and lo, and put that into the 64-bit return value.</li> </ul> <p>Specific notes:</p> <ul> <li><p>out-of-order execution can cause incorrect results, so we execute the "cpuid" instruction which in addition to giving you some information about the cpu also synchronizes any out-of-order instruction execution.</p></li> <li><p>Most OS's synchronize the counters on the CPUs when they start, so the answer is good to within a couple of nano-seconds.</p></li> <li><p>The hibernating comment is probably true, but in practice you

probably don't care about timings across hibernation boundaries.</p></li> <li><p>regarding speedstep: Newer Intel CPUs compensate for the speed changes and returns an adjusted count. I did a quick scan over some of the boxes on our network and found only one box that didn't have it: a Pentium 3 running some old database server. (these are linux boxes, so I checked with: grep constant_tsc /proc/cpuinfo)</p>< /li> <li><p>I'm not sure about the AMD CPUs, we're primarily an Intel shop, although I know some of our low-level systems gurus did an AMD evaluation.</p></li> </ul> <p>Hope this satisfies your curiosity, it's an interesting and (IMHO) under-studied area of programming. You know when Jeff and Joel were talking about whether or not a programmer should know C? I was shouting at them, "hey forget that high-level C stuff... assembler is what you should learn if you want to know what the computer is doing!"</p> ---------<p>An approach I've used in various applications is to have a generic Permission Token class which has a changeable Value property. Then you query the requested application, it tells you which PermissionTokens are needed in order to use it. </p> <p>For example, the Shipping application might tell you it needs:</p> <pre><code>new PermissionToken()<br>{<br> Target = PermissionTokenTarget.Appl ication,<br> Action = PermissionTokenAction.View,<br> Value = "ShippingApp "<br>};<br></code></pre> <p>This can obviously be extended to Create, Edit, Delete etc and, because of th e custom Value property, any application, module or widget can define its own re quired permissions. YMMV, but this has always been an efficient method for me w hich I have found to scale well.</p> ---------<h2>Big List of Resources:</h2> <ul> <li><a href="http://www.cs.indiana.edu/~dyb/pubs/nano-jfp.pdf">A Nanopass Framew ork for Compiler Education</a> </li> <li><a href="http://rads.stackoverflow.com/amzn/click/1558603204">Advanced Compi ler Design and Implementation</a> $</li> <li><a href="http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf">An Incremental Ap proach to Compiler Construction</a> </li> <li><a href="http://javadude.com/articles/antlr3xtut">ANTLR 3.x Video Tutorial</ a></li> <li><a href="http://www.onlamp.com/pub/a/onlamp/2004/04/15/parrot_compiler_const ruction.html">Building a Parrot Compiler</a></li> <li><a href="http://www.cs.man.ac.uk/~pjj/farrell/compmain.html">Compiler Basics </a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0201403536">Compiler Const ruction</a> $</li> <li><a href="http://rads.stackoverflow.com/amzn/click/0442275366">Compiler Desig n and Construction</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0805321667">Crafting a Com

piler with C</a> $</li> <li><a href="http://en.wikipedia.org/wiki/Compilers%3a_Principles%2C_Techniques% 2C_and_Tools">Dragon Book</a> $ - Widely considered "the book" for compiler writ ing.</li> <li><a href="http://www.cs.indiana.edu/eopl/">Essentials of Programming Language s</a></li> <li><a href="http://flipcode.com/archives/articles.shtml">Flipcode Article Archi ve</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/1931841578">Game Scripting Mastery</a> $</li> <li><a href="http://www.icemanind.com/VMCS.pdf">How to build a virtual machine f rom scratch in C#</a> </li> <li><a href="http://research.microsoft.com/~simonpj/papers/pj-lester-book/">Impl ementing Functional Languages</a></li> <li><a href="http://www.codeproject.com/KB/recipes/programminglanguagetoools.asp x">Implementing Programming Languages using C# 4.0</a></li> <li><a href="http://en.wikipedia.org/wiki/Interpreter_pattern">Interpreter patte rn</a> (described in <a href="http://rads.stackoverflow.com/amzn/click/020163361 2">Design Patterns</a> $) specifies a way to evaluate sentences in a language</l i> <li><a href="http://pragprog.com/titles/tpdsl/language-implementation-patterns"> Language Implementation Patterns: Create Your Own Domain-Specific and General Pr ogramming Languages</a></li> <li><a href="http://compilers.iecc.com/crenshaw/">Lets Build a Compiler</a> - Th e <a href="http://www.stack.nl/~marcov/compiler.pdf">PDF</a> version</li> <li><a href="http://tinyurl.com/5txtuk">Linkers and Loaders</a> $ (Google Books) </li> <li><a href="http://rads.stackoverflow.com/amzn/click/0521562473">Lisp in Small Pieces (LiSP)</a> $</li> <li><a href="http://llvm.org/docs/tutorial/">LLVM Tutorial</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0521607647">Modern Compile r Implementation in ML</a> $ - There is a <a href="http://rads.stackoverflow.com /amzn/click/052182060X">Java</a> $ and <a href="http://rads.stackoverflow.com/am zn/click/0521607655">C</a> $ version as well - widly considered a very good book </li> <li><a href="http://rads.stackoverflow.com/amzn/click/013630740X">Object-Oriente d Compiler Construction</a></li> <li><a href="http://www.parrotblog.org/2008/03/targeting-parrot-vm.html">Parrot Tutorial</a></li> <li><a href="http://www.dickgrune.com/Books/PTAPG_1st_Edition/">Parsing Techniqu es - A Practical Guide</a></li> <li><a href="http://www-old.oberon.ethz.ch/WirthPubl/ProjectOberon.pdf">Project Oberon</a> - Look at chapter 13</li> <li><a href="http://rads.stackoverflow.com/amzn/click/0137302673">Programming a Personal Computer</a> $</li> <li><a href="http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/">Programi ng Languages: Application and Interpretation</a></li> <li><a href="http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AITR-474.pd f">Rabbit: A Compiler for Scheme</a></li> <li><a href="http://cm.bell-labs.com/who/ken/trust.html">Reflections on Trusting Trust</a> - a quick guide</li> <li><a href="http://msdn.microsoft.com/en-us/magazine/cc136756.aspx">Roll Your O wn Compiler for the .NET framework</a> a quick toturial form MSDN</li> <li><a href="http://mitpress.mit.edu/sicp/">Structure and Interpretation of Comp uter Programs</a></li> <li><a href="http://www.cis.upenn.edu/~bcpierce/tapl/">Types and Programming Lan guages</a></li> <li><a href="http://prog21.dadgum.com/30.html">Want to Write a Compiler?</a> - a quick guide</li> <li><a href="http://www.hokstad.com/writing-a-compiler-in-ruby-bottom-up-step-1.

html">Writing a Compiler in Ruby Bottom Up</a></li> </ul> <p>Legend:<br> Link to a PDF<br> $ Link to a printed book</p> ---------<p>If the fact that the first button is used by default is consistent across bro wsers, why not put them the right way round in the source code, then use CSS to switch their apparent positions? <code>float</code> them left and right to switc h them around visually, for example.</p> ---------<p><a href="http://trolltech.com/products/qt/" rel="nofollow">Qt Cross-Platform Application Framework</a></p> <p>Qt is a cross-platform application framework for desktop and embedded develop ment. It includes an intuitive API and a rich C++ class library, integrated tool s for GUI development and internationalization, and support for Java and C++ deve lopment</p> <p>They have a plug-in for Visual Studio that costs a bit of money, but it is wo rth every penny.</p> ---------<p>Have a DTS job (or a job that is started by a windows service) that runs at a given interval. Each time it is run, it gets information about the given table by using the system <a href="http://msdn.microsoft.com/en-us/library/ms186778.as px">INFORMATION_SCHEMA</a> tables, and records this data in the data repository. Compare the data returned regarding the structure of the table with the data re turned the previous time. If it is different, then you know that the structure h as changed.</p> <p>Example query to return information regarding all of the columns in table ABC (ideally listing out just the columns from the INFORMATION_SCHEMA table that yo u want, instead of using <em>select *</em> like I do here):</p> <pre><code>select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'ABC' </code></pre> <p>You would monitor different columns and INFORMATION_SCHEMA views depending on how exactly you define "changes to a table".</p> ---------<p>John Resig did <a href="http://ejohn.org/blog/easy-pdf-sharing/" rel="nofollo w">a script to extract images from a PDF as PNG files using ImageMagick</a>.</p> ---------<p>Oracle has got an <a href="http://download.oracle.com/oll/tutorials/SQLInject ion/index.htm" rel="nofollow">extensive tutorial on that topic</a></p>

---------<p>I didn't try it, but I did see an article on Code Project that implements C# scripting in a .NET application.</p> <p><a href="http://www.codeproject.com/KB/cs/cs-script_for_cp.aspx" rel="nofollo w">http://www.codeproject.com/KB/cs/cs-script_for_cp.aspx</a></p> ---------<p>What is the difference between <a href="http://msdn.microsoft.com/en-us/libra ry/9a6a2sxy.aspx"><code>Math.Floor()</code></a> and <a href="http://msdn.microso ft.com/en-us/library/system.math.truncate.aspx"><code>Math.Truncate()</code></a> in .NET?</p> ---------<p>Check out <a href="http://filehelpers.sourceforge.net/">FileHelpers</a>.</p> ---------<p>Ummm. Maybe I am missing something about the question here, but if you have long/lat info, you also have the direction of north?</p> <p>It seems you need to map geodesic coordinates to a projected coordinates syst em. For example osgb to wgs84.</p> <p>The maths involved is non-trivial, but the code comes out a only a few lines. If I had more time I'd post more but I need a shower so I will be boring and li nk to the <a href="http://en.wikipedia.org/wiki/Geographic_coordinate_system" re l="nofollow">wikipedia</a> entry which is pretty good.</p> <p>Note: Post shower edited.</p> ---------<p>SQLite databases exist independently, so there's not way to do this from the database level.</p> <p>You will have to write your own code to do this.</p> ---------<P>I'm trying to read binary data using C#. I have all information about the lay out of the data in the files I want to read. I'm able to read the data "chunk by chunk", i.e. getting the first 40 bytes of data converting it to a string, get the next 40 bytes, ...</P> <P>Since there are at least three slighlty different version of the data, I woul d like to read the data directly into a struct. It just feels so much more right than by reading it "line by line".</P> <P>I have tried the following approach but to no avail:</P><PRE><CODE>StructType aStruct; int count = Marshal.SizeOf(typeof(StructType)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(stream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); aStruct = (StructType) Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeo f(StructType));

handle.Free(); </CODE></PRE> <P>The stream is an opened FileStream from which I have began to read from. I ge t an AccessViolationException when using Marshal.PtrToStructure.</P> <P>The stream contains more information than I'm trying to read since I'm not in terested in data at the end of the file.</P> <P>The struct is defined like:</P><PRE><CODE>[StructLayout(LayoutKind.Explicit)] struct StructType { [FieldOffset(0)] public string FileDate; [FieldOffset(8)] public string FileTime; [FieldOffset(16)] public int Id1; [FieldOffset(20)] public string Id2; } </CODE></PRE> <P>The examples code is changed from original to make this question shorter.</P> <P>How would I read binary data from a file into a struct?</P> ---------<pre><code>&lt;form name="form1" id="form1" method="post" autocomplete="off" action="http://www.example.com/form.cgi"&gt; </code></pre> <p>This will work in IE and FF, the downside is that it is not XHTML standard.</ p> ---------<p>Use a non-standard name and id for the fields, so rather than "name" have "na me_". Browsers will then not see it as being the name field. The best part about it is that you can do this to some but not all fields and it will autocomplete some but not all fields.</p> ---------<p>Use subversion, it's easy to setup, easy to use, and has plenty of tools. Any future revision system will have an import from SVN feature, so it isn't like y ou can't change down the road if your needs grow.</p> ---------<p>I found <a href="http://code.google.com/p/svnrevisionlabeller" rel="nofollow" >this</a> project on google code. This is <code>CCNET</code> plugin to generate the label in <code>CCNET</code>.</p> <p>The <code>DLL</code> is tested with <code>CCNET 1.3</code> but it works with <code>CCNET 1.4</code> for me. I'm successfully using this plugin to label my bu ild.</p> <p>Now onto passing it to <code>MSBuild</code>...</p> ----------

<p>The GNU C Library supports <a href="http://www.gnu.org/software/libtool/manua l/libc/Regular-Expressions.html" rel="nofollow">regular expressions</a>. It's o pen, and the RE code seems to be easily extractable.</p> ---------<P>Checkboxes in html forms don't have implicit labels with them. Adding an expl icit label (some text) next to it doesn't toggle the checkbox.</P> ---------<p>A solution (albeit one that defers handling of the null value to the code) co uld be:</p> <p>DateTime yesterday = DateTime.Now.Date.AddDays(-1);</p> <pre><code>var collection=<br> from u in db.Universe<br> select new<br> {<br> u.id,<br> u.name,<br> MaxDate =(DateTime?)<br> (<br> from h in db.History<br> where u.Id == h.Id<br> &amp;&amp; h.dateCol &lt; yesterday<br> select h.dateCol <br> ).Max()<br> };<br></code></pre> <p>This does not produce exactly the same SQL, but does provide the same logical result. Translating "complex" SQL queries to LINQ is not allways straightforwar d.</p> ---------<p>I believe <a href="http://www.fabforce.net/dbdesigner4/" rel="nofollow">DB De signer</a> does something like that. And I think they even have a free version. </p> <p><em>edit</em> Never mind. Michael's link is much better.</p> ---------<p>There's a PHP5 "database migration framework" called Ruckusing. I haven't use d it, but the <a href="http://code.google.com/p/ruckusing/wiki/CompleteExamples" rel="nofollow">examples</a> show the idea, if you use the language to create th e database as and when needed, you only have to track source files.</p> ---------<p><a href="http://martinfowler.com/eaaDev/uiArchs.html">Martin Fowler's website (and his books) have fantastic in-depth articles on various ui patterns and wha t they address.</a></p> ---------<P>Depends on the version, 4 is by value, 5 is by reference.</P> ---------<p>I would be a bit reluctant to use nested classes here. What if you created a n abstract base class for a "multimedia driver" to handle the back-end stuff (wo rkhorse), and a separate class for the front-end work? The front-end class coul d take a pointer/reference to an implemented driver class (for the appropriate m edia type and situation) and perform the abstract operations on the workhorse st ructure.</p>

<p>My philosophy would be to go ahead and make both structures accessible to the client in a polished way, just under the assumption they would be used in tande m.</p> <p>I would reference something like a <a href="http://qt-project.org/doc/qt-4.8/ qtextdocument.html" rel="nofollow">QTextDocument</a> in Qt. You provide a direc t interface to the bare metal data handling, but pass the authority along to an object like a QTextEdit to do the manipulation.</p> ---------<p>Here's a dynamic sql script I've used in the past. It can be further modifie d but it will give you the basics. I prefer scripting it to avoid the mistakes you can make using the Management Studio:</p> <pre><code><br>Declare @OldDB varchar(100)<br>Declare @NewDB varchar(100)<br>Dec lare @vchBackupPath varchar(255)<br>Declare @query varchar(8000)<br><br><br>/*Te st code to implement <br>Select @OldDB = 'Pubs'<br>Select @NewDB = 'Pubs2'<br>Se lect @vchBackupPath = '\\dbserver\C$\Program Files\Microsoft SQL Server\MSSQL.1\ MSSQL\Backup\pubs.bak'<br>*/<br><br>SET NOCOUNT ON;<br><br>Select @query = 'Crea te Database ' + @NewDB<br>exec(@query)<br><br>Select @query = '<br>Declare @vBAK Path varchar(256)<br>declare @oldMDFName varchar(100)<br>declare @oldLDFName var char(100)<br>declare @newMDFPath varchar(100)<br>declare @newLDFPath varchar(100 )<br>declare @restQuery varchar(800)<br><br>select @vBAKPath = ''' + @vchBackupP ath + '''<br>select @oldLDFName = name from ' + @OldDB +'.dbo.sysfiles where fil ename like ''%.ldf%''<br>select @oldMDFName = name from ' + @OldDB +'.dbo.sysfi les where filename like ''%.mdf%''<br>select @newMDFPath = physical_name from ' + @NewDB +'.sys.database_files where type_desc = ''ROWS''<br>select @newLDFPath = physical_name from ' + @NewDB +'.sys.database_files where type_desc = ''LOG''< br><br>select @restQuery = ''RESTORE DATABASE ' + @NewDB + <br>' FROM DISK = N'' + '''''''' + @vBAKpath + '''''''' + <br>'' WITH MOVE N'' + '''''''' + @oldMDFNa me + '''''''' + <br>'' TO N'' + '''''''' + @newMDFPath + '''''''' + <br>'', MO VE N'' + '''''''' + @oldLDFName + '''''''' + <br>'' TO N'' + '''''''' + @newLDF Path + '''''''' + <br>'', NOUNLOAD, REPLACE, STATS = 10''<br><br>exec(@restQuer y)<br>--print @restQuery'<br><br><br>exec(@query)<br><br><br><br><br><br></code> </pre> ---------<p>The <a href="http://library.gnome.org/devel/glib/stable/" rel="nofollow">Glib </a> library used on the Gnome project may also be some use. Moreover it is pret ty well tested.</p> <p>IBM developer works has a good tutorial on its use: <a href="http://www.ibm.c om/developerworks/linux/tutorials/l-glib/resources.html" rel="nofollow">Manage C data using the GLib collections</a></p> ---------<p>In your example above, when 'i' will always be positive and a higher range wo uld be beneficial, unsigned would be useful. Like if you're using 'declare' stat ements, such as: </p> <pre><code>#declare BIT1 (unsigned int 1)<br>#declare BIT32 (unsigned int really bignumber)<br></code></pre> <p>Especially when these values will never change.</p>

<p>However, if you're doing an accounting program where the people are irrespons ible with their money and are constantly in the red, you will most definitely wa nt to use 'signed'.</p> <p>I do agree with saint though that a good rule of thumb is to use signed, whic h C actually defaults to, so you're covered.</p> ---------<P>I was wondering if there is any good and clean oo implementation of bayesian filtering for spam and text classification? For learning purposes.</P> ---------<p>I'm working on a <strong>multithreaded</strong> C++ application that is corru pting the heap. The usual tools to locate this corruption seem to be inapplicab le. Old builds (18 months old) of the source code exhibit the same behaviour as the most recent release, so this has been around for a long time and just wasn' t noticed; on the downside, source deltas can't be used to identify when the bug was introduced - there are <em>a lot</em> of code changes in the repository.</p > <p>The socket a set laces, > prompt for crashing behaviuor is to generate throughput in this system transfer of data which is munged into an internal representation. I have of test data that will periodically cause the app to exception (various p various causes - including heap alloc failing, thus: heap corruption).</p

<p>The behaviour seems related to CPU power or memory bandwidth; the more of eac h the machine has, the easier it is to crash. Disabling a hyper-threading core or a dual-core core reduces the rate of (but does not eliminate) corruption. Th is suggests a timing related issue.</p> <p>Now here's the rub:<br> When it's run under a lightweight debug environment (say <code>Visual Studio 98 / AKA MSVC6</code>) the heap corruption is reasonably easy to reproduce - ten or fifteen minutes pass before something fails horrendously and exceptions, like a n <code>alloc;</code> when running under a sophisticated debug environment (Rati onal Purify, <code>VS2008/MSVC9</code> or even Microsoft Application Verifier) t he system becomes memory-speed bound and doesn't crash (Memory-bound: CPU is not getting above <code>50%</code>, disk light is not on, the program's going as fa st it can, box consuming <code>1.3G</code> of 2G of RAM). So, <strong>I've got a choice between being able to reproduce the problem (but not identify the cause ) or being able to idenify the cause or a problem I can't reproduce.</strong></p > <p>My current best guesses as to where to next is:</p> <ol> <li>Get an insanely grunty box (to replace the current dev box: 2Gb RAM in an <c ode>E6550 Core2 Duo</code>); this will make it possible to repro the crash causi ng mis-behaviour when running under a powerful debug environment; or</li> <li>Rewrite operators <code>new</code> and <code>delete</code> to use <code>Virt ualAlloc</code> and <code>VirtualProtect</code> to mark memory as read-only as s oon as it's done with. Run under <code>MSVC6</code> and have the OS catch the b ad-guy who's writing to freed memory. Yes, this is a sign of desperation: who t he hell rewrites <code>new</code> and <code>delete</code>?! I wonder if this is going to make it as slow as under Purify et al.</li> </ol>

<p>And, no: Shipping with Purify instrumentation built in is not an option.</p> <p>A colleague just walked past and asked "Stack Overflow? Are we getting stack overflows now?!?"</p> <p>And now, the question: <strong>How do I locate the heap corruptor?</strong></ p> <hr> <p>Update: balancing <code>new[]</code> and <code>delete[]</code> seems to have gotten a long way towards solving the problem. Instead of 15mins, the app now g oes about two hours before crashing. Not there yet. Any further suggestions? T he heap corruption persists.</p> <p>Update: a release build under Visual Studio 2008 seems dramatically better; c urrent suspicion rests on the <code>STL</code> implementation that ships with <c ode>VS98</code>.</p> <hr> <blockquote> <ol> <li>Reproduce the problem. <code>Dr Watson</code> will produce a dump that mig ht be helpful in further analysis. </li> </ol> </blockquote> <p>I'll take a note of that, but I'm concerned that Dr Watson will only be tripp ed up after the fact, not when the heap is getting stomped on.</p> <blockquote> <p>Another try might be using <code>WinDebug</code> as a debugging tool which is quite powerful being at the same time also lightweight.</p> </blockquote> <p>Got that going at the moment, again: not much help until something goes wrong . I want to catch the vandal in the act.</p> <blockquote> <p>Maybe these tools will allow you at least to narrow the problem to certain component.</p> </blockquote> <p>I don't hold much hope, but desperate times call for...</p> <blockquote> <p>And are you sure that all the components of the project have correct runtim e library settings (<code>C/C++ tab</code>, Code Generation category in VS 6.0 p roject settings)?</p> </blockquote> <p>No I'm not, and I'll spend a couple of hours tomorrow going through the works pace (58 projects in it) and checking they're all compiling and linking with the appropriate flags. <hR> Update: This took 30 seconds. Select all projects in the <code>Settings</code> dialog, unselect until you find the project(s) that don't have the right setting s (they all had the right settings).</p>

---------<p>It sounds like <code>this.Opacity</code> is a double value, and the compiler doesn't like you trying to cram a decimal value into it.</p> ---------<p>It depends, what is the nature of the site? If the sites customers are expose d to Identity Theft or similar horrific things, it is your duty to report the is sue to outside authorities. The question is, how?</p> <p>I would suggest contacting <a href="http://consumerist.com/" rel="nofollow">T he Consumerist</a> and demonstrating your exploit to them. They will bring enoug h media attention to the issue that the company will be forced to do something a bout it.</p> <p>If on the other hand, it's a silly web forum for turtle lovers... well, if th ey don't care, move on to bigger and better things.</p> ---------<p>I listen to the <a href="http://javaposse.com" rel="nofollow">javaposse</a> r egularly, they cover mostly Java, but not solely.</p> ---------<p>I am seconding the WMWare angle. Most of the open source OSes have a complete machine ready to roll, so there is no install time and VMWare Player is free to use with these.</p> <p>Also, some emulators that attempt to simulate a different resolution fail to take the browser into account and the virtual machine can replicate this better. </p> ---------<p>Looks like you're right. That's the only approach. </p> <p>This seems like a good detailed explanation of your advice: <a href="http://a jaxpatterns.org/Unique_URLs" rel="nofollow">http://ajaxpatterns.org/Unique_URLs< /a></p> ---------<p>You can print from the command line using the following:</p> <blockquote> <p>rundll32.exe %WINDIR%\System32\mshtml.dll,PrintHTML "%1"</p> </blockquote> <p>Where %1 is the file path of the html file to be printed.</p> <p>If you don't need to print from memory (or can afford to write to the disk in a temp file) you can use:</p>

<pre><code>using (Process printProcess = new Process())<br>{<br> string syste mPath = Environment.GetFolderPath(Environment.SpecialFolder.System);<br> prin tProcess.StartInfo.FileName = systemPath + @"\rundll32.exe";<br> printProcess .StartInfo.Arguments = systemPath + @"\mshtml.dll,PrintHTML """ + fileToPrint + @"""";<br> printProcess.Start();<br>}<br></code></pre> <p>N.B. This only works on Windows 2000 and above I think.</p> ---------<P>Make sure you keep a record of your e-mail message(s). You might need it in c ourt.</P> ---------<p>I would look into IMAP</p> <p><a href="http://us3.php.net/imap" rel="nofollow">IMAP, POP3 and NNTP</a></p> ---------<p>You do the unit testing by mocking out the database connection. This way, you can build scenarios where specific queries in the flow of a method call succeed or fail. I usually build my mock expectations so that the actual query text is ignored, because I really want to test the fault tolerance of the method and how it handles itself -- the specifics of the SQL are irrelevant to that end. </p> <p>Obviously this means your test won't actually verify that the method <em>work s</em>, because the SQL may be wrong. This is where integration tests kick in. F or that, I expect someone else will have a more thorough answer, as I'm just beg inning to get to grips with those myself.</p> ---------<p>I am thinking off the top of my head here. If you load both as Data Tables in the same Data Sets, and define a relation between the two over SKU, and then ru n a query on the Data Set which produces the desired result.</p> ---------<p>One of the many comparisons:</p> <p><a href="http://wiki.scummvm.org/index.php/CVS_vs_SVN" rel="nofollow">http:// wiki.scummvm.org/index.php/CVS_vs_SVN</a></p> <p>Now this is very specific to that project, but a lot of stuff apllies in gene ral.</p> <p>Pro Subversion:</p> <blockquote> <ul> <li>Support for versioned renames/moves (impossible with CVS): Fingolfin, Ende r</li> <li>Supports directories natively: It's possible to remove them, and they are versioned: Fingolfin, Ender</li> <li>File properties are versioned; no more "executable bit" hell: Fingolfin</l i>

<li>Overall revision number makes build versioning and regression testing much easier: Ender, Fingolfin</li> <li>Atomic commits: Fingolfin</li> <li>Intuitive (directory-based) branching and tagging: Fingolfin</li> <li>Easier hook scripts (pre/post commit, etc): SumthinWicked (I use it for Do xygen after commits)</li> <li>Prevents accidental committing of conflicted files: Salty-horse, Fingolfin </li> <li>Support for custom 'diff' command: Fingolfin</li> <li>Offline diffs, and they're instant: sev </li> </ul> </blockquote> ---------<p>Variables containing primitive types are passed by value in PHP5. Variables c ontaining objects are passed by reference. There's quite an interesting article from Linux Journal from 2006 which mentions this and other OO differences betwee n 4 and 5.</p> <p><a href="http://www.linuxjournal.com/article/9170" rel="nofollow">http://www. linuxjournal.com/article/9170</a> </p> ---------<p>No, because while you thought LINQ is really just syntactic sugar, it actuall y heavily used expression trees -- a feature absent in .NET 2.0.</p> <p>That being said .NET 3.5 only builds up on top of .NET 2.0, and that's the re ason why the IL doesn't look "different" or "special".</p> <p>I do not see a reason why you shouldn't just install the .NET 3.5 Framework. Everything .NET 2.0 will work fine on it, promise :)</p> ---------<p>I would say, don't worry so much about such micro performance. It is much be tter to just get something to work, and then make it as clear and concise and ea sy to read as possible. The worst thing you can do is sacrifice readability for an insignificant amount of performance.</p> <p>In the end, the best way to deal with performance issues is to save them for when you have data that indicates there is an actual performance problem... othe rwise you will spend a lot of time micro-optimizing and actually cause higher ma intenance costs for later on.</p> <p>If you find this parsing situation is really the bottleneck in your applicati on, THEN is the time to try and figure out what the fastest way to solve the pro blem is. I think Jeff (and many others) have blogged about this sort of thing a lot.</p> ---------<p>I have a little game written in C#. It uses a database as back-end. It's a <a href="http://en.wikipedia.org/wiki/Collectible_card_game">trading card game </a>, and I wanted to implement the function of the cards as a script.</p> <p>What I mean is that I essentially have an interface, <code>ICard</code>, whic h a card class implements (<code>public class Card056 : ICard</code>) and which contains function that are called by the game.</p>

<p>Now, to make the thing maintainable/moddable, I would like to have the class for each card as source code in the database and essentially compile it on first use. So when I have to add/change a card, I'll just add it to the database and tell my application to refresh, without needing any assembly deployment (especia lly since we would be talking about 1 assembly per card which means hundreds of assemblies).</p> <p>Is that possible? Register a class from a source file and then instantiate it , etc.</p> <pre><code>ICard Cards[current] = new MyGame.CardLibrary.Card056(); Cards[current].OnEnterPlay(ref currentGameState); </code></pre> <p>The language is C#, but extra bonus if it's possible to write the script in a ny .NET language.</p> ---------<p>I've provided a solution for Python... please flesh this out with examples fo r other languages.</p> ---------<p>That's definitely a good way to do it. But you if you happen to be using a d atabase that supports LINQ to SQL, it can be a lot more fun. It can look someth ing like this:</p> <pre><code>MyDB db = new MyDB("Data Source=...");<br>var q = from db.MyTable<br> select c;<br>foreach (var c in q)<br> Console.WriteLine(c.MyField.ToStr ing());<br></code></pre> ---------<p>Why not use <code>For Each</code>? That way you don't need to care what the <code>LBound</code> and <code>UBound</code> are.</p> <pre><code>Dim x, y, z x = Array(1, 2, 3) For Each y In x z = DoSomethingWith(y) Next </code></pre> ---------<p>So I hear a lot of opinions about this and I wanted to see if there was anyth ing resembling a consensus. When is it appropriate to use an unsigned variable o ver a signed one? What about in a <code>for</code> loop?</p> <pre><code>for (unsigned int i = 0; i &lt; someThing.length(); i++) { SomeThing var = someThing.at(i); // You get the idea. } </code></pre>

<p>As I said, I hear a lot of opinions, but not a lot of consensus. I know Java doesn't have unsigned values, and that must have been a concious decision on Sun 's part. </p> <p>Looking forward to hearing everybody's opinion.</p> ---------<p>Does the <a href="https://www.adobe.com/cfusion/tdrc/index.cfm?product=flashp ro" rel="nofollow">Flash Trial</a> version not last long enough (30 days) for yo u to evaluate if Flash is the right choice for you?</p> <p>@Bill, no probs, reading between the lines isn't my strong point sorry for an y confusion :)</p> ---------<p>any of the popular editors can be turned into an ide.</p> <p>I use Vi on the console and have used various gui editors over the years. Th is doesn't just go for linux I use Crimson Editor on windows as a C/python/z80as m ide.</p> ---------<p>Past year's ICFP contests have interesting problems. <a href="http://www.boun dvariable.org/" rel="nofollow">2006's</a> is quite a lot of fun and has lots of different problems to work on, from building your own VM to coding in a 2D circu it language.</p> ---------<p><strong>AppDomain.UnhandledException</strong> is an <strong>event</strong>, n ot a global exception handler. This means, by the time it is raised, your applic ation is already on its way down the drain, and there is nothing you can do abou t it, except for doing cleanup and error logging.</p> <p>What happened behind the scenes is this: The framework detected the exception , walked up the call stack to the very top, found no handlers that would recover from the error, so was unable to determine if it was safe to continue execution . So, it started the shutdown sequence, and fired up this event as a courtesy to you so you can pay your respects to your already-doomed process. This happens w hen an exception is left unhandled in the main thread.</p> <p>There is no single-point solution to this kind of error. You need to put a re al exception handler (a catch block) upstream of all places where this error occ urs and forward it to (for example) a global handler method/class that will dete rmine if it is safe to simply report and continue, based on exception type and/o r content.</p> <p>Edit: It is possible to disable (=hack) the error-reporting mechanism built i nto Windows so the mandatory "crash and burn" dialog does not get displayed when your app goes down. However, this becomes effective for <em>all</em> the applic ations in the system, not just your own.</p> ---------<p>I know several people who were in a situation like this.</p>

<p>Let's say, you were trying out random sites for basic XSS/SQL Injection vulne rabilities, and you've found one that could be easily compromised. You email the admin/webmaster, but they don't reply. </p> <p>What would you do?</p> ---------<p>I want to print HTML from a C# web service. The Web Browser control is overk ill, and does not function well in a service environment, nor does it function w ell on a system with very tight security constraints. Is there any sort of free .NET library that will support the printing of a basic HTML page? Here is the code I have so far, which does not run properly.</p> <pre><code>public void PrintThing(string document) { if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) { Thread thread = new Thread((ThreadStart) delegate { PrintDocument(document); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); } else { PrintDocument(document); } } protected void PrintDocument(string document) { WebBrowser browser = new WebBrowser(); browser.DocumentText = document; while (browser.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } browser.Print(); } </code></pre> <p>This works fine when called from UI-type threads, but nothing happens when ca lled from a service-type thread. Changing <code>Print()</code> to <code>ShowPri ntPreviewDialog()</code> yields the following IE script error:</p> <blockquote> <p>Error: 'dialogArguments.___IE_PrintType' is null or not an object<br /> URL: res://ieframe.dll/preview.dlg</p> </blockquote> <p>And a small empty print preview dialog appears.</p> ---------<p>This is a tricky one and I've always relied on techniques, such as permission -based emails (i.e. only sending to people you have permission to send to) and n ot using blatantly <em>spamish</em> terminology.</p>

<p>Of late, some of the emails I send out programmatically have started being sh uffled into people's spam folder automatically and I'm wondering what I can do a bout it.</p> <p>This is despite the fact that these particular emails are not ones that human s would mark as spam, specifically, they are emails that contain license keys th at people have paid good money for, so I don't think they're going to consider t hem spam</p> <p>I figure this is a big topic in which I am essentially an ignorant simpleton. </p> ---------<p>Martin Fowler wrote my favorite article on the subject, <a href="http://marti nfowler.com/articles/evodb.html">http://martinfowler.com/articles/evodb.html</a> . I choose not to put schema dumps in under version control as <em>alumb</em> a nd others suggest because I want an easy way to upgrade my production database.< /p> <p>For a web application where I'll have a single production database instance, I use two techniques:</p> <h1>Database Upgrade Scripts</h1> <p>A sequence database upgrade scripts that contain the DDL necessary to move th e schema from version N to N+1. (These go in your version control system.) A < em>version_history</em> table, something like</p> <pre><code>create table VersionHistory (<br> Version int primary key,<br> UpgradeStart datetime not null,<br> UpgradeEnd datetime<br> );<br></code>< /pre> <p>gets a new entry every time an upgrade script runs which corresponds to the n ew version.</p> <p>This ensures that it's easy to see what version of the database schema exists and that database upgrade scripts are run only once. Again, these are <strong> not</strong> database dumps. Rather, each script represents the <strong>changes </strong> necessary to move from one version to the next. They're the script th at you apply to your production database to "upgrade" it.</p> <h1>Developer Sandbox Synchronization</h1> <ol> <li>A script to backup, sanitize, and shrink a production database. Run this af ter each upgrade to the production DB.</li> <li>A script to restore (and tweak, if necessary) the backup on a developer's wo rkstation. Each developer runs this script after each upgrade to the production DB.</li> </ol> <p><em>A caveat: My automated tests run against a schema-correct but empty datab ase, so this advice will not perfectly suit your needs.</em></p> ----------

Potrebbero piacerti anche