instruction stringlengths 0 30k ⌀ |
|---|
Using git to grep through a file's previous versions? |
|git| |
Is there a command that would allow me to check if the string "xyz" was ever in file foo.c in the repository and print which revisions they were found in?
|
I had this problem as well. I was under heavy time pressure (aren't we all) and I went with option #1, and only updated rows that changed.
If you swap item 1 with item 10, just do two updates to update the order numbers of item 1 and item 10. I know it is algorithmically simple, and it is O(n) worst case, but that w... |
lining up function parameter lists with vim |
|vim|editor|whitespace| |
When defining or calling functions with enough arguments to span multiple lines, I want vim to line them up. For example,
` def myfunction(arg1, arg2, arg, ...`
`_______________argsN-1, argN)`
I'm using undrescores because I don't know how to make it work with markdown either, but the idea is for argsN-1 to... |
Make sure the z-index of the auto-complete div is a larger number than the divs that constitute the rounded corner box. Microsoft puts the z-index of the top elements to 20000 or 100000 I believe. Might be wise to do the same. |
FPDF has always worked out for me. There is a lot of robust functionality in there, and you just gotta keep at it to find it.
The ImageEPS class extension is VERY useful for making things print ready, though it is not without its issues (as its a rather old extension and doesn't support .ai and .eps files very we... |
I saw your request on the F# mailing list. Hope I can help.
You could use type extension and reflection to allow this. We simple extend the generic list type with the pluck function. Then we can use pluck() on any list. An unknown property will return a list with the error string as its only contents.
<pre>
type ... |
I saw your request on the F# mailing list. Hope I can help.
You could use type extension and reflection to allow this. We simple extend the generic list type with the pluck function. Then we can use pluck() on any list. An unknown property will return a list with the error string as its only contents.
<pre>type ... |
I saw your request on the F# mailing list. Hope I can help.
You could use type extension and reflection to allow this. We simple extend the generic list type with the pluck function. Then we can use pluck() on any list. An unknown property will return a list with the error string as its only contents.
NOTE: You ... |
As suggested [here][1], I could check out the [CERT Database][2].
[1]: http://stackoverflow.com/questions/87393/what-are-the-major-vulnerabilities-of-windows-2003-iis
[2]: http://www.kb.cert.org/vuls/ |
If you are wondering why you should use windbg over Visual Studio, then you need to read [Advanced Windows Debugging][1]. Any time you need to debug a truly ugly problem windbg has better technology to do it with than Visual Studio. Windbg has a more powerful scripting language and allows you to write DLLs to automat... |
If you are wondering why you should use windbg over Visual Studio, then you need to read [Advanced Windows Debugging][1]. Any time you need to debug a truly ugly problem windbg has better technology to do it with than Visual Studio. Windbg has a more powerful scripting language and allows you to write DLLs to automat... |
"netstat -natp" is what I always use. |
My recommendation would be to keep this information in configuration files for the application. Even better would be to inject the appropriate values for a given environment into the configuration during the build process, assuming your build process has some kind of macro-replacement functionality. This way you can ... |
If you have a smallish number of possible strings, you can assign an index to each and use bitmaps. That way a simple bitwise and will tell you if there's overlap.
If that's not practical, your inverted index setup is probably going to be hard to match for speed, especially if you only have to build it once. (does t... |
Trialware/licensing strategies |
|licensing|trialware| |
I wrote a utility for photographers that I plan to sell online pretty cheap ($10). I'd like to allow the user to try the software out for a week or so before asking for a license. Since this is a personal project and the software is not very expensive, I don't think that purchasing the services of professional licensin... |
I agree with a previous poster that SQL Trace and tkprof are a good place to start. I also highly recommend the book [Optimizing Oracle Performance][1], which discusses similar tools for tracing execution and analyzing the output.
[1]: http://www.amazon.com/Optimizing-Oracle-Performance-Cary-Millsap/dp/05960052... |
You do realize that [ is an alias (often a link, symbolic or hard) for /usr/bin/test, right? So perhaps the actual problem is different versions of /usr/bin/test ? |
You do realize that [ is an alias (often a link, symbolic or hard) for /usr/bin/test, right? So perhaps the actual problem is different versions of /usr/bin/test ?
OTOH, ksh is likely overriding it with an internal alias of some kind. Maybe there's a way to get it to not do that? or maybe you can explicitly alias... |
You do realize that [ is an alias (often a link, symbolic or hard) for /usr/bin/test, right? So perhaps the actual problem is different versions of /usr/bin/test ?
OTOH, ksh overrides it with a builtin. Maybe there's a way to get it to not do that? or maybe you can explicitly alias [ to /usr/bin/test, if /usr/bin... |
public static void Main()
{
List<List<string>> tuples = new List<List<string>>();
string [] tuple = {"one", "four"};
tuples.Add(new List<string>(tuple));
tuple = new string [] {"one"};
tuples.Add(new List<string>(tuple));
tuple = new string [] {"three"};
tuples.Add(new List<... |
Suppose I have a collection (be it an array, generic List, or whatever is the **fastest** solution to this problem) of a certain class, let's call it `ClassFoo`:
class ClassFoo
{
public string bar;
public float baz;
//... etc ...
}
Now I want to obtain as fast as possible all the ... |
Suppose I have a collection (be it an array, generic List, or whatever is the **fastest** solution to this problem) of a certain class, let's call it `ClassFoo`:
class ClassFoo
{
public string word;
public float score;
//... etc ...
}
Now I want to obtain as fast as possible all t... |
Fastest way to find objects from a collection matched by condition on string member |
|c#|string|arrays|collections|performance| |
Suppose I have a collection (be it an array, generic List, or whatever is the **fastest** solution to this problem) of a certain class, let's call it `ClassFoo`:
class ClassFoo
{
public string word;
public float score;
//... etc ...
}
Assume there's going to be like 50.000 items i... |
With the constraint that the condition clause can be "anything", then you're limited to scanning the entire list and applying the condition.
If there are limitations on the condition clause, then you can look at organizing the data to more efficiently handle the queries.
For example, the code sample with the "byF... |
I saw your request on the F# mailing list. Hope I can help.
You could use type extension and reflection to allow this. We simple extend the generic list type with the pluck function. Then we can use pluck() on any list. An unknown property will return a list with the error string as its only contents.
NOTE: You ... |
I saw your request on the F# mailing list. Hope I can help.
You could use type extension and reflection to allow this. We simple extend the generic list type with the pluck function. Then we can use pluck() on any list. An unknown property will return a list with the error string as its only contents.
type... |
Why is using Javascript eval function a bad idea? |
|javascript|performance|security|eval| |
The eval function is a powerful and easy way to dynamically generate code so what are the caveats? |
I think maybe you're looking for a spline algorithm.
Here is a spline tutorial, which you might find helpfull:
[http://www.doc.ic.ac.uk/~dfg/AndysSplineTutorial/index.html]
The subject is also covered in most books on graphics programming.
Cheers.
|
|web-services| |
I recently heart from WSDL.Exe, but did not find a download link.
Anybody know the link? |
|web-services|.net| |
|.net|web-services|wsdl|sdk| |
@rslite is right, .NET doesn't give such filtering out-of-box, but it's not hard to implement:
static IEnumerable<string> GetNonSystemDirs(string path)
{
var dirs = from d in Directory.GetDirectories(path)
let inf = new DirectoryInfo(d)
where (inf.Attributes ... |
Quick hack: Delete the directory, go one level up, and run svn update. |
Is there a better way to explain the behaviour differences between structs and classes in .net? |
|c#|.net|junior-programmer| |
The code below shows a sample that I've used recently to explain the different behaviour of structs and classes to someone brand new to development. Is there a better way of doing so? (Yes - the code uses public fields - that's purely for brevity)
namespace StructsVsClasses
{
class Program
... |
Namespaces have nothing to do with assemblies - any mapping between a namespace and the classes in an assembly is purely due to a naming convention (or coincidence). |
I wrote the engine for my personal blog in maybe 6 hours during one weekend, with comments, labels, simplified markup, sitemap, feeds and so on. It was great fun and I learned a lot of Django.
If you decide to go this way, look at [generic views](http://docs.djangoproject.com/en/dev/ref/generic-views/#date-based-gen... |
For inter-process mutexes you want these calls:
> [CreateMutex][5]
> [WaitForSingleObject][6]
> [ReleaseMutex][7]
> [CloseHandle][8]
These are the underlying Win32 API calls that CMutex is a wrapper around.
For in-process only mutexes you can also use these calls, which are faster:
> [InitializeCri... |
In a sense, you can consider "pointers" to be one of the two most fundamental types in software - the other being "values" (or "data") - that exist in a huge block of uniquely-addressable memory locations. Think about it. Objects and structs etc don't really exist in memory, only values and pointers do. In fact, a poin... |
Thanks everyone for useful commments. In the end the simplest solution was to limit the amount of data being stored, implementing code that adjusts the data according to how large the store is, and fetching data from the server on demand if its not stored locally. Thats interesting that the limit is increased in OS 4.5... |
Chris Anderson says in the Framework Design Guidelines book:
> [T]his is just about a pattern. By having event arguments packaged in a class you get better versioning semantics. By having a common pattern `(sender, e)` it is easily learned as the signature for all events.
There are situations mostly involving int... |
Yeah, don't say "inline" because that means something specific in other languages. Most likely the performance difference is either zero or so small it doesn't matter, it's just a matter of preference. Do you want to write it out in separate statements to make it more clear, or write it all on one line to type it out q... |
You cannot change the value of your argument (arr) if it's not passed in by reference (&). In general, you would want to return the pointer, so your method should be:
arr=foo();
It's bad juju to try to reassign arguments; I don't recommend the (&) solution. |
Compartment items not displayed in DSL diagram |
|visual-studio|diagram|dsl| |
<p>OK, so things have progressed significantly with my DSL since I asked <a href="http://stackoverflow.com/questions/82776/how-do-i-reference-a-diagram-in-a-dsl-t4-template">this question</a> a few days ago.</p>
<p>As soon as I've refactored my code, I'll post my own answer to that one, but for now, I'm having another... |
Those two lines would compile down to the same thing. I would pick whichever one is easier for you read. Inlining normally refers to something [a bit different][1].
[1]: http://en.wikipedia.org/wiki/Inline_function |
The structure is still created, you just do not have a reference for it.
|
As far as I know, there a four frameworks available for unit testing with .NET these days
* NUnit
* MbUnit
* MSTest
* xUnit
NUnit has always been out in front but the gap has closed in the last year or so. I still prefer NUnit myself, especially as they added a fluent interface a while back which makes tests v... |
I for one am not happy with them. I don't think they have a place in the constructor, or MS should got back and refactor them to allow you to use them in a private fasion. If I construct an object I want to pass in some PRIVATE data. I want it set from the outside world once and that's it. With Object Initializers ... |
Notice that unlike conventional "per site" logins, OpenID gives you an identity that potentially transcends individual sites. Better yet, this identity is even a URI so its perfect for using with RDF to exchange or query arbitrary metadata about the identity.
You can do a few things with an OpenID that you can't do ... |
use: ClientScript.RegisterClientScriptInclude(key, url);
|
make a javascript function that will collect the pieces of form data, and then sends that data to an ASHX handler. the ASHX handler will do some work, and can reply with a response.
This is an example I made that calls a database to populate a grid using AJAX calls. There are better libraries for doing AJAX (prototy... |
Subclipse used to prompt but users complained. We did not want to add two update options. The easiest way to do it is just Team > Switch and do not change the URL. Switch and update are the same code paths within Subversion. If you do not change the URL it is just behaving like update and the Switch dialog exposes a... |
It is synchronous from the point of view of the component generating the event. The control's thread of execution will call out into the receivers code and things are out of its control at that point.
Clients receiving the events must make sure they return quickly. If they need to do some significant amount of wor... |
In implementation 1 the clsObject will not get instantiated until it is used. If it is never used, then the clsObject.Class_Initialize event will never fire.
In implementation 2, the clsObject instance will be created at the same time that the clsMyClass is instantiated. The clsObject.Class_Initialize will alway... |
Ant OS-specific copy task |
|java|ant|copy| |
I have an Ant script that performs a copy operation using the [copy task][1]. It was written for Windows and has a hardcoded C:\ path as the todir argument. I see the exec task has an OS argument, is there a similar way to branch a copy based on OS?
[1]: http://ant.apache.org/manual/CoreTasks/copy.html |
I believe it's because it can execute any javascript function from a string. Using it makes it easier for people to inject rogue code into the application. |
Its a lot harder to maintain and debug mainly. Its like a goto - you can use it, but it makes it harder to find problems and on the people how may need to make changes later. |
JSF selectItem label formatting |
Thanks everyone for useful commments. In the end the simplest solution was to limit the amount of data being stored, implementing code that adjusts the data according to how large the store is, and fetching data from the server on demand if its not stored locally. Thats interesting that the limit is increased in OS 4.6... |
First off, use cookie based only unless you have a very specific good business reason not to. I had a client that insisted on url based sessions only for a project. very insecure and a pain to work with.
One good idea is to regenerate the session on each request. this makes hijack much less likely.
Another thing ... |
First off, use cookie based only unless you have a very specific good business reason not to. I had a client that insisted on url based sessions only for a project. very insecure and a pain to work with.
One good idea is to regenerate the session on each request. this makes hijack much less likely. For example.
... |
C++: Step 1: ExtractIconEx. Step 2: ??? Step 3: SetMenuItemBitmaps |
|c++|winapi|icons| |
I'm experimenting with adding icons to a shell extension. I have this code (sanitized for easy reading), which works:
InsertMenu(hmenu, index, MF_POPUP|MF_BYPOSITION, (UINT)hParentMenu, namestring);
The next step is this code:
HICON hIconLarge, hIconSmall;
ICONINFO oIconInfo;
ExtractIconEx("c... |
I'm experimenting with adding icons to a shell extension. I have this code (sanitized for easy reading), which works:
InsertMenu(hmenu, index, MF_POPUP|MF_BYPOSITION, (UINT)hParentMenu, namestring);
The next step is this code:
HICON hIconLarge, hIconSmall;
ICONINFO oIconInfo;
ExtractIconEx("c... |
According to Benchmark, the second is slightly slower. Possibly it has something to do with the condition, but here's results for a very simple case:
<pre>
<code>
use Benchmark;
timethese(10000000, {
'if' => '$m=5;if($m > 4){my $i=0;}',
'and' => '$m=5; $m > 4 and do {my $i =0}',
});
</code>... |
The "'Boolean' in the middle of a string" part sounds a bit unlikely, I'd check first if there is any occurrence of it in the code with something like
m/"[^"]*Boolean[^"]*"/
And if there is none or a few, just ignore that case. |
The constant 'year' is wrong. It expects just 'y'.
<xsl:variable name="now" select="umbraco.library:CurrentDate()"/>
<xsl:value-of select="umbraco.library:DateAdd($now, 'y', 1)"/>
|
One way you could do this would be to create an in memory table and insert rows into it when you catch an exception. You would then re-raise the exception and the next function up the chain would then have a chance to handle the exception or also log the exception to the in memory table. It's nasty, but unfortunately... |
Well, .NET has never been able to fully counter the inertia of Visual Basic 6 (I still see a few shops here and there who are just *beginning* to shift to .NET), so one has to consider the inertia of ASP.NET Webforms and how it is deployed everywhere at the moment.
ASP.NET MVC will reach wide adoption, no doubt, but... |
According to [this page][1], GDB is searching backward in the object code to find the beginning of a function, and it is hitting an imposed limit. If you can set the fence post limit to 0 or increase it, you might avoid the error, but it will take longer to run.
[1]: http://www.delorie.com/gnu/docs/gdb/gdb_179.htm... |
Get list of XML attribute values in Python |
|python|xml|xpath| |
I need to get a list of attribute values from child elements in Python.
It's easiest to explain with an example.
Given some XML like this:
<elements>
<parent name="CategoryA">
<child value="a1"/>
<child value="a2"/>
<child value="a3"/>
</parent>
... |
I need to get a list of attribute values from child elements in Python.
It's easiest to explain with an example.
Given some XML like this:
<elements>
<parent name="CategoryA">
<child value="a1"/>
<child value="a2"/>
<child value="a3"/>
</parent>
... |
Uploadeds files will be accessible through the $_FILE global variable, other parameters will be accessible trough the $_GET global variable. |
Not sure about code coverage itself, but you can find an [XML debugger and profiler from Oxygen][1] which might help you out.
[1]: http://www.oxygenxml.com/xslt_debugger.html |
Personally, I chose a consistent approach across languages: I do `if (var)` (or equivalent) only if var is declared as boolean (or defined as such, in C we don't have a specific type). I even prefix these variables with a `b` (so it would be `bVar` actually) to be sure I won't accidentally use another type here.
I d... |
Spawning an interactive telnet session from a shell script |
|bash|telnet| |
I'm trying to write a script to allow me to log in to a console servers 48 ports so that I can quickly determine what devices are connected to each serial line.
Essentially I want to be able to have a script that, given a list of hosts/ports, telnets to the first device in the list and leaves me in interactive mode ... |
Can you record audio with a Java Midlet on a Nokia phone (N80/N95) without the JVM leaking memory? |
|java|audio|memory-leaks|midlet|nokia| |
I would like to repeatedly capture snippets of audio on a Nokia mobile phone with a Java Midlet. My current experience is that using the code in Sun's documentation (see: <http://java.sun.com/javame/reference/apis/jsr135/javax/microedition/media/control/RecordControl.html>) and wrapping this in a "while(true)" loop wor... |