instruction
stringlengths
0
30k
You have to know what the encoding of the file is, and then decode the ByteBuffer into a CharBuffer using that encoding. Assuming the file is ASCII: import java.util.*; import java.io.*; import java.nio.*; import java.nio.channels.*; import java.nio.charset.*; public class Buffer ...
LLBLGen Pro is an excellent tool which allows you to write a database agnostic solution. It's really quick to pick up the basic features. Advanced features aren't much more challenging. I highly recommend you check it out.
Chapter 1 of "The Art of Computer Programming" aims to provide exactly this.
There is discussion of this, including links to browser testing and backwards compatibility, in <a href="http://greenbytes.de/tech/webdav/draft-reschke-rfc2231-in-http-latest.html">this draft RFC</a>. <a href="http://tools.ietf.org/html/rfc2183">RFC 2183</a> indicates that such headers should be encoded according to...
From: http://askville.amazon.com/download-accelerator-protocol-work-advantages-benefits-application-area-scope-plz-suggest-URLs/AnswerViewer.do?requestId=9337813 Quote: The most common way of accelerating downloads is to open up parllel downloads. Many servers limit the bandwith of one connection so opening more in...
|c#|asp.net|
Having a heckuva time with this one, though I feel I'm missing something obvious. I have a control that inherits from System.Web.UI.WebControls.Button, and then implements an interface that I have set up. So think... public class Button : System.Web.UI.WebControls.Button, IMyButtonInterface { ... } In the cod...
Process.StartTime Access Denied
|c#|.net-1.1|windows-server-2000|
My code needs to determine how long a particular process has been running. But it continues to fail with an access denied error message on the Process.StartTime request. This is a process running with a User's credentials (ie, not a high-privilege process). There's clearly a security setting or a policy setting, or *so...
In my experience DTOs are most useful for: 1. Strictly defining what will be sent over the wire and having a type specifically devoted to that definition. 2. Isolating the rest of your application, client and server, from future changes. 3. Interoperability with non-.Net systems. DTOs certainly aren't a requir...
The biggest benefit is probably that it will help you understand the architecture of the application much better. You'll be able to see very clearly how your dependencies chains work and be able to make changes to individual parts without requiring you to change things that are unrelated. You'll end up with a loosely...
Have you tried putting a Application.DoEvents() in here if (dlgRes == DialogResult.Yes) { Application.DoEvents(); ProcessAllUpdates(um2); }
How do I treat an integer as an array of bytes in Python?
|python|
I'm trying to decode the result of the Python os.wait() function. This returns, according to the Python docs: > a tuple containing its pid and exit status indication: a 16-bit number, whose low byte is the signal number that killed the process, and whose high byte is the exit status (if the signal number is zero); t...
This will do what you want: signum = status & 0xff exitstatus = (status & 0xff00) >> 8
I'm probably misremembering, but I thought that Joel's question was about **counting** the "on" bits rather than reversing them.
You can unpack the status using [bit-shifting](http://docs.python.org/ref/shifting.html) and [masking](http://docs.python.org/ref/bitwise.html) operators. low = status & 0x00FF high = (status & 0xFF00) >> 8 I'm not a Python programmer, so I hope got the syntax correct.
If you're talking about switching 1's to 0's and 0's to 1's, using Ruby: n = 0b11001100 ~n If you mean reverse the order: n = 0b11001100 eval("0b" + n.to_s(2).reverse) ♥ Ruby
If you're talking about switching 1's to 0's and 0's to 1's, using Ruby: n = 0b11001100 ~n If you mean reverse the order: n = 0b11001100 eval("0b" + n.to_s(2).reverse) If you mean counting the on bits, as mentioned by another user: n = 123 count = 0 0.upto(8) { |i| count =...
As a bare minimum: mscoree.lib MSVCRT.lib mfc90.lib (adjust version appropriately) And iterate from there.
Watch out for the Gnu Scientific Library. It's licensed under the GPL rather than LGPL. As other folks mentioned, the Boost random classes are a good start. Their implementation conforms to the PRNG code slated for TR1: http://www.boost.org/doc/libs/1_35_0/libs/random/index.html http://www.open-std.org/jtc1/sc...
This is just a standard location to store frequently used SQL scripts. The reports-pgsql.sql script creates a table for storing these queries, the database they are intended to be run on, a title and some descriptive text about what they do. PhpPgAdmin has functionality to browse and execute these reports. It's a pr...
I believe the idea is that many servers limit or evenly distribute bandwidth across connections. By having multiple connections, you're cheating that system and getting more than your "fair" share of bandwidth.
If you happen to be using ASP.NET, you might want to check out the [ASP.NET RSS Toolkit](http://www.codeplex.com/ASPNETRSSToolkit). It's useful for both generating and consuming feeds.
Simplest thing to do is to slice it into itself: @array = $array[0..42];
Your options are near limitless (I've outlined five approaches here) but your strategy will be dictated by exactly what your specific needs and goals are. Least code: #best for trimming down large arrays into small arrays @array = $array[0..42]; Most efficient for trimming a small number off of a l...
Your options are near limitless (I've outlined five approaches here) but your strategy will be dictated by exactly what your specific needs and goals are. (all examples will convert @array to have no more than 42 elements) Least code: #best for trimming down large arrays into small arrays #0..41 is a 4...
Your options are near limitless (I've outlined five approaches here) but your strategy will be dictated by exactly what your specific needs and goals are. (all examples will convert @array to have no more than $N elements) ------ [EDIT] As others have pointed out, the way suggested in the original question ...
Actualy, .Net can natively run all these languages because it ransforms all of them in MSIL, provided you have installed the proper compiler. To do so, you can use visual studio and create a project, using various languages. Import you code and adapt it to fit the .net library. A think it´s a lot of work, but if you...
If there's a lesson we can learn from the Internet and Web 2.0 kinds of things, it's that people love customization. That's what iGoogle and hundreds of other sites are all about. If you can build customization in to your GUI, chances are your customers will love you for it. Also, take a look at how other projects...
If there's a lesson we can learn from the Internet and Web 2.0 kinds of things, it's that people love customization. That's what iGoogle and hundreds of other sites are all about. If you can build customization in to your GUI, chances are your customers will love you for it. Also, take a look at how other projects...
1. On a single processor machine and a desktop application, you use multi threads so you don't freeze the app but for nothing else really. 2. On a single processor server and a web based app, no need for multi threading because IIS handles most of it. 3. On a multi processor machine and desktop app, you are sugges...
I use Ant's copy with a filter file. In the directory with the config file with variables I have a directory with a file for each environment. The build script know the env and uses the correct variable file.
The biggest benefit is that it will help you understand or even uncover the architecture of your application. You'll be able to see very clearly how your dependency chains work and be able to make changes to individual parts without requiring you to change things that are unrelated. You'll end up with a loosely coupl...
On some systems (Solaris, for example), there's no default action, so you need to add the -print command. find /usr -name '*.foo' -print
On some systems (Solaris, for example), there's no default action, so you need to add the -print command. find /usr -name '*.foo' -print
you can always just use the as cast: c as IMyButtonInterface; if (c != null) { // c is an IMyButtonInterface }
Short answer: there's no way to do inline variable assignment in a while loop in Python. Meaning that I **cannot** say: while x=next(): // do something here! Since that's not possible, there are a number of "idiomatically correct" ways of doing this: while 1: x = next() if ...
These are usually referred to as client side certificates. I've not actually used it but a modified version of restful-authentication can be found here [here][1] that looks like what your after. I found this via [Dr. Nic's post][2] [1]: http://github.com/labria/restful-authentication/tree/master [2]: ht...
Is gettimeofday() guaranteed to be of microsecond resolution?
|c++|c|linux|unix|timer|
So I find myself porting a game that was originally written for the Win32 API to Linux (well, porting the OS X port of the Win32 port to Linux), and have implemented QueryPerformanceCounter by giving the uSeconds since the process start up: BOOL QueryPerformanceCounter(LARGE_INTEGER* performanceCount) { ...
Kieron does a good job of summarizing GI. It's really for enterprise web applications, not consumer-y widgets. The overhead of loading the entire GI framework and waiting a second or two for it to load doesn;t seem like much if you're firing up a call center or an employee provisioning application you're going to use...
> Suppose a programmer is actually doing > this in the right manner already, then > do we really need the concept of > foreign keys? Theoretically no, However there have never been a piece of software without bugs. Bugs in application code are typically not that dangerous - you identify the bug and fix it, an...
I suppose you are talking about *foreign key constraints enforced by the database*. You probably already are using foreign keys, you just havent told the database about it. > Suppose a programmer is actually doing > this in the right manner already, then > do we really need the concept of > foreign keys? Theor...
It's all about [Little's Law][1]. Specifically each stream to the web server is seeing a certain amount of TCP latency and so will only carry so much data. Tricks like increasing the TCP window size and implementing selective acks help but are poorly implemented and generally cause more problems than they solve. Hav...
FileStream simply exposes an IO.Stream around a file object, and uses buffers. It doesn't read the entire file in the constructor (the file could be larger than RAM). The performance issue is most likely in the hashing, and you can perform some simple benchmarks to prove whether it's because of file IO or the algor...
Okie doke, I think I just figured this out. As I said above, the key bit of knowledge is that the cert doesn't matter, so long as it's generated with an algorithm that supports AES 256-bit encryption (e.g., RSA). Just to make sure that we're on the same page, for my testing, I generated my self-signed cert using th...
Prevent multiple instances of a given app in .NET?
|c#|.net|
In .NET, what's the best way to prevent multiple instances of an app from running at the same time? And if there's no "best" technique, what are some of the caveats to consider with each solution?
Javascript is single-threaded and can't access the filesystem, so I don't think you have to worry about those. I'm not sure if there's a way to set a timeout to guard against infinite loops, but you could always spawn a (Java) thread that executes the script, and then kill the thread after so much time.
in c++ OpenCV (open source Computer Vision library from Intel) let you create an AVI file and just push frames inside... but it's like shooting with a cannon to a fly.
One easy work around is to pass the page number to your button's Clicked event as you construct the buttons. for (int page = 0; page < n; page++){ int the_page = page; NotebookPage p = new NotebookPage (); ... Button b = new Button ("Close page {0}", the_page); b.Cli...
To paraphrase an old quote: A programmer had a problem. He thought, "I know, I'll use threads." Now the programmer has two problems. (Often attributed to JWZ, but it seems to predate his use of it talking about regexes.) A good rule of thumb is "Don't use threads, unless there's a very compelling reason to use th...
Best way to encapsulate complex Oracle PL/SQL cursor logic as a view?
|oracle-database|plsql|
I've written PL/SQL code to denormalize a table into a much-easer-to-query form. The code uses a temporary table to do some of its work, merging some rows from the original table together. The logic is written as a [pipelined table function][1], following the pattern from the linked article. The table function uses ...
|sql|oracle-database|plsql|
Most download 'accelerators' really don't speed up anything at all. What they are good at doing is congesting network traffic, hammering your server, and breaking custom scripts like you've seen. Basically how it works is that instead of making one request and downloading the file from beginning to end, it makes say fo...
What is the .NET equivalent of php var_dump?
|.net|reflection|framework|
I remember seeing a while ago that there is some method in maybe the Reflection namespace that would recursively run ToString() on all of an object's properties and format it nicely for display. Yes, I know everything I could want will be accessible through the debugger, but I'm wondering if anyone knows that comm...
It looks like you don't have closing quotes around your @RespondentFilters <pre>'8ec94bed-fed6-4627-8d45-21619331d82a, 114c61f2-8935-4755-b4e9-4a598a51cc7f'</pre> Since GUIDs do a string compare, that's not going to work. Your best bet is to use some code to split the list out into multiple values. Something...
They don't, generally. To answer the substance of your question, the assumption is that the server is rate-limiting downloads on a per-connection basis, so simultaneously downloading multiple chunks will enable the user to make the most of the bandwidth available at their end.
How to disable browser postback warning dialog
|asp.net|javascript|internet-explorer-7|
I have an asp.net application that runs exclusively on IE7 (internal web site). When a user needs to enter data, I pop up a child window with a form. When the form closes, it calls javascript:window.opener.location.reload(true) so that the new data will display on the main page. The problem is that the browser co...
You might also consider [boost::any][1]. I've used it for heterogeneous containers. When reading the value back, you need to perform an any_cast<T>. It will throw a bad_any_cast if it fails. If that happens, you can catch and move on to the next type. I *believe* it will throw a bad_any_cast if you try to any_cast a...
Based on what D2VIANT referenced > Full Article: http://www.hanselman.com/blog/CatchingRedBitsDifferencesInNET20AndNET20SP1.aspx I was able to find additional resources which list the changes in .NET SP1 some of the types added/affected are listed below - System.DateTimeOffset - System.GCCollectionMode - Syste...
I don't see what the big deal is.. var something = someMethod(); // Type of 'something' not clear <-- not to the compiler! You still have full intellisense on 'something', and for any ambiguous case you have your unit tests, right? ( do you? ) It's not varchar, it's not dim, and it's certainly not dyna...
It's a matter of taste. All this fussing about the *type* of a variable disappears when you get used to dynamically typed languages. That is, *if* you ever start to like them (I'm not sure if everybody can, but I do). C#'s `var` is pretty cool in that it *looks* like dynamic typing, but actually is **static** typing...
I don't know without trying it, but what if you programatically wire up the button's event handler? For instance, in the code-behind for the User Control itself, in Init or Load (not sure): AddHandler Button1.Click, AddressOf Button1_Click If that doesn't do anything, I know it's less efficient, but what if y...
What's the easiest non-memory intensive way to output XML from Python?
|python|xml|streaming|
Basically, something similar to System.Xml.XmlWriter - A streaming XML Writer that doesn't incur much of a memory overhead. So that rules out xml.dom and xml.dom.minidom. Suggestions?
not built in, but if you add <7z command here> 2>&1 NUL to the end of your command line, it will redirect all the output into the null device and stops it echoing to the screen. This is the ms-dos equivalent of 2>&1 /dev/null in linux and unix systems.
Windows Form with Resizing Frame and no Title Bar?
|c#|winforms|resize|titlebar|
How can I hide the title bar from a Windows Form but still have a Resizing Frame?
All that the `test` attribute looks for to determine if something is true is the string "true" (case in-sensitive). For example, the following code will print "Hello world!" <c:if test="true">Hello world!</c:if> The code within the `<%= %>` returns a boolean, so it will either print the string "true" or "fal...
I worked for four years as the main developer in a web agency, as I wrote from ground-up my first two or three websites, I soon realized that it was going to be a very boring task to do it all the times. So I started writing my own web site generator engine. My starting point was this site http://www.codegeneration....
AFAIK, there is not a switch for that, but you could hide the output redirecting it to a file, for example (DOS batch): 7z.exe ... normal parameters > DumpFile.txt This way all the output ends in DumpFile.txt and not on the screen.
Debugging an exception in an empty catch block
|ide|
I'm debugging a production application that has a rash of empty catch blocks *sigh*: try {*SOME CODE*} catch{} Is there a way of seeing what the exception is when the debugger hits the catch in the IDE?
|c++|linux|c|unix|timer|
|c++|c|linux|unix|timer|
Static is bad for extensibility since static methods and fields cannot be extended or overridden by subclasses. It's also bad for unit tests. Within a unit test you cannot keep the side effects of different tests from spilling over since you cannot control the classloader. Static fields initialized in one unit test...
sparkes <a href="#28569">wrote</a> > If you think you have found a bug in > GCC the mailing lists will be glad you > dropped by but generally they find > some hole in your knowledge is to > blame and mock mercilessly :( I figured I'd try my luck here first before going to the GCC mailing list to show my incom...
System.getProperty("user.dir"); The above method gets the user's working directory when the application was launched. This is fine if the application is launched by a script or shortcut that ensures that this is the case. However, if the app is launched from somewhere else (entirely possible if the command li...
The underlying code needs to be able to call OpenProcess, for which you may require SeDebugPrivilege. Is the process you're doing the StartTime request on running as a different user to your own process?
You should be able to use .mywidth{ width:100px; } <input class="mywidth" > <textarea class="mywidth"></textarea>
Yes, there is. Try doing something like this: <textarea style="width:80%"> </textarea> <input type="text" style="width:80%" /> Both should equate to the same size. You can do it with absolute sizes (px), relative sizes (em) or percentage sizes.
I've written PL/SQL code to denormalize a table into a much-easer-to-query form. The code uses a temporary table to do some of its work, merging some rows from the original table together. The logic is written as a [pipelined table function][1], following the pattern from the linked article. The table function uses ...
You can use the Factory pattern to request a reference to cManager by both aManager and bManager as needed. http://msdn.microsoft.com/en-us/library/ms954600.aspx
I just use different Spring XML configuration files for each machine, and make sure that all the bits of configuration data that vary between machines is referenced by beans that load from those Spring configuration files. For example, I have a webapp that connects to a Java RMI interface of another app. My app get...
I usually have Project Directory src - actual source doc - documentation lib - libraries referenced from source dep - installation files for dependencies that don't fit in lib db - database installation script In work with Visual Studio, I'm not sure if this works the same ...