input
stringlengths
51
42.3k
output
stringlengths
18
55k
how to change javascript function to ActionScript 3? <p>anybody can help me to change that javascript function to AS3?</p> <p>thanks :)</p> <pre><code> function parseURLtoVars(strLocation){ var rArray = new Array(); var key; var urlString = new String(strLocation); if (urlString.search(/\?/)&gt;-1){ v...
<p>this returns params as an object, to return a boolean should be a simple edit.</p> <pre><code>function getParams(documentRoot):Object { try { var params:Object = LoaderInfo(documentRoot.loaderInfo).parameters; var pairs:Object = {}; var key:String; for(key in params) { pairs.key = String(params.key); } ...
Why is git-cvsimport missing one major patchset? <p>This is a followup to <a href="http://stackoverflow.com/questions/683091/how-do-i-debug-git-cvsimport-cant-see-complicated-commit">a previous question of mine</a>.</p> <p>I can look through the output of cvsps (saved in my ~/.cvsps directory) and see a patchset for a...
<p>Well, this may be the problem. My git-cvsimport lines look like this:</p> <pre><code>git cvsimport -p x ... </code></pre> <p>The -p x is is supposed to pass the -x option to cvsps to tell it to ignore the cached output that it left lying around from previous runs. I thought the main reason to do that was so that...
HTML divs popup to select columns <p>I have a web application(ASP.NET2.0 C#) and in it, I have a gridview that gets its data from a datasource.</p> <p>I wanted to add the following feature: the user can click a button "select columns", and a box pops up with a list of all the columns(a checkboxlist in a div, possibly)...
<p>HI, Its better to make the display of div to be none rather than setting visibility to hidden. If visibility is set to hidden even if the div doesn't show up but it will take the rendering space which in some situation might not be that good.</p> <p>You can dynamically create a div using createNode and then by abso...
JMS Topic Creation in JBoss 5 AS <p>In Jboss 4, when I deployed an ear with an MDB for a topic that had not been specified in the deployment descriptors, the server would automatically create the topic (after posting a warning saying that topic didn't exist).</p> <p>In Jboss 5, it doesn't seem to automatically create ...
<p>From the JBoss community forums -- <a href="https://jira.jboss.org/jira/browse/JBAS-6013" rel="nofollow">This JIRA</a> was added in 5AS.</p> <p>Unfortunately it looks like there is no way to implement createDestination globally in the standardjboss.xml descriptor -- You have to add a custom jboss.xml descriptor to ...
Valid email address regular expression? <p>I have done some testing but I wanted to ask if anyone sees a problem with this ruby regular expression for email validation:</p> <pre><code>/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i </code></pre> <p>Look good?</p> <p>Thanks,</p> <p>Tony</p>
<p>You were close, have to add just a few more characters:</p> <pre><code>(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?: \r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031...
Linq query loses order <p>I have a view in my database that produces ordered results, but when I run a Linq query over that view, the results are no longer ordered (at least, according to the foreach I use to iterate over the results, and according to the debugger). Is this a known difficulty with Linq, or am I missin...
<p>Your linq query is:</p> <pre><code>var rootQuery = from ne in siteMapTable where ne.ParentID == null select ne; </code></pre> <p>This will generate sql like so</p> <pre><code>SELECT * FROM SiteMapTable WHERE ParentID == @P1 </code></pre> <p>You can take this sql to the database, r...
Draw Gaussian curve in Java <p>I'm coding an interactive applet with <a href="http://code.google.com/p/piccolo2d/" rel="nofollow">Piccolo</a> and I need to include a Gaussian curve (aka <a href="http://en.wikipedia.org/wiki/Normal%5Fdistribution" rel="nofollow">Normal distribution chart</a>) inside it.</p> <p>I imagin...
<p>Don't know if it works, but Google threw up <a href="http://vase.essex.ac.uk/software/JavaPlot/code/ac/essex/graphing/charts/continuous/Gaussian.java.html" rel="nofollow">this code to plot a Gaussian distribution</a>.</p> <p>The home page for this project is <a href="http://vase.essex.ac.uk/software/JavaPlot/" rel=...
Drupal node?destination not working <p>I've troubles with Drupal 6 and (maybe) mod_rewrite:</p> <p>if I go to <em><a href="http://127.0.0.1/drupal/node/115/edit?destination=admin%2Fcontent%2Fnode" rel="nofollow">http://127.0.0.1/drupal/node/115/edit?destination=admin%2Fcontent%2Fnode</a></em> and then I save the node,...
<p>It does look like a configuration problem, because this normally works. You can debug it by adding some dsm() dumps in <code>includes/common.inc/drupal_goto()</code> : this is where the <code>destination</code> parameter is processed.</p> <p>Note that if some module traps your form submission, for instance by decla...
File and Directory Security with IPrincipal <p>I need to gain access to the files and directories that the current IPrincipal has access to via the Directory.GetDirectories() and Directory.GetFiles() methods, without listing the other files. The process itself is running as NETWORK SERVICE, so it must change the princ...
<p>Windows impersonation solves this problem by using the login details to acquire a user token. This token can then be used to obtain a WindowsIdentity, which is then used to generate an impersonation context. Within this context scope, you can then access the file system <em>as</em> the impersonated user.</p> <p>O...
Exception thrown when resources declaration order changed <p>I get exception when declare resources in this order:</p> <pre><code>&lt;Window.Resources&gt; &lt;sys:Object x:Key="resourceA"&gt;&lt;/sys:Object&gt; &lt;x:Array x:Key="resourceB" Type="sys:String"&gt; &lt;sys:String&gt;foo&lt;/sys:String&gt...
<p>I think you might find a possible solution <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9db5f1f5-f3a9-402c-9869-08d3624eea59/" rel="nofollow">here</a></p>
Python: an iteration over a non-empty list with no if-clause comes up empty. Why? <p>How can an iterator over a non-empty sequence, with no filtering and no aggregation (<code>sum()</code>, etc.), yield nothing?</p> <p>Consider a simple example:</p> <pre><code>sequence = ['a', 'b', 'c'] list((el, ord(el)) for el in s...
<p><code>odd_integers_up_to_length(el).next()</code> will raise StopIteration, which isn't caught there, but is caught for the generator expression within it, stopping it without ever yielding anything.</p> <p>look at the first iteration, when the value is 'a':</p> <pre><code>&gt;&gt;&gt; odd_integers_up_to_length('a...
Prevent/stop auto anchor link from occurring <p>I need to prevent the automatic scroll-to behavior in the browser when using link.html#idX and &lt;div id="idX"/&gt;.</p> <p>The problem I am trying to solve is where I'm trying to do a custom scroll-to functionality on page load by detecting the anchor in the url, but s...
<p><a href="http://www.inmotiondesign.nl/playground/?p=20">This</a> seems the only option I can see with ids:</p> <pre><code>$(document).ready(function() { $.scrollTo('0px'); }); </code></pre> <p>It doesn't automatically scroll to classes.</p> <p>So if you identify your divs with unique classes you will lose a bit...
What's the point of basis path coverage? <p>The article at <a href="http://www.onjava.com/pub/a/onjava/2007/03/02/statement-branch-and-path-coverage-testing-in-java.html?page=2" rel="nofollow">onjava</a> seems to imply that basis path coverage is a sufficient substitute for full path coverage, due to some linear-indepe...
<p>[Disclaimer: I've never heard of this technique before, it just looks interesting so I've done a few searches and here's what I think I've found out. Hopefully someone who knows what they're talking about will contribute too...]</p> <p>I think it's supposed to be a better way of generating branch coverage tests, no...
Help with regex pattern <p>I have a txt file and each line has a set of random strings, I need to select only the lines that contains only the characters: 1234567890qwertyuiopasdfghjklzxcvbnm-._~</p> <p>I'm reading line by line and verifying char by char, I don't think it's the best way to do that, and I think a RegEx...
<pre><code> /^[-0-9a-z._~]*$/ ^ :: matches the start of a string/start of a line [ :: start of a character class, means match any one of the contained characters - :: dash has a special meaning in character classes, so to avoid having it interpreted for its special meaning, list it first 0-9 ...
Inversion of control for your Inversion of control container? <p>I've recently had to update a relatively large control library that uses Ninject 1.0 to Ninject 2.0 to help resolve some issues I had with 1.0. The update has gone well and I think Ninject 2.0 is a lot quicker.</p> <p>However to try and avoid this proble...
<p>Support property injection, and inject dependencies to "this". </p> <p>In my case, I have a base class that calls StructureMap.BuildUp(this), and the user control would have properties like:</p> <pre><code>public IBlogService _blogService{get;set;} public IEmailService _emailService{get;set;} </code></pre> <p>The...
How can I determine all the codepoints that do not have glyphs in a font using FreeType? <p>This question is closely related to</p> <p><a href="http://stackoverflow.com/questions/103725/is-there-a-way-to-programatically-determine-if-a-font-file-has-a-specific-unicode">http://stackoverflow.com/questions/103725/is-there...
<p>With FreeType in particular, you may use the <a href="http://freetype.sourceforge.net/freetype2/docs/reference/ft2-base_interface.html#FT_Get_Char_Index" rel="nofollow">FT_Get_Char_Index</a> function. This function returns a glyphID of 0 to indicate an unmapped glyph.</p> <p>In more general terms: first you'd need ...
What is the name of this anti-pattern? <p>Surely some of you have dealt with this one. It tends to happen when programmers get a bit too taken by OO and forget about performance and having a database.</p> <p>For an example, lets say we have an Email table and they need to be sent by this program. At start-up, it loo...
<p>I'll have a go at it and coin the name "the lazy filter (anti) pattern".</p>
Adobe AIR from Flash a big disaster? <p>Does anyone have any experience with building AIR apps from within Flash CS3? I inherited an AIR app that is being build from within Flash and is doing my head in to get build.</p> <p>First of all, the AIR app doesn't run from with the Flash IDE. There is no document class and w...
<p>While it is possible to compile projects created in Flash Professional using Flash Builder, and vice versa, if the project has any significant complexity, doing so becomes non-trivial.</p> <p>If the person who created the project was using Flash Builder, I would expect that opening the project in (even a trial vers...
Pig Latin in MIPS Assembly <p>In my MIPs Assembly Programming class I've been tasked with writing a program that converts a string into simplified pig latin.</p> <p>Simplified pig latin assumes all words in the string are at least 2 characters long, and every word has its first letter shifted to the end followed by "a...
<p>You almost certainly have a string of the form:</p> <pre><code>stackoverflow is great\n </code></pre> <p>where <code>\n</code> is a newline character. This would translate into:</p> <pre><code>tackoverflowsay siahy reat\ngay </code></pre> <p>if you simplistically detected the end of the word as either space or n...
Setting a column's default value to be the logged in user name in Access 2007 <p>I have an Access file developed using Access 2003, and am trying to work with it using Access 2007.</p> <p>Some tables have a "changedby" column, which has a default value of</p> <pre><code>=Environ("username") </code></pre> <p>This is ...
<p>Check out this <a href="http://www.access-programmers.co.uk/forums/showthread.php?t=115442" rel="nofollow">thread</a>.</p> <p>It's states that you have to wrap the environ call in a <a href="http://www.access-programmers.co.uk/forums/showthread.php?t=76173" rel="nofollow">function</a> to get around the Access "sand...
Why is List<T> not thread-safe? <p>from this site:</p> <p><a href="http://crfdesign.net/programming/top-10-differences-between-java-and-c">http://crfdesign.net/programming/top-10-differences-between-java-and-c</a></p> <blockquote> <p>Unfortunately, List&lt;> is not thread-safe (C#’s ArrayList and Java’s Vec...
<p>You really need to classify Java's Vector's type of thread safety. Javas Vector is safe to be used from multiple threads because it uses synchronization on the methods. State will not be corrupted. </p> <p>However, Java's vector's usefulness is limited from multiple threads without additional synchronization. F...
What searching algorithm/concept is used in Google? <p>What searching algorithm/concept is used in Google?</p>
<p><a href="http://infolab.stanford.edu/~backrub/google.html">The Anatomy of a Large-Scale Hypertextual Web Search Engine</a> </p>
Can I transpose a file in Vim? <p>I know I can use AWK but I am on a Windows box. I am making a function for others that may not have AWK. I also know I can write a C program but I would love not have to create maintain and compile something for a little Vim utility I am making. </p> <p>The original file might be</...
<p>Here is a command in Vim language. So you don't have to compile Vim with +python support.</p> <pre><code>function! s:transpose() let maxcol = 0 let lines = getline(1, line('$')) for line in lines let len = len(line) if len &gt; maxcol let maxcol = len endif endf...
what is the exact difference between Closed and Stopped State in PPP State machine <p>I wanted to know what is the exact difference between Closed and Stopped State in PPP State machine.</p> <p>It would be great full if someone explain in detail.</p> <p>I am designing ppp stack using C++.</p> <p>Thanks a lot in adv...
<p>"Closed" means the PPP state machine for that link, has been shut down (closed) through either some user intervention (link shutdown) or the underlying physical layer going down (alarm detection, etc). </p> <p>"Stopped" means either 1) The PPP state machine did not succeed in the negotiation and hence stopped, and ...
null used with logical operator <p>I have a table with name,age and address.I have totally five rows of data in the table.For some rows the age is left null.I have to display all the data where age is not null. </p> <p>select * from sample_table where (age !=null);</p> <p>But no output is displayed and it doesn't giv...
<p>With NULL you have to use <code>IS</code> or <code>IS NOT</code>. The following query should work:</p> <pre><code>SELECT * FROM sample_table WHERE (age IS NOT NULL) </code></pre>
How can you tell if a trigger is enabled in PostgreSQL? <p>My googling-fu is failing me. How to know if a PostgreSQL trigger is disabled or not?</p>
<p>It's my first day with postresql, but I think you can check the trigger state via pg_trigger system table: <a href="http://www.postgresql.org/docs/current/static/catalog-pg-trigger.html" rel="nofollow">http://www.postgresql.org/docs/current/static/catalog-pg-trigger.html</a></p> <p>The columns you will need are <co...
Why can't I leverage 4GB of RAM in my computer to process less than 2GB of information in C#? <p>Scenario: over 1.5GB of text and csv files that I need to process mathematically. I tried using SQL Server Express, but loading the information, even with BULK import takes a very long time, and ideally I need to have the e...
<p>Yes, String.Split creates a new String object for each "piece" - that's what it's meant to do.</p> <p>Now, bear in mind that strings in .NET are Unicode (UTF-16 really), and with the object overhead the cost of a string in bytes is approximately <code>20 + 2*n</code> where <code>n</code> is the number of characters...
.Net: Retrieving data from threads <p>This is an Easy Q, but great help:</p> <p>Under title" <em>Retrieving data from threads</em> MSDN (<a href="http://msdn.microsoft.com/en-us/library/ts553s52%28VS.71%29.aspx" rel="nofollow">Here</a>) introduces a way to get data from a child thread by using callback method which is...
<p>"You" ;-p</p> <p>Callbacks are still executed on the worker thread; they provide the data back to the calling <strong>code</strong> - but they don't have an inbuilt way of interrupting the calling <strong>thread</strong>. It is your code's responsibility to push that work back to the main thread if necessary. For e...
How to read third party cookies works across different domains? <p>I know this question has been asked before, but many answers don't give clear samples with codes on how to do this using ASP.NET 2.0. A simple C# is preferred, but I can also accept VB.NET or F#.</p> <p>This <a href="http://stackoverflow.com/questions/...
<p>It is a security feature that one can only read cookies from the same domain that created the cookies. Trying to read "foreign" cookies is a sign of malicious intentions.</p>
What`s wrong with qt 4.5.0 integration with Visual Studio 2008? <p>I downloaded and installed qt evaluation for vs2008 and expect it to be integrated with VS, but it is not. It is trial 30 days commercial license. What`s wrong with it or may be I got it wrong?</p>
<p>The Visual Studio integration is a separate download: <a href="http://www.qtsoftware.com/downloads/visual-studio-add-in" rel="nofollow">http://www.qtsoftware.com/downloads/visual-studio-add-in</a></p>
Code to create Sorting for a GridView in ASP.net in Code Behind? <p>This is my code code for the Page_Load Event</p> <pre><code> OdbcConnection myConnection; DataSet dataSet = new DataSet(); OdbcDataAdapter adapter; //making my connection myConnection = new O...
<p>I usually do this:</p> <pre><code> public string SortField { get { return (string) ViewState["_sortField"]; } set { ViewState["_sortField"] = value; } } public string SortDir { get { return (s...
Update via XML or SQLite db file if possible? <p>I'm developing an app using UITableView driven content.</p> <p>Current testing is done with local XML of size 100kb. This info should update about once every 2 months. The flow is reading pre-sorted XML -> convert to NSDictionary -> UITableView</p> <p>Since parsing XML...
<p>I don't understand the question...you have a sqlite database on a server somewhere and you want to know if it's possible to download via http? Yes, of course, just open a NSURLConnection and grab the data.</p> <p>If you want to somehow <strong>transform</strong> XML from an http source to a sqlite database, well, t...
Vectorization <p>I have a problem with graphs in Excel (2003). I have several matrices :</p> <p>a b c d e f g h</p> <p>i j k l m n o p</p> <p>q r s t u v w x</p> <p>I want to plot the vector z = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t), so I pick one row at a time in "series" under graphs using...
<p>For this kind of numerical task with a simple intent (plot a graph) and simply formatted data, you are better off using a plotting program like Gnuplot. Excel is designed for fewer values and more complex tasks, so you're running into its limitations.</p> <p>Gnuplot in particular is scriptable, and can generate gra...
Assign double value to label in C# <p>How do i assign double value to a string ? </p> <p>Example : </p> <p>double a = 5.5,b= 6.0;<br /> double sum = a + b ; </p> <p>Lable1.Text = sum.ToString(); </p> <p>Result :<br /> 11.5 </p> <p>but in label i am getting only 11...how do i display 11.5 in lable ? </p>
<pre><code>Label1.Text = sum.ToString("#0.0"); </code></pre> <p>Generally speaking, "0" is a zero placeholder and "#" is a digit placeholder. You can find more info <a href="http://msdn.microsoft.com/en-us/library/0c899ak8.aspx">here</a>. You can also try</p> <pre><code>Label1.Text = sum.ToString("F1"); </code></pre>...
Class containing auto_ptr stored in vector <p>In an answer to <a href="http://stackoverflow.com/questions/700588/is-it-safe-to-store-objects-of-a-class-which-has-an-stdautoptr-as-its-member-v">http://stackoverflow.com/questions/700588/is-it-safe-to-store-objects-of-a-class-which-has-an-stdautoptr-as-its-member-v</a> I ...
<p>Objects stored in containers are required to be "CopyConstructable" as well as "Assignable" (C++2008 23.1/3).</p> <p>Your class tries to deal with the CopyConstructable requirement (though I'd argue it still doesn't meet it - I edited that argument out since it's not required and because it's arguable I suppose), b...
What is your experience with ARM Jazelle? <p>I'm evaluating between open source and closed source JVM for ARM. In particular, the closed source JVM can make use of Jazelle (java acceleration for newer ARMs).</p> <p>Do you have any experice with this technology?</p> <p>(And BTW, which OS do you use with it?)</p>
<p>I worked for a big wireless handset maker. Our team was porting J2ME to the ARM-based handsets. We had 2 guys working on using Jazelle; no OS, just on raw ARM9 silicon. Sadly, it stayed in research because the JIT got the performance we needed without having to pay the license fees for Jazelle.</p> <p>If you acc...
try-catch not working? <p>I'm using a try-catch block in the following Actionscript 3 code:</p> <pre><code>try { this._subtitle = new SubtitleController(subtitlePath, _framerate); this._subtitle.addEventListener(Event.COMPLETE, subtitleLoaded); } catch (e:Error) { trace('subtitle not found'); } </code></pr...
<p>IOErrors/NetworkErrors are asynchronous errors. They are not thrown when the method causing them is called as normal runtime errors. Otherwise the execution would have have to stop completely until a (for example) a file is completely loaded ... </p>
html form within mail client <p>Ok, get this.</p> <p>I have been assigned to write an html form to be EMAILED to clients so that they can fill it in and submit it FROM THE EMAIL CLIENT! apparently emailing a link to the existing form on our website is not good enough.</p> <p>I am still trying to get my head around th...
<p>This is not a good idea on many fronts:</p> <ol> <li><p>Not all email clients will support a form post from HTML see: <a href="http://www.campaignmonitor.com/blog/post/2435/how-forms-perform-in-html-emai/" rel="nofollow">http://www.campaignmonitor.com/blog/post/2435/how-forms-perform-in-html-emai/</a></p></li> <li...
Passing Interface's method as parameter <p>Is it possible to pass interface's method as parameters?</p> <p>I'm trying something like this:</p> <pre><code>interface type TMoveProc = procedure of object; // also tested with TMoveProc = procedure; // procedure of interface is not working ;) ISomeInterface = in...
<p>If you were using Delphi 2009, you could do this with an anonymous method:</p> <pre><code>TSomeObject = class(TObject) public procedure Move(MoveProc: TProc); end; procedure Usage; var o: TSomeObject; i: ISomeInterface; begin o := TSomeObject.Create; i := GetSomeInterface; o.Move(procedure() begin i.Ne...
BackgroundWorker Thread in IIS7 - FAIL! <p>Just wondering if anyone has had any trouble using a BackgroundWorker Thread in a site running under IIS 7 in Integrated Pipeline mode?</p> <p>I am trying to use such a beast to update the database schema (admin function, obviously), and it works perfectly in Cassini, but whe...
<p>It is probably an exception. Perhaps you're running with different set of rights between the two environments. </p>
Should I do all the exercises in K&R? <p>This is a quick slightly subjective question I need to ask. In order to become a proficient C programmer, I felt I'd learn C from the k&amp;r. I find the book a little easygoing, difficult to understand sometimes but easygoing on the whole.</p> <p>My question here is, do I ha...
<p>First, best of luck with your learning of C.</p> <p>What to do to become a proficient programmer per se, is something very very crude. I will answer that with an analogy. You may complete all the exercises at the end of the book, but fail to complete the first practical program you are assigned to work upon. In ano...
Sql Server time 1 hour behind <p>I have a datetime column in a table called 'createdDate' were the default value is set to getutcdate(). However when a row is added to the table the createdDate's time value is 1 hour behind the system time. So my question is how do I increase the current database system timestamp by 1 ...
<p>It sounds like your servers are aware of daylight saving (GMT, BST and so on), and your database is resolutely using UTC.</p> <p>Use GetDate() if you want your dates in the <em>database</em> to match the database <em>server</em>'s time.</p> <p>Alternatively, uncheck the box to "automatically adjust clock for dayli...
What is use of operators and alerts in SQL server management studio? <p>Can anyone explain why and where to use operators and alerts in SQL server management studio?</p>
<p>Operators and alerts are intended to support SQL Server jobs, which in turn are managed by the SQL Server Agent.</p> <p>Lets say you had a SQL Server instance that processed a significant number of jobs. You may want to assign a particular operator responsiblity for certain jobs and so choose to inform them of the ...
ChannelFactory.CreateChannel and proxy instantiation is slow in WCF <p>I have a client-server application, in which the client communicates with the server using WCF (WCF is used both in the client and the server). My problem is, that instantiating the auto-generated proxy in the client, in the following way: <pre><cod...
<p>Even though it is already outdated, it may be useful for somebody else searching for the same. Problem could be with DNS resolution problem, that might be solved in SP1. So you can check if it happens only when you use host name or also with specified IP address.</p>
Silverlight 3 - RIA Services and LINQ <p>This is a basic LINQ question.</p> <p>In my RIA Services Application, I have a Family object with Contacts in a child list. This is a entity framework application.</p> <p>I am wondering why when I select my fam the child list of Contacts are not loaded, well I know that it mus...
<p>I think you should have something similar to:</p> <p>ContextContainer.LoadFamilies(fam, null);</p> <p>The "LoadFamilies" is autogenerated from RIA services.</p> <p>there should then be an OnLoaded event when the async result has been completed.</p> <p>you can then say somelistbox.ItemSource = e.LoadedEntities</p...
Search multiple indices at once using Lucene Search <p>I am using Zend_Search_Lucene to implement site search. I created separate indices for different data types (e.g. one for users, one for posts etc). The results are similarly divided by data type however there is an 'all' option which should show a combination of t...
<p>So after some research you have to use Zend_Search_Lucene_Interface_MultiSearcher. I don't see any mention of it in the documentation as of this writing but if you look at the actual class in ZF 1.8 it's straightforward t use</p> <pre><code>$index = new Zend_Search_Lucene_Interface_MultiSearcher(); $index-&gt;addIn...
Is there a JQuery plugin which combines Draggable and Selectable <p>I'm looking to implement a web interface with a number of items which can be selected and dragged around to position them, <strong>either in groups or singly</strong>. Rather like the Windows Desktop, really.</p> <p>We're using JQuery already, so add...
<p>I also needed to do same thing, and i didn't want to use interface extension from eyecon.ro. After some research, I found <a href="http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/" rel="nofollow"><em>Combining Selectables And Draggables Using jQuery UI</em></a>. It is nice...
Mdi form ensure visible <p>I am developing a c# .NET app with MDI forms. When the Mdi children are moved around and using the scroll bars some forms will be outside the displayed area. I would like to do to the Mdi children something similar to TreeNode.EnsureVisible() which moves the TreeView scrollbars until the Node...
<p>You could call the method ActivateMdiChild(childForm) on the parent Window which bring the focus on the childForm. HTH</p>
Spring Hibernate SQL Query <p>I have a VO class which has the getter and setter of another VO class too. For example:</p> <pre><code>Class DocumentVO{ PrintJobVO job; PrintRunVO run; String id; getters and setters.. } </code></pre> <p>Now I have a requirement to use the Native SQL Query using spring hiber...
<p>Use the Result Transformer concept in your plain SQL query.</p> <pre><code>String query = "myquery"; SQLQuery q = session.createSQLQuery(query); q.addScalar("param1", Hibernate.STRING); q.addScalar("param2", Hibernate.STRING); q.setResultTransformer(Transformers.aliasToBean(MyVO.class)); q.setParameter("queryParam1...
indentation of multiline string <p>I have a script that uses the cmd Python module. The cmd module uses a triple quoted multiline string as it's help text. Something like this</p> <pre><code>def x(self, strags = None): """class help text here and some more help text here""" </code></pre> <p>When running t...
<p>Personally I try to follow <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> which refers the reader to <a href="http://www.python.org/dev/peps/pep-0257/" rel="nofollow">PEP 257</a> for Docstring Conventions. It has an entire section on multi-line docstrings.</p>
how do I pull a remote tracking branch while in the master branch <p>I'm in master and I do a git pull, I get a message indicating I need to pull a remote branch.</p> <p>Typically I do a <em>git co [branch]</em> then <em>git pull/rebase</em>.</p> <p>Is there a way to git pull/rebase of [branch] without having to do a...
<p>If you combine Apikot and Jeremy you get:</p> <pre><code>git pull --rebase origin branch </code></pre> <p>Or, if you haven't set the branch mapping up in your config:</p> <pre><code>git pull --rebase origin &lt;src&gt;:&lt;dst&gt; </code></pre>
ASP.NET MenuItem Individual Styles <p>I'm hoping to use an ASP.NET Menu Control for navigation through my site. However, I've got a requirement that each MenuItem must be styled differently (different colors, both static, and onHover). Without creating a custom class that would inherit from MenuItem, is this possible?<...
<p>Short of overriding RenderContents on Menu, your options are very limited. Most of what you'd need is private and sealed and you won't get anywhere there.</p> <p>My solution would be to use templates. You could use MenuItem.Value or Depth and and ItemIndex to identify each item and provide necessary attributes.</p>...
Visual Studio 2008 Database Addon <p>I am currently trying out visual studio to access sql server databases instead of using SQL Server Management Studio.</p> <p>It was a good surprise how easy it is to setup and use a connection do a database and for the moment it has a positive impact on my productivity.</p> <p>My ...
<p>Red Gate SQL Prompt integrates into VS 2008, but it costs money...</p> <p>Edit: <a href="http://stackoverflow.com/questions/414404/are-there-free-sql-server-mgmt-studio-autocomplete-add-ins">Are there Free SQL Server Mgmt Studio Autocomplete Add-ins?</a> This may not work in VS though...</p>
How can I return an instance of a dynamically-built type to a WCF service expecting an interface? <p>I want to have an operation contract that returns an interface. </p> <p>My problems:</p> <p>1) I want to register dynamically with the service the known type that will be returned, or to have WCF accept the type. I no...
<p>I've run into the same situation : I think you <strong>have</strong>, by design, to use the [KnownType] attribute so the serializer know which implementation to wait for.</p> <p>The key point is that the serializer receives some bytes with only little metadata regarding how to read them (mainly, the type's name). T...
Google App Engine database inconsistency <p>Im writing a twitter app in Google App Engine. It accepts commands as Direct Messages, so i have setup a third party cronjob service to invoke a handler that processes DMs at regular intervals. I have a Model 'Info' that has just one entry, it stores some common data which ar...
<p>The Google AppEngine datastore uses BigTable under the covers, which is a distributed database system. Because of this, updates might not be visible immediately since the new data has not yet reached every distributed table (Amazon calls this "eventual consistency" in their SimpleDB). You should be fine after a few ...
Silverlight 3 - dataform errorsummary with RIA validation <p>I got a dataform partially working with RIA services (I can fetch and edit data).</p> <p>The problem is that I added validation to my RIA service fields. Ex: from my metadata.cs file </p> <p>[StringLength ( 50, ErrorMessage= "bad data dude!" , MinimumLength...
<p>Visual Studio breaks because it sees an error it believes is not handled. If you just continue the program the error will be handled and the failed validation will show as expected.</p> <p>You can tell VS not to stop on an user unhanded ValidationException using the Debug/Exceptions dialog in VS.</p>
ASP.NET MVC - Cascading Drop Down <p>I'm currently learning ASP.NET MVC and using Nhibernate.</p> <p>I would like to use Cascading Drop-Down Boxes. Has anyone managed to get cascading drop-down boxes working in MVC?</p> <p>Updated: I have looked at the following website: <a href="http://stephenwalther.com/blog/archiv...
<p>You may want to read this <a href="http://stephenwalther.com/blog/archive/2008/09/07/asp-net-mvc-tip-41-creating-cascading-dropdown-lists-with-ajax.aspx" rel="nofollow">TIP</a>.</p> <p>In this tip, Stephen Walter demonstrates three methods of creating cascading dropdown lists. First, he shows you how to alter the l...
ASP.NET URL-rewriting options <p>I've seen some .NET sites that obviously are using some sort of URL-rewriting method, but the one that intrigues me the most are ones that look like:</p> <p><strong><a href="http://www.somesite.com/pages/an-example-page.aspx" rel="nofollow">http://www.somesite.com/pages/an-example-page...
<p>There is a System.Web.Routing addition in the new MVC Framework you can use to do it in 3.5 or I believe it is included in the 3.5 SP1 install.</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.web.routing.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.web.routing.aspx</a></p>
Software to test C# code <p>Consider i have a C# code, I need some tool that would perform an analysis of my code and report bugs and vulnerabilities. Are there any open source tools, something like klocwork.?</p>
<p><a href="http://msdn.microsoft.com/en-us/library/bb429476.aspx" rel="nofollow">FxCop</a> can perform static analysis of compiled assemblies, <a href="http://www.jetbrains.com/resharper/" rel="nofollow">ReSharper</a> can analyze your program at source code level. Certain editions of Visual Studio have Code Analysis b...
ASP.NET/IIS equivalent of Java/WAS context-root <p>In Java on WebSphere Application Server if I want my servlets, etc., to start with a certain root path, I use the context-root property in the EAR deployment descriptor (application.xml). For example, my servlet is named GetData, but I want the URL to be www.mysite.com...
<p>One option would be Url Rewritting - <a href="http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx" rel="nofollow">http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx</a></p> <p>On the other hand, if you have your dynamic asp.net site se...
toggle div visibility with a checkbox list <p>I have a web application(ASP.NET2.0 C#). Within it, I have a div that contains a checkbox list and a button.</p> <p>I want to toggle the div viewing, so I got some javascript code online to help me.</p> <p>Heres the code:</p> <pre><code>&lt;script language="javascript"&g...
<p>Have you tried using display instead of visiblity?</p> <p>For example, instead of:</p> <pre><code>document.getElementById(layer_ref).style.visiblity = "hidden"; document.getElementById(layer_ref).style.visiblity = "visible"; </code></pre> <p>Use:</p> <pre><code>document.getElementById(layer_ref).style.display = ...
Best way to change clustered index (PK) in SQL 2005 <p>I have a table which has a clustered index on two columns - the primary key for the table. It is defined as follows:</p> <pre><code>ALTER TABLE Table ADD CONSTRAINT [PK_Table] PRIMARY KEY CLUSTERED ( [ColA] ASC, [ColB] ASC )WITH (SORT_IN_TEMPDB = OFF, IGNOR...
<p>This isn't a complete answer to your question, but make sure that if you have any other indexes on the table that you drop those first. Otherwise SQL Server will have to rebuild them all when you remove the clustered index then rebuild them all again when you add back a new clustered index. The usual steps are:</p> ...
What is data is submitted to Google when using google maps? <p>I have been asked by a client to map data, but the client does not what any other data besides addresses for geocoding to be sent to another server. Does the Google maps API submit other data besides addresses and latitude/longitude to Google?</p> <p>For e...
<p>It shouldn't be submitted at all, it depends on how you are paring the XML file.</p> <pre> GDownloadUrl("AMBest2bil50bil.xml", function(doc) { var xmlDoc = GXml.parse(doc); var markers = xmlDoc.documentElement.getElementsByTagName("marker"); for (var i = 0; i "+name+"<br>Total Assets:...
C++ socket server on Mac. Help! <p>Hey everyone. I'm planning on writing a socket server in C++ running on a Mac. I've been searching through a great portion of the internet without any results. Anyone knows where to start? Or even got a basic source code? Much appreciated.</p>
<p>i think the ASIO Library is platform independent enough for that.</p> <p>Look here: <a href="http://www.boost.org/doc/libs/1%5F38%5F0/doc/html/boost%5Fasio.html" rel="nofollow">Boost Asio</a> <a href="http://think-async.com/Asio/" rel="nofollow">Asio Only</a></p>
Cannot update document property on ItemAdded event when using Vista <p>We are trying to create a custom event handler that would fire on ItemAdded event. The event handler then updates the document with a unique ID value to a column in this document library. </p> <p>Our solution works fine, except when a user on Vista...
<p>We have noticed exactly the same thing happening. When the 2007 doc is added to the library, the properties from the list are added to it (blank). </p> <p>Then the (synchronous) event handler is called, updating the list with the correct values for the UniqueID column. </p> <p>Then the inbuilt property mapping to ...
Service Host Resolving - C# Equivalent to RMI Registry? <p>I'm taking a Masters capstone course early and doing my project in C# while everyone else is doing theirs in Java. The project has 4 services and requires a name server that maps service names to sockets. The instructor is suggesting that the students use RMI...
<p>You can use the UDDI server that comes with Windows Server 2K3/8. This will give you discovery of your services. Other than that you would need a 3rd party package or roll your own.</p>
Are uninitialized struct members always set to zero? <p>Consider a C struct:</p> <pre><code>struct T { int x; int y; }; </code></pre> <p>When this is partially initialized as in </p> <pre><code>struct T t = {42}; </code></pre> <p>is <em>t.y</em> guaranteed to be 0 or is this an implementation decision of th...
<p>item 8.5.1.7 of standard draft:</p> <blockquote> <p>-7- If there are fewer initializers in the list than there are members in the aggregate, then each member not explicitly initialized shall be default-initialized (dcl.init). [Example:</p> <pre><code>struct S { int a; char* b; int c; }; S ss = { 1, "asdf...
Make an option selected based on $_GET. Is this even possible? <p>I have a quick question.</p> <p>Is it possible to do something like this?</p> <p>The options are generated dynamically based on foreach loop. I want the loop to stop where the $_GET['t'] equals the $k and make it selected.</p> <pre><code>&lt;option va...
<p>You get the undefined error because "t" is not in your <code>$_GET</code> request.</p> <p>make sure you are calling the right url (i.e.: example.com/script.php?t=test)</p> <p>Do make sure you are checking for the value (as others suggested) with <code>isset($_GET['t'])</code></p>
Eclipse keeps running my old web application <p>OMG - what is going on with Eclipse (3.3 Europa) - has anyone come accross this problem (bearing in mind I have been messing about with uninstalling different Tomat containers and installing others - but anyway thats another story)</p> <p>When I change a line of code or ...
<p>Have a look at:</p> <blockquote> <p>Windows>Preferences>Server>Launching...</p> </blockquote> <p>and:</p> <blockquote> <p>Project>Build Automatically</p> </blockquote> <p>maybe you accidentally disabled the auto-deploy features.</p>
How can I change the image displayed in an UIImageView programmatically? <p>I have an <code>IBOutlet</code> to an <code>UIImageView</code>, but when I look at the <code>UIImageView</code> doc, I can't see any hint about how to programmatically change it. Do I have to fetch an <code>UIImage</code> object from that <code...
<p>If you have an IBOutlet to a UIImageView already, then all you have to do is grab an image and call setImage on the receiver (UIImageView). Two examples of grabbing an image are below. One from the Web, and one you add to your Resources folder in Xcode.</p> <pre><code>UIImage *image = [[UIImage alloc] initWithData:...
Dynamic columns when pivoting <p>I have a table of equipment, a table of customers and a sparse table of equipment and customers. I want to produce a query that returns a 1 if the equipment/Customer table record exists and a 0 if it doesn't for each customer. There are only a small number of customers in this problem, ...
<p>If you want to do that, then you have to create the query string dynamically and then pass it to the <a href="http://msdn.microsoft.com/en-us/library/ms188001.aspx" rel="nofollow"><code>sp_execute</code></a> stored procedure. AFAIK, there isn't a way to do it without constructing the query string dynamically.</p>
Login Control - Response.Redirect <p>I have a usercontrol on a page that has a login control in it. This controls the display of another user control (if the user is not logged in they get the login control user control). I have some authentication code (see below) that runs when the user clicks the "Login" button. ...
<p>The issue is the login control will itself do a redirect setting a cookie or an encrypted authentication ticket in the url (cookieless).</p> <p>I think the login control has some properties where you can tell it where it will be redirecting to (which overrides the one in the web.config).</p>
How can I make UIImageView change its image programmatically? <p>I have this code:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; landscape.image = [UIImage imageNamed:@"tenerife1.png"]; } </code></pre> <p>First, I created an <code>UIImageView</code> with <code>IBOutlet</code>. Landscape is pointing to tha...
<p>Try calling setNeedsDisplay on the view after you change the image:</p> <pre><code> [landscape setNeedsDisplay]; </code></pre>
Get schema of proc's select output <p>I'd like to put the results of a stored proc into a temp table. It seems that the temp table must be defined beforehand and an INSERT INTO will not work. </p> <p>Anyone know how to get the schema of the recordset being returned from a select statement?</p> <p>sp_help only gets ...
<p>You should be able to insert into a temp table without defining the schema using OPENQUERY: </p> <pre><code>SELECT * INTO #TempTable FROM OPENQUERY(ServerName, ‘EXEC DataBaseName.dbo.StoredProcedureName paramvalues1, paramvalues1′) </code></pre> <p>Where ServerName is the name of your Sql Server instance. See...
Looping through DirectoryEntry or any object hierarchy - C# <p>I am currently developing an application that use the System.DirectoryServices namespace to create a DirectoryEntry object and loop through the entire hierarchy to collect information. </p> <p>I do not know number of child entries for each DirectoryEntry ...
<p>Use a recursive function if you don't know the depth of the hierarchy and need to traverse down through all levels. Below is an example using depth-first traversal.</p> <pre><code>var root = new DirectoryEntry(someDN); DoSomething(root); function DoSomething(DirectoryEntry de) { // Do some work here against t...
Classic ASP crash course <p>I'm a C# and PHP developer. At work, I just got some classic ASP stuff dumped in my lap. I only need to make edits for a few weeks so I don't want to have to learn too much about legacy stuff I'll never touch again. However, I do need to be able to do my job for this duration.</p> <p>How ca...
<p><a href="http://www.w3schools.com">http://www.w3schools.com</a> has a really good ASP tutorial. It's actually what I used when I went into classic ASP from a PHP background in school.</p>
Eclipse Servlets take a long time to update <p>I'm testing running a simple Servlet from within Eclipse. When I click 'Run', the console says it is starting TomCat, and then an internal browser launches within Eclipse which shows my code.</p> <p>However, if I make any changes in the servlet and click 'Refresh' in the ...
<p>This is caused by the way servlet developing works. When modifying your servlert, it needs to be submitted to the servlet container after compiling it. The servlet container itself needs to reload the servlet, the servlet must be instantiated (servlet lifecycle). Thats a lot of things to do, which may cause you waii...
How to make MPMoviePlayerController respect the ring/silent switch? <p>I'm trying, unsuccessfully, to get the MPMoviePlayerController to play movies silently if the ring/silent switch on the iPhone is set to silent. There are no interface methods to help me out nor does the player respect the AudioSessionProperty() tr...
<p>I spent some time trying to get this to work myself. Eventually I gave up after trying, failing and reading <a href="https://devforums.apple.com/message/142085" rel="nofollow">this post on the apple dev forums</a>.</p> <blockquote> <p>"The MPMoviePlayerController establishes its own audio session and there is n...
Spring MVC form:select Tag, multiple selections not binding correctly? <p>I am trying to create a form to edit an existing database row. I am using the Spring MVC form tag to auto bind the html to a form backing object. The row has a many to many relationship with another table, which I am trying to represent with a mu...
<p>The problem is with the submission of your form. Spring isn't able to bind an object of the command, so it doesn't submit the form, but redirects you to the formView instead.</p> <p>When the binding is successfully performed, you will see this message instead:</p> <pre><code>No errors -&gt; processing submit </cod...
Ensuring method is called <p>I have this class:</p> <pre><code>public abstract class AbstractIncomingCall { /* class properties */ public void changeStatus(/*some parameters*/){ //store parameters in class properties isValid(); } protected abstract boolean isValid(); } </code...
<p>It sounds like you want changeStatus() to follow the Template Method pattern. In this pattern, you define changeStatus() in the abstract class (making it final if you don't trust people to extend properly), and have it call the required methods:</p> <pre><code>public final void changeStatus() { doSomethingSubcl...
ItemsSource + Converter + Treeview wont update <p>This one is fairly complex, hopefully I can make this clear enough for somebody to help me out. I have an object lets call it a Manager, the Manager has a collection of people that he manages, the people all implement IPerson, but different types of people have differen...
<p>The converter is applied to the property that stores the collection. Therefore, it will only be called if the collection instance itself changes (not if items in the collection are changed). One way around this would be to invalidate the collection when you want it to refresh.</p> <p>The simplest way to invalidate ...
Asp.Net Gridview Buttonfield get Row Data <p>I have a Gridview which is binded to a datatable that I created. The data in the table is ever changing.</p> <p>I added a buttonfield to the Gridview. When clicked I want to send a specific columns value in that row through a link or sent through a function.</p> <p>How do ...
<p>I found out how to do it. You set the commandName property to whatever you want to call it inside the properties.</p> <p>Then if you double click on the button after creating it in design view, it should pop up a function in the code behind page. You can then access the row by doing the following. </p> <p>protecte...
Load WPF styles or other Static Resources from an external file or assembly <p>I have a few WPF applications and I want all my styles to be in a shared assembly instead of declaring them in each application separately.</p> <p>I am looking for a way so I don't have to change all my <code>Style="{StaticResource BlahBlah...
<p>Referencing an external ResourceDictionary (XAML File):</p> <pre><code>&lt;Application.Resources&gt; &lt;ResourceDictionary Source="MyResources.xaml" /&gt; &lt;/Application.Resources&gt; </code></pre> <p>Referencing an external ResourceDictionary (DLL):</p> <pre><code>&lt;Application.Resources&gt; &lt;Res...
ASP.Net Problem in Prod/Dev <p>I am facing strange problem, Whenever I commented second <strong>if</strong> condition, it works in Production, but fail in development.</p> <p>And when I dont comments second if condtion of code, it works for development and fail for production.</p> <pre><code> protected void Page_L...
<p>Did you verify that your ASPX file was migrated up to production with the latest changes?</p> <p>It looks to me that the Action control was added in development, and the DLL file migrated up to production, but not the corresponding ASPX file.</p>
How to use ROW_NUMBER in the following procedure? <p>I have the following stored procedure which returns A, B, and the count in descending order. I am trying to use ROW_NUMBER, so I can page the records, but I want the first row number 1 to be the record with the highest count, so basically, if I return a table with 3...
<pre><code>WITH q AS ( SELECT h.A, hrl.B, dbo.f_GetCount(hrl.A,h.B) as cnt FROM dbo.hrl INNER JOIN dbo.h on h.C = hrl.C WHERE (@A IS NULL OR h.A like '%' + @A + '%') AND (@B IS NULL OR hrl.B = @B) GROUP BY hrl.B, h.A ) SELECT q.*, ROW_NUM...
Why is this bash prompt acting strangely/disappearing, and how do I fix it (OS X)? <p>I admit that I use a somewhat long-winded bash prompt:</p> <pre><code>--(username)-(Wed April 01|12:00:00)--(~ $</code></pre> <p>Recently, I got the bright idea to change it so that depending on the exit value from the previous comm...
<p>It sounds like <a href="http://forums.macosxhints.com/archive/index.php/t-17068.html">this</a> should solve your problem.</p> <p>This seems to work for me<code>*</code>:</p> <pre><code>export PS1='--(\[\e[$((32-${?}))m\]\u\[\e[0m\])-(\[\e[$((32-${?}))m\]\d\[\e[0m\]|\[\e[$((32-${?}))m\]\T\[\e[0m\])--(\[\e[$((32-${?...
Can I use a dll written in C with PHP? <p>We are interfacing with a piece of hardware developed here, and allowing access via the web. The firmware for this device is written in C, and part of that firmware is about 5000 lines of code that parses huge binary files for config data, compiled to a .dll.</p> <p>Is there ...
<p>yes, you can use it as a php extension (which are written in C), but you might need some modifications .. etc</p> <p><a href="http://devzone.zend.com/node/view/id/1021" rel="nofollow">http://devzone.zend.com/node/view/id/1021</a></p> <p>I think <a href="http://stackoverflow.com/questions/705443">this question</a> ...
Tools to compare two sites structures <p>Does anyone knows about any tools allowing to compare two almost exactly same websites?</p> <p>Simply, I have a sandbox site and production site, and would like to find out the difference between them, to know what content to move to production site.</p> <p>Thanks!</p> <p>Edi...
<p>Use <a href="http://www.httrack.com/">httrack</a> to pull down a copy of the sites, and then your favourite file comparing tool to review the differences. (I prefer <a href="http://winmerge.org/">WinMerge</a>, which can recursively run though two folders of files, has options to ignore whitespace differences and bl...
Decorators and in class <p>Is there any way to write decorators within a class structure that nest well? For example, this works fine without classes:</p> <pre><code>def wrap1(func): def loc(*args,**kwargs): print 1 return func(*args,**kwargs) return loc def wrap2(func): def loc(*args,**kwargs)...
<p>"Is there any good way to put the decorators within the namespace?"</p> <p>There's no compelling reason for this. You have module files. Those are a tidy container for a class and some decorators. </p> <p>You don't ever need decorators as methods of the class -- you can just call one method from another. </p>
How to prevent, counter or compensate for, an empty/NULL field (MySQL) returning an empty set <p>I'm learning PHP and MySQL to get a hang of server-side scripting and for personal interest/development. The first 'program,' beyond 'hello world' seems to be writing ones' own blog.</p> <p>This is a little beyond me yet a...
<p>You want a left (aka left outer) join.</p> <pre><code>select concat(c.fname, ' ', c.sname) as name, e.address as email from contacts c left join emails e on (c.contactID = e.contactID) </code></pre>
Clean, efficient algorithm for wrapping integers in C++ <pre><code>/** * Returns a number between kLowerBound and kUpperBound * e.g.: Wrap(-1, 0, 4); // Returns 4 * e.g.: Wrap(5, 0, 4); // Returns 0 */ int Wrap(int const kX, int const kLowerBound, int const kUpperBound) { // Suggest an implementation?...
<p>The sign of <code>a % b</code> is only defined if <code>a</code> and <code>b</code> are both non-negative.</p> <pre><code>int Wrap(int kX, int const kLowerBound, int const kUpperBound) { int range_size = kUpperBound - kLowerBound + 1; if (kX &lt; kLowerBound) kX += range_size * ((kLowerBound - kX) ...
In Python how can I access "static" class variables within class methods <p>If I have the following python code:</p> <pre><code>class Foo(object): bar = 1 def bah(self): print bar f = Foo() f.bah() </code></pre> <p>It complains </p> <pre><code>NameError: global name 'bar' is not defined </code></pr...
<p>Instead of <code>bar</code> use <code>self.bar</code> or <code>Foo.bar</code>. Assigning to <code>Foo.bar</code> will create a static variable, and assigning to <code>self.bar</code> will create an instance variable.</p>
static BOOL in Objective C <p>In the following code, I'm creating a category on UIColor to create a random color. However, from this code, I would have thought that the 'if' conditional would be true every time the method is run, instead of just the first time. </p> <p>I think I'm not really understanding static var...
<p>You are correct that the static variable only is set once.</p> <p>the code </p> <pre><code>static BOOL seeded = NO; </code></pre> <p>is <strong>not</strong> equivalent to</p> <pre><code>static BOOL seeded; seeded = NO; </code></pre> <p>the second one would always evaluate to NO, while the first one will evaluat...
In scons, how can I inject a target to be built? <p>I want to inject a "Cleanup" target which depends on a number of other targets finishing before it goes off and gzip's some log files. It's important that I not gzip early as this can cause some of the tools to fail.</p> <p>How can I inject a cleanup target for Scon...
<p>you shouldn't use <code>_Add_Targets</code> or undocumented features, you can just add your cleanup target to <code>BUILD_TARGETS</code>:</p> <pre><code>from SCons.Script import BUILD_TARGETS BUILD_TARGETS.append('cleanup') </code></pre> <p>if you use this documented list of targets instead of undocumented functio...
Extract the first word of a string in a SQL Server query <p>What's the best way to extract the first word of a string in sql server query?</p>
<pre><code>SELECT CASE CHARINDEX(' ', @Foo, 1) WHEN 0 THEN @Foo -- empty or single word ELSE SUBSTRING(@Foo, 1, CHARINDEX(' ', @Foo, 1) - 1) -- multi-word END </code></pre> <p>You could perhaps use this in a UDF:</p> <pre><code>CREATE FUNCTION [dbo].[FirstWord] (@value varchar(max)) RETURNS varchar(max) AS ...
Generate Complex Object from LINQ to XML in VB .NET <p>I have an XML File that I am processing using LINQ. I want to basically serialize the XML data into custom objects but don't know how.</p> <p>Simplified XML</p> <pre><code>&lt;Data&gt; &lt;Group id="1"&gt; &lt;Child id="1"/&gt; &lt;Child id="2"/&g...
<p>I think this class, paired with <code>System.Xml.Serialization.XmlSerializer</code>, will do the trick:</p> <pre><code>&lt;Serializable&gt; _ Public Class Data &lt;Serializable&gt; _ Public Class Group &lt;Serializable&gt; _ Public Class Child &lt;XmlAttribute&gt; _ Publi...
WPF exception running animation in another class <p>I can run an animation from the main window class but if I try to run the same code from another class in the same namespace I receive an exception in the storyboard begin function<br> this is the exception:<br><br> No applicable name scope exists to resolve the name ...
<p>--otherUserControl.cs</p> <pre><code>StackPanel defaultGroup; </code></pre> <p>--MainWindow.cs</p> <pre><code>this.RegisterName(otherUserControl.defaultGroup.Name, otherUserControl.defaultGroup); // RegisterName Storyboard.SetTargetName(r3d,"defaultGroup"); Storyboard.SetTargetProperty(r3d, new PropertyPath("(Vi...
C#: How do you disable a key from being pressed indefinetly in textbox's keydown event? <p>C#: How do you disable a key from being pressed indefinetly in textbox's keydown event?</p>
<p>The standard way to handle that is to create an event handler for the <code>Textbox.KeyDown</code> event and then set <code>KeyEventArgs.SuppressKeyPress</code> to true if the key pressed matches the key you want to disable. Here is an example:</p> <pre><code>yourTextBox.KeyDown += delegate(Object sender, KeyEvent...
Is there a reasonable approach to "default" type parameters in C# Generics? <p>In C++ templates, one can specify that a certain type parameter is a default. I.e. unless explicitly specified, it will use type T. </p> <p>Can this be done or approximated in C#?</p> <p>I'm looking for something like:</p> <pre><code>publ...
<p>Subclassing is the best option.</p> <p>I would subclass your main generic class: </p> <p><code>class BaseGeneric&lt;T,U&gt;</code> </p> <p>with a specific class </p> <p><code>class MyGeneric&lt;T&gt; : BaseGeneric&lt;T, string&gt;</code></p> <p>This makes it easy to keep your logic in one place (the base class)...
Excel VBA copy XL-2007 Macro-Enabled Workbook as excel-2003 file with no macros <p>I''m looking for a vba macro that will make a copy of the current Excel 2007 macro-enabled workbook with the name I specify as an Excel 2003 macro-free document. It should also keep the current workbook open and in the Excel 2007 format ...
<p>It's much, much easier to do a save as.</p> <p>Why does it have to stay open? - you can simulate it by: </p> <ul> <li>Doing a Save As to a new file </li> <li>Close the copy </li> <li>Re-open the original</li> </ul> <p>As far as removing the code look at these questions: </p> <p><a href="http://stackoverflo...