Skip to content

Instantly share code, notes, and snippets.

View kgriffs's full-sized avatar

Kurt Griffiths kgriffs

View GitHub Profile
@kgriffs
kgriffs / gist:1944487
Created February 29, 2012 21:19
Encrypting a password with an RSA key on Windows
echo|set /p="toomanysecrets" | openssl rsautl -encrypt -inkey public-key.pem -pubin | openssl base64 > secret.txt
@kgriffs
kgriffs / encrypt.sh
Created March 2, 2012 16:49
Encrypting a password with an RSA key on Linux
read -s -p "Password: " qpwd
echo $qpwd | openssl rsautl -encrypt -inkey public-key.pem -pubin | openssl base64
unset qpwd
@kgriffs
kgriffs / dry-require.js
Created July 5, 2012 20:43
DRY CommonJS/Node require pattern
[
'http',
'https',
'util',
'path',
'fs',
'request',
'url',
'stream'
@kgriffs
kgriffs / sysctl.conf
Last active April 29, 2024 11:32
Linux Web Server Kernel Tuning
# Configuration file for runtime kernel parameters.
# See sysctl.conf(5) for more information.
# See also http://www.nateware.com/linux-network-tuning-for-2013.html for
# an explanation about some of these parameters, and instructions for
# a few other tweaks outside this file.
#
# See also: https://gist.github.com/kgriffs/4027835
#
# Assumes a beefy machine with lots of network bandwidth
@kgriffs
kgriffs / nginx-gzip.conf
Created November 28, 2012 13:21
nginx gzip
# See also: http://arstechnica.com/gadgets/2012/11/how-to-set-up-a-safe-and-secure-web-server/3/
gzip on;
gzip_disable "msie6";
gzip_min_length 1100;
gzip_vary on;
gzip_proxied any;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/json application/x-javascript
@kgriffs
kgriffs / nginx-sec.conf
Created November 28, 2012 13:35
nginx security
# See also http://arstechnica.com/gadgets/2012/11/how-to-set-up-a-safe-and-secure-web-server/4/
server_tokens off;
client_max_body_size 4096k;
client_header_timeout 10;
client_body_timeout 10;
keepalive_timeout 10 10;
send_timeout 10;
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@kgriffs
kgriffs / disable_echo.py
Created June 7, 2013 00:52
Disable echo in Python
def enable_echo(enable):
fd = sys.stdin.fileno()
new = termios.tcgetattr(fd)
if enable:
new[3] |= termios.ECHO
else:
new[3] &= ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, new)
@kgriffs
kgriffs / dynamic_decorator_example.py
Created June 7, 2013 15:11
Example of dynamically decorating a method in Python
import functools
class Scooby(object):
def mood(self):
return 'frightended'
def scooby_snack(func):
@functools.wraps(func)
def brave(self):
@kgriffs
kgriffs / python-hash-bench
Last active December 20, 2015 18:58
Benchmark results from testing several python hash libs against str.__hash(), on my MBP Retina, 15-inch, Early 2013. This was run under Python 2.7. using various python hash functions. MurmurHash3 was used for the Murmur tests.
Note: "memo" is just testing constructing a string, to prove
that strings are not hashed at create time, but memoized with
__hash__(). The functions construct new strings each time,
with some variant of:
'24058098:33d2a96e-ffad-11e2-b14b-8acd18156acf' * m
Where m is passed into the test function.
---------------------------------------------