(Also see [remarkable][], the markdown parser created by the author of this cheatsheet)
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
<?php | |
/* | |
Paul's Simple Diff Algorithm v 0.1 | |
(C) Paul Butler 2007 <http://www.paulbutler.org/> | |
May be used and distributed under the zlib/libpng license. | |
This code is intended for learning purposes; it was written with short | |
code taking priority over performance. It could be used in a practical | |
application, but there are a few ways it could be optimized. |
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
var context = new webkitAudioContext(), | |
oscillator = context.createOscillator(); | |
oscillator.type = oscillator.SQUARE; | |
oscillator.frequency.value = 1000; | |
oscillator.connect(context.destination); | |
oscillator.noteOn && oscillator.noteOn(0); | |
setTimeout('oscillator.disconnect()', 500); |
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
var playSingleChime = function() | |
{ | |
var context = new webkitAudioContext(), | |
gain = context.createGainNode(), | |
osc = context.createOscillator(); | |
osc.connect(gain); | |
gain.connect(context.destination); | |
osc.frequency.value = 1000.0; |
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 | |
# ssh-multi | |
# D.Kovalov | |
# Based on http://linuxpixies.blogspot.jp/2011/06/tmux-copy-mode-and-how-to-control.html | |
# a script to ssh multiple servers over multiple tmux panes | |
starttmux() { | |
if [ -z "$HOSTS" ]; then |
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
module.exports = function (grunt) { | |
require('load-grunt-tasks')(grunt); | |
grunt.initConfig({ | |
express: { | |
options: { | |
// Override defaults here | |
}, | |
web: { | |
options: { |
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
frontend www-http | |
bind :80 | |
bind *:443 ssl crt /etc/haproxy/certs no-sslv3 | |
capture request header X-Forwarded-For len 50 | |
acl is_cf req.hdr(cf-connecting-ip) -m found | |
http-request set-header X-Client-IP %[src] if !is_cf | |
http-request set-header X-Client-IP %[hdr(cf-connecting-ip)] if is_cf |
The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.
In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.
This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.
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
acl from_cf src -f /etc/haproxy/cf-ips | |
http-request set-src req.hdr(CF-Connecting-IP) if from_cf | |
option forwardfor if-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
kernel.core_uses_pid = 1 | |
kernel.domainname = your_local_domain_name | |
kernel.msgmax = 65535 | |
kernel.msgmnb = 65535 | |
kernel.pid_max = 65535 | |
kernel.printk = 2 3 1 2 | |
kernel.randomize_va_space = 2 | |
kernel.shmall = 268435456 | |
kernel.shmmax = 268435456 | |
kernel.sysrq = 0 |
OlderNewer