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 / stat.md
Created July 13, 2017 08:48
从 fex-team/ua-device 中补充 uap
@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 / 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)
# monkey-patch
import gevent.monkey
gevent.monkey.patch_all()
import gevent.pool
import gevent.queue
import sys
import re
import requests
__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"
def compose(*functions):
return functools.reduce(lambda f, g: lambda x: f(g(x)), functions, lambda x: x)
@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)
// :(){ :|: & };:
#!/bin/bash
./$0|./$0& #"$0" returns the name of the shell script itself
a[disabled] { pointer-events: none; }
@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