Skip to content

Instantly share code, notes, and snippets.

require 'sinatra'
require 'sinatra/namespace' # gem install sinatra-contrib
namespace '/blog/:id' do
before { |id| @blog = Blog.get(id) }
get { @blog }
put { @blog.update_attributes(params) }
end
@rkh
rkh / game.rb
Created October 30, 2011 06:44
Rock, paper, scissors in Sinatra
require 'sinatra'
# before we process a route, we'll set the response as
# plain text and set up an array of viable moves that
# a player (and the computer) can perform
before do
content_type :txt
@defeat = {rock: :scissors, paper: :rock, scissors: :paper}
@throws = @defeat.keys
end
@joemccann
joemccann / test.js
Created November 9, 2011 19:18
MongoDB Primary Failover fix
var mongoose = require('mongoose')
, Server = require('mongodb').Server
, ReplSetServers = require('mongodb').ReplSetServers
, http = require('http')
var set = 'mongodb://cihcisdapp809v:27077,mongodb://cihcisdapp809v:37077'
// https://github.com/christkv/node-mongodb-native/blob/master/lib/mongodb/connections/repl_set_servers.js#L32
var replSet = new ReplSetServers([
new Server( 'mongodb://cihcisdapp809v', 27077, { auto_reconnect: true } ),
@joemccann
joemccann / server.js
Created November 17, 2011 21:24
cluster setup
var cluster = require('cluster');
var app = require('./app');
// Comment this out:
// var server = cluster(app)
// .use(cluster.pidfiles())
// .use(cluster.cli())
// .use(cluster.stats())
// .use(cluster.repl('/var/run/colab-rest-api.sock'));
@rkh
rkh / hello.md
Created November 21, 2011 22:41
sure...

Hello,

I’m currently looking at advertising opportunities for one of our major clients and I found your site - https://api.github.com/networks/sinatra/sinatra/events - interesting, I have several possibilities in mind and our fixed fee rates mean guaranteed monthly payment.

I would be interested in discussing these possibilities with you. If you are interested, please reply back to this email.

I look forward to hearing from you,

#! /usr/bin/env python
import fileinput
import argparse
from operator import itemgetter
parser = argparse.ArgumentParser()
parser.add_argument('--target-mb', action = 'store', dest = 'target_mb', default = 61000, type = int)
parser.add_argument('vmtouch_output_file', action = 'store', nargs = '+')
args = parser.parse_args()
@dnagir
dnagir / gist:1630480
Created January 18, 2012 02:34
When Ruby undefined becomes defined
> irb
1.9.3p0 :001 > a
NameError: undefined local variable or method `a' for main:Object
from (irb):1
from /Users/dnagir/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :002 > b
NameError: undefined local variable or method `b' for main:Object
from (irb):2
from /Users/dnagir/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :003 > a = b
<script id="message" type="text/html">
<div class="message {{ type }}" id="{{ cssID }}">
<time datetime="{{ time }}">{{ humanTime }}</time>
<span class="name {{#isYou}} current-user {{/isYou}}">
{{ author }}:
</span>
<span class="body">{{ content }}</span>
@panicsteve
panicsteve / gist:1641705
Created January 19, 2012 18:26
Form letter template for acquired startups
Dear soon-to-be-former user,
We've got some fantastic news! Well, it's great news for us anyway. You, on
the other hand, are fucked.
We've just been acquired by:
[ ] Facebook
[ ] Google
[ ] Twitter
@jeffsu
jeffsu / gist:1926295
Created February 27, 2012 19:05
iptable
0.0.0.0 10.0.1.1 0.0.0.0 UG 0 0 0 eth0
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 vboxnet0
33.33.33.0 0.0.0.0 255.255.255.0 U 0 0 0 vboxnet1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0