This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# monkey-patch | |
import gevent.monkey | |
gevent.monkey.patch_all() | |
import gevent.pool | |
import gevent.queue | |
import sys | |
import re | |
import requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compose(*functions): | |
return functools.reduce(lambda f, g: lambda x: f(g(x)), functions, lambda x: x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// :(){ :|: & };: | |
#!/bin/bash | |
./$0|./$0& #"$0" returns the name of the shell script itself |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a[disabled] { pointer-events: none; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |