instruction stringlengths 0 30k ⌀ |
|---|
|java|fun|homework|linkedlist| |
|java|linkedlist| |
|java|linked-list| |
Well, if you don't mind copying the original method in the subclass, you can use the following technique.
import new
def copyfunc(func):
return new.function(func.func_code, func.func_globals, func.func_name,
func.func_defaults, func.func_closure)
class Metaclas... |
I use [GeSHi][1] ("Generic Syntax Highlighter") on [pastebin.com][2]
[1]: http://qbnz.com/highlighter/
[2]: http://pastebin.com |
I use [GeSHi][1] ("Generic Syntax Highlighter") on [pastebin.com][2]
pastebin has high traffic, so I do cache the results of the transformation, which certainly reduces the load.
[1]: http://qbnz.com/highlighter/
[2]: http://pastebin.com |
The closest you can get is:
Dim var as Object
It's not exactly the same as VB6's as Any (which stores values in a Variant) but you can store variables of any type as Object, albeit boxed. |
When you select records (excluding soft-deletes) to display them in user interface/ output file, use where not isdeleted.
But when the user requests an insert operation, perform two queries.
1. Lookup all records (ignoring isdeleted value).
2. Based on first query result, perform an UPDATE if it exists (and re... |
You should try the Loki library's SafeFormat header file (http://loki-lib.sourceforge.net/index.php?n=Idioms.Printf). It's similar to boost's string format library, but keeps the syntax of the printf(...) functions.
I hope this helps!
|
Note that IE does not support XHTML parsing. Even if you use an XML declaration and/or an XHTML doctype, IE still parses the document as plain HTML. And in plain HTML, the self-closing syntax is not supported. The trailing slash is just ignored, you have to use an explicit closing tag.
Even browsers with support for... |
The META-INF folder is the home fort the [MANIFEST.MF][1] file. This file contains meta data about the contents of the JAR. For example, there is an entry called Main-Class that specifies the name of the Java class with the static main() for executable JAR files.
[1]: http://java.sun.com/developer/Books/javaprog... |
import ImageGrab
img = ImageGrab.grab()
img.save('test.jpg','JPEG')
this requires Python Imaging Library |
Prevent vim from replacing spaces with tabs when autoindent is on |
|vim|vi| |
How do I prevent vim from replacing spaces with tabs when autoindent is on
An example: if I have two tabs and 7 spaces in the beginning of the line, and `tabstop=3`, and I press Enter, the next line has four tabs and 1 space in the beginning, but I don't want that... |
Tabs and spaces in vim |
How do I prevent vim from replacing spaces with tabs when autoindent is on?
An example: if I have two tabs and 7 spaces in the beginning of the line, and `tabstop=3`, and I press Enter, the next line has four tabs and 1 space in the beginning, but I don't want that... |
Are there any resources for becoming a Cygwin "power user"? |
|windows|cygwin|nix| |
|windows|unix|cygwin| |
The first query will be faster in SQL Server which I think is slighty counter intuitive - Sub queries *seem* like they should be slower. In some cases (as data volumes increase) an `exists` may be faster than an `in`. |
Setting up Team foundation server |
|tfs| |
I have to setup team foundation server for a company, something that I don't have any experience in.
The company will have about 5 or so developers that will be using it.
Is this a big task or something that is fairly easy to do (with instructions)?
Any helpful tutorials that you can recommend?
Any recomm... |
I have seen this happen with indexes that were out of date. It could also be a parameter sniffing problem, where a different query plan is being used for different parameters that come in to the stored procedure.
You should capture the parameters of the slow calls and see if they are the same ones each time it runs... |
A strange, edge case but I encountered it recently.
If the queries run longer in the application than they do when run from within Management Studio, you may want to check to make sure that Arithabort is set off. The connection parameters used by Management Studio are different from the ones used by .NET. |
**Create a perpetual session.**
Essentially you end up emitting some JavaScript and an image tag in your master page or navigation users controls (whatever you're using for consistent navigation). This JavaScript on some interval changes the source of the image tag to an http handler endpoint (some .aspx, .ashx) whi... |
When possible, you should not store the entire contents of a file to be served in memory. Instead, aquire an InputStream for the data, and copy the data to the Servlet OutputStream in pieces. For example:
ServletOutputStream out = response.getOutputStream();
InputStream in = [ code to get source input str... |
Perhaps you could add more information which operations do you really want. I guess you want to create a set which automatically groups their elements by a key, right? The question is which operations do you want to be able to have? How are elements added to the Set? Can elements be deleted by removing them from a grou... |
Algorithm to determine Daylight Saving Time of a date? |
|java|actionscript| |
Originally I am looking for a solution in Actionscript. The point of this question is the algorithm, which detects the exact Minute, when a clock has to switch the Daylight Saving Time.
So for example between the 25th and the 31th of October we have to check, if the actual date is a sunday, it is before or after 2 ... |
For composite keys (assumed that database allows nulls in PKs) you can have maximum number_of_cols^2 - 1 entries containing nulls, (for example for composite key of 2 columns you can have 3 rows having in their primary key null, the fourth is the PK without nulls). |
Tuples, being immutable, are more memory efficient; lists, for efficiency, overallocate memory in order to allow appends without constant `realloc`s. So, if you want to iterate through a constant sequence of values in your code (eg `for direction in 'up', 'right', 'down', 'left':`), tuples are preferred, since such tup... |
Don't accidentally conflate encryption with obfuscation. We commonly obfuscate emails to prevent spam. Lots of web sites will have "webmaster \_at\_ mysite.com" to slow down crawlers from parsing the email address as a potential spam target. That should be done in the HTML templates -- there's no value to doing this... |
What are you trying to accomplish? `Map` already exposes its keys as a `Set` via its [keySet()](http://java.sun.com/j2se/1.5.0/docs/api/java/util/Map.html#keySet(\)) method. If you want a reliable iteratior order, there's [LinkedHashMap](http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedHashMap.html) and [TreeMap... |
Need more info - what kind of image is it?
is it a file that's a filesystem? if so you mount it like:
mount -o loop rootfs.img /mnt/rootfs
if it's a subdir of your filesystem that you'r exporting via nfs, you can simulat ethe environment you've created by chrooting to it:
chroot /path/to/nfs/r... |
I would use Box-Muller. Two things about this:
1. You end up with two values per iteration
Typically, you cache one value and return the other. On the next call for a sample, you return the cached value.
2. Box-Muller gives a Z-score
You have to then scale the Z-score by the standard deviation and add the mea... |
Use some Perl module to do date calculations, like recommended DateTime or Time::Piece (core from 5.10). Just increment date and print date and 0 until date will match current. |
Are you married to MySQL? <a href="http://www.postgresql.org/">Postgres</a> is ACID-compliant (like innoDB) and (when well-tuned) nearly as speedy as MyISAM. |
You definitely want to use an ORM. Any ORM is ok, but you want something that will generate a strongly typed classes. When fields get added, modified or deleted from a table, you want to be able to regenerate those classes, and deal with fixing compile time errors only. If you use a dynamic model, you're likely to have... |
You definitely want to use an ORM. Any ORM is ok, but you want something that will generate strongly typed classes. When fields get added, modified or deleted from a table, you want to be able to regenerate those classes, and deal with fixing compile time errors only. If you use a dynamic model, you're likely to have m... |
I use [devpartner][1] with MSVC 6 and XP
[1]: http://en.wikipedia.org/wiki/DevPartner |
I would suggest you use LabVIEW as you can get down to making the robot what you want to do faster and easier. LabVIEW has been designed with this mind. OfCourse C(++) are great languages, but LabVIEW does what it is supposed to do better than anything else.
People can write really good software in LabVIEW as it provi... |
The general problem is usually referred to as serialization of your application state and in your case with a source/target of a file in whatever format makes sense for you. These days the preferred input/output format is XML, and you may want to look into the existing standards in this field. The problem then become... |
Is there a common way to check in Python if an object is any function type? |
|python|types| |
I have a function in Python which is iterating over the attributes returned from dir(obj), and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use callable() for this, but I don't want to disqualify classes. The best I've come up with so ... |
I have a function in Python which is iterating over the attributes returned from dir(obj), and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use callable() for this, but I don't want to include classes. The best I've come up with so far... |
From [geekpedia][1] :
// Store integer 182
int decValue = 182;
// Convert integer 182 as a hex in a string variable
string hexValue = decValue.ToString("X");
// Convert the hex string back to the number
int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
... |
There is some documentation in iPhone SDK itself.
Other than that, just take what you know about OpenGL (or learn that via other means), and forget about all things that are "old cruft" (display lists, immediate mode, things that are in OpenGL but are not directly related to just drawing triangles). Basically, unlea... |
Also consider [Hands-On Python](http://www.cs.luc.edu/~anh/python/hands- on/). It is used as a primary text for Computer Science 150 at Loyola University. It is concise intro to Python while emphasizing good programming style and design. |
Remove `VALUES` from your SQL. |
DropdownList autoposback after client confirmation |
When I read the title 'bad BAD database design', I was curious to find out how bad it is. You didn't disappoint me :)
As others mentioned, a script would be the easiest way. This can be accomplished by writing about 15 lines of code in PHP.
SELECT * FROM ugly_table;
while(row)
foreach(row as field =... |
Read [Unix Network Programming][1] by Richard Stevens. It's a must. It explains how it all works, gives you code, and even gives you helper methods. You might want to check out some of his other books. [Advanced Programming In The Unix Enviernment][2] is a must for lower level programming in Unix is general. I don... |
Nothing in .NET that could do that directly AFAIK.
I think you are looking for **[Volume Shadow Copy][1]** on XP/Vista which is designed for this kind of task.
[1]: http://msdn.microsoft.com/en-us/library/bb968832(VS.85).aspx |
Font rendering libraries for C# / dot-NET? |
|c#|.net|fonts|text|gdi+| |
Are there any free, third-party libraries for rendering arbitrarily scaled and rotated text in dot-NET applications? Although native GDI+ allows for text scaling and rotation, its methods for determining the rendered text's dimensions are not sufficiently precise and the differences in kerning as text is added to a ren... |
What runs in a C heap vs a Java heap in HP-UX environment JVMs? |
|java|c|jvm|heap|hp-ux| |
I've been running into a peculiar issue with certain Java applications in the HP-UX environment.
The heap is set to -mx512, yet, looking at the memory regions for this java process using gpm, it shows it using upwards of 1.6GBs of RSS memory, with 1.1GB allocated to the DATA region. Grows quite rapidly over a 24-... |
When possible, you should not store the entire contents of a file to be served in memory. Instead, aquire an InputStream for the data, and copy the data to the Servlet OutputStream in pieces. For example:
ServletOutputStream out = response.getOutputStream();
InputStream in = [ code to get source input str... |
The way most people ship ruby programs, including Rails webapps, as a standalone exe is via rubyscript2exe. They describe how to package a Rails application at [http://www.erikveen.dds.nl/distributingrubyapplications/rails.html][1]. Ruby, Rails, and all the associated libraries will be included in the EXE file.
As o... |
Rails monkeypatches most things you'd care about to have a `#to_json` method.
Off the top of my head, you can do it for hashes, arrays, and ActiveRecord objects, which should cover about 95% of the use cases you might want. If you have your own custom objects, it's trivial to write your own `to_json` method for them... |
Previous comments about using abstract classes for common implementation is definitely on the mark. One benefit I haven't seen mentioned yet is that the use of interfaces makes it much easier to implement mock objects for the purpose of unit testing. Defining IPet and PetBase as Jason Cohen described enables you to m... |
I can only think of doing it in code. Look for an exact match, if the result is empty, look for a LIKE.
One other option is a WHERE within this query such that WHERE ({count from exact match}=0), in which case, it wont go through the comparison with LIKE if the exact match returns more than 0 results. But its terribl... |
You could perform some sort of block-matching motion estimation between the two images and measure the overall sum of residuals and motion vector costs (much like one would do in a video encoder). This would compensate for motion; for bonus points, do affine-transformation motion estimation (compensates for zooms and ... |
akdom has given a fairly good answer, but doesn't do its relevance justice.
Many common desktops, including Gnome, KDE and XFCE where relevant, implement the specifications laid out by <a href="http://www.freedesktop.org/">freedesktop.org</a>. Among these, is the <a href="http://standards.freedesktop.org/desktop-ent... |
Another vote for Launch4J, just wrote an ant task this morning to integrate with one of my projects. Seems to work really well |
The standard Python library module **random** has what you want:
> normalvariate(mu, sigma)
> Normal distribution. mu is the mean, and sigma is the standard deviation.
For the algorithm itself, take a look at the function in random.py in the Python library.
The [manual entry is here][1]
[1]: http://... |
Like Philip Rieck said, the margin property is only respected by container controls that perform layout. Here's an example that makes it fairly clear how the <code>TableLayoutPanel</code> respects the Margin property:
<pre><code>using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication... |
If you are staying on the same server then putting this in your .htaccess will work regardless of the server:
RedirectMatch 301 ^/terms$ /articles/terms/
Produces:
http://example.com/terms -> http://example.com/articles/terms
or:
http://test.example.com/terms -> http://test.example.com/articl... |
It's worth pointing out that the vast majority of the "higher-level" interfaces (like SQL::Abstract) and (DBIx::Simple) use DBI itself when actually performing the queries. DBI is pretty much the accepted standard method for database connection in Perl. |
You can either use a `std::set` of 3D coordinates, or a sorted `std::vector`. Both will give you logarithmic time lookup. In either case, you'll need to implement the less than comparison operator for your 3D coordinate class. |
You may know this, but for **many** commands a "C-u 10" prefix will do the trick. Unfortunately for the C-y yank command, "C-u" is redefined to mean "go back that many items in the kill ring, and yank that item".
I thought you might be able to use the copy-to-register and insert-register commands with the C-u prefi... |
What about:
#!/usr/bin/perl -w
use strict;
use warnings;
my $version_file = 'current_version';
open my $fh, '<', $version_file or die "Can't open $version_file: $!";
# Read version from file
my $version = <$fh>;
chomp $version;
# Remove whitespace (and match version)... |
WinForms are fully supported by Mono, so they are cross-platform. |
You can use exec() to run a command line script (such as command line php), and if you pipe the output to a file then your script won't wait for the command to finish.
I can't quite remember the php CLI syntax, but you'd want something like:
exec('/path/to/php -f '/path/to/file.php' | '/path/to/output.txt');
... |
If you just want to *watch* what's opened, you want to look at the ptrace() function, or the source code of the commandline strace utility. If you actually want to *intercept* the call, to maybe make it do something else, I think the options you listed - LD_PRELOAD or a kernel module - are your only options. |
Factory classes are useful for when the object type that they return has a private constructor, when different factory classes set different properties on the returning object, or when a specific factory type is coupled with its returning concrete type.
**WCF** uses ServiceHostFactory classes to retrieve ServiceHos... |
Factory classes are useful for when the object type that they return has a private constructor, when different factory classes set different properties on the returning object, or when a specific factory type is coupled with its returning concrete type.
**WCF** uses ServiceHostFactory classes to retrieve ServiceHos... |
Factory classes are useful for when the object type that they return has a private constructor, when different factory classes set different properties on the returning object, or when a specific factory type is coupled with its returning concrete type.
**WCF** uses ServiceHostFactory classes to retrieve ServiceHos... |
I've done this with user tables, where the email is a unique constraint. If someone cancels there account, their information is still needed for referential integrity, so what I to is set is_deteled to true, and add '_deleted' to the email field. In this way, if the user decides to sign up again in the future, there ... |
VB.NET does not support the as any keyword, VB.NET is a strongly typed language, you can however (with .NET 3.5) use implicit typing in VB
Dim fred = "Hello World" will implicitly type fred as a string variable. If you want to simply hold a value that you do not know the type of at design time then you can simply de... |
Here is a (slightly) simpler version:
CREATE PROCEDURE dbo.CalculateAge
@dayOfBirth datetime
AS
DECLARE @today datetime, @thisYearBirthDay datetime
DECLARE @years int, @months int, @days int
SELECT @today = getdate()
SELECT @thisYearBirthDay = dateadd(year, da... |
Here is a (slightly) simpler version:
CREATE PROCEDURE dbo.CalculateAge
@dayOfBirth datetime
AS
DECLARE @today datetime, @thisYearBirthDay datetime
DECLARE @years int, @months int, @days int
SELECT @today = GETDATE()
SELECT @thisYearBirthDay = DATEADD(year, DA... |
There are not harmful keywords. There's only harmful uses of them.
Goto is not harmful per se, neither is continue. They need to be used carefully, that's all. |
BufferedGraphicsContext Error |
|winforms|exception|multithreading|gdi+| |
I am getting the below error and call stack at the same time everyday after several hours of application use. Can anyone shed some light on what is happening?
System.InvalidOperationException: BufferedGraphicsContext cannot be disposed of because a buffer operation is currently in progress.
at System.Drawing.B... |
Using the each syntax will prevent the entire set of keys from being generated at once. This can be important if you're using a tie-ed hash to a database with millions of rows. You don't want to generate the entire list of keys all at once and exhaust your physical memory. In this case each serves as an iterator whe... |
Reading files in use and system files on Windows XP & Vista using .NET |
|windows|c#|operating-system| |
I have this idea for an free backup application.
The largest problem I need to solve at the moment is how to access files which are being used or are system files. I would like the application to be able to perform a full backup of files (i.e. not on a disk sector by sector level).
I'll turn the server part of th... |
|c#|.net|windows| |
I have this idea for a free backup application.
The largest problem I need to solve at the moment is how to access files which are being used or are system files. I would like the application to be able to perform a full backup of files (i.e. not on a disk sector by sector level).
I'll turn the server part of the... |
Here is what I did...
Public Function GetString(ByVal memStream As MemoryStream) As String
' Important to reset the stream otherwise you will just get an empty string.
memStream.Position = 0
Using reader As New StreamReader(memStream)
Return reader.ReadToEnd()
End... |
Using a StreamReader to convert the MemoryStream to a String.
Public Function GetString(ByVal memStream As MemoryStream) As String
' Important to reset the stream otherwise you will just get an empty string.
memStream.Position = 0
Using reader As New StreamReader(memStream)
... |