Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
set -u
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
APP_ROOT=/k/app_name/current
PID=/var/run/unicorn/unicorn.pid
ENV=production
@cyx
cyx / hack.sh
Created March 31, 2012 12:30 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
def run_pg_fouine():
info = host_info[env.host_string]
db_name = info.tags.get('Name')
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 0/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
time.sleep(30)
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 500/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
run('tail -n 100000 /var/log/postgresql/postgresql-9.*-main.log > /tmp/pgfouine.txt')
run('gzip -f /tmp/pgfouine.txt')
@cyx
cyx / config.ru
Created April 7, 2012 17:33 — forked from soveran/config.ru
Small Cuba App.
require "cuba"
run Cuba.new { on(root) { res.write "hello, world" } }
@cyx
cyx / example.rb
Created April 20, 2012 04:37 — forked from myobie/example.rb
class Book < Ohm::Model
collection :authors, :Author
end
class Author < Ohm::Model
reference :book, :Book
attribute :name
attribute :mood
index :mood
end
@cyx
cyx / hack.sh
Created May 25, 2012 11:08 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@cyx
cyx / raskell.rb
Created August 20, 2012 14:16 — forked from andkerosine/raskell.rb
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@cyx
cyx / gist:3690597
Created September 10, 2012 12:13 — forked from inkel/gist:3690584
Monit Redis
check process redis-server
with pidfile "/var/run/redis.pid"
start program = "/etc/init.d/redis-server start"
stop program = "/etc/init.d/redis-server stop"
if 2 restarts within 3 cycles then timeout
if totalmem > 100 Mb then alert
if children > 255 for 5 cycles then stop
if cpu usage > 95% for 3 cycles then restart
if failed host 127.0.0.1 port 6379 then restart
if 5 restarts within 5 cycles then timeout
@cyx
cyx / mandrill.webhook.rb
Created September 19, 2012 20:51
Example of Mandrill Mailbox Routes payload
[{"event"=>"inbound",
"ts"=>1348084981,
"msg"=>
{"raw_msg"=>
"Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50])\n\tby app02.transact (Postfix) with ESMTPS id 113FA160008E\n\tfor <[email protected]>; Wed, 19 Sep 2012 16:03:01 -0400 (EDT)\nReceived: by pbcmd12 with SMTP id md12so3511454pbc.37\n for <[email protected]>; Wed, 19 Sep 2012 13:03:00 -0700 (PDT)\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=google.com; s=20120113;\n h=mime-version:from:date:message-id:subject:to:content-type\n :content-transfer-encoding:x-gm-message-state;\n bh=nj7aRozzB6DfuzLS5/RWru2ni7V73l9sEZWbQhPgc4Y=;\n b=TyTdKUhjpecuS7QeXUN8cP23fuG8nar8EdkyHuNqyDPBVm8n5R1bH+YLJEL2KhZ2kf\n EskBsvgjKW2qallcEcN+yoI6JR16g6mXzRTGXENMCJ2fI9sbTo1a3K3ZQ9AfFbjOTtDf\n F8L1PF8HpHtXRDAYsPRSlc6JCaAzWMfscE0l9g63DMx0jxC6hkpEGzNBlBUqK+hV7y6w\n FeJ6njxlS+1x2/UfjYj8Y9rKZNWCbElGnHOIvpDeq8AE/RXWXs06/G8ggSB8lr90MfCj\n u
@cyx
cyx / gist:4232011
Created December 7, 2012 09:09 — forked from derekcollison/gist:4227635
Early results from high-performance NATS server
I have some early benchmark results for our work on a high performance NATS server in Go.

Quick Summary:
We can process ~2M msgs/sec through the system, and the ingress and egress are fairly well balanced.

The basics of the architecture are intelligent buffering and IO calls, fast hashing algorithms and subject distributor/routing, and a zero-allocation hand-written protocol parser.

In addition, I used quite a bit of inlining to avoid function overhead, no use of defer, and little to no object allocation within the fast path. I will share more details and the code at a future date.