Skip to content

Instantly share code, notes, and snippets.

View shenwei356's full-sized avatar
💭
I'm very busy recently.

Wei Shen shenwei356

💭
I'm very busy recently.
View GitHub Profile
@shenwei356
shenwei356 / Makefile
Created February 10, 2017 12:47 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@shenwei356
shenwei356 / howto
Created December 26, 2016 13:41
save_page.js
var system = require('system');
var page = require('webpage').create();
page.open(system.args[1], function()
{
console.log(page.content);
phantom.exit();
});
package main
import (
"fmt"
)
type IntGenerator struct {
Chan chan int
n int
}
@shenwei356
shenwei356 / generate_data.py
Last active June 17, 2016 02:08
quering by item list
#!/usr/bin/env python
import argparse
import random
parser = argparse.ArgumentParser(description="generate test data",
epilog="https://github.com/shenwei356/")
parser.add_argument('-n',
type=int,
default=700000,
help='number of query list')
// run:
//
// go test -test.bench="." -test.cpuprofile=prof.out
// go tool pprof ./gist.test prof.out
package main
import (
"bytes"
"testing"
)
@shenwei356
shenwei356 / data.gff
Last active August 29, 2015 14:20
extract_cds_by_gff, Perl and Python version
scaf001 glean mRNA 20 30 0.4 - . somestring
scaf001 glean CDS 30 50 . + 0 asdfasd
scaf003 glean CDS 10 25 0.4 - . somestring
@shenwei356
shenwei356 / groupby.py
Last active August 28, 2015 05:59
sorting needed before groupby!!!!!!
#!/usr/bin/python
import re
from itertools import groupby
s = '11M1D31M1I3M1D48M2I1M1D28M'
g = re.findall('\d+[A-Z]', s) # ['11M', '1D', '31M', '1I', '3M', '1D', '48M', '2I', '1M', '1D', '28M']
kv = [[x[-1], int(x[0:-1])] for x in g] # [['M', 11], ['D', 1], ['M', 31], ['I', 1], ['M', 3], ['D', 1], ['M', 48], ['I', 2], ['M', 1], ['D', 1], ['M', 28]]
kv = sorted(kv, key=lambda e: e[0]) # fuck !! sorting needed!
stat = { k: sum((g[1] for g in group)) for k, group in groupby(kv, key=lambda e: e[0])}
print(stat) # {'M': 122, 'I': 3, 'D': 3}