To be able to debug an application is very important to understand the flow of an application's logic and data. It helps solving logical bugs and adds value to the programming experience and code quality.
Two popular gems for debugging are debugger (for ruby 1.9.2 and 1.9.3) and byebug (for ruby &g...
When adding a LIMIT to a UNION, this is the pattern to use:
( SELECT ... ORDER BY x LIMIT 10 )
UNION
( SELECT ... ORDER BY x LIMIT 10 )
ORDER BY x LIMIT 10
Since you cannot predict which SELECT(s) will the "10" will come from, you need to get 10 from each, then further whittle do...
Strict mode also prevents you from deleting undeletable properties.
"use strict";
delete Object.prototype; // throws a TypeError
The above statement would simply be ignored if you don't use strict mode, however now you know why it does not execute as expected.
It also prevents you fr...
To create a parallel collection from a sequential collection, call the par method. To create a sequential collection from a parallel collection, call the seq method. This example shows how you turn a regular Vector into a ParVector, and then back again:
scala> val vect = (1 to 5).toVector
vect:...
There are several scopes that are available only in a web-aware application context:
request - new bean instance is created per HTTP request
session - new bean instance is created per HTTP session
application - new bean instance is created per ServletContext
globalSession - new bean instance i...
When using async queries, you can execute multiple queries at the same time, but not on the same context. If the execution time of one query is 10s, the time for the bad example will be 20s, while the time for the good example will be 10s.
Bad Example
IEnumerable<TResult1> result1;
IEnumera...
In [188]: s = pd.Series(["a","b","c","a","c"], dtype="category")
In [189]: s
Out[189]:
0 a
1 b
2 c
3 a
4 c
dtype: category
Categories (3, object): [a, b, c]
In [190]: df = pd.DataFrame({"A":["a&q...
package com.example.my.package;
The package declaration should not be line wrapped, regardless of whether it exceeds the recommended maximum length of a line.
Indentation level is four spaces.
Only space characters may be used for indentation. No tabs.
Empty lines must not be indented. (This is implied by the no trailing white space rule.)
case lines should be indented with four spaces, and statements within the case should be indented with another f...
One variable per declaration (and at most one declaration per line)
Square brackets of arrays should be at the type (String[] args) and not on the variable (String args[]).
Declare a local variable right before it is first used, and initialize it as close to the declaration as possible.
Declaration annotations should be put on a separate line from the declaration being annotated.
@SuppressWarnings("unchecked")
public T[] toArray(T[] typeHolder) {
...
}
However, few or short annotations annotating a single-line method may be put on the same line as the method if...
Note the use of {{range .}} and {{end}} to cycle over the collection.
package main
import (
"fmt"
"os"
"text/template"
)
func main() {
const (
letter = `Dear {{range .}}{{.}}, {{end}} How are you?`
)
tmpl, err := template...
First, here's what can happen when text/template is used for HTML. Note Harry's FirstName property).
package main
import (
"fmt"
"html/template"
"os"
)
type Person struct {
FirstName string
LastName string
Street string
Cit...
for /L %%A in (1,2,40) do echo %%A
This line will iterate from 1 to 39, increasing by 2 each time.
The first parameter, 1, is the starting number.
The second parameter, 2, is the increment.
The third parameter, 40, is the maximum.
Use itertools.chain to create a single generator which will yield the values from several generators in sequence.
from itertools import chain
a = (x for x in ['1', '2', '3', '4'])
b = (x for x in ['x', 'y', 'z'])
' '.join(chain(a, b))
Results in:
'1 2 3 4 x y z'
As an alternate constructo...
import std.stdio;
T min(T)(in T arg1, in T arg2) {
return arg1 < arg2 ? arg1 : arg2;
}
void main() {
//Automatic type inference
writeln(min(1, 2));
//Explicit type
writeln(min!(ubyte)(1, 2));
//With single type, the parenthesis might be ommited
...