instruction stringlengths 0 30k ⌀ |
|---|
If you are working in the plane and you want the <a href="http://en.wikipedia.org/wiki/Euclidean_distance">Euclidean distance</a> "as the crow flies":
// Cities are points x0,y0 and x1,y1 in kilometers or miles
dx = x1 - x0;
dy = y1 - y0;
dist = sqrt(dx*dx + dy*y); // * is faster than pow for squ... |
I would just go by
throw new exception("WhatCausedIt")
if you want to handle your exceptions, you could pass a code instead of "WhatCausedIt" an then react to the different answers with a switch statement. |
Yes, what you're looking for is COMET (http://en.wikipedia.org/wiki/Comet_(programming)). Other good Google terms to search for are AJAX-push and reverse-ajax.
|
Yes, what you're looking for is COMET <http://en.wikipedia.org/wiki/Comet_(programming)>. Other good Google terms to search for are AJAX-push and reverse-ajax.
|
It is possible to recover it if Git hasn't garbage collected yet.
Get an overview of dangling commits with fsck:
$ git fsck --lost-found
dangling commit b72e67a9bb3f1fc1b64528bcce031af4f0d6fcbf
Recover the dangling commit with rebase:
$ git rebase b72e67a9bb3f1fc1b64528bcce031af4f0d6fcbf
... |
Where is a good place to start programming GUIs for windows? |
|c++|c|mfc|winapi|windows-api|qt| |
I have experience writing console and network client/server apps in C and C++, but I know next to nothing about using the win32 visual API, MFC, QT, WxWidgets, etc. Where is a good place to start, and what method should I specialize in, so as to be future ready and robust? |
|mfc|winapi|windows-api|qt| |
|winapi|mfc|qt| |
Sending a mouse click to a button in the taskbar using C# |
|c#|win32api|.net|window| |
In an application that I am currently working on, a requirement is to bring a window of an external application to the foreground. Making Win32 API calls such as BringWindowToTop and SetForeground window do not work all the time. This is due to some restrictions within Windows XP. What I would like to do instead is ... |
|c#|win32api|.net|windows| |
|c#|.net|windows|winapi| |
Getting UI text from external app in C# |
|c#|interop|win32api| |
Is it possible to get UI text from an external application in C#.
In particular, is there a way to read Unicode text from a label (I assume it's a normal Windows label control) from an external Win32 app that was written by a 3rd party? The text is visible, but not selectable by mouse in the UI.
I assume there i... |
You can also search through both the Form and QueryString collections at the same time so that the data will be found regardless of the the request method.
value = Request("formElementID")
|
If all you are doing is iterating through the list, you can define a method that returns the list as IEnumerable (for .NET).
By returning the interface that provides just the functionality you need, if some new collection type comes along in the future that is better/faster/a better match for your application, as lo... |
You can use **unsafe** C# code and **pointers** in critical bottleneck points to make it run faster. Those behave much like C++ code and I believe it executes _as fast_.
But most of the time, C# is JIT-ted to uber-fast already, I don't believe there will be much differences as with what everyone has said.
But one... |
You can use **unsafe** C# code and **pointers** in critical bottleneck points to make it run faster. Those behave much like C++ code and I believe it executes _as fast_.
But most of the time, C# is JIT-ted to uber-fast already, I don't believe there will be much differences as with what everyone has said.
But one... |
My process for situations where I think performance may be an issue:
1. Make it work.
2. Make it clear.
3. Test the performance.
4. If there are meaningful performance issues: refactor for speed.
Note that this does not apply to higher-level design decisions that are more difficult to change at a later sta... |
There IS one difference - you can't use String without "using System;" beforehand. |
JQuery is more focused on a lot of nice utility functions, and makes DOM manipulation a whole lot easier. Basically, I consider it to be Javascript as it should have been. It's a supremely helpful addition to the Javascript language itself.
ExtJS is a suite of GUI components with specific APIs... Use it if you want ... |
An interface is essentially a contract that a class has certain methods or attributes; programming to an interface rather then a direct implementation allows for more dynamic and manageable code, as you can completely swap out implementations as long as the "contract" is still held.
In the case you describe, passing... |
Not an easy way, at least until a good provider is produced.
Really MS should provide at least an OLEDB Linq provider. After all, Linq to Sql is basically an implementation of IQueryable with designer support. |
Honestly the ASP.NET Membership / Roles features would work perfectly for the scenario you described. Writing your own tables / procs / classes is a great exercise and you can get very nice control over minute details, but after doing this myself I've concluded it's better to just use the built in .NET stuff. A lot of ... |
If you use [PowerShell][1], you could write a script that let you change the priority of a process. I found the following PowerShell function on the [Monad blog][2]:
function set-ProcessPriority {
param($processName = $(throw "Enter process name"), $priority = "Normal")
get-process -process... |
Why should I practice Test Driven Development and how should I start? |
|testing|tdd| |
Lots of people talk about writing tests for their code before they start writing their code. This practice is generally known as Test Driven Development or TDD for short. What benefits do I gain from writing software this way? How do I get started with this practice? |
You should pass self() to the child as one of the arguments to the entry function.
spawn_link(?MODULE, child, [self()]). |
Grid Hosting for Windows |
|.net|hosting| |
Are there any **good** grid-hosting companies out there that offer .NET stacks? Something like MediaTemple - which won't host the worlds fastest websites, but for the price is far better than "shared hosting". I've used Rackspace's Mosso, but it sucked - it never felt like a normal .NET stack (caching was odd, site rec... |
Try [gogrid.com][1] they seem to have a very nice following in the cloud computing circles.
[1]: http://www.gogrid.com |
The benefits part has [recently been covered](http://stackoverflow.com/questions/2260/what-is-tdd), as for where to start....on a small enterprisey system where there aren't too many unknowns so the risks are low. If you don't already know a testing framework (like NUnit), start by learning that. Otherwise start by wri... |
In my opinion, the single greatest thing is that it clearly allows you to see if your code does what it is supposed to. This may seem obvious, but it is super easy to run astray of your original goals, as I have found out in the past :p |
I personally would say go with the plan you have.. A good hash code is the best way to see if an object is "as-is".. Theres tons of hashing algorithms you can look at, check out the obvious [Wikipedia page](http://en.wikipedia.org/wiki/Hash_function) on hash functions and go from there..
Override GetHashCode and go ... |
For the fourth bullet: No you can't specify where you want to add the column. Here is the syntax for ALTER TABLE: <http://doc.ddart.net/mssql/sql70/aa-az_5.htm>
In MySQL they offer an ALTER TABLE ADD ... AFTER ... but this doesn't appear in T-SQL.
If you want to reorder the columns you'll have to rebuild the tabl... |
I feel the best combination of DRYness and forcing the contract is as follows (in pseudocode):
class Base {
public final constructor(name) {
constructor(name, null)
end
public abstract constructor(name, description);
}
or, alternatively:
class Base {
public a... |
duplicating jquery datepicker |
|jquery| |
the datepicker function only works on the first input box that is created.
i'm trying to duplicate a datepicker by cloning the div that is containing it.
<a href="#" id="dupMe">click</a>
<div id="template">
input-text <input type="text" value="text1" id="txt" />
date time picker <input type="te... |
|javascript|jquery| |
I hadn't realised that you can't call Parent.DesignMode (and I have learned something about 'protected' in C# too...)
Here's a reflective version: (I suspect there might be a performance advantage to making designModeProperty a static field)
static bool IsDesignMode(Control control)
{
PropertyI... |
Initially, use an **8 * 8 integer array** to represent the chess board.
You can start programing using this notation. Give point values for the pieces. For example:
white queen = 9
black queen = -9
etc.
After you develop the basic backbones of your application and clearly understand the working of t... |
Initially, use an **8 * 8 integer array** to represent the chess board.
You can start programing using this notation. Give point values for the pieces. For example:
**White**
9 = white queen
5 = white rook
3 = bishop
3 = knight
1 = pawn
**black**
-9 = white queen
-5 =... |
How to use the SharePoint MultipleLookupField control? |
|sharepoint|multiplelookupfield| |
I want to use the MultipleLookupField control in a web page that will run in the context of SharePoint. I was wondering if anyone would help me with an example, which shows step by step how to use the control two display two SPField Collections. |
How do I remove an item from a stl vector with a certain value? |
|c++|stl| |
I was looking at the API documentation for stl vector, and noticed there was no method on the vector class that allowed the removal of an element with a certain value. This seems like a common operation, and it seems odd that there's no built in way to do this. |
It's the implementations that doesn't support multi-threading. Currently Google Gears is providing a way to use some form of concurrency by executing external processes but that's about it.
The new browser Google is supposed to release today (Google Chrome) executes some code in parallel by separating it in process.... |
SQL: Returning the sum of items depending on which type it is |
|sql|sql-server| |
I have one field that I need to sum lets say named items
However that field can be part of group a or b
In the end I need to have all of the items summed for group a and group b |
I have one field that I need to sum lets say named items
However that field can be part of group a or b
In the end I need to have all of the items summed for group a and group b
when I say grouped I mean there is a LEFT OUTER JOIN to another table the previous table has a type for the items and the one being joine... |
I have one field that I need to sum lets say named items
However that field can be part of group a or b
In the end I need to have all of the items summed for group a and group b
when I say grouped I mean there is a LEFT OUTER JOIN to another table the previous table has a type for the items and the one being joine... |
I have one field that I need to sum lets say named items
However that field can be part of group a or b
In the end I need to have all of the items summed for group a and group b
when I say grouped I mean there is a LEFT OUTER JOIN to another table the previous table has a type for the items and the one being joine... |
I have one field that I need to sum lets say named items
However that field can be part of group a or b
In the end I need to have all of the items summed for group a and group b
when I say grouped I mean there is a LEFT OUTER JOIN to another table the previous table has a type for the items and the one being joine... |
i started out using [free text box][1] when i was doing a lot of asp.net programming, but now that most of what i do is php i've moved to the [FCK editor][2].
while the change wasn't necessarily prompted by the language, i feel that the fck editor is a better choice because of it's versatility.
[1]: http://fr... |
Targeting multiple versions of .net framework |
|.net| |
Suppose I have some code that would, in theory, compile against *any* version of the .net framework. Think "Hello World", if you like.
If I actually compile the code, though, I'll get an executable that runs against one *particular* version.
Is there any way to arrange things so that the compiled exe will just ... |
Suppose I have some code that would, in theory, compile against *any* version of the .net framework. Think "Hello World", if you like.
If I actually compile the code, though, I'll get an executable that runs against one *particular* version.
Is there any way to arrange things so that the compiled exe will just ... |
@Espo: Thanks for the great advice on where to start. Your link would have been better if I had been configuring sendmail for its first use instead of taking an existing configuration and making this small change. However, once I knew to look for stuff on "SmartHost", I found an easier way.
All I had to do was edi... |
As mentioned prior snippets are what you are looking for.
For reference look here:
http://manual.macromates.com/en/snippets
http://screenflicker.com/mike/code/div-snippets/ |
For what it's worth, Perforce is a potential option if you truly stick to 1 or 2 users. Current perforce docs says you have have 2 users and 5 clients without having to start purchasing licenses.
You might have reasons to switch to perforce depending on your workflow and if you have need of branching the way perfor... |
Programmaticly building htpasswd. |
|php|automation|.htpasswd| |
Is there a programmatic way to build htpasswd files, without depending on OS specific functions (i.e. exec(), passthru())? |
You should make sure that GPG is in your path when the cronjob is running. Your best guess would be do get the full path of GPG (by doing `which gpg`) and running it using the full path (for example `/usr/bin/gpp...`).
Some other debugging tips:
- output the value of `$?` after running GPG (like this: echo "$?"... |
One of my favorite uses of reflection is the below Java dump method. It takes any object as a parameter and uses the Java reflection API print out every field name and value.
import java.lang.reflect.Array;
import java.lang.reflect.Field;
public static String dump(Object o, int callCount) {
... |
Using Zend Framework and setting a Zend_Form_Element form field to be required, how do I change the validator used to ensure that the element is not blank |
|php|zend|zend-framework|validation| |
When using a Zend_Form, the only way to validate that a input is not left blank is to do
$element->setRequired(true);
If this is not set and the element is blank, it appears to me that validation is not run on the element.
If I do use setRequired(), the element is automatically given the standard Not... |
If you want to upgrade every site on a server you could probably make changes to the machine.config |
Using a rotary encoder with AVR Micro controller |
|microcontroller|avr|encoder|atmega| |
I'm having trouble getting a rotary encoder to work properly with AVR micro controllers. The encoder is a mechanical [ALPS encoder][1], and I'm using [Atmega168][2].
[1]: http://no.farnell.com/1520815/passives/product.us0?sku=alps-ec12d1524401
[2]: http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf |
|microcontroller|avr|atmega|encoder| |
I'm having trouble getting a rotary encoder to work properly with AVR micro controllers. The encoder is a mechanical [ALPS encoder][1], and I'm using [Atmega168][2].
**Clarification**
I have tried using an External Interrupt to listen to the pins, but it seems like it is too slow. When Pin A goes high, the interr... |
NHibernate Session.Flush() Sending Update Queries When No Update Has Occurred |
|c#|.net|nhibernate| |
I have an NHibernate session. In this session, I am performing exactly 1 operation, which is to run this code to get a list:
public IList<Customer> GetCustomerByFirstName(string customerFirstName)
{
return _session.CreateCriteria(typeof(Customer))
.Add(new NHibernate.Expression.EqExpression("F... |
Communication between pages |
The first is faster because bitwise operations such as xor are usually very hard to visualize for the reader.
Faster to understand of course, which is the most important part ;) |
Is there any way to sticky a file in subversion |
|svn|tortoisesvn| |
We have been working with CVS for years, and frequently find it useful to sticky a single file here and there. Is there any way to do this in subversion, specifically from TortoiseSVN? |
|svn| |
Automated Builds |
|build-automation|subversion|nant| |
I currently use [subversion][1] for my version control via [AhnkSVN][2] and Visual Studio. I recently started using [Tree Surgeon][3] to set up my projects. It creates a build script automatically using [NAnt][4]. I would like to be able to automate builds regularly projects within SVN. I like the idea of doing a b... |
|svn|nant|build-automation| |
Can't create a subversion repository with Eclipse 3.4.0, svn 1.5.1 |
|subversion|macos|eclipse| |