Skip to content

Instantly share code, notes, and snippets.

View ryansch's full-sized avatar

Ryan Schlesinger ryansch

View GitHub Profile
require 'rubygems/format'
define :rvm_cookbook_gem, :action => :install do
remote_file params[:name] do
action :create_if_missing
backup false
end
ruby_block "Load gemspec and install gem" do
block do
ruby_block "rvm use default" do
block do
Chef::Mixin::Command.popen4('bash -l -c "rvm use default && env"') do |p,i,o,e|
o.each_line do |line|
next if line.nil?
line.chomp!
next if line.empty?
env_bits = line.split("=")
ENV[env_bits[0]] = env_bits[1]
undefined method `[]' for nil:NilClass
The error occurred line 73 of /path/to/lib/ruby/gems/1.8/gems/mixlib-log-1.1.0/lib/mixlib/log.rb in method 'level' while executing:
71 def level(lv=nil)
72 if lv.nil?
** @@levels.find() {|l| logger.level==l[1]}[0]
74 else
75 self.level=(lv)
# hack for the chef - we cannot read file in http_request resource
ruby_block "Set attributes for http request for #{database[:name]} #{database[:kind]}" do
block do
request = resources(:http_request => "Create backup record for #{database[:name]} #{database[:kind]}")
request.message({:backup => {:filename => compressed_file_name, :kind => database[:kind], :size => File.size(compressed_file_path)}})
end
end
http_request "Create backup record for #{database[:name]} #{database[:kind]}" do
url "http://some-url/backups"
@ryansch
ryansch / s3up.py
Created May 17, 2011 22:51 — forked from mtigas/0001.markdown
Command-line s3 uploader that uses the MultiPart (chunked) S3 upload functionality to parallelize and speed up large file uploads.
#!/usr/bin/env python
# coding=utf-8
#
# s3up.py
# 2010-2011, Mike Tigas
# https://mike.tig.as/
#
# Usage:
# s3up filename
# Uploads the given file to the DEFAULT_BUCKET (see below)
@ryansch
ryansch / redis-em.mdown
Created May 25, 2011 20:44 — forked from zacharyvoase/redis-em.mdown
Redis + EventMachine - CPS == WIN.

A (Nicer) Redis Client for EventMachine

Redis is my favourite key/value store; it’s flexible, easy to set up and insanely fast. [EventMachine][] is a popular Ruby library for doing asynchronous I/O using an event loop. Bindings already [exist][em-redis] for accessing a Redis server using EM’s async-I/O (courtesy of Jonathan Broad), but unfortunately the resulting code has to use [Continuation-Passing Style][cps] via Ruby blocks. A very basic example of what that looks like follows:

"let g:solarized_visibility="normal"
"let g:solarized_specialbg="off"
"color solarized
color ry-solarized
"color torte
"highlight NonText guifg=#4a4a59
"highlight SpecialKey guifg=#4a4a59
# .bashrc
# User specific aliases and functions
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f .bash_completion ]; then
require 'daemon_controller'
require 'socket'
REPO_DIR = '/path/to/repos'
WHITELIST = %w{hostthis}
LISTEN = '1.2.3.4'
PORT = '9418'
PID_FILE = 'git-daemon.pid'
LOG_FILE = 'git-daemon.log'
LOCK_FILE = "#{PID_FILE}.lock"
Bluepill.define_process_condition(:running_time) do
def initialize(options = {})
@below = options[:below]
end
def run(pid)
started = `ps -p #{pid} -o command`.match(/since (\d+)/)[1].to_i
Time.now - Time.at(started)
rescue
0