instruction
stringlengths
0
30k
I have a list of data object to sort. I want to do something like <pre>list.sort(function(item1, item2){ return item1.attr - item2.attr; }) </pre> to sort it based on a string attribute of the object. But found that the minus(-) operator does not work for strings in javascript. So how do you do string compari...
Sorry, stupid question. You should use > or < and == here. So the solution would be: <pre> list.sort(function(item1, item2){ var val1 = item1.attr; var val2 = item2.attr; if (val1 == val2) return 0; if (val1 > val2) return 1; if (val1 < val2) ...
Saw a mention of List.ForEach above; 2.0 introduced a bevy of predicate-based collection operations - Find, FindAll, Exists, etc. Coupled with anonymous delegates you can almost achieve the simplicity of 3.5's lambda expressions.
Well, this oughta work... if ( item1.attr < item2.attr ) return -1; if ( item1.attr > item2.attr ) return 1; return 0;
Well, this oughta work... if ( item1.attr < item2.attr ) return -1; if ( item1.attr > item2.attr ) return 1; return 0; **[Edit:** uh, and i guess you could also use `localeCompare()`... return item1.attr.localeCompare(item2.attr); I did not previously know about it. Heh, coo...
You can use LINQ as well, var processExists = Process.GetProcesses().Any(p => p.ProcessName.Contains("<your process name>"));
How do I stop visual studio from automatically inserting asterisk during a block comment?
|visual-studio|tips-and-tricks|
I'm tearing my hair out with this one. If I start a block comment ( /* ) in VS.NET 2005+ then carriage return, VS insists that I have another asterisk ( * ). I know there's an option to turn this off but I just can't find it. Anyone know how to turn this feature off?
Is the dialog's parent window set correctly?
Is the dialog's parent window set correctly? After I posted this, I started my own Windows Forms application and reproduced the problem you describe. I have two dialogs, one works correctly the other does not and I can't see any immediate reason is to why they behave differently. I'll update this post if I find out.
You could try the approach used by code generation tools like CodeSmith. Create a SQL template with placeholders. At runtime, read the template into a string and substitute the placeholders with actual values. This is only useful if all the SQL code follow a pattern.
I've used [XmlUnit][1] in the past and found it to be useful. It can be used to validate XML against a schema or compare your XML against a string. It is clever enough to understand XML's parsing rules. For example it knows that "&lt;e1/&gt;" is equivalent to "&lt;e1&gt;&lt;/e1&gt;" and can be configured to ignore ...
Can MS Visual Studio compile projects using 2 or 4 cores on CPU?
|visual-studio|
Is it any compilator option of flag?
Do you mean this?: //create the mail message MailMessage mail = new MailMessage(); //set the addresses mail.From = new MailAddress("me@mycompany.com"); mail.To.Add("you@yourcompany.com"); //set the content mail.Subject = "This is an email"; mail.Body = "this ...
What is the best way to set the permissions for a specific user on a specific folder on a remote machine?
|c#|.net|deployment|
We have a deployment system at my office where we can automatically deploy a given build of our code to a specified dev environment (dev01, dev02, etc.). These dev environments are generalized virtual machines, so our system has to configure them automatically. We have a new system requirement with our next version; we...
We have a deployment system at my office where we can automatically deploy a given build of our code to a specified dev environment (dev01, dev02, etc.). These dev environments are generalized virtual machines, so our system has to configure them automatically. We have a new system requirement with our next version; we...
Migrating a bigger project like this from as2 will be more than a simple search and replace. The new syntax is fairly similar and simple to adapt (as lilserf mentioned) but if nothing else the fact that as3 is more strict and the new event model will mostly likely cause a lot of problems. You'll probably be better off ...
Using the above method will create the files one level above your current directory. If you want the play lists to all go to one directory you'd need to do something like: #!/bin/sh MYVAR=`pwd | sed "s|/|_|g"` ls > /playlistdir/$MYVAR-list.txt
Rendering Graphics in C#
|c#|xna|gdi+|rendering|
Are there any other way to render graphics in C# beyond GDI+ and XNA? (For the development of a tile map editor)
Is there a FLASH editor that supports intellisense & step-into debugging?
|ide|flash|
I'm considering using Flash but I'm pretty addicted to Intellisense and Step-at-a-time debugging.
|ide|flash|actionscript|
Is there a FLASH editor that supports autocomplete & step-into debugging?
|flash|ide|actionscript|autocomplete|
I'm considering using Flash but I'm pretty addicted to autocomplete and Step-at-a-time debugging.
This is equivalent to the backtick solution: ls > $(pwd).txt
http://cs-sdl.sourceforge.net/index.php/Main_Page is the solution I've come to love. If you need 3d on top of it, you can use Tao.OpenGL to render inside it. It's fast, industry standard (SDL, that is), and cross-platform.
I suspect the problem may be that there are spaces in one of the directory names. For example, if your working directory is "/home/user/music/artist name". Bash will be confused thinking that you are trying to redirect to /home/user/music/artist and name.txt. You can fix this with double quotes ls > "$(pwd).t...
Resettable Java Timer
|java|timer|
I'd like to have a java.utils.Timer with a resettable time in java. E.g. the timer should be able to do something like: Timer timer = new Timer(); timer.schedule(timerTask, 5000); //Timer starts in 5000 ms //At some point between 0 and 5000 ms... setNewTime(timer, 8000); //timerTask w...
I'd like to have a java.utils.Timer with a resettable time in java.I need to set a once off event to occur in X seconds. If nothing happens in between the time the timer was created and X seconds, then the event occurs as normal. If, however, before X seconds has elapsed, I decide that the event should occur after ...
Tool for commandline "bookmarks" on windows?
|commandline|
Im searching a tool which allows me to specify some folders as "bookmarks" and than access them on the commandline (on Windows XP) via a keyword. Something like: C:\> go home D:\profiles\user\home\> go svn-project1 D:\projects\project1\svn\branch\src\> I'm currently using a bunch of batch file...
|command-line|
With just a Batch file, try this... (save as filename "go.bat") @echo off set BookMarkFolder=c:\data\cline\bookmarks\ if exist %BookMarkFolder%%1.lnk start %BookMarkFolder%%1.lnk if exist %BookMarkFolder%%1.bat start %BookMarkFolder%%1.bat if exist %BookMarkFolder%%1.vbs start %BookMarkFolder...
Is the dialog's parent window set correctly? After I posted this, I started my own Windows Forms application and reproduced the problem you describe. I have two dialogs, one works correctly the other does not and I can't see any immediate reason is to why they behave differently. I'll update this post if I find out....
In a past project I needed to prevent multiple execution of a process, so I added a some code in the init section of that process which creates a named mutex. This mutext was created and acquired before continuing the rest of the process. If the process can create the mutex and acquire it, then it is the first one runn...
I'm usually in the "shorter is better" camp. Your example is good: ObjectA a = getTheUser(session.getState().getAccount().getAccountNumber()); I would cringe if I saw that over four lines instead of one--I don't think it'd make it easier to read or understand. The way you presented it here, it's clear that yo...
You can buy a fairly inexpensive subscription to zipcodes with lat and long info here: [http://www.zipcodedownload.com/][1] [1]: http://www.zipcodedownload.com/
As others have stated, you have no control how programs process image files and therefore some programs may find the images valid others may not. However, there is a bigger issue here. Judging by your question, I'm deducing you're practicing "security through obscurity." It's widely considered a very bad practice....
Are Javascript strings immutable, do I need a "string builder" in js?
|javascript|string|
does javascript use immutable or mutable strings?
In my opinion in most cases DTO objects are not needed when dealing with LINQ. Generated LINQ classes can be easily tested. LINQ gives you ability to query your data from different sources using identical queries. It gives you ability to test your queries against lists of objects instead of real db.
Apparently this is a bug. Because they are adding it to potential rendering values, they just forgot to include it. I would recommend creating a bug on codeplex, and download the source and modify it for your needs.
I'm tempted to point you to the Design Patterns book for this generic question :p Seriously, I think the answer is no. You can't write extensible code by default, it will be both hard to write/extend and awfully inefficient (Mozilla started with the idea of being very extensible, used XPCOM everywhere, and now they ...
It is very common and generally a good practice for any build process to do a 'clean' before doing any significant build. This prevents any 'artifacts' from previous builds to taint the output. A clean is essentially what you are doing by deleting the working copy.
That looks correct: [http://dev.mysql.com/doc/refman/5.0/en/binary-log.html#option_mysqld_binlog-ignore-db][1]. According to that reference: > There are some --binlog-ignore-db > rules. Does the default database match > any of the --binlog-ignore-db rules? > > - Yes: Do not write the statement, and exit. ...
If you are using a compiled language such as C or C++, it may be a good idea to look at plugin support via scripting languages. Both Python and Lua are excellent languages that are used to script a large number of applications (Civ4 and blender use Python, Supreme Commander uses Lua, etc). If you are using C++, c...
Doing a full delete before or after your build is good practice. This means that there is no chance of your build environment picking up an out of date file. Your building exactly against what is in the repository. Deleting the working copy is possible as I have done it with Nant. In Nant I would have a clean s...
Doing a full delete before or after your build is good practice. This means that there is no chance of your build environment picking up an out of date file. Your building exactly against what is in the repository. Deleting the working copy is possible as I have done it with Nant. In Nant I would have a clean s...
I had the need to do this on one of my recent projects. Here is the scheme that I am using for generating the SQL: - Each component of the query is represented by an Object (which in my case is a Linq-to-Sql entity that maps to a table in the DB). So I have the following classes: Query, SelectColumn, Join, WhereCo...
You can if you setup an external tool pointing to MsBuild to build the solution with the multiple process flag /m. Scott Hanselman wrote a [nice post][1] on how to accomplish this, so I won't repeat what he has already done. [1]: http://www.hanselman.com/blog/FasterBuildsWithMSBuildUsingParallelBuildsAndMulti...
You're not the only one who has hit compatablity issues with tooltips between these DLLS. I too have had **nothing but trouble** with the new tooltips in the themable common controls. We have already been monkeying with mouse messages and active/deactivating the tips before adding the manifest and theming our a...
I've been using the jQuery [flot][1] graph library. It's open source and does axis/tick generation quite well. I'd suggest looking at it's code and pinching some ideas from there. [1]: http://code.google.com/p/flot/
Use regular expression to parse the relevant integer out and compare them.
What is your codebase? Java or C++? [![alt text][1]](http://www.eclipseplugincentral.com/Web_Links-index-req-viewlink-cid-678.html) eUML2 for Java is a powerful UML modeler designed for Java developper in Eclipse [1]: http://www.soyatec.com/euml2/images/product_euml2_110x80.png
MSDN answers your question: [Using Multiple Processors to Build Projects][1] [1]: http://msdn.microsoft.com/en-us/library/bb383805.aspx
This appears to be correct for your *nested* Foo tags: <NewDataSet> <Foo> <!-- Foo-Id: 0 --> <Bar>abcd</Bar> <Foo>efg</Foo> <!-- Foo-Id: 1, Parent-Id: 0 --> </Foo> <Foo> <!-- Foo-Id: 2 --> <Bar>hijk</Bar> <Foo>lmn</Foo> <!--...
Use [SetWindowLongPtr][1]. SetWindowLongPtr was created to replace SetWindowLong in these instances. It's LONG_PTR parameter allows you to store a pointer for both 32-bit or 64-bit compilations. LONG_PTR SetWindowLongPtr( HWND hWnd, int nIndex, LONG_PTR dwNewLong ); R...
[SetWindowLongPtr][1] was created to replace SetWindowLong in these instances. It's LONG_PTR parameter allows you to store a pointer for both 32-bit or 64-bit compilations. LONG_PTR SetWindowLongPtr( HWND hWnd, int nIndex, LONG_PTR dwNewLong ); Remember that the constant...
[SetWindowLongPtr][1] was created to replace [SetWindowLong][2] in these instances. It's LONG_PTR parameter allows you to store a pointer for 32-bit or 64-bit compilations. LONG_PTR SetWindowLongPtr( HWND hWnd, int nIndex, LONG_PTR dwNewLong ); Remember that the constant...
Make sure optimizations are disabled. Optimizations must be off when you debug else it can lead to very erratic behaviours like those.
Make sure you are debuging using the debug configuration, not the release one. Also make sure optimizations are disabled in debug configuration. Optimizations must be off when you debug else it can lead to very erratic behaviours like these. --- For C# projects, which I am assuming the question is about looking ...
As an alternative, you could try using something like [Terminals][1]. It allows you to have multiple remote desktop windows open at once all as tabs in the same window. Quite cool. Also, it is open source so you can change it's behavior if needed (although I don't believe it steals focus like a normal RDP session does)...
Is the standard Java 1.6 [javax.xml.parsers.DocumentBuilder][1] class thread safe? Is it safe to call the parse() method from several threads in parallel? The JavaDoc doesn't mention the issue, but the [JavaDoc for the same class][2] in Java 1.4 specifically says that it *isn't* meant to be concurrent; so can I assu...
You'll want to look at the [FileSystemWatcher][2] class. Here's an [example][3] of how you might use it. // monitor_fs.cpp // compile with: /clr #using <system.dll> using namespace System; using namespace System::IO; ref class FSEventHandler { public: void...
If you can't run a process when the change occurs, then there's not much you can do except scan the filesystem, and check the modification date/time. This requires you to store each file's last date/time, though, and compare. You can speed this up by using the [archive bit][1] (though it may mess up your backup sof...
Doing a full delete before or after your build is good practice. This means that there is no chance of your build environment picking up an out of date file. Your building exactly against what is in the repository. Deleting the working copy is possible as I have done it with Nant. In Nant I would have a clean s...
In our rails app I have a secret (unpulished url, restricted to a certain class of authenticated user) action which literally does this render :text => `svn info #{RAILS_ROOT}` (this is the equivalent of Process.Start( "svn info..." ) if you're only familiar with .net) If I'm wondering if the guy who manag...
Generate Insert SQL statements from a csv file
|sql|csv|firebird|
I need to import a csv file into Firebird and I've spent a couple of hours trying out some tools and none fit my needs. The main problem is that all the tools I've been trying like [EMS Data Import][1] and [Firebird Data Wizard][2] expect that my csv file contains all the information needed by my Table. I need to...
Well, if it's a CSV, and it this is a one time process, open up the file in Excel, and then write formulas to populate your data in any way you desire, and then write a simple Concat formula to construct your SQL, and then copy that formula for every row. You will get a large number of SQL statements which you can exec...
It's a bit crude - but for one off jobs, I sometimes use Excel. If you import the CSV file into Excel, you can create a formula which creates an INSERT statement by using string concatenation in the formula. So - if your CSV file has 3 columns that appear in columns A, B and C in Excel, you could write a formula li...
I wrote some C# code to scan the cipher and give me some stats back. Here are some interesting results: With a chunk size of 3, - There are 236 chunks. - There are 172 duplicates. - The 323 code shows up a whopping total of 29 times! - The 333 code shows up 11 times. - All othe...
If you are looking to do this from a Windows command line, there is a tool called [blat][1] that can be used from a CMD prompt. It is a bit more fun from PowerShell. Since PowerShell has access to the .NET Framework, you can use the classes from System.Net.Mail to send email. There is an example script on the [Pow...
FogBugz compared to OnTime
|fogbugz|issue-tracking|ontime|
Has anyone used both FogBugz and Axosoft's OnTime and care to offer an opinion? AxoSoft has a big [feature comparison chart][1] but I'm also interested in more subjective thoughts on things like ease of use and stability. [1]: http://www.axosoft.com/products/ontime_competition.aspx
|bug-tracking|fogbugz|ontime|
I have done this using the MAPISendMail function and several internal classes to wrap some of the other MAPI related structures. As long as this is the only use, it is possible although not trivial to do safely as it requires a very close attention to the various unmanaged data types and memory allocation/deallocation ...
Huge Web App With Memory Leak in IE 6
|memory|internet-explorer-6|leak|
Run [jconsole][1]. It is included in the Java SDK and is run from the command line. I'm not sure what OS you are using, but on windows you can just pass it the PID of the java process. It should tell you exactly what thread is causing the problem. Our, you can use a commercial profiler like YourKit or any number of...
Run [jconsole][1]. It is included in the Java SDK and is run from the command line. I'm not sure what OS you are using, but on windows you can just pass it the PID of the java process. It should help you find the thread that is causing the problem. Or, you can use a commercial profiler like YourKit or any number of...
JavaScript strings are indeed immutable.
> Mnebuerquo wrote: > >> Also, I had source code access to the >> process I was trying to start. If you >> can not modify the code, adding the >> mutex is obviously not an option. I don't have source code access to the process I want to run. I have ended up using the proccess MainWindowHandle to switch to...
Strings in Javascript are immutable
If you want to test private methods of a legacy application where you can't change the code, one option is [jMockit][1], which will allow you to create mocks to an object even when they're private to the class. [1]: https://jmockit.dev.java.net/