Skip to content

Instantly share code, notes, and snippets.

View lihuanshuai's full-sized avatar
:octocat:
rusting

Li Huanshuai lihuanshuai

:octocat:
rusting
View GitHub Profile
@lihuanshuai
lihuanshuai / matplot-scatter.py
Created October 18, 2016 16:05
散点图 demo
"""
Simple demo of a scatter plot.
"""
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
@lihuanshuai
lihuanshuai / spacemacs-layer-dep.sh
Last active October 18, 2016 16:07
spacemacs-layer相关依赖
# for js analyzer
sudo npm install -g ternjs
# in project root
touch .tern-project
# for gtags
sudo apt-get install global
wget https://raw.githubusercontent.com/Schnouki/dotfiles/master/globalrc -O ~/.globalrc
# for cscope
def compose(*functions):
return functools.reduce(lambda f, g: lambda x: f(g(x)), functions, lambda x: x)
__attribute__ ((noreturn)) static void
usage(int code)
{
fprintf(stderr,
"Usage: %s [-behuwxMACHPWY] [-c vcpus] [-F <pidfile>] [-g <gdb port>] [-l <lpc>]\n"
" %*s [-m mem] [-p vcpu:hostcpu] [-s <pci>] [-U uuid] -f <fw>\n"
" -A: create ACPI tables\n"
" -c: # cpus (default 1)\n"
" -C: include guest memory in core file\n"
# monkey-patch
import gevent.monkey
gevent.monkey.patch_all()
import gevent.pool
import gevent.queue
import sys
import re
import requests
@lihuanshuai
lihuanshuai / random_header.py
Created April 7, 2017 07:04
random http headers
import random
user_agents = ['1', '2', '3']
class RandomHeader(dict):
def __getitem__(self, key):
if key == 'User-Agent':
return random.choice(user_agents)
return super(RandomHeader, self).__getitem__(key)
@lihuanshuai
lihuanshuai / reduced_dict.py
Created April 13, 2017 04:44
对于每个 key,仅选取最小(或最大)值作为 value
def gen_reduced_dict(iterable, key=None, reverse=False):
key = (lambda x: x) if key is None else key
d = {}
for k, v in iterable:
if k not in d:
d[k] = v
pv = d[k]
cmp_ = (lambda x, y: x > y) if reverse else (lambda x, y: x < y)
if cmp_(key(v), key(pv)):
d[k] = v
@lihuanshuai
lihuanshuai / stat.md
Created July 13, 2017 08:48
从 fex-team/ua-device 中补充 uap
import tables as tb
from numpy import array
from scipy import sparse
def store_sparse_mat(path, name, m, separator='__'):
if (m.__class__ not in [sparse.csr.csr_matrix, sparse.csc.csc_matrix]):
raise TypeError("This code only works for csr/csc matrices")
with tb.openFile(path, 'a') as f:
for par in ('data', 'indices', 'indptr', 'shape'):
@lihuanshuai
lihuanshuai / stat.md
Last active July 28, 2017 03:44
从 fex-team/ua-device 中补充 uap
We couldn’t find that file to show.