Skip to content

Instantly share code, notes, and snippets.

View ryansch's full-sized avatar

Ryan Schlesinger ryansch

View GitHub Profile
@ryansch
ryansch / link_multiple_switches.yaml
Last active March 12, 2023 09:37 — forked from aderusha/link_multiple_switches.yaml
Home Assistant Blueprint: Link Multiple Switches v1.0.1
@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 / 0-readme.md
Created December 7, 2012 20:36 — forked from burke/0-readme.md
ruby-1.9.3-p327 cumulative performance patch for rbenv without gc patch

ruby-1.9.3-p327 cumulative performance patch for rbenv without gc patch

This installs a patched ruby 1.9.3-p327 with various performance improvements without a backported COW-friendly GC to make things happy on heroku, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@ryansch
ryansch / rbenv-install-system-wide.sh
Created February 20, 2012 18:39
rbenv install and system wide install on Ubuntu 10.04 LTS.
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Add rbenv to the path:
@ryansch
ryansch / move_to_rds.rb
Created January 24, 2012 23:51 — forked from guenter/move_to_rds.rb
A quick and dirty script to move a database into Amazon RDS (or any other database). Can transfer part of the data beforehand.
require 'fileutils'
start_time = Time.now
SOURCE_DB = {
:name => 'db_name',
:user => 'db_user',
:password => 'db_pass',
:host => 'localhost'
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
@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:

@ryansch
ryansch / chef.rb
Created May 3, 2011 21:33 — forked from morgoth/chef.rb
# 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"
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]
@ryansch
ryansch / Capfile
Created December 8, 2010 00:07 — forked from tompata/Capfile
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
after 'deploy:finalize_code', 'deploy:web:disable'
after 'deploy:start', 'deploy:web:enable'
namespace :deploy do