instruction stringlengths 0 30k ⌀ |
|---|
Code formatting is personal taste. As long as it is easy to read, it would pay for maintenance! |
Careful not to use the `input` function , unless you know what you're doing . Unlink `raw_input` , `input` will accept any python expression , so it's kinda like `eval` |
In order for this format to have "advantage", we really need some equivalent C code in another format to compare to!
Where I work, this indentation scheme is used in order to facilitate a home-grown folding editor mechanism.
Thus, I see nothing fundamentally wrong with this format - within certain rational limits... |
Bruce Schneier has a good response to this kind of problem.
> Cryptography is not the solution to your security problems. It might be part of the solution, or it might be part of the problem. In many situations, cryptography starts out by making the problem worse, and it isn't at all clear that using cryptography is... |
GCC has intrinsics for atomic operations; I suspect you can do similar with other compilers, too. Never rely on the compiler for atomic operations; optimization will almost certainly run the risk of making even obviously atomic operations into non-atomic ones unless you explicitly tell the compiler not to do so. |
If you wanted to use [basetype].Invoke("Dispose"...) then you could implement the function call without the debugger complaining. Then later when the base type actually implements the IDisposable interface it will execute the proper call.
|
I assume that you've already ruled out the tools in "org.eclipse.swt.dnd" for some reason? There are some examples [here][1] on how to go about using them, in case you haven't. If what you really want to do is drag&drop, you're going to have to do some work with those tools. At that point, really the question become... |
You can always implement your own [OpenID][1] server. There is already a [Python library for OpenID][2] so it should be fairly easy.
[1]: http://openid.net/what/
[2]: http://openidenabled.com/python-openid/ |
You can always implement your own [OpenID][1] server. There is already a [Python library for OpenID][2] so it should be fairly easy.
Of course you don't need to accept logins authorized by other servers in your applications. Accept credentials authorized only by your own server.
**Edit:** I have found an [implem... |
If you have an existing ActiveDirectory infrastructure, that will be the way to go. This will be particularly advantageous to companies that have already had Windows servers set up for authentication. If this is the case, I'm leaning towards your first bullet point in "sample implementations".
Otherwise it will be a... |
In your web.xml you can configure a servlet to load at startup. Do this, then in the init method in the servlet you can set up a Timer / TimerTask to do whatever it is you need to do. TimerTasks are like Threads except you can schedule them when to run. |
In your web.xml you can configure a servlet to load at startup.
Syntax:
<servlet servlet-name='hello'
servlet-class='test.HelloWorld'><br>
<load-on-startup/><br>
</servlet>
Do this, then in the init method in the servlet you can set up a Timer / TimerTask to do whatever it is yo... |
Normally I use like this way.
<a href='<%# DataBinder.Eval(Container.DataItem,"Id",""/Admin/Content/EditResource.aspx?ResourceId={0}") %'> |
Do you really want to tie your pages to your own custom scripting language? Or are you just looking to write your client-side code in something that's not javascript? If the latter try [MileScript](http://milescript.org/), [haXe](http://haxe.org/doc/intro), or [Google Web Toolkit](http://code.google.com/webtoolkit/) |
I support the use of [doxygen][1].
This tool generated a javadoc like bunch of html pages, allowing to index all the code, to browse in it (where is this function used, and by which function...), like you can do in an IDE. It is very easy to make it work.
I had once to maintain 2000 files of C code of a 15 years ... |
If you're inserting text from a database or such (which one usually do), convert all "<br />"'s to &vbCrLf. Works great for me :) |
DropDownList doesn't postback on SelectedIndexChanged |
|asp.net|drop-down-menu| |
I'm writing an ASP.Net webform with some DropDownList controls on it. Then user changes selected item in one of dropdowns, ASP.Net doesn't seem to handle SelectedIndexChanged event until form is submitted with a 'Submit' button click.
How do I make my dropdowns handle SelectedIndexChanged instantly?
P.S. It's a cla... |
Here is the most important piece of advice I was given by a C++ guru, and it helped me in a few critical occasions to find bugs in my code:
* Use const methods when a method is **not supposed** to modify the object.
* Use const references and pointers in parameters when the object is **not supposed** to modify the ... |
Can you not use the monitor power button? |
There are only three free AAC encoders that I know of that are available through a commandline interface:
1. FAAC (LPGL), which is honestly pretty bad (the quality is going to be significantly worse than LAME at the same bitrate). Its fine though if you're willing to go for higher bitrates (>>128kbps) and need AAC... |
To answer this question well requires more information about you:
- what is your programming ability?
If it's high, I would probably start with Ogre (the best strictly rendering open source engine, IMHO) or another open source game engine, such as Delta3D, if you want additional features (sound, physics, etc.)... |
How do I copy image data to the clipboard in my XUL application? |
|javascript|xul|xpcom|xulrunner| |
I have a XULRunner application that needs to copy image data to the clipboard. I have figured out how to handle copying text to the clipboard, and I can paste PNG data from the clipboard. What I can't figure out is how to get data from a data URL into the clipboard so that it can be pasted into other applications.
T... |
This [article][1] explains how to use HwndHost along with a few other Win32 API calls to accomplish the task.
[1]: http://www.ddj.com/windows/197003872?pgno=2 |
Does Java save its runtime optimizations? |
|java|optimization|caching| |
My professor did an informal benchmark on a little program and the Java times were: 1.7 seconds for the first run, and 0.8 seconds for the runs thereafter. Is this due entirely to the loading of the runtime environment into the operating environment or is it influenced by Java's optimizing the code and storing the res... |
Aupajo has it right. I will, however, point you towards a bookmarklet framework I worked up for our site (www.iminta.com).
The bookmarklet itself reads as follows:
javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('src','http://www.imi... |
I'm pretty sure that the <code>Handles</code> clause is just syntactic sugar and inserts an <code>AddHandler</code> statement into your constructor. I tested using this code and disabled the application framework so the constructor wouldn't have extra stuff:
<pre><code>
Public Class Form1
Public Sub New()
... |
I don't think continue could ever be as difficult as goto since continue never moves execution out of the code block that it is in. |
We have had good luck with Holux GPS recievers (designed for samsung q1). A farily simple connect over serial port and you can read the NMEA string. |
Save registry values in WinCE using a C# app |
|c#|registry|windows-ce| |
I'm working on a WinCE 6.0 system with a touchscreen that stores its calibration data (x-y location, offset, etc.) in the system registry (HKLM\HARDWARE\TOUCH\). Right now, I'm placing the cal values into registry keys that get put into the OS image at build time. That works fine for the monitor that I get the origin... |
Function.toSource():
function x() {
alert("Hello World");
}
eval ("x = " + (x + "").replace(
'Hello World',
'STACK OVERFLOW BWAHAHA"); x("'));
x(); |
If you run your own server go the module way, it's somewhat faster.
If you're on a shared server the decision has already been taken for you, usually on the CGI side. The reason for this are filesystem permissions. PHP as a module runs with the permissions of the http server (usually 'apache') and unless you can chmod... |
Process.Start(@"C:\Program Files\Microsoft Office\Officexx\excel.exe", "yourfile.xml");
That being said, you will still get the message box. I suppose that you could use the Interop, but I am not sure how well it will work for you. |
What emails clients are being used out there? |
|email|statistics|usage|outlook| |
This is not "exactly" a programming question, but it's highly related. We are writing an app that sends out email invitations for a client (no, it's not spam). Their designer gave us an HTML and CSS template to use which is fine. The problem is that it looks like crap in Outlook 2007 because Microsoft decided to use... |
|html|email|outlook|statistics| |
For starters, it would be helpful if you clarify what you mean by "raw". Traditionally this means that you want to craft all of the layer 4 header (TCP/UDP/ICMP... header), and perhaps some of the IP header on your own. For this you will need more than beej's tutorial which has been mentioned my many here already. I... |
Bruce Schneier has a good response to this kind of problem.
> Cryptography is not the solution to your security problems. It might be part of the solution, or it might be part of the problem. In many situations, cryptography starts out by making the problem worse, and it isn't at all clear that using cryptography is... |
Bruce Schneier has a good response to this kind of problem.
> Cryptography is not the solution to your security problems. It might be part of the solution, or it might be part of the problem. In many situations, cryptography starts out by making the problem worse, and it isn't at all clear that using cryptography is... |
Mike Chamber's idea will help you but it will still be slower than using something serverside, since you'll have to make a request for each file anyway. It's essentially the same of what you're saying yourself, but when you're explicitly asking for the headers it will be slightly faster. Use a Socket to do the request:... |
Great question. With source control you can still do your "F5" refresh process. But after each edit (or a few minor edits) you want to check your code in so you have a copy backed up.
Depending on the source control system, you don't have to explicitly check out the file each time. Just editing the file will check i... |
How to create a windows service from java app |
|java|windows|service| |
I've just inherited a java application that needs to be installed as a service on XP and vista. It's been about 8 years since I've used windows in any form and I've never had to create a service, let alone from something like a java app (I've got a jar for the app and a single dependency jar - log4j). What is the magi... |
Installing the [Visual Studio SDK](http://http://www.microsoft.com/downloads/details.aspx?familyid=30402623-93ca-479a-867c-04dc45164f5b) will install the "Package Load Analyzer" package. This allows you to see what package failed to load and why. |
Installing the [Visual Studio SDK](http://www.microsoft.com/downloads/details.aspx?familyid=30402623-93ca-479a-867c-04dc45164f5b) will install the "Package Load Analyzer" package. This allows you to see what package failed to load and why. |
If you can't change the file extension (and just return plain text, the caller shouldn't care about the file extension, js is plain text) then you can set up a handler on IIS (assuming it's IIS) to handle javascript files.
See this link - http://msdn.microsoft.com/en-us/library/bb515343.aspx - for how to setup II... |
I suggest you to read [The C++ Programming Language][1] book (written by Bjarne Stroustrup). It may not be the best book to begin with, but it is definitely on you should read, sooner or later.
[1]: http://www.research.att.com/~bs/3rd.html |
I think there should be more use of continue!
Too often I come across code like:
for (...)
{
if (!cond1)
{
if (!cond2)
{
... highly indented lines ...
}
}
}
instead of
for (...)
{
if (cond1 || cond2)
... |
I think your best bet is the attachment_fu plug-in:
http://github.com/technoweenie/attachment_fu/tree/master
|
I think your best bet is the attachment_fu plug-in:
http://github.com/technoweenie/attachment_fu/tree/master
UPDATE: Found some more info here http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/a81beffb93708bb3 |
How to add a Timeout to Console.ReadLine()? |
|c#|.net|console|io|timeout| |
I have a console app in which I want to give the user *x* seconds to respond to the prompt. If no input is made after a certain period of time, program logic should continue. We assume a timeout means empty response.
What is the most straightforward way of approaching this? |
Is **`continue`** any more harmful than, say, **`break`**?
If anything, in the majority of cases where I encounter/use it, I find it makes code clearer and less spaghetti-like. |
You can write good code with or without continue and you can write bad code with or without continue.
There probably is some overlap with arguments about goto, but as far as I'm concerned the use of continue is equivalent to using break statements (in loops) or return statement from anywhere in a method body - if us... |
The most reliable way is to determine which files are impacted by the QFE and use `System.Diagnostics.FileVersionInfo.GetVersionInfo(path)` on each file and compare the version numbers.
edit: I think there's a way to check the uninstall information in the registry as well, but if the QFE ever becomes part of a Servi... |
What about a sliding window...
ABCBABabABBCbcBCBVbvBCbcBCAB
__ABCBABABABBCBCBCBVBVBCBCBCAB
(the lower case letters are the matches)
now we removed strings of length two and get:
ABCBABABBCBCBVBCBCAB
___ABCBABABBCBCBVBCBCAB
none of length three...
ABCBABABBCBCBVBCBCAB
... |
What about a sliding window...
ABCBAbabaBBCbcbcBVbvBCbcbcAB
__ABCBABABABBCBCBCBVBVBCBCBCAB
(the lower case letters are the matches)
now we removed strings of length two and get:
ABCBABBCBVBCAB
Of course if you want to remove maximal strings first, you should start with offset to half t... |
deleting a buffer through a different type of pointer? |
|c++|memory-management| |
Say I have the following C++:
char *p = new char[cb];
SOME_STRUCT *pSS = (SOME_STRUCT *)p;
delete pSS;
Is this safe according to the C++ standard? Do I need to cast back to a char* and then use delete[]? I know it'll work in most C++ compilers, because it's plain-ordinary-data, with no destructors. ... |
_Precedence_ rules specify priority of operators (which operators will be evaluated first, e.g. multiplication has higher precedence than addition, PEMDAS).
The _associativity_ rules tell how the operators of same precedence are grouped. Arithmetic operators are left-associative, but the assignment is right associa... |
I couldn't get used to screen until I found a way to set a 'status bar' at the bottom of the screen that shows what 'tab' or 'virtual screen' you're on and which other ones there are. Here is my setup:
[roel@roel ~]$ cat .screenrc
# Here comes the pain...
caption always "%{=b dw}:%{-b dw}:%{=b dk}[ %{-... |
How can one use mutli threading in php applications |
|php|multithreading| |
Is there a realistic way of implementing a multi-threaded model in php whether truly or just simulating it. Some time back it was suggested that you can force the operating system to load another instance of the php executable and handle other simultaneous processes.
The problem with this is that when the php code f... |
How can one use multi threading in php applications |
Two tips but not a complete answer :
You should be able to use
rake db:migrate:up
to force it to go forward, but then you risk missing interleaved migrations from other people on your team
if you run
rake db:migrate
twice, it will reapply all your migrations
I encounter the same behav... |
Sharepoint: Best way to display lists of non-Sharepoint content with "compatible" UI? |
|sharepoint|xslt|list|web-parts| |
I've built a web part for Sharepoint that retrieves data from an external service. I'd like to display the items in a way that's UI-compatible with Sharepoint (fits in with its surroundings.)
I'm aware of the "DataFormWebPart" but was unable to get one working properly. It requires a valid DataSource and I was una... |
Instead of nesting using statements, you can just write out the .Dispose calls manually - but you'll almost certainly miss one at some point.
Either run FxCop or something else that can make sure that all IDisposable-implementing type instances have a .Dispose() call, or deal with the nesting. |
I assume you want to activate the action of taking a picture from the computer which the camera is attached to. If that is the case then the first thing I would do is search for an API for that particular camera model. I don't believe there is a standard protocol/framework for interacting with digital cameras besides a... |
You don't have to nest with multiple usings:
using (FileStream fs = new FileStream("c:\file.txt", FileMode.Open))
using (BufferedStream bs = new BufferedStream(fs))
using (StreamReader sr = new StreamReader(bs))
{
// all three get disposed when you're done
} |
> Garbage collection is a must (as is
> the ability to avoid its use when
> necessary)
You can't disable a garbage collector temporarily. You would need a deterministic garbage collector then. But such a beast does come with a performance hit also. I think BEA JRockit is such a beast and then you should stick to J... |
Microsoft's official position is that installing multiple office versions on the same pc is not supported and not recommended, and Access 2007 seems to be designed to prove that to us!
That said, you can avoid most issues by doing the following:
1 - Splitting the db into a back end and front end. Place the back ... |
I found you a [Big Huge Thesaurus][1] with a web API, and a dictionary at [Aonaware][2] that looks like it uses SOAP
[1]: http://words.bighugelabs.com/
[2]: http://services.aonaware.com/DictService/ |
Reasons why PHP would echo errors, even with error_reporting(0)? |
|php|error-reporting|ini-set| |
What are some reasons why php would force errors to show, no matter what you tell it to disable?
I have tried error_reporting(0) and ini_set('display_errors',0) with no luck. |
BugzScout in hosted Fogbugz |
|fogbugz| |
Is it possible to use BugzScout in the fogcreek-hosted version of Fogbugz? |
|fogbugz|bugzscout|fogbugz-on-demand| |
As Sam mentioned, the xlsx file extension is probably a good route to go. However, there is more involved than just saving the xml file as xlsx. An xlsx is actually a zip file with a bunch of xml files inside folders. I found some good sample code [here][1] which seems to give some good explanations although I haven't ... |
Sorry it seems I can't post a comment without enough Rep so...
I think it's too difficult for eclipse to degrade safely to a lower standard because it can't really know if you've used something from the newer web standard. So if it just allows you do to that it could cause your program to fail on an older version.
... |
Use sub references, and closures. A good perlish example of this
sort { lc($a) cmp lc($b) } @items |
Best keyboard for custom Dvorak-based programming layout |
|keyboard|dvorak|java|python| |
I'm considering switching to a Dvorak-based keyboard layout, but one optimized for programming (mostly) Java and python (e.g. [DDvorak][1], [Programmer Dvorak][2], etc.). What particular keyboard would be best for such an undertaking?
Thanks.
[1]: http://www.siteuri.ro/dvorak/DDvorak.aspx
[2]: http://www.kau... |
|java|python|keyboard|dvorak| |