Skip to content

Instantly share code, notes, and snippets.

@lifuzu
lifuzu / build.gradle
Created December 17, 2013 18:20
To check if a folder exists or not, and to write to the file
//To check if a folder exists or not, and to write to the file
// Create a File object representing the folder 'A/B'
def folder = new File( 'A/B' )
// If it doesn't exist
if( !folder.exists() ) {
// Create all folders up-to and including B
folder.mkdirs()
}
@lifuzu
lifuzu / build.gradle
Created December 17, 2013 18:27
To upload multiple existing jars to maven repository with gradle
// To upload a jar via gradle you must declare that jar as a publish artifact and add it to a specific configuration using the artifacts closure:
apply plugin:'maven'
configurations{
allJars
}
artifacts{
allJars file("path/to/jarFile.jar")
}
@lifuzu
lifuzu / branch.gradle
Last active December 31, 2015 16:29
Gets the version name from the latest Git tag
/*
* Get the current branch name
*/
def getCurrentBranchName = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'symbolic-ref', 'HEAD', '--short'
standardOutput = stdout
}
return stdout.toString().trim()
@lifuzu
lifuzu / ab_eventlet.log
Last active January 2, 2016 08:48
performance analysis of gevent, eventlet and node.js
$ ab -n 1000 -c 100 http://localhost:6785/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 100 requests
...
Finished 1000 requests
configurations {
apt
}
dependencies {
compile 'com.squareup.dagger:dagger:1.1.0'
apt 'com.squareup.dagger:dagger-compiler:1.1.0'
}
android.applicationVariants.all { variant ->
@lifuzu
lifuzu / build.gradle
Last active January 2, 2016 10:48
Upload packages to Nexus artifact server
/*
* The name of the package. Also used as the name uploaded to the maven repo.
*/
def artifactId='DemoApp'
/*
* The group definition.
*/
def groupId='com.lifuzu.app'
@lifuzu
lifuzu / build.gradle
Created January 6, 2014 23:34
Download packages from Nexus artifacts server
/*
* The platform OS definition.
*/
def getPlatformOS() {
def os = System.properties['os.name'].toLowerCase()
// by default we set the platform as 'linux'
def platform = 'linux'
// on Mac OS, System.properties['os.name'] return 'Mac OS X'
if (os.contains('mac')) {
platform = 'darwin'
@lifuzu
lifuzu / buildlogcmd.sh
Created January 7, 2014 18:33
Bash function collections
function buildlogcmd {
log=$1
shift
echo "Build: $*" >> "$log"
echo " `pwd`" >> "$log"
echo " `date`" >> "$log"
echo "" >> "$log"
$* 2>&1 | tee -a "$log"
status=${PIPESTATUS[0]}
if [ $status != 0 ]; then
@lifuzu
lifuzu / bashrc
Created January 9, 2014 06:00
display command line with git branch and remote, and colorful
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_git_remote() {
git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD 2> /dev/null) 2> /dev/null
}
render_git_info() {
branch=$(parse_git_branch)
if [ $branch ]; then
echo "($(parse_git_remote)->$(parse_git_branch))"
@lifuzu
lifuzu / bash.sh
Created January 10, 2014 06:12
bash to list mysql database, set them to array
while read dbname; do dbarray+=("$dbname"); done < <(mysql -u username -ppassword -e 'show databases;' -B | grep reviewdb)
echo ${dbarray[*]}
for dbname in `echo ${dbarray[*]}`; do echo $dbname; done