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 comparison? |
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)
return -1;
});
</pre> |
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, cool, learned something.
**]**
|
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 "<e1/>" is equivalent to "<e1></e1>" and can be configured to ignore or include whitespace.
[1]: http://xmlunit.sourceforge.net/ |
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 is a sample body with html in it. <b>This is bold</b> <font color=#336699>This is blue</font>";
mail.IsBodyHtml = true;
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
From http://www.systemnetmail.com/faq/3.1.2.aspx |
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 need to give certain user accounts read/write access to certain folders (specifically, giving the ASPNET user read/write to a logging folder).
I'm pretty sure we could do this with WMI or scripts (we use Sysinternals PSTools in a few places for deployment), but I'm not sure what is the best way to do it. The deployment system is written in C# 2.0, the dev environment is a VM with Windows XP. The VM is on the same domain as the deployment system and I have administrator access. |
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 need to give certain user accounts read/write access to certain folders (specifically, giving the ASPNET user read/write to a logging folder).
I'm pretty sure we could do this with WMI or scripts (we use Sysinternals PSTools in a few places for deployment), but I'm not sure what is the best way to do it. The deployment system is written in C# 2.0, the dev environment is a VM with Windows XP. The VM is on the same domain as the deployment system and I have administrator access.
Edit: There's not really a right answer for this, so I'm hesitant to mark an answer as accepted. |
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 by more or less rewriting almost everything from scratch, possibly using the old code as a guide.
Migrating from as2 -> as3 in terms of knowledge is fairly simple though. If you know object oriented as2, moving on to as3 won't be a problem at all.
You still don't have to use mxml for your UI unless you specifically want to. Mxml just provides a quick way to build the UI (etc) but if you want to do it yourself with actionscript there's nothing stopping you (this would also probably be easier if you already have that UI in as2 code). Flex (Builder) is just a quick way to do stuff you may not want to do yourself, such as building the UI and binding data but essentially it's just creating a part of the .swf for you -- there's no magic to it ;) |
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).txt"
Also, you may not want to redirect to $(pwd).txt. In the example above, you would be redirecting the output to the file "/home/user/music/artist name.txt" |
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 will fire in 8000ms from NOW.
I don't see a way to do this using the utils timer, as if you call cancel() you cannot schedule it again.
The only way I've come close to replicating this behavior is by using javax.swing.Timer and involves stopping the origional timer, and creating a new one. i.e.:
timer.stop();
timer = new Timer(8000, ActionListener);
timer.start();
Is there an easier way?? |
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 Y seconds instead, then I want to be able to tell the timer to reset its time so that the event occurs in Y seconds.
E.g. the timer should be able to do something like:
Timer timer = new Timer();
timer.schedule(timerTask, 5000); //Timer starts in 5000 ms (X)
//At some point between 0 and 5000 ms...
setNewTime(timer, 8000); //timerTask will fire in 8000ms from NOW (Y).
I don't see a way to do this using the utils timer, as if you call cancel() you cannot schedule it again.
The only way I've come close to replicating this behavior is by using javax.swing.Timer and involves stopping the origional timer, and creating a new one. i.e.:
timer.stop();
timer = new Timer(8000, ActionListener);
timer.start();
Is there an easier way?? |
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 files, but editing them by hand is a daunting task. On Linux there is [cdargs][1] or [shell bookmarks][2] but I haven't found something on windows.
[1]: http://www.skamphausen.de/software/cdargs/
[2]: http://kore-nordmann.de/blog/shell_bookmarks.html |
|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%%1.vbs
if exist %BookMarkFolder%%1.URL start %BookMarkFolder%%1.URL
Any shortcuts, batch files, VBS Scripts or Internet shortcuts you put in your bookmark folder (in this case "c:\data\cline\bookmarks\" can then be opened / accessed by typing "go *bookmarkname*"
e.g. I have a bookmark called "stack.url". Typing go stack takes me straight to this page.
You may also want to investigate [Launchy][1]
[1]: http://www.launchy.net/
|
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.
Raymond Chen where are you! |
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 running. If another process already controls the mutex, then the one which fails is not the first so it exits immediately.
I was just trying to prevent a second instance from running, due to dependencies on specific hardware interfaces. Depending on what you need with that "switch to" line, you might need a more specific solution such as a process id or handle.
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'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 you're digging for a single object. This isn't better:
obja State = session.getState();
objb Account = State.getAccount();
objc AccountNumber = Account.getAccountNumber();
ObjectA a = getTheUser(AccountNumber);
This is a compromise:
objb Account = session.getState().getAccount();
ObjectA a = getTheUser(Account.getAccountNumber());
but I still prefer the single line expression. Here's an anecdotal reason: it's difficult for me to reread and error-check the 4-liner right now for dumb typos; the single line doesn't have this problem because there are simply fewer characters. |
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. Use Google to find a plethora of articles about the topic. |
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 realized it was a mistake and started to remove it where it doesn't make sense).
what makes sense to do is to identify the pieces of your system that can be meaningfully extended and support a proper API for these cases (e.g. language support plug-ins in an editor). You'd use the relevant patterns, but the specific implementation depends on your platform/language choice.
IMO, it also helps to use a dynamic language - makes it possible to tweak the core code at run time (when absolutely necessary). I appreciated that Mozilla's extensibility works that way when writing Firefox extensions. |
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.
> - No: Write the query and exit.
Since you only have ignore commands, all queries will be written to the log as long as the default (active) database doesn't match one of the ignored databases.
[1]: http://dev.mysql.com/doc/refman/5.0/en/binary-log.html#option_mysqld_binlog-ignore-db |
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++, check out the boost python library. Otherwise, python ships with headers that can be used in C, and does a fairly good job documenting the C/python API. The documentation seemed less complete for Lua, but I may not have been looking hard enough. Either way, you can offer a fairly solid scripting platform without a terrible amount of work. It still isn't trivial, but it provides you with a very good base to work from. |
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 script in its own folder outwith the one I want to delete and would then invoke it from CC.net.
I assume this should also be possible with a batch file |
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 script in its own folder outwith the one I want to delete and would then invoke it from CC.net.
I assume this should also be possible with a batch file
@pauldoo
I prefer my CI server to do a full delete as I don't want any surprise when I go to do a release build, which should always be done from a clean state. But it should be able to handle both, no reason why not |
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, WhereCondition, Sort, GroupBy. Each of these classes contains all details relating to that component of the query.
- The last five classes are all related to a Query object. So the Query object itself has collections of each class.
- Each class has a method that can generate the SQL for the part of the query that it represents. So creating the overall query ends up calling Query.GenerateQuery() which in turn enumerates through all of the sub-collections and calls their respective GenerateQuery() methods
It is still a bit complicated, but in the end you know where the SQL generation for each individual part of the query originates (and I don't think that there are any big switch statements). And don't forget to use StringBuilder. |
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/FasterBuildsWithMSBuildUsingParallelBuildsAndMulticoreCPUs.aspx |
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 application - so it sounds like what your doing isn't too crazy.
We're still living with problems with TTN_NEEDTEXT messages being send constantly as the mouse moves (not just when hovering), positioning problems with large tips (maybe not something new), and odd unicode messages being sent instead of the ANSI versions (which I plan to post as a question at some point).
I've been working on a small scratch program on the side trying to come up with a more stable tooltip system. One where I handle showing (including detecting the hover) and hiding the tip. I could post some of the code if you care to see it. |
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> <!-- Foo-Id: 3, Parent-Id: 2 -->
</Foo>
</NewDataSet>
So this correctly becomes 4 records in your result, with a parent-child key of "Foo-Id-0"
Try:
<NewDataSet>
<Rec> <!-- Rec-Id: 0 -->
<Bar>abcd</Bar>
<Foo>efg</Foo>
</Rec>
<Rec> <!-- Rec-Id: 1 -->
<Bar>hijk</Bar>
<Foo>lmn</Foo>
</Rec>
</NewDataSet>
Which should result in:
Bar Foo Rec-Id
abcd efg 0
hijk lmn 1
|
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
);
Remember that the constants have changed too, so usage looks like:
SetWindowLongPtr(hWnd, GWLP_USERDATA, this);
[1]: http://msdn.microsoft.com/en-us/library/ms644898%28VS.85%29.aspx |
[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 constants have changed too, so usage now looks like:
SetWindowLongPtr(hWnd, GWLP_USERDATA, this);
Also don't forget that now to retrieve the pointer, you must use [GetWindowLongPtr][2]:
LONG_PTR GetWindowLongPtr(
HWND hWnd,
int nIndex
);
And usage would look like (again, with changed constants):
LONG_PTR lpUserData = GetWindowLongPtr(HWND hWnd, GWLP_USERDATA);
MyObject* pMyObject = (MyObject*)lpUserData;
[1]: http://msdn.microsoft.com/en-us/library/ms644898%28VS.85%29.aspx
[2]: http://msdn.microsoft.com/en-us/library/ms633585%28VS.85%29.aspx |
[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 constants have changed too, so usage now looks like:
SetWindowLongPtr(hWnd, GWLP_USERDATA, this);
Also don't forget that now to retrieve the pointer, you must use [GetWindowLongPtr][3]:
LONG_PTR GetWindowLongPtr(
HWND hWnd,
int nIndex
);
And usage would look like (again, with changed constants):
LONG_PTR lpUserData = GetWindowLongPtr(hWnd, GWLP_USERDATA);
MyObject* pMyObject = (MyObject*)lpUserData;
[1]: http://msdn.microsoft.com/en-us/library/ms644898%28VS.85%29.aspx
[2]: http://msdn.microsoft.com/en-us/library/ms633591%28VS.85%29.aspx
[3]: http://msdn.microsoft.com/en-us/library/ms633585%28VS.85%29.aspx |
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 at the tags, the optimization option would be located in the "Build" tab of "Project > Properties..." Last option of "General" it's called "Optimize Code". |
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).
![Terminals Screenshot][2]
[1]: http://www.codeplex.com/Terminals
[2]: http://farm2.static.flickr.com/1184/1473284484_045bc95644.jpg?v=0 |
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 assume that in 1.6 it is?
The reason is that I have several million tasks running in an ExecutorService, and it seems expensive to call DocumentBuilderFactory.newDocumentBuilder() every time.
[1]: http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilder.html
[2]: http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilder.html |
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 OnChanged (Object^ source, FileSystemEventArgs^ e)
{
Console::WriteLine("File: {0} {1}",
e->FullPath, e->ChangeType);
}
void OnRenamed(Object^ source, RenamedEventArgs^ e)
{
Console::WriteLine("File: {0} renamed to {1}",
e->OldFullPath, e->FullPath);
}
};
int main()
{
array<String^>^ args = Environment::GetCommandLineArgs();
if(args->Length < 2)
{
Console::WriteLine("Usage: Watcher.exe <directory>");
return -1;
}
FileSystemWatcher^ fsWatcher = gcnew FileSystemWatcher( );
fsWatcher->Path = args[1];
fsWatcher->NotifyFilter = static_cast<NotifyFilters>
(NotifyFilters::FileName |
NotifyFilters::Attributes |
NotifyFilters::LastAccess |
NotifyFilters::LastWrite |
NotifyFilters::Security |
NotifyFilters::Size );
FSEventHandler^ handler = gcnew FSEventHandler();
fsWatcher->Changed += gcnew FileSystemEventHandler(
handler, &FSEventHandler::OnChanged);
fsWatcher->Created += gcnew FileSystemEventHandler(
handler, &FSEventHandler::OnChanged);
fsWatcher->Deleted += gcnew FileSystemEventHandler(
handler, &FSEventHandler::OnChanged);
fsWatcher->Renamed += gcnew RenamedEventHandler(
handler, &FSEventHandler::OnRenamed);
fsWatcher->EnableRaisingEvents = true;
Console::WriteLine("Press Enter to quit the sample.");
Console::ReadLine( );
}
It also exists in [.NET][1] (for future searchers of this type of problem)
-Adam
[1]: http://articles.techrepublic.com.com/5100-10878_11-6165137.html
[2]: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(VS.80).aspx
[3]: http://msdn.microsoft.com/en-us/library/chzww271(VS.80).aspx |
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 software, so proceed carefully).
> An archive bit is a file attribute
> present in many computer file systems,
> notably FAT, FAT32, and NTFS. The
> purpose of an archive bit is to track
> incremental changes to files for the
> purpose of backup, also called
> archiving.
>
> As the archive bit is a binary bit, it
> is either 1 or 0, or in this case more
> frequently called set (1) and clear
> (0). The operating system sets the
> archive bit any time a file is
> created, moved, renamed, or otherwise
> modified in any way. The archive bit
> therefore represents one of two
> states: "changed" and "not changed"
> since the last backup.
>
> Archive bits are not affected by
> simply reading a file. When a file is
> copied, the original file's archive
> bit is unaffected, however the copy's
> archive bit will be set at the time
> the copy is made.
So the process would be:
1. Clear the archive bit on all the files
1. Let the file system change over time
1. Scan all the files - any with the archive bit set have changed
This will eliminate the need for your program to keep state, and since you're only going over the directory entries (where the bit is stored) and they are clustered, it should be very, very fast.
If you can run a process during the changes, however, then you'll want to look at the [FileSystemWatcher][2] class. Here's an [example][3] of how you might use it.
It also exists in [.NET][4] (for future searchers of this type of problem)
Perhaps you can leave a process running on the machine watching for changes and creating a file for you to read later.
-Adam
[1]: http://en.wikipedia.org/wiki/Archive_bit
[2]: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(VS.80).aspx
[3]: http://msdn.microsoft.com/en-us/library/chzww271(VS.80).aspx
[4]: http://articles.techrepublic.com.com/5100-10878_11-6165137.html |
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 script in its own folder outwith the one I want to delete and would then invoke it from CC.net.
I assume this should also be possible with a batch file. Take a look at the rmdir command http://www.computerhope.com/rmdirhlp.htm
@pauldoo
I prefer my CI server to do a full delete as I don't want any surprise when I go to do a release build, which should always be done from a clean state. But it should be able to handle both, no reason why not |
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 manages the servers has updated the site recently, I can hit this URL, and have a look |
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 write some custom SQL in the insert statement, for example, I have a cvs file with the city name, but as my database already has all the cities in another table (normalized), I need to write a subselect in the insert statement to lookup for the city and write its ID, also I have a stored procedure to cread GUIDS.
My Insert statement would be something like this:
INSERT INTO PERSON (ID, NAME, CITY_ID) VALUES((SELECT NEW_GUID FROM CREATE_GUID), :NAME, (SELECT CITY_ID FROM CITY WHERE NAME = :CITY_NAME)
I know that it is very easy to write an application to do this, but I don't like to reinvent the wheel, and I'm sure that there are some tools out there to do it.
Can you guys give me some advice?
[1]: http://www.sqlmanager.net/products/ibfb/dataimport
[2]: http://www.sqlmaestro.com/products/firebird/datawizard/help/06_01_05_csv/ |
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 execute anywhere you want. |
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 like...
="INSERT INTO MyTable (Col1, Col2, Col3) VALUES (" & A1 & ", " & B1 & ", " & C1 & ")"
Then you can replicate the formula down all of your rows, and copy and paste the answer into a text file to run against your database.
Like I say - it's crude - but it can be quite a 'quick and dirty' way of getting a job done! |
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 other codes show up 7 times or less.
- 35 chunks start with a 2.
- 200 chunks start with a 3. (Interesting!)
- 1 chunk starts with a 4.
- Despite the cipher containing 2s, 3s, 4s, 5s, 6s, 7s, 8s, and 9s, chunks only start with 2 and 3, except the 1 chunk that starts with 4.
- There are no 0s.
- There are no 1s.
- There are 115 2s.
- There are 293 3s.
- There are 56 4s.
- There are 38 5s.
- There are 49 6s.
- There are 52 7s.
- There are 63 8s.
- There are 42 9s.
I'd describe the 323 appearance count highly irregular. I'd also suggest that the fact that all of the chunks start with either 3 or 2 (barring the 1 appearance of a 4 chunk) is also highly irregular.
I've ran the same analysis using chunks of 2, 4, and 8, and the results look more or less random. At this point, I'm leaning towards a 3 chunk. |
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 [PowerShell Community Script Repository][2].
[1]: http://www.blat.net/
[2]: http://poshcode.org/180 |
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 and GC. While it still isn't supported, I am using this in production code (although it hasn't shipped yet).
When I asked Matt Stehle about this, the response I received was:
> I really don't know of a much better way to do this and any issues you ran into here would be probably reproducible in a supported scenario (i.e. VB6 or unmanaged C++). Just know that if you ever ran into a scenario were an issue was caused specifically by this function being called from .NET that we wouldn't have any other recommendation for you then to not use .NET.
Not exactly a blessing on using it, but also not saying there are any other options to actually do this from managed code. |
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 other profilers.
[1]: http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html |
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 other profilers.
[1]: http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html |
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 the process once I have found it is alread running:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
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/ |