instruction
stringlengths
0
30k
I sometimes need to modify OSS code or other peoples' code (usually C-based, but sometimes C++/Java) and find myself "grep"ing headers for types, function declarations etc. as I follow code flow and try to understand the system. Is there a good tool that exists to aid in code browsing. I'd love to be able to click on...
You could derive a class from TreeView and then add a singleton static property. That way you are effectively adding a global field that references the single instance of the class but have the benefit of it being namespace scoped to that class.
You can't get anything better than [SourceInsight][1]. [1]: http://www.sourceinsight.com
I've heard amazing things about [OpenGrok][1]. I know another team at my place of employ uses it and they find it very handly. From its web site: > OpenGrok is a fast and usable source > code search and cross reference > engine. It helps you search, > cross-reference and navigate your > source tree. It can under...
Why would you need to do away with globals? I understand the stigma of globals being bad and all, but sometimes just having a global data structure with all elements is the fastest solution. You make a trade-off: code clarity and less future problems for performance. That's the meaning being 'Don't optimize yet'....
Below is my current char* to hex string function. I wrote it as an exercise in bit manipulation. It takes ~7ms on a AMD Athlon MP 2800+ to hexify a 10 million byte array. Is there any trick or other way that I am missing? How can I make this faster? Compiled with -O3 in g++ static const char _hex2asciiU_...
Here is a simple approach: It's in C# (I don't have VB compiler at the moment) public Form1() { InitializeComponent(); Hide(); } private void Form1_Load(object sender, EventArgs e) { Thread.Sleep(10000); Show(); } Correct solution is to not cre...
Here is a simple approach: It's in C# (I don't have VB compiler at the moment) public Form1() { InitializeComponent(); Hide(); // Also Visible = false can be used } private void Form1_Load(object sender, EventArgs e) { Thread.Sleep(10000); Show(); // O...
When you have some repetitive action to take Macros are usually faster than regex. Just type q[0-9a-z] in normal mode Many people use qq because it's fast. Press q in normal mode again to stop recording. Then just type @[0-9a-z] in normal mode to repeat what you just recorded. @...
Single Form Hide on Startup
|vb.net|winforms|
I have an application with one form in it, and on the Load mehtod i need to hide the form. The form will display itself when it has need to (think along the lines of a outlook 2003 style popup), but i cant for the life of me work out how to hide the form on load without something messy. Any suggestions?
I'm pretty sure that the const keyword does not imply the data can't be changed/is constant, only that the data will be treated as read-only. Consider this: const volatile int *const serial_port = SERIAL_PORT; which is valid code. How can volatile and const co-exist? Simple. volatile tells the compiler to alw...
Make sure IsAdministrator is virtual. Also, be sure you call _mocks.ReplayAll()
Redirect command to input of another in Python
|python|bash|diff|http-redirect|vimdiff|
I would like to replicate this in python: gvimdiff <(hg cat file.txt) file.txt (hg cat file.txt outputs the most recently committed version of file.txt) I know how to pipe the file to gvimdiff, but it won't accept another file: $ hg cat file.txt | gvimdiff file.txt - Too many edit arguments: "-...
Because python is a dynamic language, it's not usually a good idea to give a variable and a function the same name. id() is a function in python, so it's recommend not to use a variable named id. Bearing that in mind, that applies to all functions that you might use... a variable shouldn't have the same name as a fun...
Sorry for the long code sample, but more than half of it is debugging code to help you get it set up. Assuming your server already has a modern version of PHP (at `/usr/bin/php`) with the PDO library, and that you have a database table named `fwd_table` with columns `caller_id` and `destination`, you should be able ...
We are getting very slow compile times, which can take upwards of 20+ minutes on dual core 2GHz, 2G Ram machines. A lot of this is due to the size of our solution which has grown to 70+ projects, as well as VSS which is a bottle neck in itself when you have a lot of files. (swapping out VSS is not an option unfort...
We are getting very slow compile times, which can take upwards of 20+ minutes on dual core 2GHz, 2G Ram machines. A lot of this is due to the size of our solution which has grown to 70+ projects, as well as VSS which is a bottle neck in itself when you have a lot of files. (swapping out VSS is not an option unfort...
Try this: var input = 'foo bar "lorem ipsum" baz'; var R = /(\w|\s)*\w(?=")|\w+/g; var output = input.match(R); output is ["foo", "bar", "lorem ipsum", "baz"] Note there are no extra double quotes around lorem ipsum Although it assumes the input has the double quotes in the right plac...
> Is it possible to store these regular expressions in a cache on disk in a pre-compiled manner to avoid having to execute the regex compilations on each import? Not easily. You'd have to write a custom serializer that hooks into the C `sre` implementation of the Python regex engine. Any performance benefits would b...
I found it to be bloated, documentation exercise that was used mainly as a contract-acquiring/maintaining vehicle. Once we had the contract, then it was an exercise in getting around the process. As a developer, I got nothing out of it but lost MONTHS of my professional life fiddle-farting around with CMMI. The ...
C:\tmp\text>dos2unix hello.txt helloUNIX.txt Sed is even more widely available andcan do this kind of thing also if dos2unix is not installed C:\tmp\text>sed s/\r// hello.txt > helloUNIX.txt You could also try tr: cat hello.txt | tr -d \r > helloUNIX2.txt Here are the results: ...
If you are needing to have a reusable method for adding text, you can create a new Style/ControlTemplate that has an additional TextBlock to display the text. You can hijack the TextSearch.Text attached property to set the text on a progress bar. If it doesn't need to be reusable, simply put the progress bar in a ...
You're using the built-in .NET role manager that saves to a SQL Server instance I take it? What format are your user object in when you're currently looking at them to evaluate the criteria? If you post a code sample I have an idea...
I use either a local darcs repo, or just merge the changes in gradually. With merging (opendiff opens FileMerge, a merge program that comes with Xcode; replace with your favorite merge tool): cp file file.new svn revert file opendiff file.new file -merge file merge the related changes, save the merg...
I use either a local darcs repo, or just merge the changes in gradually. With merging (opendiff opens FileMerge, a merge program that comes with Xcode; replace with your favorite merge tool): cp file file.new svn revert file opendiff file.new file -merge file merge the related changes, save the merg...
I think this has to do with Gamma correction. Take a look at this [http://www.hanselman.com/blog/GammaCorrectionAndColorCorrectionPNGIsStillTooHard.aspx][1] [1]: http://www.hanselman.com/blog/GammaCorrectionAndColorCorrectionPNGIsStillTooHard.aspx
It sounds like you want to join the tables aliased as pwd and ewd in your snippet based first on an exact match, and if that fails, then on the like comparison you have now. Try this: LEFT JOIN weblog_data AS pwd1 ON (pwd.field_id_41 != '' AND pwd.field_id_41 = ewd.field_id_32) LEFT JOIN weblog_data AS p...
Microsoft has a number of research projects in the area of having a managed-code OS, in other words kill with Win32 API. See Mary Jo Foley's article: [Rebuilding a Legacy][1] [1]: http://reddevnews.com/features/article.aspx?editorialsid=2555
We are getting very slow compile times, which can take upwards of 20+ minutes on dual core 2GHz, 2G Ram machines. A lot of this is due to the size of our solution which has grown to 70+ projects, as well as VSS which is a bottle neck in itself when you have a lot of files. (swapping out VSS is not an option unfort...
a shot in the dark - are you painting from multiple threads? If you are doing painting related work, do it on the GUI thread or synchronize your code carefully.
Python regular expression for HTML parsing
|python|regex|
I want to grab the value of a hidden input field in HTML. <input type="hidden" name="fooId" value="12-3456789-1111111111" /> I want to write a regular expression in Python that will return the value of fooId, given that I know the line in the HTML follows the format <input type="hidden" name="fooId" va...
The following JavaScript code works only in Spidermonkey and Rhino, and it operates on E4X nodes--i.e., this is useful only for server-side JavaScript, but it might give someone a starting point for doing a jQuery version. (It's been very useful to me on the server side, but I haven't needed it on the client badly enou...
Just take the relevant piece of code from jQuery, John Resig has covered most of the bases on this issue already in jQuery.
Don't know if this works with your requirements or not, but you could constrain T to be a Type that implements an interface such as IComparable and then use the ComparesTo() method from that interface (which IIRC supports/handles nulls) like this: public void MyMethod<T>(T myArgument) where T : IComparable ...
Guitar tuners don't use FFT's or DFT's. Usually they just count zero crossings. You might not get the fundamental frequency because some waveforms have more zero crossings than others but you can usually get a multiple of the fundamental frequency that way. That's enough to get the note although you might be one or mor...
Try this: if (EqualityComparer<T>.Default.Equals(myArgument, default(T))) that should compile, and do what you want.
That's just a wild guess, but could it be, that a thread locks itself by trying to acquire a lock twice? Probably it would help if you could post some code.
Sorry for the long code sample, but more than half of it is debugging code to help you get it set up. I'm assuming your server already has a modern version of PHP (at `/usr/bin/php`) with the PDO library, and that you have a database table named `fwd_table` with columns `caller_id` and `destination`. In /var/lib/...
In general modern servers can handle very large numbers of concurrent connections. I've worked on systems having over 8,000 concurrently open TCP/IP sockets. You will need a high quality servicing interface to handle that kind of load, check out [libevent][1] or [libev][2]. [1]: http://monkey.org/~provos/lib...
Pex enables parameterized unit testing and uses dynamic symbolic execution (some kind of automated exploratory testing) to generate inputs. Pex can understand the semantics of MSIL, i.e. of any managed method call. In the '123' example, Pex would find both tests. It lets developers write *parameterized* unit tests -...
On Intel MacOSX, you can use the built-in system atomic operations. There isn't a provided atomic get or set for either 32 or 64 bit integers, but you can build that out of the provided CompareAndSwap. You may wish to search XCode documentation for the various OSAtomic functions. I've written the 64-bit version below. ...
Python regular expression for HTML parsing (BeautifulSoup)
|python|regex|screen-scraping|
As an experienced TDD'er, this is a question that I'm frequently asked by other developers. For me, it's a mistake to get sucked into a Mockist vs. Classicist debate, as such a discussion is misleading. State-based and behaviuour-based unit testing are two different tools in your toolbox, and there's no reason why they...
Let me guess: the help "icon" is actually a link with a `javascript:` url? Change it to a real button, a real link, or at least put the functionality in an onclick event handler (that prevents the default behavior). Problem solved. <!-- clicking this link will do nothing. No onbeforeunload handler triggered. ...
There are a few options: 1. The **classic cast**: `Foo foo = (Foo)bar` 1. The **`as` cast operator**: `Foo foo = bar as Foo` 1. The **'is' test**: `bool is = bar is Foo` --- 1. The **classic cast** needs to needs to check if bar can be safely cast to Foo (quick), and then actually do it (slower), or thr...
|c#|winforms|vb.net|
What is the best way to integrate TFS version control with XCode?
|version-control|tfs|xcode|
Working on implementing TFS throughout our organization. It is easy to integrate with .NET projects and any platform that uses Eclipse or a derivative of Eclipse for editing. What's the best way to use TFS version control with XCode (now that I find out we need to write some iPhone applications)?
The correct name for 'one-way encryption algorithm' is 'hashing algorithm' (you did mean a way to 'scramble' a password so that it can never be recovered, right?) Do not use md5 in modern applications, successful attacks on it have been showing up since 2004 (see http://www.doxpara.com/md5_someday.pdf for references...
I found another: [NeutralResourcesLanguageAttribute][1]. According to [this][2] blog post it helps the loader in finding the right satellite assemblies faster by specifying the culture if the current (neutral) assembly. [NeutralResourcesLanguageAttribute("nl" , UltimateResourceFallbackLocation.Satellite)] [...
I found another: [NeutralResourcesLanguageAttribute][1]. According to [this][2] blog post it helps the loader in finding the right satellite assemblies faster by specifying the culture if the current (neutral) assembly. [NeutralResourcesLanguageAttribute("nl", UltimateResourceFallbackLocation.MainAssembly)] ...
rake db:migrate doesn't detect new migration ?
|ruby-on-rails|activerecord|migration|
Experienced with Rails / ActiveRecord 2.1.1 * You create a first version with (for example) ruby script\generate scaffold product title:string description:text image_url:string * This create (for example) a migration file called 20080910122415\_create\_products.rb * You apply the migration with rake db:migrate * ...
For Linux: [Google Perftools](http://code.google.com/p/google-perftools/) * Faster than valgrind (yet, not so fine grained) * Does not need code instrumentation * Nice graphical output (--> kcachegrind) * Does memory-profiling, cpu-profiling, leak-checking
The book *Programming Pearls* by Jon Bentley covers this kind of stuff quite nicely. A must-read.
As long as your web services layer and client layer use the .NET DateTime type, it should serialize and deserialize properly as an SOAP-standard local date/time w/ Timezone information such as: 2008-09-15T13:14:36.9502109-05:00 If you absolutely, positively must know the timezone itself (i.e. the above could be E...
Valid characters in a Java class name
|java|class|name|naming-guidelines|invalid-characters|
What characters are valid in a Java class name? What other rules govern Java class names (for instance, Java class names cannot begin with a number)?
This works pretty well: setTimeout(MyInitFunction, 0);
You could just extract that snippet into a separate method for creating the TextInput, then you'd get a function-scoped value that you need. Seems slightly cleaner that stashing the node away in "data". Something like this: for each (var node:XML in xml.node) { var textInput:TextInput = createTextI...
The closure only captures a *reference* to the variable, not its current value. Since local variables are Function-scoped (not block-scoped) each iteration through the loop creates a closure that captures a reference to the same variable. You could extract the TextInput creation code into a separate function, whic...
If you create a branch, and delete the unwanted files in one commit, you should be able to cherry-pick any subsequent commits back into your main branch without merging the commit that deletes the data files. See the <a href="http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html">manual for git cherry...
Accessing App.config in a location different from the binary
|c#|
In a .NET Win console application, I would like to access an App.config file in a location different from the console application binary. For example, how can C:\bin\Text.exe get its settings from C:\Test.exe.config?
Best practice: escape, or encodeURI / encodeURIComponent
|javascript|encoding|query-string|
When encoding a query string to be sent to a web server - what is the best practice to use from javascript: Use escape: escape("% +&="); OR use encodeURI() / encodeURIComponent() encodeURI("http://www.google.com?var1=value1&var2=value2"); encodeURIComponent("var1=value1&var2=value2"); ...
This is really the sort of thing you want to filter on in SQL. I don't think there is any trick to get around doing a linear scan of your data and get the results you want. If doing this in SQL isn't an option then maybe you can avoid creating a second list and just sort your main user array and have the display onl...
Otto made a <a href="http://stackoverflow.com/questions/65865/cant-locate-foopm-in-inc-how-to-install-a-missing-perl-module#65911">good suggestion</a>. This works for Debian too, as well as any other Debian derivative. The missing piece is what to do when apt-cache search doesn't find something. $ sudo apt-get...
encodeURI() - the escape() function is for javascript escaping, not HTTP.
There are some good answers in the other thread on this, but I wonder if something involving a spectral analysis would work? I.e., break the image down to it's phase and amplitude information and compare those. This may avoid some of the issues with cropping, transformation and intensity differences. Anyway, that's ...
The code below will convert the decimal value d to hex. It also allows you to add padding to the hex result. so 0 will become 00 by default. function decimalToHex(d, padding) { var hex = d.toString(16).toUpperCase(); padding = typeof (padding) === "undefined" || padding === null ? padding = 2 :...
The code below will convert the decimal value d to hex. It also allows you to add padding to the hex result. so 0 will become 00 by default. function decimalToHex(d, padding) { var hex = parseInt(d, 16); padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding; ...
You'll need a separate object, like StepDiff with collections for removed and added items. The easiest way to do something like this is to copy the collections from each of the old and new objects, so that StepDiff has collectionOldStepDocs and collectionNewStepDocs. Grab the shorter collection and iterate through ...
Using a list comprehension would build a temporary list, which could eat all your memory if the sequence being searched is large. Even if the sequence is not large, building the list means iterating over the whole of the sequence before `in` could start its search. The temporary list can be avoiding by using a gener...
For a breadth-first search you need to store at least two things. One is the set of already visited nodes and the other is the set of nodes that are directly reachable from the visited nodes but are not visited themselves. Then you keep moving states from the latter set to the former, adding newly reachable states to t...
I heard of people using selenium as a free/open source testing tool. A quick google revealed a FLEX API for it. Not sure if it works or is still in development, but it may be worth a look. http://sourceforge.net/projects/seleniumflexapi/
Fastest api for rendering text in WinForms?
|c#|windows|performance|
We need to optimize the text rendering for a c# WinForms application displaying a large number of small strings in an irregular grid. At any time there can be well over 5000 cells visible that update 4x/second. The font family and size is consistent across the cells, though the color may vary from cell to cell, as wi...
We need to optimize the text rendering for a c# WinForms application displaying a large number of small strings in an irregular grid. At any time there can be well over 5000 cells visible that update 4x/second. The font family and size is consistent across the cells, though the color may vary from cell to cell, as wi...
To add your own custom editing when the user selects a property grid value you need to implement a class that derives from UITypeEditor. You then have the choice of showing just a small popup window below the property area or a full blown dialog box. What is nice is that you can reuse the existing implementations. S...
I'm a graphics guy, not a programmer, so I'm not sure this will help you. BUT! I make all my GUIs multi-frame "movies" and write each gui thread on a different frame. Make sure that you only have 1-3 threads, and set your FPS to 30 or 60. This is useful for little projects because its bug-resistant and implementa...
Have you checked out Microsoft's [ClickOnce Deployment][1]? If I remember correctly you can embed a manifests which would help with dealing with protected modes automatically, saving you those headaches with the APIs. I believe ClickOnce is geared for the same thing your ActiveX installer was designed to do. S...
Have you checked out Microsoft's [ClickOnce Deployment][1]? If I remember correctly you can embed a manifests which would help with dealing with protected modes automatically, saving you those headaches with the APIs. I believe ClickOnce is geared for the same thing your ActiveX installer was designed to do. S...
For interactive work, [Matplotlib][1] is the mature standard. It provides an OO-style API as well as a Matlab-style interactive API. [Chaco][2] is a more modern plotting library from the folks at Enthought. It uses Enthought's Kiva vector drawing library and currently works only with Wx and Qt with OpenGL on the wa...
How to create a DOM from a User's input in PHP5?
|php|web-applications|dom|php5|
I can't seem to find any decent info about this on the web. Any advice?