A branch is just a pointer to a commit, so you can freely move it around. To make it so that the branch is referring to the commit aabbcc, issue the command
git reset --hard aabbcc
Please note that this will overwrite your branch's current commit, and as so, its entire history. You might loose s...
Example from the standard library (core.clj:807):
(defmacro and
"Evaluates exprs one at a time, from left to right. If a form
returns logical false (nil or false), and returns that value and
doesn't evaluate any of the other expressions, otherwise it returns
the value of the last e...
section .data
msg db "Hello world!",10 ; 10 is the ASCII code for a new line (LF)
section .text
global _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, 13
syscall
mov rax, 60
mov rdi, 0
syscall
If you want to e...
You can update multiple columns in a table in the same statement, separating col=val pairs with commas:
UPDATE person
SET country = 'USA',
state = 'NY'
WHERE city = 'New York';
You can also update data in a table based on data from another table:
UPDATE person
SET state_code = cities.state_code
FROM cities
WHERE cities.city = city;
Here we are joining the person city column to the cities city column in order to get the city's state code. This is then used to updat...
Everything in .NET is an object, hence every type has ToString() method defined in Object class which can be overridden. Default implementation of this method just returns the name of the type:
public class Foo
{
}
var foo = new Foo();
Console.WriteLine(foo); // outputs Foo
ToString() is i...
Strings are immutable. You just cannot change existing string. Any operation on the string crates a new instance of the string having new value. It means that if you need to replace a single character in a very long string, memory will be allocated for a new value.
string veryLongString = ...
// m...
Using GNU grep
grep -r 'pattern' <directory path>
To also list line numbers of matches use -n option
grep -rn 'pattern' <directory path>
To search only files with particular glob pattern
grep --include='*.txt' -r 'pattern' <directory path>
Exclude file patterns or direc...
Say we are working on a class representing a Person by their first and last names. We have created a basic class to do this and implemented proper equals and hashCode methods.
public class Person {
private final String lastName; //invariant - nonnull
private final String firstName; //in...
Variables declared inside a function only exist (unless passed) inside that function.
x <- 1
foo <- function(x) {
y <- 3
z <- x + y
return(z)
}
y
Error: object 'y' not found
Variables passed into a function and then reassigned are overwritten, but only insi...
Functions called within a function (ie subfunctions) must be defined within that function to access any variables defined in the local environment without being passed.
This fails:
bar <- function() {
z <- x + y
return(z)
}
foo <- function() {
y <- 3
z <-...
The on.exit() function is handy for variable clean up if global variables must be assigned.
Some parameters, especially those for graphics, can only be set globally. This small function is common when creating more specialized plots.
new_plot <- function(...) {
old_pars <- par(m...
A module is a single Python file that can be imported. Using a module looks like this:
module.py
def hi():
print("Hello world!")
my_script.py
import module
module.hi()
in an interpreter
>>> from module import hi
>>> hi()
# Hello world!
In order to check whether a value is NaN, isnull() or notnull() functions can be used.
In [1]: import numpy as np
In [2]: import pandas as pd
In [3]: ser = pd.Series([1, 2, np.nan, 4])
In [4]: pd.isnull(ser)
Out[4]:
0 False
1 False
2 True
3 False
dtype: bool
Note that n...
Create custom class for calling multipart/form-data HttpURLConnection request
MultipartUtility.java
public class MultipartUtility {
private final String boundary;
private static final String LINE_FEED = "\r\n";
private HttpURLConnection httpConn;
priva...