input
stringlengths
51
42.3k
output
stringlengths
18
55k
why grails uses "static" vars instead of annotations <p>for example:class </p> <pre><code>Book { static mapping = { batchSize 10 } } </code></pre> <p>could be:</p> <pre><code>@Configration(batchSize=10) class Book { ... } </code></pre>
<p>The main reason is that Grails was developed for Groovy 1.1 which didn't support annotations. I guess one of the next versions will support annotations but as alamar said, annotations can't be changed at runtime. Therefore, the current approach is more flexible.</p>
How can I find non ascii strings in an array of strings, in Rails 2.0/ruby 1.8.6? <p>I have an array full of user logins that was loaded from the database. What's the simplest and efficient way to keep only the logins that contain non-ascii characters?</p> <pre><code>logins = Users.find(:all).map{|user|user.login} lo...
<p>You can abuse Ruby's built in regular expression character classes for this</p> <p>[:print:] contains all ASCII printable characters. It doesn't contain ASCII characters like beeps or, importantly, multibyte characters.</p> <p>Working on the assumption that your users are unlikely to have ASCII BEEP as a characte...
How is MapReduce a good method to analyse http server logs? <p>I've been looking at MapReduce for a while, and it seems to be a very good way to implement fault-tolerant distributed computing. I read a lot of papers and articles on that topic, installed Hadoop on an array of virtual machines, and did some very interest...
<p><strong>Can the MapReduce concept really be applied to weblogs analysis ?</strong></p> <p>Yes. </p> <p>You can split your hudge logfile into chunks of say 10,000 or 1,000,000 lines (whatever is a good chunk for your type of logfile - for apache logfiles I'd go for a larger number), feed them to some mappers that w...
GLatLngBounds - wrong center and zoom level <p>I'm trying to use GLatLngBounds to make all the markers on the map visible. Below is a small example of what I'm doing.</p> <pre><code>INV.createMap = function(containerId) { var map = null; var geocoder = null; var bounds = new GLatLngBounds(); if (GBrow...
<p>The last argument of the function call below specifies the zoom level:</p> <pre><code>map.setCenter(new GLatLng(54.729378425601766, 25.279541015625), 15); </code></pre> <p><a href="http://www.codeproject.com/KB/scrapbook/googlemap.aspx" rel="nofollow">This article</a> talks a bit about zooming. So the zooming leve...
Dataset Acceptchanges in SQL Server <p>I am loading my ADO.net dataset in by select query in command object. If I clear the dataset data with Acceptchanges will it delete the data in the sql server.</p> <p>If not Please let me Know how to do?</p>
<p>No, it will not.</p> <p>You will have to make sure that each DataRow in your DataTable is marked as 'Deleted'. That is, the rowstate of each row will have to be set to Deleted. You can do that by traversing all rows, and call the Delete method for each Row.</p> <p>Then, you'll have to call the Update method of th...
Resources.openRawResource() issue Android <p>I have a database file in <code>res/raw/</code> folder. I am calling <code>Resources.openRawResource()</code> with the file name as <code>R.raw.FileName</code> and I get an input stream, but I have an another database file in device, so to copy the contents of that db to th...
<p>Yes, you should be able to use <code>openRawResource</code> to copy a binary across from your raw resource folder to the device.</p> <p>Based on the example code in the API demos (content/ReadAsset), you should be able to use a variation of the following code snippet to read the db file data.</p> <pre><code>InputS...
Encode xml column values as xml in sql server <p>I have a method that is taking vales directly from the database, building a string of xml and then writing the xml to a file.</p> <p>This is fine until I get special characters eg "'", "&lt;", "&amp;" etc.</p> <p>Does anyone know of something in Sql Server that would a...
<p>Use <code>FOR XML</code> clause.</p> <p>It can build <code>XML</code> from multiple values automatically:</p> <pre><code>WITH q AS ( SELECT 'Barnes &amp; Noble' AS shop UNION ALL SELECT 'Marks &amp; Spencer' ) SELECT * FROM q FOR XML AUTO, TYPE --- &lt;q shop="Barnes &amp;am...
How to get a DateDiff-Value in milliseconds in VBA (Excel)? <p>I need to calculate the difference between two timestamps in milliseconds. Unfortunately, the DateDiff-function of VBA does not offer this precision. Are there any workarounds?</p>
<p>You could use the method described <a href="http://www.tek-tips.com/faqs.cfm?fid=2292">here</a> as follows:-</p> <p>Create a new class module called <code>StopWatch</code> Put the following code in the <code>StopWatch</code> class module:</p> <pre><code>Private mlngStart As Long Private Declare Function GetTickCou...
jquery title attribute text pop-up hide <p>I'm currently using the title attribute of my 'a' tag to show and hide images that correspond with this tag.</p> <p>However, when you hover on the 'a' there is the annoying title text that pops up.</p> <p>Can I disable this pop-up text with out completely disabling the title...
<p>You can try using your own custom attributes instead of using the "title" attribute.</p> <pre><code>&lt;a customtagattribute="some value" id="link1" href="#"&gt;Linkety!&lt;/a&gt; </code></pre> <p>EDIT: <a href="http://en.wikipedia.org/wiki/JSON" rel="nofollow" title="JSON">JSON</a> key value pairs can also be use...
SELECT forum topic with most different participants <p>So, i'm building a members rewarding system for my forum and got stuck on this query for selecting "forum topic with most different participants".</p> <p>I already have this query that counts how many posts (replies) each forum topic in last 24 hours has.</p> <pr...
<pre><code>SELECT poster.*, COUNT(DISTINCT odgovori.author) AS different FROM poster JOIN odgovori ON odgovori.na = poster.id_poster GROUP BY poster.id ORDER BY different DESC LIMIT 1 </code></pre>
Simple formula for determining date using week of month? <p>Given a standard piece of scheduling information, such as "the second Tuesday in June 2009" or "the last Friday in July 2009", what's the simplest and most efficient formula to translate that into a date?</p> <p><strong>Inputs:</strong> </p> <ul> <li><code>w...
<p>Something like:</p> <pre><code>static DateTime GetDate(int year, int month, DayOfWeek dayOfWeek, int weekOfMonth) { // TODO: some range checking (&gt;0, for example) DateTime day = new DateTime(year, month, 1); while (day.DayOfWeek != dayOfWeek) day = day.AddDays(1); if (weekOfMonth &gt; 0) ...
Is there any special setting of proxy server for WinInet API? <p>I am using the WinInet API to get to internet files using HTTP. Everything works unless the user goes through a proxy server.</p> <p>I'm using InternetOpen with INTERNET_OPEN_TYPE_PRECONFIG which is supposed to get and use the proxy info from the registr...
<p>That's correct. I just use InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0) and it works. May be it isn't the proxy ?</p>
Runtime-dynamic properties in QPropertyEditor <p>I am using the QPropertyEditor from Qt-Apps.org.</p> <p>is it possible to create a class with exposed Properties where the amount of properties is runtime-dynamic? So for example you have a class which represents a vector of floats with an arbitrary length which is not ...
<p>By using <a href="http://doc.trolltech.com/4.5/qobject.html#setProperty" rel="nofollow">dynamic properties</a> ...</p> <p>In your class u can set at runtime the dynamic properties of that class</p> <pre><code>DynamicPropertiesClassForQPropertyEditor() { QVector&lt;int&gt; properties; ///.... fill in theva...
OO Design Pattern on a Package/Assembly/Namespace level? <p>I was looking at <a href="http://stackoverflow.com/questions/939167/c-circular-reference-and-cannot-see-namespace">this question</a> and I wondered to myself are there any design patterns/rules of thumb that you can use when breaking up your project into packa...
<p>Design patters are best practices concerning the behavior and state of code that you write not so much about the organization of that code. Just think about your types and what they are and what they do, common types will fall into common namespaces.</p>
C# read image object in to web request <p>Hey, I'm currently trying to send an image file to a web server using a web request, a memory stream and an image object.</p> <p>This is my current method for sending the request:</p> <pre><code> public void Send(Image image) { //Assign the request here too, ju...
<p>You should close SW before sending the request.</p> <p>Also, instead of converting the byte array to ASCII and then writing it to a StreamWriter, you should write the byte array directly to the request stream. (And then close the request stream before sending the request)</p>
Java_swt in eclipse <p>Can someone tell me where I can find the executeable "java_swt"?</p> <p>I see multiple sites that say it is embedded in eclipse, and other sites say it is shipped with Mac swt drops. I have the zip file for a mac called "swt-3.5M6-carbon-macosx.zip" and i have the eclipse IDE installed on my tes...
<p>Instead of looking for this java_swt, I instead changed my bash executeable the application bundle launches to references my Jar file directly. The swt jar is in the bundle with my app jar, as well as the jni libraries under a dll folder. folder structure is:</p> <pre> |Contents Info.plist PkgInfo |MacO...
Detect empty buffer on a windows handle without using readfile() <p>I was wondering if there was any function along the lines of IsBufferEmpty() to use on a synchronous handle rather than using ReadFile() and waiting for it to return false. I need something to eliminate the delay that ReadFile() takes to try to read da...
<p>Is this for serial port communication?</p> <p>If so, you can use the <a href="http://msdn.microsoft.com/en-us/library/aa363180%28VS.85%29.aspx" rel="nofollow"><code>ClearCommError()</code></a> function:</p> <pre><code>DWORD com_errors = 0; COMSTAT com_stat; ClearCommError(serial_port_handle, &amp;com_errors, &amp...
PostSharp - automate event subscription and collection addition <p>A repeating routine task that I would like to solve using PostSharp is event subscription and collection addition. I would like to subscribe parent's object procedure to each child object's event (children are conatained in a List). I would also like to...
<p>I would use the following pattern:</p> <ol> <li><p>Use a custom collection (for instance inherit from Collection). Override InsertItem and subscribe to child events from there. The constructor of the collection takes the parent as a parameter. So no need for PostSharp here.</p></li> <li><p>You can use PostSharp to ...
What is this RenderAction doing, and how? <p>I am reviewing some ASP.NET MVC code developed by a third party and have encountered the following markup in a View:</p> <pre><code>&lt;div class="panel_body"&gt; &lt;% Html.RenderAction(((string[])Model)[0], "Customer"); %&gt; &lt;/div&gt; &lt;!-- Some HTML omitted ...
<p>Because the view is not strongly-typed, <code>Model</code> is of type object. Obviously, they have actually assigned an array of strings to the Model variable and the name of the action to be rendered is the first element of the array. Thus, they cast the Model to a string array and extract the first element.</p> ...
Trim() FormCollection values <p>Hi<br> I'm fooling around with the NerdDinner tutorial Dinner Edit control.<br> I get a FormCollection as one of the arguments, can I trim the data in it before I use UpdateModel().</p> <pre><code> [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, FormCollection form...
<p>Instead of using the raw form values, you could use a model binder to bind to a custom object.</p> <p>You can create your own model binder by implementing the IModelBinder interface. In IModelBinder.BindModel method you could trim or do any other string manipulation you want. </p> <p>Once this is done, your actio...
How do I use a transaction in LINQ to SQL using stored procedures? <p>I have a piece of code that looks something like this (ClearImportTable and InsertPage are stored procedures):</p> <pre><code>datacontext.ClearImportTable() //Essentially a DELETE FROM table for (int i = 1; i &lt; MAX_PAGES; ++i){ datacontext.In...
<p>You can do a transaction scope:</p> <pre><code> using (var transaction = new TransactionScope()) { // do stuff here... transaction.Complete(); } </code></pre> <p>If an exception occurs or the using block is left without hitting the transaction.Complete() then everything performed within the using block...
Have You Started Using C++0x? <p>Most of the compilers <a href="http://stackoverflow.com/questions/657511/c-compiler-that-supports-c0x-features">already support C++0x</a>. Have you started using C++0x or are you waiting for the definition of x? I have to do some refactoring of my code; should I start using the new feat...
<p>C++0x is not a completed standard yet. It's likely that there will be many revisions before an international accepted standard is released. So it all depends, what are you writing code for? If it's for an work-assignment i would stick with regular C++, wait for the standard to be set and give the programming communi...
setInterval/setTimeout return value <p>Two questions:</p> <ol> <li><p>How is the value returned from <code>setInterval</code> and <code>setTimeout</code> (the ones used to clear the timers) calculated?</p></li> <li><p>Is it possible for both the functions to return the same value during runtime? For example:</p> <p><...
<p><a href="http://msdn.microsoft.com/en-us/library/ms536749%28VS.85%29.aspx">Returns a value which can be used to cancel the timer.</a> So, it would seem unlikely that they return the same value (unless they are reusing values and one of the timers has already been cancelled)</p> <p><a href="https://developer.mozilla...
Using prevent default to take over spacebar <p>I have some code like this to take over the space bar's function:</p> <pre><code> $(document).keypress(function (e) { e.preventDefault(); if (e.which == 32) { // func } }); </code></pre> <p>Unfortunately this destroys all key's defaults.</p> <p>This...
<p>Try this:</p> <pre><code>//e= e || window.event); you may need this statement to make sure IE doesn't keep the orginal event in motion var code; if (e.keyCode) { code = e.keyCode; } else if (e.which) { code = e.which; } if (code == 32) { if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } ...
WPF Databinding based on conditions <p><strong>Goal</strong> Develop a custom control which displays summary data for a specified week.</p> <p>The data passed in would be as follows:</p> <pre><code>3rd May 2009 Customer A $2000 4th May 2009 Customer A $3900 6th May 2009 Customer B $1...
<p>If I understand you correctly, you want to display some tabular data in a list format. Is this correct?</p> <p>What do you know about the data input? Is it guaranteed to implement an interface, or inherit from a base class? If the later, then I think that data templates are the way to go - create a data template fo...
page load() or page init() <p>In asp.net, when do you bind your gridviews? at Page Load() or Page Init()....why?</p>
<p>You should generally bind at or after Load(). The Init() event is intended to allow you to create any dynamically created controls before binding occurrs, so that they exist when binding needs to take place. Load() is not the only option, however...if you need to delay binding on a control for whatever reason, you c...
How can I insert a time string into a GDB log? <p>I recently discovered that you can set breakpoints in Xcode that will print to the console and auto-continue -- meaning you can insert log statements without having to write NSLog() calls and recompile (on-the-fly logging, woot).</p> <p>Only problem is that it seems to...
<p>Read the <a href="http://sourceware.org/gdb/current/onlinedocs/gdb%5F6.html#SEC40" rel="nofollow">GDB manual about Breakpoint Command Lists</a></p> <blockquote> <p>You can give any breakpoint (or watchpoint or catchpoint) a series of commands to execute when your program stops due to that breakpoint. For example,...
Computing average values over sections of date/time <p><strong>Problem:</strong></p> <p>I have a database of sensor readings with a timestamp for the time the sensor was read. Basically it looks like this:</p> <pre><code>Sensor | Timestamp | Value </code></pre> <p>Now I want to make a graph out of this data and I wa...
<pre><code>SELECT DAY(Timestamp), HOUR(Timestamp), MINUTE(Timestamp), AVG(value) FROM mytable GROUP BY DAY(Timestamp), HOUR(Timestamp), MINUTE(Timestamp) WITH ROLLUP </code></pre> <p><code>WITH ROLLUP</code> clause here produces extra rows with averages for each <code>HOUR</code> and <code>DAY</code>, like...
How to use MacOS Shark to profile my application? <p>I have a XCode project. I can build and debug with it. Is it possible for me to use Shark to do profiling of my application (e.g. find out what % of the time spent on what method? How many objects are created and destroyed? Where does each object created?</p> <p>Th...
<p>Yes, you can run Shark on your application to get time profile information; see for example <a href="http://developer.apple.com/tools/shark%5Foptimize.html" rel="nofollow">this Apple tutorial</a>. dtrace is another option; but has a steeper learning curve.</p> <p>For more general profiling, like object allocation,...
keypress event in jQuery <p>I have a page with two button. When I press '5' I want that button1 to be clicked and on pressing '6' Button 2 to be clicked. Is it possible using jQuery?</p> <p>Can I also handle Ctrl+5 in jQuery?</p>
<p>I recommend binding to the <a href="http://docs.jquery.com/Events/keyup" rel="nofollow">keyup event</a> to prevent event duplicate firings. Here's some sample assuming buttons with Ids, button1 and button2.</p> <pre><code>$(function() { $(document).keyup(function(e) { if(e.keyCode == 53 || e.keyCode == 1...
Which of these select statements is "better," and why? <p>I have 2 table person and role. I have to all the persons based on role.</p> <pre><code>select person.* from person inner join role on person.roleid = role.id Where role.id = @Roleid </code></pre> <p>or</p> <pre><code>select person.* from person inner join ro...
<p>The first is better because it's logically coherent. The scoping condition isn't relevant to the join, so making it a part of the join is a kludge, and in this case an unhelpful one.</p>
ColdFusion 8 as WAR on JBoss 4.2.3 WEB-INF/flex-config.xml error <p>I have done this by the book multiple times and have also tried using someone else's WAR to deploy, but I keep getting the same error. I am running JBoss 4.2.3 and have tried this on multiple installations (of 4.2.3)</p> <p>I have verified that the su...
<p>I found a solution. It's insane, but it's worked twice now (on OS X, at least).</p> <p>copy the WEB-INF directory to your file system root.</p> <p>Ex: cp -R ./cfusion.war/WEB-INF /</p> <p>start the instance. Everything works.</p> <p>Delete the newly copied file system root /WEB-INF folder.</p> <p>From now on...
Out of Memory allocLargeObjectOrArray from ResultSet <p>I'm using JDBC to get a large amount of data. The call completes successfully, but when <code>resultSet.next()</code> is called, I get the following error:</p> <pre><code>java.lang.OutOfMemoryError: allocLargeObjectOrArray - Object size: 15414016, Num elements: 7...
<p>Beware that until the first resultSet.next() call the results may not yet be read from the database or still be in another caching structure somewhere.</p> <p>You should try limit your Select to return a sane amount of results and maybe repeat the call until there are no more results left if you need all the data.<...
Recursion algorithms: suggested patterns and practices? <p>I am writing a utility that reflects on two object graphs and returns a value to indicate whether the graphs are identical or not. It got me thinking, is there a generally accepted pattern for writing a recursion algorithm that returns a value from some where i...
<p>I don't see any benefits of your version when compared to this highly trivial version:</p> <pre><code>public static bool IsChanged(T current, T previous) { //perform recursion if (graphIsChanged) return true; else return IsChanged(current, previous); } </code></pre> <p>As an added benefit...
Is there a quick way in javascript to determine if an ancestor node is positioned absolutely without walking up the entire tree? <p>I need to determine if an HTML element is nested inside an element that is positioned absolutely. (1)*</p> <p>e.g. I can do this:</p> <pre><code>function hasAbsoluteAncestor(obj){ whil...
<p>"Seems" fairly expensive? This sounds an awful lot like premature optimization to me.</p> <p>Do you know it's expensive? Have you tested it?</p> <p>I'm actually willing to bet that it's not terribly expensive. Even on really complex HTML pages with really deep nodes, what are we talking about here - 30 iteratio...
How to run JavaScript on the server <p>I'm writing an iPhone app that needs to interact with the Google Maps API, therefore I must user JavaScript (please correct me if I'm wrong) to access the results and the route created.</p> <p>Since the JavaScript support in native iPhone apps is quite poor and slow, my idea was ...
<p>Besides server-side Javascript, you could access Google Maps API from wrappers in other languages; for example, <a href="http://code.google.com/p/pymaps/" rel="nofollow">here</a> is an open-source project that wraps the API for Python (it does so by generating and wrapping the needed Javascript) -- that may or may n...
Copy Data from a table in one Database to another separate database <p>Basically I have a two databases on SQL Server 2005.</p> <p>I want to take the table data from one database and copy it to another database's table.</p> <p>I tried this:</p> <pre><code>SELECT * INTO dbo.DB1.TempTable FROM dbo.DB2.TempTable </code...
<p>SELECT ... INTO creates a new table. You'll need to use INSERT. Also, you have the database and owner names reversed.</p> <pre><code>INSERT INTO DB1.dbo.TempTable SELECT * FROM DB2.dbo.TempTable </code></pre>
Send parameter to addhandler? <p>I have a button in a grid that I created programmatically. The button edits some data in a table using data in a hidden column of the grid that the button is in. Normally I send a hidden field the row data using javascript onclientclick of the button then make the changes to the databas...
<p>By convention, all event handlers accept two parameters: the sender, and the EventArgs. If you need to send custom information to the listeners, create a new class that inherits from EventArgs and contains the information that you need to communicate.</p> <p>Check out <a href="http://www.codeproject.com/KB/vb/StepB...
Apache URL Rewriting, <p>I am trying to get URL rewriting to work on my website. Here is the contents of my .htaccess:</p> <pre><code>RewriteEngine On RewriteRule ^blog/?$ index.php?page=blog [L] RewriteRule ^about/?$ index.php?page=about [L] RewriteRule ^portfolio/?$ index.php?page=portfolio [L] #RewriteRule ^.*$ ind...
<p>Yes, the Last flag means it won't apply any of the rules following this rule <em>in this request</em>.</p> <p>After rewriting the URL, it makes an internal request using the new rewritten URL which would match your last <code>RewriteRule</code> and thus your redirects go into an infinite loop.</p> <p>Use the <a hr...
Team Foundation Server 2005 and SQL Express 2005 <p>I haven't seen anything that says SQL Express 2005 is not supported for use with Team Foundation Server 2005. </p> <p>However, when I attempt the installation I get all sorts of errors "SQL Agent service not installed", "SQL Server 2005 Analysis Services service is ...
<p>Yes, SQL Server Standard or higher is required for current versions of TFS. When you purchase a full copy of Team Foundation Server it comes with a restricted use SQL Standard Edition license under the following terms: </p> <ul> <li>You may only use the SQL Server software with Visual Studio Team Foundation Server...
Can comments appear before the DOCTYPE declaration? <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/69828/does-the-doctype-declaration-have-to-be-the-first-tag-in-an-html-document">Does the DOCTYPE declaration have to be the first tag in an HTML document?</a> </...
<p>It is <strong>fully valid</strong> to do</p> <pre><code>&lt;!-- this, --&gt; &lt;!DOCTYPE html&gt; </code></pre> <p><strong>However,</strong> it brings <strong>all</strong> versions of IE into <strong>quirks-mode</strong> (unless it is <em>forced</em> into no-quirks mode — see the <strong>Gotchas</strong> secti...
Trigger an event on a specific part of an image <p>I want to trigger an event handler when the user hovers on a particular part of the image, like the center of the image or the right side of the image (area would include, say, about a 100 pixels). I am not using any framework, so this is normal javascript that I am wo...
<p><a href="http://www.quirksmode.org/js/events%5Fproperties.html#position" rel="nofollow">Quirksmode about mouse position</a></p> <p>Given the craziness involved here I would:</p> <ol> <li>Use a framework (I just did something like this with Mootools)</li> <li>Put absolutely positioned divs over the image and listen...
Possible to get Excanvas to work in IE 8? <p>I used to work on a jQuery plugin named 'BeautyTips' and it was working just fine. But, since I've installed IE 8, this plugin stop working because it needs Excanvas to make IE draw the vectors, images etc.</p> <p>I've tried to download the newer version of Excanvas but it'...
<p>The new 'standards' mode of IE8 turns off some nonstandard features. Among them VML, which is used by excanvas. I just set for IE7 'standards' mode, so it still works.</p> <pre><code>&lt;meta http-equiv="X-UA-Compatible" content="IE=7" /&gt; </code></pre> <p>Frustrating, but i don't know of any advantage brought...
Two different HTTPService classes in Flex <p>Why are there two different HTTPService classes in Flex? <a href="http://livedocs.adobe.com/flex/2/langref/mx/rpc/http/HTTPService.html">this</a> and <a href="http://livedocs.adobe.com/flex/2/langref/mx/rpc/http/mxml/HTTPService.html">this</a></p> <p>And the second one inhe...
<p>One of the objects (the first link you posted) is the HTTPService Object itself.</p> <p>The second is the object that wraps the HTTPService object and gives it the additional functionality for the &lt;mxml /&gt; tag.</p> <p>The two probably weren't combined because you don't necessarily need the implementation of ...
Validating a slug in Django <p>I'm guessing this is going to involve regexp or something, but I'll give it a shot. At the minute, a user can break a website by typing something similar to <code>£$(*£$(£@$&amp;£($</code> in the title field, which is converted into a slug using Django <code>slugify</code>.</p> <p>B...
<p>SLUG_REGEX = re.compile('^[-\w]+$')</p>
Why does my Perl script delete the contents of whole file when I try to edit the file? <p>I am running the following code to open a file (test) and edit(search and replace) it. Program seems to open the file but instead of replacing it deletes everything in the file. I am not sure why that is happening. Can anyone help...
<p><code>open(FILE, "&gt;filename")</code> opens the file in replace mode, writing over whatever there was previously.</p> <p>Also, you cannot have a regexp in the substitution pattern <code>$replace</code>.</p> <p>If I understood your intent correctly, this could be replaced with an one-liner</p> <pre><code>perl -p...
Viewbox behavior that I cannot understand <p>I have a DataTemplate that's used as a logo to describe a Version object. The logo is simply an image and some text on top of it.</p> <p>I have to use the DataTemplate in 2 places: - As the Content of a Button - As a thumbnail item of a ListBox</p> <p>The thing is, the log...
<p>Alright, here is how the problem was solved:</p> <ol> <li>Remove Width=175 in DataTemplate's Grid</li> <li>Adjust the font sizes again</li> </ol> <p>My font sizes were adjusted for a crate image of 175x175. The crate image is 256x256. If you don't specify Width=175 in the Grid element, it seems the ViewBox will co...
KDE development debugging <p>In a kde3 game called ksirtet (a tetris clone) when playing against a computer the human player cannot move the tetris piece left/right. I'm trying to fix it but cannot debug in gdb. After the line "kapp->exec()" gdb stops responding, the game runs and I cannot input any command do gdb to s...
<p>Generally speaking, you wouldn't want to debug into the event loop unless necessary. That said, you probably want to scatter a sprinkling of breakpoints at places of interest, especially where you think the code should be running after the key press. If you try to step through the event loop code from the beginnin...
c# p/invoke difficulties marshalling pointers <p>I am attempting to call into a native .dll from c# using p/invoke. I'm able to make the call (no crash, the function returns a value), but the return code indicates "A pointer parameter does not point to accessible memory." I've resorted to trial and error in order to ...
<p>You have two obvious errors here. In your struct definition you should be using byte[] instead of char[] for szDescription and szSystemStatus. </p> <p>Also the last parameter in your pInvoke call is not a pointer. When you make your call to MyFunction hService is zero and therefore an invalid pointer as far as the ...
wxPython won't close Frame with a parent who is a window handle <p>I have a program in Python that gets a window handle via COM from another program (think of the Python program as an addin) I set this window to be the main Python frame's parent so that if the other program minimizes, the python frame will too. The pr...
<p>I wonder if your <code>Close</code> call may be hanging in the close-handler. Have you tried calling <code>Destroy</code> instead? If that doesn't help, then the only solution would seem to be "reparenting" or "detaching" your frame -- I don't see a way to do that in <code>wx</code>, but maybe you could drop down t...
naming conventions when doing O/R mapping <p>I am mapping my database tables to my java objects. Generally I name my tables in the plural form in that a table holding books information is called BOOKS. The java object represents however one book and should be called Book. Similarly for AUTHORS/Author etc. </p> <p>On t...
<p>Your initial thoughts are spot on.</p> <p>Objects should be singular, as each object is individual.</p> <p>Tables should be plural, as the table contains all.</p> <p>Check out the naming conventions built into Ruby on Rails, they're relevant. </p>
is a database intermediary good system design? <p>background: we've got a number of server processes and client apps that are used entirely internally, in a fairly controlled environment. we capture a significant amount of data every day that goes into a couple database machines. most everything is c#, with a few c++ a...
<p>It depends on what you're trying to accomplish with it. According to <a href="http://www.lhotka.net/WeBlog/PermaLink.aspx?guid=efa88d0a-2388-4909-bee1-c9bddb6e9868" rel="nofollow">Rocky Lhotka</a>, you should only add a tier if you are forced to, kicking and screaming all the way. </p> <p>I agree with him: don't ti...
disable the validation for an specific button when using jQuery plugin: Validation <p>I'm using <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" rel="nofollow">jquery validation</a> with asp.net. The problem is, I have the search button and the comments button in the same form. When the users wa...
<p>Move the validation to the click event of the button and use <a href="http://docs.jquery.com/Events/jQuery.Event#event.preventDefault.28.29" rel="nofollow">preventDefault</a>() if it fails validation.</p> <pre><code>$("#yourButtonId").click( function(event){ if (formIsInvalidForSubmission) event.preventDefau...
How is the iPhone SMS compose view implemented? <p>Regarding the SMS compose view as show in the picture below: <img src="http://www.kennethlund.dk/wordpress/wp-content/uploads/2008/08/iphone%5Fsms.jpg" alt="alt text" /></p> <p>I have two questions:</p> <p>1) How is the text entry box implemented? There are no standa...
<p>Searching stackoverflow for "uitextView size" produces these results:</p> <p><a href="http://stackoverflow.com/questions/50467/how-do-i-size-a-uitextview-to-its-content">http://stackoverflow.com/questions/50467/how-do-i-size-a-uitextview-to-its-content</a></p> <p><a href="http://stackoverflow.com/questions/728704/...
Is it possible to compile assembly code in MSVC++? <p>Is it possible to create, edit, link, compile (is compile the word?) etc. assembly code in MSVC++?</p> <p>Also, if it's not possible, how can I create an .exe out of plain text, ie: convert the text into whatever format is required to use assembly code, then turn t...
<p>On x86, yes. You can use the <a href="http://msdn.microsoft.com/en-us/library/45yd4tzz%28VS.80,printer%29.aspx" rel="nofollow">__asm</a> keyword to put assembly inline in your standard source files, and use the normal MS compile/link tools to compile everything together.</p> <p>On x64 (or x86), you may need to use...
Creating and executing a Merge Replication programatically <p>Let me preface this by saying I now realize how stupid I am and was. I have been developing for 1 year (to the day) and this was the first thing I wrote. I now have come back to it and I can't make heads or tails of it. It worked at one point on a very s...
<p>All the compiler is telling you is that the Server and ReplicationDatabase are output parameters and yet you are not assigning anything to them before returning from the LocalDBConn method.</p> <p>When using out parameters you should perform a null check on them to ensure they have been initialized outside the meth...
Need help with greedy quantifier <p>I'm doing a simple search-and-replace in Perl, but I need some help. These are lines in a file: </p> <pre><code>1001(seperator could be "anything")john-1001(seperator could be "anything")mark 1001(seperator could be "anything")mark-1001(seperator could be "anything")john </code></...
<p>It's almost impossible to answer this without having some idea of what the separator can be -- which characters, how many characters, etc. A non-greedy arbitrary separator would look like this:</p> <pre><code>s/\b1001\b(?=.*?\bjohn\b)/2001/ </code></pre> <p>This replaces "1001" when followed by "john" while matchi...
Breaking up SQL script <p>I am writing a rather long SQL script that is running close to 2000 lines of code. Since it becomes really difficult to comprehend a long script, I would like to break it up into logical units and separate them out in other SQL files.</p> <p>What would be the best way of doing this? Would eac...
<p>Take advantage of stored procedures and functions. If you're doing pure SQL, there's no better place for the logical units of your code. Also, it makes it much easier to maintain/edit your code.</p> <p>That being said, if your script is that long, you may want to take a look at what you're doing, and think about an...
Why isn’t ObjectDataSource’s matching algorithm as flexible as…? <p><br></p> <p>Even though <em>UpdateNames</em> stored procedure only takes one parameter named <em>@First</em>, we are still able to define additional parameter named <em>Last</em>, and the update will still be successful:</p> <pre><code> &lt;...
<p>The ObjectDataSource trades one kind of flexibility for another.</p> <p>You are correct that your function's parameters much match the listed parameters exactly, but it is for a good reason.</p> <p>The ObjectDataSource lets you define multiple functions to handle different parameters, so if you want to support a U...
.NET for a legacy VC++ 6.0 developer <p>What are some of the best books/approaches to learn .NET for a legacy VC++ 6.0 developer? I am hesitant to learn a new language like C# or VB.NET for various reasons. I am experienced in C++/Win32 programming. I am more inclined towards learning C++/CLI to get hands on .NET devel...
<p>If you want to use .NET with your programs, you're probably better off learning C# instead. Through macros and custom operator definitions, C++/CLI really is an entirely new language.</p> <p>C++/CLI is best for native-library interop scenarios that are too complex for C#/pinvoke to handle.</p> <p>Some interesting ...
How do I put data in a Masterpage? <p>How do you put a strongly typed object in ASP.NET MVC into the master page? </p> <p>Do you have a <code>ViewModelBase</code> class that contains master page information and inherit from it for every view model, or is there a better approach?</p>
<p>Alex,</p> <p>I think what you are asking is, "Where is my master page controller?"</p> <p>Have a look at the following link. It explains how to create an "Application Controller," an abstract class that can be inherited by your other controllers, so that you only have to write the code once that pushes your neede...
How do I Extract the First character of a symbol in scheme? <p>I want it to extract all the words that have a letter e in them. eg. </p> <pre><code>(ewords '(i e ee o oo)) -&gt; '(e ee) </code></pre> <p>Berkeley's 61a lecture uses (first 'word) to extract the first character of the word. However DrScheme screams at m...
<p>You'll need to convert it to a string explicitly:</p> <pre><code>(first (symbol-&gt;string 'word)) -&gt; "w" </code></pre> <p>(I'm not sure off the top of my head whether <code>first</code> operates on strings. You can use <code>string-&gt;list</code> to convert to a list and then take the <code>first</code> if i...
Translating 32-bit paths to their WOW64 equivalents <p>Is there any function that I can call to in a 32-bit app that would convert the paths that it thinks it's using to and from the paths that it's actually using? (For instance, call it to convert the path for a folder in Program Files to a path in Program Files (x86)...
<p>Is browsing through Program Files and Windows\System32 a use-case for your app? I encourage you to abandon solving this problem, as it gets <em>really</em> ugly. Either stay all in the 32-bit world, or recompile for x64. Living in the "in-between" world of WOW64 will make your code much more complex.</p> <p>If you ...
Extract Unique Pairs from Table Containing Reciprocal Relationships <p>Consider a <strong><em>SQL Server 2005</em></strong> database with a bunch of data on a lot of people, a large chunk of whom are <em>married</em>. To track relationships among people, a <strong>Relationship</strong> table exists that serves to link ...
<p>Since you've encapsulated GetOrderPair, I have no idea the logic behind it, but I'll at least give you what I do:</p> <pre><code>select distinct case when Person1 &gt; Person2 then Person2 else Person1 end as Person1, case when Person1 &gt; Person2 then Person1 else Person2 end as Person2 from couples w...
c++ functor and function templates <p>consider this simple and pointless code.</p> <pre><code>#include &lt;iostream&gt; struct A { template&lt;int N&gt; void test() { std::cout &lt;&lt; N &lt;&lt; std::endl; } }; int main() { A a; a.test&lt;1&gt;(); } </code></pre> <p>It is a very simple ex...
<p>You can only call</p> <pre><code>a.operator()&lt;1&gt;(); </code></pre> <p>but that would not be using a functor. Functors need a non template operator(), as they must be able to be called as <em>varname()</em> and that won't work with your code. </p> <p>To make it a real functor change your code a template class...
OnValidate() and LINQ to Entities <p>I would like to implement some business rule validation like Scott Guthrie did in his MVC Nerddinner tutorial (<a href="http://nerddinnerbook.s3.amazonaws.com/Part3.htm" rel="nofollow">http://nerddinnerbook.s3.amazonaws.com/Part3.htm</a>), but I'm running into a problem trying to do...
<p>You can do data validation in linq-to-entities, but it is different from linq-to-sql, as you've discovered. See the following link:</p> <p><a href="https://cuttingedge.it/blogs/steven/pivot/entry.php?id=46" rel="nofollow">data validation in linq-to-entities</a></p>
VBScript SQL sanitization <p>Wary of Jeff Atwood's "<a href="http://www.codinghorror.com/blog/archives/001268.html" rel="nofollow">Bathroom Wall of Code</a>" post, I thought it would be useful to have a trustworthy SQL sanitisation function for VBScript, similar to PHP's <code>mysql_real_escape_string()</code> function...
<p>Don't do it. Use parameterized queries instead.</p>
Related posts from the blogosphere - dynamic integration of Google Blogsearch RSS on wordpress category pages <p>OK, I'm looking for a method to put the three latest "news" from Google Blogsearch/Twitter search feeds into the bottom of category Pages. Maybe like this (assuming we're on the archive page for the "Sports"...
<p>You've got a couple of issues in that code. The first is you have a <code>&lt;?php</code> inside an already opened <code>&lt;?php</code> section. Concatenation is the answer to that problem.</p> <p>The second is the function <code>single_cat_title()</code> <strong>displays</strong> the category title by default. Me...
Is there a way to hide the tab bar of JTabbedPane if only one tab exists? <p>I want a behavior similar to e.g. Firefox where the list of available tabs does only show up if at least two tabs exist.</p> <p>I wasn't able to find anything like that, yet.</p> <p>The best idea I had was changing the layout manually:</p> ...
<p>You can override the UI method that calculates the height for the tab button area, forcing the height to <code>0</code> when there's only one tab:</p> <pre><code>tabbed_pane.setUI(new BasicTabbedPaneUI() { @Override protected int calculateTabAreaHeight(int tab_placement, int run_count, int max_tab_heigh...
How to Bitwise compare a String <p>I am working on a function that takes in a series of permission strings, less than 255 characters and assigns them to an entity. Each string assigned is unique, but there are so many that dropping them into an array, serializing them and pushing into a database and pulling them out l...
<p>The essential thought here is this:</p> <blockquote> <p>The other option would be just auto-number the permission strings and have their mask be 2^auto-number. But that would limit the number of permission strings to around 64ish.</p> </blockquote> <p>If your permission strings are truly independent of one anoth...
How do I Apply an Anonymous Function from a List in Scheme? <p>I am learning Scheme. What is wrong with the code below?I want to write a program that takes the first function from the list and then applies that to a number?</p> <pre><code> (define num 3) ;;I want to do something like this which returns 3 ...
<p>You're quoting, with ' the lambda, so it isn't being evaluated.</p> <p>If you just feed in (λ (x) x) at the prompt, DrScheme shows you <code>#&lt;procedure&gt;</code>, which means it has actually evaluated the lambda, and given you back a closure. By quoting it, you're giving Scheme just a list of symbols.</p> <p...
Missing 'Median' Aggregate Function in Django? <p>The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (<a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#id8">link text</a>). Is there a reason Median is missing from the list? </p> <p>Implement...
<p>Because median isn't a SQL aggregate. See, for example, the <a href="http://www.postgresql.org/docs/8.3/static/functions-aggregate.html">list of PostgreSQL aggregate functions</a> and <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html">the list of MySQL aggregate functions</a>.</p>
looking for suggesions re: accessing data and populating List/arraylist/list <p>I am looking to do something like this:</p> <ol> <li>access records in db with a datareader. I won't know how many records will come back - somewhere between 1 and 300 most of the time. The data will look something like this "0023","Eric",...
<p>The standard answer here, short of using a persistence layer like the Entity Framework, is to create "entity" classes with the fields you need. Something like:</p> <pre><code>class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } </code...
How to Change Mouse Cursor in PythonCard <p>How do I change the mouse cursor to indicate a waiting state using Python and PythonCard? </p> <p>I didn't see anything in the documentation.</p>
<p>PythonCard builds on top of wx, so if you import wx you should be able to build a suitable cursor (e.g. with <code>wx.CursorFromImage</code>), set it (e.g. with <code>wx.BeginBusyCursor</code>) when your wait begins, and end it (with <code>wx.EndBusyCursor</code>) when your wait ends.</p>
SSLStream.BeginRead and IOCP <p>Just like socket Begin\End methods use IOCP, would that also be true for SSLStream Begin\End Read\Write methods</p> <p>if not how do you get a tcp\ip server on SSL to scale thanks </p>
<p>Since the <code>SslStream</code> presumably is wrapped around a regular <code>SocketStream</code> I would say this is highly likely, because at some point the async <code>SslStream</code> is going to have to perform a read on the underlying stream. It is only logical that it would implement this in terms of an async...
php mysql fulltext search: lucene, sphinx, or? <p>This is admittedly <em>similar</em> to (but not a duplicate of) <a href="http://stackoverflow.com/questions/737275/pros-cons-of-full-text-search-engine-lucene-sphinx-postgresql-full-text-search">http://stackoverflow.com/questions/737275/pros-cons-of-full-text-search-eng...
<p>One advantage of Sphinx is that you can "interpose" it between your clients and the MySQL server, and it will only "interfere" on queries specifically addressing it, transparently bouncing the others off MySQL -- see e.g <a href="http://www.mysqlperformanceblog.com/2009/04/19/talking-mysql-to-sphinx/" rel="nofollow"...
Problem validating filetypes in an ASP.NET FileUpload control with RegularExpressionValidator <p>code:</p> <pre><code>&lt;span&gt;Upload Adobe Acrobat file&lt;img src="../../Images/UI/pdf.jpg" style="height: 25; width: 20" height="25" width="20" /&gt;&lt;/span&gt; &lt;asp:FileUpload ID="uplPdf" runat="server" /&gt...
<p>Try this in your RegularExpressionValidator</p> <pre><code>&lt;asp:RegularExpressionValidator ID="valPdf" runat="server" ErrorMessage="Only PDF files are allowed!" ValidationExpression=".+.(P|p)(D|d)(F|f)$" Display="Dynamic" ControlToValidate="uplPdf" ValidationGroup="upload" /&gt; </code></pre> <p>Then ...
Variable optimized away by compiler <p>I started debugging some code attempting to find my mistake. When I attempt to <code>p tlEntries</code> from the debugger I get the</p> <p><code>&lt;variable optimized away by compiler&gt;</code></p> <p>message while stopped on the <code>if</code> statement. The following is my...
<p>The proper solution is to declare the variable in a different way as follows:</p> <pre><code>volatile NSArray *tlEntries; </code></pre> <p>Indeed, the volatile keyword is used exactly to inform the compiler that it must not try to optimize the code related to that variable in any way. Kind regards.</p>
Dual-queue producer-consumer in .NET (forcing member variable flush) <p>I have a thread which produces data in the form of simple object (record). The thread may produce a thousand records for each one that successfully passes a filter and is actually enqueued. Once the object is enqueued it is read-only. </p> <p>I ha...
<p>Have you tried the obvious: is microcode update applied on the fancy 8-core box(via BIOS update)? Did you run Windows Updates to get the latest processor driver?</p> <p>At the first glance, it looks like you're locking your containers. So I am recommending the systems approach, as it sound like you're not seeing ...
How to check for and remove a photo from an iPhoto album using AppleScript <p>I want to write an AppleScript to import a photo into an album. If a photo with the same file-name already exists in the given album, I want to remove the existing one first, then proceed with the import. I tried:</p> <pre><code>if album "My...
<p>It turns out the answer is really simple:</p> <pre><code>remove (every photo of album "MyAlbum" whose image filename is "pic1.jpg") </code></pre>
MVC ActionLink adds VS solution name to url <p>For some reason when I run my project locally, everything works just fine. When I publish my site live to my shared hosting server, the actionlink causes links to come out as</p> <p>http// www.mydomain.com/MySolutionName/Account.aspx/LogOn</p> <p>when it should be</p> <...
<p>Check whether you published to a virtual directory named MySolutionName under the root of the web site. If you did, then this is expected behavior.</p>
Flash-based file upload (swfupload) fails with Apache/mod-wsgi <p><strong>This question has been retitled/retagged so that others may more easily find the solution to this problem.</strong></p> <p><hr /></p> <p>I am in the process of trying to migrate a project from the Django development server to a Apache/mod-wsgi ...
<p>Normally apache runs as a user "www-data"; and you could have problems if it doesn't have read/write access. However, your setup doesn't seem to use apache to access the '/home/sk/src/sitename/uploads'; my understanding from this config file is unless it hit /static or /media, apache will hand it off WGSI, so it mig...
Django model inheritance w/ custom inclusion_tags <p>I'm gonna try and simplify this as much as possible. Lets say i have the following:</p> <h1>models.py</h1> <pre><code>class Person(models.Model): name = models.CharField(max_length=255) def getRealPerson(self): # is there a better way to do this? ...
<p>See <a href="http://stackoverflow.com/questions/929029/how-do-i-access-the-child-classes-of-an-object-in-django-without-knowing-the-name/929982#929982">this answer</a> for an efficient way to get the right person type sub-object after querying on the Person table.</p> <p>Once you have that working, you should be ab...
Eclipse 3.5: How to get file name from Editor? <p>Can anyone tell me how to get file name from editor?</p> <p>I just made my own editor to open xml file and create a few section to display the data. Now I want to read the XML file and place it inside the section.</p> <p>I think I now how to read xml data but I don't ...
<p>I realise this is old, but since I stumbled upon it while searching for a solution to the exact same problem, I want to add a note to the answer by VonC:</p> <pre><code>IFileEditorInput </code></pre> <p>is hidden in the <em>org.eclipse.ui.ide</em> plug-in, so in order for the solution to work your plug-in needs to...
Request in src attribute of <img> tag is not processing <p>Hi All : I have a request which contains parameters and response will give barcode image. We are using Comergent frame work. </p> <pre><code>&lt;img src="../direct/bestbuy?cmd=BBFBGenerateBarCode&amp;type=code128&amp;msg=12345&amp;fmt=JPEG&amp;height=10&amp;hr...
<p>This may seem like an elementary issue, and I apologize if you have already discovered that this isn't the problem, but if you are using the literal path of <code>../direct/bestbuy?cmd=BBFBGenerateBarCode&amp;type=code128&amp;msg=12345&amp;fmt=JPEG&amp;height=10&amp;hrsize=5pt</code> in your email, you will never ge...
How do you split source code in C into separate files? <p>I'm trying to read other peoples code but most code is broken up into separate files. I haven't learned how to do that yet. How do you split up code into separate files? And how do you find the right source code file for a function?</p>
<p>The key technique is using "header files", aka <code>.h</code> files, to expose the "should be visible from the outside" parts of each "source file", aka <code>.c</code> file. For finding sources across many files, see <a href="http://ctags.sourceforge.net/" rel="nofollow">ctags</a>, unless the IDE you're using supp...
Auto click a hyperlink <p>How do I automatically click a Hyerlink or LinkButton using jQuery</p> <pre><code>&lt;asp:Hyperlink id="ttt" PostBackUrl="Hut.htm"&gt;Click&lt;/asp:Hyperlink&gt;or&lt;asp:LinkButton id="ttt" PostBackUrl="Hut.htm"&gt;Click&lt;/asp:LinkButton&gt; </code></pre>
<p>You can use the <a href="http://docs.jquery.com/Events/click" rel="nofollow">jQuery click()</a> function without any arguments to simulate a users click.</p> <p>The only tricky part with asp.net controls is the ID will be some unwieldy generated ID like ctr_00_0001 so you'll have to use a class to target the button...
SQL Server Linked Server query running out of memory <p>I have a DBF file on a network share that I'm trying to select into a SQL Server table.</p> <p>This query:</p> <pre><code>SELECT * FROM OPENQUERY(MyLinkedServer, 'SELECT * FROM DP') </code></pre> <p>... throws this error:</p> <p>OLE DB provider "MSDASQL" for l...
<p>Linked server queries use memory from an area outside of the SQL Server buffer pool called memToLeave, which is used for servicing connection threads and now the sql clr amongs other things. On 32-bit it's 384 MB in size which can be inadequate for some scenarios.</p> <p>If you need to adjust your SQL Server Memory...
Getting Google Spreadsheets as Excel using C# <p>I presume the following are the steps I should do:</p> <p>A) I need to post the following for login:</p> <p>POST /accounts/ClientLogin HTTP/1.0 Content-type: application/x-www-form-urlencoded</p> <p>accountType=HOSTED_OR_GOOGLE&amp;Email=jondoe@gmail.com&amp;Passwd=no...
<p>Another thing to look at is Fiddler:</p> <p><a href="http://www.fiddler2.com/fiddler2/" rel="nofollow">http://www.fiddler2.com/fiddler2/</a></p> <p>Use it to get an idea of the interactions between your browser and google when you download your spreadsheet 'normally', and then code your application to mimic it.</p...
Difference between static in C and static in C++?? <p>What is the difference between the static keyword in C and C++?</p>
<p>The <code>static</code> keyword serves the same purposes in C and C++.</p> <ol> <li><p>When used at file level (outside of a function), it sets the visibility of the item it's applied to. Static items are not visible outside of their compilation unit (e.g., to the linker). Their duration is the same as the duration...
Single Table Inheritance routing? <p>I have single table inheritance working just fine for my app. I have two user subtypes (Athlete and Company) that inherit the super-type User. </p> <p>Let's say I am listing all users, and want a link to each user's profile from this list. I want to link to the athletes controller ...
<p>you can even do that much simpler, Rails recognizes which type of user it has to deal with, so let's say you have the instance variable @user wich can either be an Athlete or a Company, you can just do that</p> <pre><code>= link_to "Profile", @user </code></pre> <p>BAM! Rails magic!</p>
Can anyone provide a rational explanation as to why a web server must assist in the creation of upload progress bars? <p>I've been putting together a small personal website in rails and have gotten to the point where I need to be able to upload files. This is an almost trivial task and took no time at all.</p> <p>Wha...
<p>The true limitation here are HTML Forms. They were invented over 10 years ago when the upload of larger files seemed completely unfeasible. So they provide you only with one callback: when the entire upload is done (ACTION parameter).</p> <p>Luckily, there are some free flash based uploaders out there that offer pr...
More control on ASP.Net MVC's Authorize; to keep AJAX requests AJAXy <p>I have some action methods behind an Authorize like:</p> <pre><code>[AcceptVerbs(HttpVerbs.Post), Authorize] public ActionResult Create(int siteId, Comment comment) { </code></pre> <p>The problem I have is that I'm sending a request through AJAX ...
<p>Thanks to Lewis comments I was able to reach this solution (which is far from perfect, posted with my own comments, if you have the fixes feel free to edit and remove this phrase), but it works:</p> <pre><code>public class AjaxAuthorizeAttribute : AuthorizeAttribute { override public void OnAuthorization(Author...
What is the technical name of the syntactic feature "long foo = 12L;" style casting of harded-coded values in Java? <p>Today, I was trying to cast a hard-coded value into a short and S did not work. So, I went to search for it, but I realized that I do not even know what this feature of Java's syntax is called. Is ther...
<p>They are called <em>literals</em>.</p> <p>From the <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html" rel="nofollow">Primitive Data Types</a> page of The Java Tutorials:</p> <blockquote> <p>A literal is the source code representation of a fixed value; literals are represented ...
How to make XHTML "table" with fluid table rows <p>Basically i want to be able to make a a grid of boxes, where i can align text at the top middle and bottom of each box, and have the boxes on the same row resize when text in another box on its row pushes it down.</p> <p>If you look at this HTML 4 code, it achieves wh...
<p>There's <a href="http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/" rel="nofollow">a cross-browser way to achieve grid using CSS</a> with <code>display:inline-block</code>, however it may not be as flexible as you'd like (and code is pretty ugly if you want to support Firefox 2).</p> <p>The issu...
Is MVC from Microsoft the new Struts for Dot net? <p>I have not used MVC but am merely wondering as a Java person, hence the q.</p>
<p>I never really worked with Struts, but this wiki might be of use for comparisson:</p> <p><a href="http://en.wikipedia.org/wiki/Comparison%5Fof%5Fweb%5Fapplication%5Fframeworks" rel="nofollow">http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks</a></p>
Comparing entities while unit testing with Hibernate <p>I am running JUnit tests using in memory HSQLDB. Let's say I have a method that inserts some values to the DB and I am checking if the method inserted the values correctly. Note that order of the insertion is not important.</p> <pre><code>@Test public void should...
<p>I found this more practical. Instead of fetching all results at once, I am fetching results according to the criterias and asserting they are not null.</p> <pre><code>public void should_insert_correctly() { Inserter out = new Inserter(session); // out: object under test out.insert(); Criteria criteria;...
Database Design: Defining a relation between entities in database <p>I want to design a database for my application, and I have a question about the way to define a relation between the entities.</p> <p>I have 2 related entities which ID is compound. For example:</p> <ul> <li>an address entity which are identified by...
<p>Whether or not you have <strong>G</strong>UID the second option is easier to code and design. When you select data by joining two tables you'll only need the identifier columns indexed. The other way you need composite indexes for just this join.</p> <p>Having unique primary keys in tables in a enterprise corporate...
How can I check if a file exists using Emacs Lisp? <p>I would like emacs to mark files that are generated as read-only when they're opened. The part of the puzzle that I'm missing is how to check if a file "exists". I currently have the following:</p> <pre><code>;; ;; get file extension ;; (defun get-ext (file-name)...
<p>try <code>file-exists-p</code></p> <p>"Return t if file filename exists (whether or not you can read it.)"</p>
Variables in jsp pages with "included" pages <p>What are the scoping rules for variables in a jsp page with pages added to them using tags?</p> <p>My understanding is that an included page is essentially copied verbatum into the page, which would lead me to assume that if I've declared a variable in a Parent jsp that...
<p>In JSP there are two ways of including other jsp pages.</p> <pre><code>&lt;%@include file="include.jsp"%&gt; </code></pre> <p>and</p> <pre><code>&lt;jsp:include page="include.jsp" /&gt; </code></pre> <p>If you use the former, then any variable declared on the parent JSP will be in scope in the include.jsp (of co...