instruction
stringlengths
0
30k
`file` is the actual type (using e.g. `file('myfile.txt')` is calling its constructor). `open` is a factory function that will return a file object. In python 3.0 `file` is going to move from being a built-in to being implemented by multiple classes in the `io` library (somewhat similar to Java with buffered readers...
Two reasons: The python philosophy of "There ought to be one way to do it" and `file` is going away. `file` is the actual type (using e.g. `file('myfile.txt')` is calling its constructor). `open` is a factory function that will return a file object. In python 3.0 `file` is going to move from being a built-in to b...
I'm not sure how to add them (never needed to), but I'm pretty sure <code>/etc/inittab</code> is where you'd add runlevels. Although I'd have to agree with Zathrus that other runlevels are available but unused. On Debian, only 1 and 2 are used, really. I'm not sure how Ubuntu has it set up, though. However, if you h...
There's a great chapter in Steve McConnell's [Code Complete][1] that runs through specification documents and what they should contain. When I was tasked to build an Architecture and Business Analysis team at a company that had never had either, I used McConnell's spec chapter to create the outline for the Technical...
When is multi-threading not a good idea?
|multithreading|language-agnostic|
I was recently working on an application that sent and received messages over Ethernet and Serial. I was then tasked to **add** the monitoring of DIO discretes. I throught, > "No reason to interrupt the main > thread which is involved in message > processing, I'll just create > ***another thread*** that monit...
I like [960 Grid System][1]. It's a lightweight, easy to use css which devides the screen into 12 (or 16) columns. You can use it for a 3 column design and align the rest of your content accordingly. [1]: http://960.gs/
If you have ReSharper then, select the solution, right click and select cleanup code. Resharper will then go through every code file in the solution. As to removing project references, when the compiler runs it won't add the reference if no code uses that dll.
I like [dotProject][1] for actual task tracking. You can easily attack the database to get your on statistical data out of it if needen. For the planning proces I use [Microsoft Project][2] mainly because I'm used to it. I also used the open source tool [OpenProj][3]. Changing tasks in dotProject is painful, so...
Well, your *explanation* isn't an explanation at all, it's an observation of behavior, which is different. If you want an explanation of what the difference is, then you need a piece of text *explaining* it. And the behavior explained can be demonstrated with the code. The page linked to by Grimtron is good for d...
Well, your *explanation* isn't an explanation at all, it's an observation of behavior, which is different. If you want an explanation of what the difference is, then you need a piece of text *explaining* it. And the behavior explained can be ed with the code. The page linked to by Grimtron is good for detailing a...
It is nice to not have to check for NULL, and some languages make it easier -- e.g. C#'s non-NULLable types, or Haskell which doesn't have NULLs but can express a missing value with the Maybe type constructor. A NULL is distinct from an empty list. You can take the point-of-view that someone passing in a NULL where...
It is helpful to understand the very low levels of the computer. For example there are developers who will say the CPU executes some sort of "new object" instruction. There is of course no such instruction, management of objects happens several layers of abstraction higher. It is good to understand the distinction, so ...
`Date d = new Date();`
Date d = new Date(); String formatted = SimpleDateFormat ("yyyy-MM-dd:HH-mm-ss").format (d); System.out.println (formatted);
Date d = new Date(); String formatted = new SimpleDateFormat ("yyyy-MM-dd:HH-mm-ss").format (d); System.out.println (formatted);
You could put this in your .vimrc file to prevent hilighting alltogether, if you don't find it useful (like me). set nohlsearch
There is hlsearch and nohlsearch. :help hlsearch will provide more information. If you want to bind F12 to toggle it on/off you can use this: map <F12> :nohlsearch<CR> imap <F12> <ESC>:nohlsearch<CR>i vmap <F12> <ESC>:nohlsearch<CR>gv
If you are hashing a fixed set of words, the best hash function is often a [perfect hash function][1]. However, they generally require that the set of words you are trying to hash is known at compile time. Detection of keywords in a [lexer][2] (and translation of keywords to tokens) is a common usage of perfect hash fu...
I think scope is the biggest issue here, as you have pointed out. In the "while" example, the iterator is declared outside the loop, so it will continue to exist after the loop is done. This may cause issues if this same iterator is used again at some later point. E. g. you may forget to initialize it before using...
When using javascript: **Don't use browser detection** Write code that tests itself for given cases exhibited by browsers, otherwise you'll simply be writing code for a very very small population. Its better to use <code>"typeof foo == 'undefined'"</code> and browser specific tricks where you need them. jQuer...
How do stop mysql on a Mac OS install
|mysql|macos|
I installed it it via mac ports, what is the command I need to stop the server (i need to test how my app behave when MySQL is dead)
A useful approach for serialising instances of non-serializable classes (or at least subclasses of) is known a Serial Proxy. Essentially you implement writeReplace to return an instance of a completely different serializable class which implements readResolve to return a copy of the original object. I wrote an example ...
I don't see why your technique of hardcoding the default implementation could not be used together with an IOC container. Just, the dependencies you don't specify in the configuration would take the default implementation. Or am I missing something?
Apparently you want: sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop Have a further read here: http://www.simplisticcomplexity.com/2007/10/27/start-and-stop-mysql-in-mac-os-x-105-leopard/
There seem to have been attempts at having a SLIME-like integration of Lisp in Vim, but none have really gone as far as needed to be really useful. I think ECL's integration has been done, though, but not committed upstream. You should find all relevant links from [Cliki's page about Vim](http://www.cliki.net/vim).
Mac SQLite editor
|user-interface|mac|sqlite|
I am aware of [CocoaMySQL][1] but I have not seen a Mac GUI for SQLite, is there one? My Google search didn't turn up any Mac related GUI's which is why I'm asking here rather than Google. [1]: http://cocoamysql.sourceforge.net/
Add the calling method to the LogEntry's ExtendedProperties dictionary; assuming you haven't removed the ExtendedProperties tokens from the formatter template, of course. Put something like this in a logging wrapper: public void LogSomething(string msg) { LogEntry le = new LogEntry { Message = m...
::SendMessage( )
|c++|
LRESULT result = ::SendMessage(hWnd, s_MaxGetTaskInterface, (WPARAM)&pUnkReturn, 0); The value of result after the call is 0 I expect it to return with a valid value of pUnkReturn , but it returns with a NULL value . Necessary Information before this call : const UINT CMotionUtils::s_MaxGetTaskInterfa...
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
|python|
In many places,(1,2,3) and [1,2,3] can be used interchangably. When should I use one or the other, and why?
This might be a reference to [RSpec][1], which is a really clever way of developing tests as a series of requirements. I'm still getting used to it, but it's been very handy in both defining what I need to do and then ensuring I do it. [1]: http://rspec.info/
Some of the really big dogs, such as [ERwin Data Modeler][1], will go object to DB. You need to have the big bucks to afford the product though. [1]: http://ca.com/us/products/product.aspx?id=260
So I tried both options on my WordPress db. I looked for the category "Tech" in my posts with the tags "Perl" AND "Programming". [Eric's][1] worked once I added a missing comma in the initial select statement. It returned 3 records. The problem is that the section that is looking for the "post_tag" is actually wo...
Deploying a Git subdirectory in Capistrano
|ruby-on-rails|deployment|git|capistrano|
My master branch layout is like this: / <-- top level /client <-desktop client source files /server <- Rails app What I'd like to do is only pull down the /server directory in my deploy.rb, but I can't seem to find any way to do that. The /client directory is huge, so setting up a hook to copy /server to / ...
Actually, you definately can, and it's beautiful, ugly, and crazy at the same time! You can replace sys.stdout and sys.stderr with StringIO objects that collect the output. Here's an example, save it as evil.py: import sys import StringIO s = StringIO.StringIO() sys.stdout = s ...
An **Event** declaration adds a layer of abstraction and protection on the **delegate** instance. This protection prevents clients of the delegate from resetting the delegate and its invocation list and only allows adding or removing targets from the invocation list.
|language-agnostic|multithreading|
I was recently working on an application that sent and received messages over Ethernet and Serial. I was then tasked to **add** the monitoring of DIO discretes. I throught, > "No reason to interrupt the main > thread which is involved in message > processing, I'll just create > ***another thread*** that monit...
What about quicksort? Exchange can do that too, might be more "stable" by your terms, but quicksort is faster.
Microsoft designed console and GUI apps to be mutually exclusive. This bit of short-sightedness means that there is no perfect solution. The most popular approach is to have two executables (eg. cscript / wscript, java / javaw, devenv.com / devenv.exe etc) however you've indicated that you consider this "cheating". ...
Several functions in the C standard library return an 'error code' integer as result. Since noErr is defined as 0, a quick check can be 'if it's 0, it's Ok'. The same convention carried to a Unix process' 'result code'; that is, an integer that gave some inidication about how a given process finished. In Unix shel...
[Aptana Studio IDE][1] has a nice javascript debugger. The community version supports only Firefox, the professional one also supports Internet Explorer. [1]: http://www.aptana.com/studio
What's the best source to learn about database replication mechanisms?
|database|computer-science|replication|
What's the widest overview and where are the deepest analysis of different replication methods and problems?
I would do the following: $string = <<< heredoc plain text and now a function: %s heredoc; $string = sprintf($string, testfunction()); Not sure if you'd consider this to be more elegant ...
You can use anywhere, css files are not a requirement. using css files however is recommended as it makes the site easier to maintain and change in the future
Have to? No. You *can* do it however you prefer. Generally it's better stype to keep your CSS out of your html whenever possible though.
That's what i usually do. At least at the begining. When a page design gets close to final, I move most things to the 'main' style.css
To expand on Nils answer (yes it will throw), but what happens when it throws is sometimes confusing in the spec. In 17.2.2 of the specification (regarding maps / exceptions), if insert() throws, that function has no effect. This is a strong guarantee for map. This differs from containers using contiguous alloca...
You can define CSS at three levels, externally, embedded in the document (inside a &lt;style&gt; tag), or inline on the element. Depending on your needs, you might use all three, as a rule of thumb external sheets are good for overall styles as you can apply them globally. If you have specific cases that you must h...
<code>people</code> and <code>otherPeople</code> contain objects of type <code>IQueryable&lt;Person></code>. If you iterate over both, separatly, it will run two queries. If you only iterate over <code>otherPeople</code>, it will run the expected query, with two where clauses. If you do <code>.ToList()</code> on...
Look at the subprocess module in the sdtlib: from subprocess import call call(["ls", "-l"]) The advantage of subprocess vs system is that it is more flexible (you can get the stdout, stderr, the "real" status code, better error handling, etc...). I think os.system is deprecated, too, or will be: http:...
naming columns in excel with Complex sql
|sql|excel|
I’m trying to run this sql using get external .. it work but when I try to rename the subqurrys or anything for that matter it remove it. I tried as, as and the name in '', as then the name in "", and the same with space. what is the right way to do that? sql for completeness sake >>select list_na...
From http://codex.wordpress.org/Theme_Development The following is an example of the first few lines of the stylesheet, called the style sheet header, for the Theme "Rose": /* Theme Name: Rose Theme URI: the-theme's-homepage Description: a-brief-description Author: your-name Author...
The biggest benefit of using generics in your example is that it changes what would be a run time error into a compile time error. List list = new ArrayList(); list.add(new Integer(42)); String hi = (String) list.get(0); // run time error List<String> list = new ArrayList<String>(); l...
I think that it may be just the default way Windows handles changing the selected index of the default combo box control. It'll scroll down only as much as it needs to show the selected item, it doesn't care about what comes before or after.
Although both are really fine, I tend to use the first example because it is easier to read. There are fewer operations happening on each line with the while() loop, making the code easier for someone new to the code to understand what's going on. That type of construct also allows me to group initializations i...
By "mips programming language" I assume you mean MIPS Assembly Language. Learning an assembly language is beneficial to know, it helps you map the code you write to how it will run on the hardware. This can help expose you to more low level concerns like cache misses, branching, out-of-order execution, and other th...
Your example doesn't start ssh at all, at least not with my version of TRAMP ("2.1.13-pre"). Both <tt>find-file</tt> and <tt>save-buffer</tt> work great.
/lkjasdf has always been faster than :noh for me
go to [the source](http://c2.com/doc/oopsla89/paper.html) - Kent Beck, Ward Cunningham, ever heard of them?
I agree that the for loop should be used whenever possible but sometimes there's more complex logic that controls the iterator in the body of the loop. In that case you have to go with while.
Iterate with for loop or while loop?
|java|
Using Divs to display table-like data
|css|
I want to display data like the following: Title Subject Summary Date So my html looks like: div class="title" /div div class="subject" /div .... etc. The problem is, all the text doesn't appear on a single line. I tried adding display="block" but that doesn't seem to work. What...
I want to display data like the following: Title Subject Summary Date So my html looks like: div class="title" /div div class="subject" /div .... etc. The problem is, all the text doesn't appear on a single line. I tried adding display="block" but that doesn't seem to work. What...
How to use one object's method to update another object's attribute?
|c++|oop|methods|
I have three (C++) classes: Player, Hand, and Card. Player has a member, hand, that holds a Hand. It also has a method, getHand(), that returns the contents of hand. Hand Player::getHand() { return hand; } Hand has a method, addCard(Card c), that adds a card to the hand. I want to do this: ...
Stable, efficient sort?
|sorting|
I'm trying to create an unusual associative array implementation that is very space-efficient, and I need a sorting algorithm that meets all of the following: 1. Stable (Does not change the relative ordering of elements with equal keys.) 2. In-place or almost in-place (O(log n) stack is fine, but no O(n) space usag...
|language-agnostic|algorithm|data-structures|sorting|
If getHand() returns by-value you're modifying a copy of the hand and not the original.
What is the declaration of getHand()? Is it returning a new Hand value, or is it returning a Hand& reference?
Can you post your code? If getHand() is not returning a reference you will be in trouble.
Looking through the Qt source it seems that when a slot is called from QMetaObject::invokeMethod the return type can be specified and the return value obtained. (Have a look at invokeMethod in the Qt help) I could not find many examples of this actually being used in the Qt source. One I found was bool QA...
|c++|winapi|
One reason you might want to use an IOC Container would be to facilitate late configuration of your software. Say, for instance, you provide several implementations of a particular interface - the customer (or your professional services team) can decide which one to use by modifying the IOC configuration file.
You can always use command "mysqladmin shutdown"
The problem in your example is that you link the input of your script (and indirectly of `telnet`) to the output of the `echo`. So after `echo` is done and `telnet` is started, there is no more input to read. A simple fix could be to replace `echo "testhost"` by `{ echo "testhost"; cat; }`.
The problem in your example is that you link the input of your script (and indirectly of `telnet`) to the output of the `echo`. So after `echo` is done and `telnet` is started, there is no more input to read. A simple fix could be to replace `echo "testhost"` by `{ echo "testhost"; cat; }`. Edit: `telnet` doesn't se...
Artificially create a connection timeout error
|network-programming|tcp|connection|networking|