Skip to content

Instantly share code, notes, and snippets.

@lakemove
lakemove / main.go
Created Nov 14, 2020
golang v4 UUID generator
View main.go
package main
import (
"crypto/rand"
"encoding/hex"
"fmt"
)
func main() {
id := make([]byte, 16)
@lakemove
lakemove / gist:34602b4c7c64052ae563cb27f5dd5cfe
Last active Sep 9, 2019
search, select and execute from bash history
@lakemove
lakemove / run-groovy.ipynb
Created Jan 13, 2018
run groovy in jupyter/ipython notebook, put it in one cell and ctrl+enter to run
View run-groovy.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lakemove
lakemove / groovy-in-bash.sh
Created Jan 13, 2018
run groovy script in bash script
View groovy-in-bash.sh
#!/bin/bash
GREETINGS='HELLO GROOVY AND BASH'
echo $GREETINGS
#to interpret bash variable , remove single quotes in 'EOF'
groovy -e "new GroovyShell().evaluate(System.in.text)" <<'EOF'
println("this is groovy print")
EOF
@lakemove
lakemove / oneliner.groovy
Created Jun 20, 2017
one liner in groovy
View oneliner.groovy
//turn list into map
assert [1:2,3:4] == [[1,2],[3,4],[1,2]].collectEntries {it} //{[it[0],it[1]]}
//sublist from nth to end
assert [3,4,5,6] == [1,2,3,4,5,6][2..-1]
assert [3,4,5,6] == [1,2,3,4,5,6][2, 3..-1]
//string to number
assert 1.2 == "1.2" as double
@lakemove
lakemove / coursera_download.sh
Created Mar 23, 2016
download all video lectures, of a single course
View coursera_download.sh
curl -s -b "$cookie" "https://class.coursera.org/bitcointech-001/lecture" | grep download.mp4\?lecture_id | awk -F\" '{print $4}' | xargs curl -s -b "$cookie" | awk -F\" '{print $2}' | while read -r line; do wget --content-disposition "$line" ;done
while read -r line; do wget --content-disposition "$line"; done
@lakemove
lakemove / DeadSimpleAuthFilter.java
Last active Aug 29, 2015
Form based authentication Filter, with in Servlet Container
View DeadSimpleAuthFilter.java
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;
View gist:5b804f0c9dda892d80d9
@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");
View gist:503dd08604dca95681f7
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:9929800
Last active Aug 29, 2015
calculate mean and variance in a single iteration
View gist:9929800
// 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;