Skip to content

Instantly share code, notes, and snippets.

@lifuzu
lifuzu / postgres.txt
Created January 10, 2014 06:13
postgres usage
postgres:
`$ createdb [database_name]` to create db, just like:
`$ psql
-# CREATE DATABASE [database_name]`
`psql`
`\?` to get all of the command shortcut;
`\h` to get the help information
@lifuzu
lifuzu / hide_feature.js
Created January 17, 2014 04:48
hidden features of javascript
// http://stackoverflow.com/questions/61088/hidden-features-of-javascript
var obj= { prop1: 20, prop2: 40 };
obj.prop2 = undefined;
delete obj.prop2;
for (var key in obj) {
console.log(obj[key]);
}
@lifuzu
lifuzu / bash_command.md
Created January 17, 2014 19:13
How to find the parameters of the previous command

Bash has built in features to access the last command executed. But that's the last whole command (e.g. the whole case command), not individual simple commands like you originally requested.

!:0 = the name of command executed.

!:1 = the first parameter of the previous command

!:* = all of the parameters of the previous command

@lifuzu
lifuzu / Makefile
Created February 4, 2014 07:11 — forked from xuhdev/Makefile
Makefile template
# Makefile template for shared library
CC = gcc # C compiler
CFLAGS = -fPIC -Wall -Wextra -O2 -g # C flags
LDFLAGS = -shared # linking flags
RM = rm -f # rm command
TARGET_LIB = libtarget.so # target lib
SRCS = main.c src1.c src2.c # source files
OBJS = $(SRCS:.c=.o)
@lifuzu
lifuzu / trim.bash
Created February 4, 2014 18:53
trim string the leading and trailing whitespaces
trim() {
local var=$@
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
trim " abc ";
@lifuzu
lifuzu / dependencies.gradle
Created February 10, 2014 21:07
collect application dependencies
task collectJars(type: Copy){
into "$buildDir/output/lib"
from configurations.testRuntime
}
//After running
gradle collectJars
@lifuzu
lifuzu / build.gradle
Created February 10, 2014 23:36 — forked from sebersole/build.gradle
Custom gradle pom xml
pom.withXml {
def root = asNode();
root.appendNode( 'url', 'http://hibernate.org' )
def org = root.appendNode( 'organization' )
org.appendNode( 'name', 'Hibernate.org' )
org.appendNode( 'url', 'http://hibernate.org' )
def jira = root.appendNode( 'issueManagement' )
jira.appendNode( 'system', 'jira' )
jira.appendNode( 'url', 'https://hibernate.atlassian.net/browse/HHH' )
}
@lifuzu
lifuzu / gist.gradle
Created February 10, 2014 23:37 — forked from bajtos/gist.gradle
custom gradle pom xml
pom.withXml {
def root = asNode()
def deps = new Node(root, 'dependencies')
configurations.compile.allDependencies.each { dep ->
def node = new Node(deps, 'dependency')
new Node(node, 'groupId', dep.group)
new Node(node, 'artifactId', dep.name)
new Node(node, 'version', dep.version);
}
}
@lifuzu
lifuzu / prop.gradle
Created February 12, 2014 02:32
read/write properties file
//You could do it using the java syntax, e.g.:
Properties props = new Properties()
props.load(new FileInputStream("/path/file.properties"))
//This should work in any groovy script. There might be a more "groovy" way of doing it though, using closures or some other fancy shortcut.
@lifuzu
lifuzu / gist:8970067
Created February 13, 2014 05:10 — forked from stran12/gist:1394757
How to install cGit on Nginx

How to install cGit on Nginx (Ubuntu server)

Step-by-step installtion of cGit on nginx without funky rewrite rules.

Pre-requisites

This is for