Skip to content

Instantly share code, notes, and snippets.

@coderanger
coderanger / chunked.rb
Created April 6, 2012 00:11
Transfer-Encoding:chunked for Faraday
class Chunked < FaradayMiddleware::ResponseMiddleware
define_parser { |body|
return if body.empty?
raw_body = body
decoded_body = []
until raw_body.empty?
chunk_len, raw_body = raw_body.split("\r\n", 2)
chunk_len = chunk_len.split(';',2).first.hex
break if chunk_len == 0
decoded_body << raw_body[0, chunk_len]
@coderanger
coderanger / ungemnasium.rb
Created April 10, 2012 07:02
Clean up after Gemnasium
require 'octokit'
c = Octokit::Client.new(:login => "...", :password => "...")
conn = c.instance_exec{connection}
c.repos.each do |r|
puts "Trying to unsub #{r.name}"
begin
conn.get("/repos/#{c.login}/#{r.name}/hooks").body.each do |hook|
@coderanger
coderanger / default.rb
Created April 24, 2012 20:09
Chef resource alias
class Chef
class Recipe
def new_name(*args, &block)
method_missing(:old_name, *args, &block)
end
end
end
@coderanger
coderanger / Rakefile
Created May 27, 2012 23:58
Invoke Librarian from Rake automatically
desc "Run librarian"
task :librarian do
puts "** Syncing with Cheffile"
system("librarian-chef install")
end
# Extend the existing task to also call librarian
task :update do
Rake::Task[:librarian].invoke
end
@coderanger
coderanger / __init__.py
Created June 11, 2012 00:57
Edited version of opscode's fabfile/
import os
from fabric.api import env, task, roles, run
from fabric.utils import abort
from chef import ChefAPI, autoconfigure
from chef.fabric import chef_roledefs
if 'OC_USER' in os.environ:
env.user = os.environ['OC_USER']
class Chef
class SubResourceCollection < ResourceCollection
def initialize(parent)
@parent = parent
super()
end
def lookup(resource)
super
rescue Chef::Exceptions::ResourceNotFound
@coderanger
coderanger / holidays.py
Created March 23, 2013 22:49
Find streaks of days that overlap no holidays
# coding=utf-8
import datetime
from dateutil.parser import parse
# From http://www.huffingtonpost.com/2013/01/01/religious-holidays-2013_n_2372650.html
raw_holidays = """
Baha'i Holidays 2013:
Jan 20 - World Religion Day
Mar 2-20 - Baha'i Fast
Mar 20 - Nowruz (Baha'i, Zoroastrian, Iranian New Year)
@coderanger
coderanger / platforms.yml
Last active December 20, 2015 14:39
EC2 platform configuration for test-kitchen
----
platforms:
- name: ubuntu-12.04
driver_config:
image_id: ami-d726abbe
username: ubuntu
- name: ubuntu-10.04
driver_config:
image_id: ami-1ab3ce73
username: ubuntu
@coderanger
coderanger / gist:6429373
Last active December 22, 2015 06:09 — forked from ewdurbin/gist:6429299
url = require('url')
querystring = require('querystring')
component_name = (organization_id, component_id, cb) ->
http.get"http://#{organization_id}.statuspage.io/index.json", (res) ->
payload = JSON.parse(res.body.payload)
for comp in payload.components
if comp.id == component_id
return cb(comp.name)
@coderanger
coderanger / pycon.md
Last active December 23, 2015 00:49
Possible PyCon 2014 talks

1: Application Deployment State of the Onion

An overview of the moving pieces in app deployment currently (ex. chef, puppet, salt, ansible, git, omnibus, compass, less, DB migrations, databases).

Description

Deploying a moderately complex web application has become quite a challenge over the years. As best-practices have evolved, it has become progressively more time-consuming to keep up with what tools exist and how to use them effectively. This talk will provide an overview of the ecosystem and provide pointers for more information about individual components or problems.

Audience