Skip to content

Instantly share code, notes, and snippets.

View Winslett's full-sized avatar

Christopher Winslett Winslett

View GitHub Profile
@Winslett
Winslett / gist:1176330
Created August 28, 2011 06:49
Possible EY Backup Reloading Across Servers
#
# Possible cross-server database restoring of databases by adding the following at line 79 of:
#
# /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/ey_cloud_server-1.4.24/lib/ey_backup/cli.rb
#
# Then, you could run the following:
#
# eybackup -E my_other_environment -D my_local_db_name_if_different --restore 9:mybackedup_database.sql.gz
#
opts.on("-E", "--environment EY_Environment", "Engine Yard Environment.") do |environment|
@Winslett
Winslett / gist:1255731
Created October 1, 2011 07:34
Engine Yard Backup from RDS
diff -r winslett.ey_cloud_server-1.4.24/lib/ey_backup/cli.rb /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/ey_cloud_server-1.4.24/lib/ey_backup/cli.rb
77a78,81
>
> opts.on("-h", "--host HOSTNAME", "Remote hostname to connect, defaults to local") do |host|
> options[:host] = host
> end
diff -r winslett.ey_cloud_server-1.4.24/lib/ey_backup/engine.rb /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/ey_cloud_server-1.4.24/lib/ey_backup/engine.rb
6c6
< attr_reader :username, :password
---
@Winslett
Winslett / gist:1533816
Created December 29, 2011 12:17
Bash Function to Split MySQL Dumps - BSD Split Only
function split_db_dump {
if [ -f $1 ]
then
split -p 'Table structure' $1
for file in x*
do
head -n1 $file | grep -oE '`[^`]+`' | sed 's/`//g' | xargs -n1 -I {} mv $file {}
done
else
echo "File name is required"
@Winslett
Winslett / mongoid.yml
Created June 1, 2012 20:41
MongoHQ & Heroku
heroku config:set MONGOHQ_URL='mongodb://myusername:mypassword@flame.mongohq.com:27017/my_database'
@Winslett
Winslett / gist:3130646
Created July 17, 2012 17:13
Ruby - MongoDB Forked Connection Pattern
require 'rubygems'
require 'mongo'
@conn = Mongo::Connection.new("localhost", 27017, :pool_size => 10, :pool_timeout => 5)
@db = @conn['mongomapper_resque_development']
@coll = @db['users']
puts @db.command({getLastError: 1})
1.upto(10) do
@Winslett
Winslett / gist:4135972
Created November 23, 2012 14:51
Night Before Christmas
Twas the night before Christmas, when all through the house
Not a creature was stirring, not even a mouse.
The stockings were hung by the chimney with care,
In hopes that St Nicholas soon would be there.
The children were nestled all snug in their beds,
While visions of sugar-plums danced in their heads.
And mamma in her ‘kerchief, and I in my cap,
Had just settled our brains for a long winter’s nap.
@Winslett
Winslett / gist:5010481
Last active December 14, 2015 01:59
Mongoid Sample
production:
sessions:
default:
uri: mongodb://<username>:<password>@<host>:<port>/<database_name>
options:
skip_version_check: true
consistency: :strong
safe: true
max_retries: 30
retry_interval: 1
@Winslett
Winslett / gist:6a674ae858ab92f13038
Created April 13, 2015 20:15
Ruby Binary Search
require 'benchmark'
class Data
class << self
@@key_values = {}
def put(key, value, time)
@@key_values[key] ||= []
@@key_values[key] << {time: time, value: value}
true
1. Eat Bi-Rite ice cream in Dolores Park
2. Tan yourself with other hip San Francisco residents at Dolores Park
3. Visit Bi-Rite grocery store in the Mission
4. Visit Golden Gate park and climb to the top of the DeYoung Museum
5. Stare at beautiful art at the San Francisco Museum of Modern Art (“SFMoMA”)
6. Window shop on Valencia St in The Mission - start at 16th and Valencia and walk to 25th and Valencia
7. Visit the Ferry Building Farmers Market (on Saturdays) under the Bay Bridge
8. Take a cable car on the California Line to Pac Heights and meander back down Fillmore St
9. Eat dim-sum in the largest China Town in the USA (Koi Palace in Daly City which is South of San Francisco is considered excellent for this)
10. See a concert at the Great American Music Hall
@Winslett
Winslett / gist:8e0ab9066d4888ee760e
Last active August 29, 2015 14:24
ruby-pg connection retry from PG::UnableToSend
uri = URI.parse(ENV['POSTGRES_URL'])
$query_postgres = lambda do |sql|
begin
$postgres ||= PG.connect(uri.hostname, uri.port, nil, nil, uri.path[1..-1], uri.user, uri.password)
$postgres.exec(sql)
rescue PG::UnableToSend
$postgres = nil
retry
end