Skip to content

Instantly share code, notes, and snippets.

View poll.sh
#!/usr/bin/env bash
while true
do
num=$(ec2-describe-instances | grep running | wc -l | awk '{print $1}')
echo $num
[[ $num < 15 ]] && say yo yo yo yo yo yo yo yo
sleep 300
done
View example_links.json
@csexton
csexton / page.json
Created Mar 7, 2014
Mike Amundsen's Pagination Suggestion from the json+collection mailing list
View page.json
// sample paging
{
"collection" :
{
"version" : "1.0",
"href" : URI,
"links" : [
{"href" : "...", "rel" : "first"},
{"href" : "...", "rel" : "previous"},
{"href" : "...", "rel" : "next"},
View a.md
{
  "users": [{
    "id": "1",
    "name": "Guille",
    "posts": { "href": "http://example/posts" },
    "links": {
      "posts": [1,2,3,4,5]
    }
  }]
View gist:9531313
#define AppDelegate (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
@csexton
csexton / jbuilder.rb
Created Mar 14, 2014
Extend the jbuilder api to support JSON API conventions
View jbuilder.rb
class Jbuilder
def links! model, *args
args.each do |arg|
if model.reflections[arg].collection?
_set_value arg, model.send(arg).map(&:id)
else
_set_value arg, model.send(arg).id
end
end
end
@csexton
csexton / post-receive
Created Apr 15, 2014
radbot.git/hooks/post-receive
View post-receive
#!/bin/bash
echo "Deploying radbot, yo"
GIT_WORK_TREE=/var/radbot git checkout -f
echo "Bundling like a boss"
cd /var/www/radbot && bundle update
echo "Restarting radbot"
View backup-dewback
#!/bin/bash
cd /Users/csexton
# Rsync to Dreamhost
OPTIONS="-e ssh --relative --compress --archive --delete-excluded --progress --human-readable "
SERVER="backup.remote:cs-dewback"
rsync $OPTIONS Projects Pictures Documents $SERVER \
--exclude="OmniFocus Backups" \
--exclude="*vmwarevm" \
View t.rb
require 'rspec'
require 'rspec/autorun'
def pack_size(desc)
if (desc.match(/([\d]+)[\s]pack/i))
$1.to_i
else
1
end
end
View pack_size.rb
def pack_size(desc)
if (desc.match(/([\d]+)[\s]pack/i){ |m| pack_count = m[:pack_count].to_i }
$1.to_i
else
1
end
end
def pack_size(desc)
You can’t perform that action at this time.