Skip to content

Instantly share code, notes, and snippets.

@lakemove
lakemove / gist:9929800
Last active August 29, 2015 13:58
calculate mean and variance in a single iteration
// http://en.wikipedia.org/wiki/Variance
// http://upload.wikimedia.org/math/a/3/3/a336557f138eb90bafc9e6ebc00e926d.png
var data = [{x: 1, p: 0.1}, {x: 2, p: 0.3}, {x: 8, p: 0.6}]; //{x:probability}
var mu = 0, sigma = 0;
for (i in data) {
mu += i.p * i.x;
sigma += i.p * i.x * i.x;
@lakemove
lakemove / coursera-download.sh
Last active August 29, 2015 13:56
download coursera lecture videos
#!/bin/bash
# download video by providing video url and cookie.
# saved file name will be from Content-Disposition
function download() {
local url=$1
local cookies=$2
local filename=$(curl -I -L -s --cookie "$cookies" "$url" | grep Content-Disposition | python -c "import sys, urllib as ul; print ul.unquote(sys.stdin.read());" | awk -F\" '{print $2}')
echo "start to download $filename"
@lakemove
lakemove / ti-svn-structure.sh
Created March 28, 2013 06:34
showcase svn automated operations and invoking Java from shell script
#!/bin/bash
WORKDIR=/tmp/svn-work-dir
mkdir $WORKDIR && cd $WORKDIR
svn info svn+ssh://subversion.evenex.com/svn/comp/OutgoingDocumentReceiveService/branches/FDD-4256 >/dev/null
if [ $? -eq 0 ]; then
echo "branch already exist, delete it [y/n](y)?"
svn rm svn+ssh://subversion.evenex.com/svn/comp/OutgoingDocumentReceiveService/branches/FDD-4256 -m "delete to create"
fi
@lakemove
lakemove / jgit.sh
Created March 21, 2013 03:19
self-executable shell commandline shamelessly copied from [jgit|http://www.eclipse.org/jgit/download/]
cmd=
for a in "$@"
do
case "$a" in
-*) continue ;;
*) cmd=$a; break; ;;
esac
done
use_pager=
@lakemove
lakemove / blog-app.conf
Created October 29, 2012 02:23
node upstart script
description "blog-app server"
author "Jay"
start on startup
stop on shutdown
script
#Your scripts
cd /home/jay/works/blog-app
@lakemove
lakemove / web
Created October 25, 2012 01:02
The essence of this technique
//pure-CSS drop down menus
div.menu-bar ul ul {
display: none;
}
div.menu-bar li:hover > ul {
display: block;
}
//image pre-loader
function preloadImages() {
@lakemove
lakemove / hudson-run.sh
Created August 8, 2012 03:42
script to bootstrap hudson in tomcat
#/bin/bash
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_25
export CATALINA_HOME=/usr/lib/apache-tomcat-7.0.26
export CATALINA_BASE=/srv/hudson-ci
export HUDSON_HOME=/srv/hudson-ci/hudson-home
export PATH=$JAVA_HOME/bin:$PATH
# see http://stackoverflow.com/questions/76327/how-can-i-prevent-java-from-creating-hsperfdata-files
# to disable it , use "-XX:-UsePerfData" ,
@lakemove
lakemove / commands.sh
Last active October 7, 2015 10:08
useful shell commands
# tcpdump ldap traffic to a file, then can be analyzed by wireshark
sudo tcpdump -vv -w /tmp/ldapdump -i lo port 389
#sniff http traffic
sudo ngrep -q -d eth0 -W byline host example.com and port 8180
#Search recursively to find a word or phrase in certain file types, such as C code
find . -name "*.[ch]" -exec grep -i -H "search pharse" {} \; | column -t -s ":"
#search empty folder
@lakemove
lakemove / commandline.bat
Created June 14, 2012 01:41
customized windows commandline
@ECHO OFF
doskey ls=dir /b $*
rem Java
set JAVA_HOME=C:\opt\jdk1.6.0_25
set Path=%JAVA_HOME%\bin;%Path%
rem Maven
set MVN_HOME=C:\opt\apache-maven-3.0.4
@lakemove
lakemove / pom.xml
Created June 9, 2012 08:39
maven pom.xml basic structure
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.liulijie</groupId>
<artifactId>blog-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>