Skip to content

Instantly share code, notes, and snippets.

@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 / 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;
deb http://ubuntu.v2ex.com/ubuntu/ quantal main restricted universe multiverse
deb-src http://ubuntu.v2ex.com/ubuntu/ quantal main restricted universe multiverse
deb http://ubuntu.v2ex.com/ubuntu/ quantal-updates main restricted universe multiverse
deb-src http://ubuntu.v2ex.com/ubuntu/ quantal-updates main restricted universe multiverse
deb http://ubuntu.v2ex.com/ubuntu/ quantal-backports main restricted universe multiverse
deb-src http://ubuntu.v2ex.com/ubuntu/ quantal-backports main restricted universe multiverse
deb http://ubuntu.v2ex.com/ubuntu/ quantal-security main restricted universe multiverse
deb-src http://ubuntu.v2ex.com/ubuntu/ quantal-security main restricted universe multiverse
deb http://extras.ubuntu.com/ubuntu quantal main
deb-src http://extras.ubuntu.com/ubuntu quantal main
@lakemove
lakemove / gist:5b804f0c9dda892d80d9
Created December 12, 2014 06:37
javamail read mail
@Test
public String readMailTest() throws Exception {
Properties props = new Properties();
props.put("mail.imap.host", "imap.sina.cn");
Session session = Session.getDefaultInstance(props);
IMAPStore store = (IMAPStore) session.getStore("imap");
store.connect("sgmall_test_001", "sgmall_test_001");
Folder emailFolder = store.getFolder("INBOX");
@lakemove
lakemove / DeadSimpleAuthFilter.java
Last active August 29, 2015 14:14
Form based authentication Filter, with in Servlet Container
package com.surdoc.enterprisecloud.web;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
@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 / 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 / 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 / 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 / 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