Skip to content

Instantly share code, notes, and snippets.

@geoffgarside
geoffgarside / pg_backup.sh
Created January 7, 2013 10:01
PostgreSQL Database Backup/Restore migration help script
#!/bin/sh
#
backupdir="./pg_backups"
pgdump_args="-bF c"
pgdumpall_globals_args=""
pg_backup() {
if [ ! -d ${backupdir} ]; then
echo Creating $backupdir
From: app/serializers/nameserver_serializer.rb @ line 4 NameserverSerializer#attributes:
4: def attributes
5: hash = super
=> 6: binding.pry
7: hash
8: end
1.8.7 (#<NameserverSerializer:0x1102735d8>):0 > object_id
=> 2282986220
@geoffgarside
geoffgarside / gist:2692955
Created May 14, 2012 09:34
Git post-receive hook for Rails with Pow
#!/bin/sh
# Handle previously empty directory.
if [ $1 = 0000000000000000000000000000000000000000 ]; then
old=4b825dc642cb6eb9a060e54bf8d69288fbee4904
else
old=$1
fi
# Touch tmp/restart.txt so Pow will restart the server
@geoffgarside
geoffgarside / gist:2593820
Created May 4, 2012 10:16
Makefile wrapper to help GNUMake related RubyGem extensions build properly on FreeBSD/Solaris.
#!/bin/sh
#
# Makefile wrapper to help GNUMake related RubyGem extensions
# build properly on FreeBSD/Solaris.
#
# Write this file to ~/bin/make
# $ chmod 755 ~/bin/make
# $ export PATH=$HOME/bin:$PATH
#
# Can now "gem install" or "bundle install" or whatever you need.
# abcdefghijklmnopqrstuvwxyz
# sn rgh o la m tdyibe
def encode(string, key = "abcdefghijklmnopqrstuvwxyz")
ord_a = "a".ord
string.chars.map do |c|
case c
when /[a-z]/
n = key.index(c)
n ? (n + ord_a).chr : c
when /[A-Z]/
@geoffgarside
geoffgarside / README.md
Created December 18, 2011 23:12 — forked from bergie/README.md
Falsy Values tutorials
class Thinger
def starts_at=(v)
v = DateTime.parse(v, "%m/%d/%Y %h:%M%p") if v.kind_of?(String)
write_attribute(:starts_at, v)
end
end
class Venue
def as_json(options = {})
super(options.merge(:include => [:city]))
end
end
@geoffgarside
geoffgarside / ip_address_validator.rb
Created November 4, 2011 14:55
Rails 3.x IP Address validator class
# The IP Address Validator accepts the following options
#
# * allow_nil - allows nil values
# * allow_blank - allows blank values
# * allow_cidr - allows /prefixlen CIDR masks in values
#
# the validator will use regular expressions in an attempt to prevent
# malformed IP addresses from being passed to the IPAddr.new initializer
# as this method can be very slow to raise exceptions for malformed input.
class IpAddressValidator < ActiveModel::EachValidator
require 'net/https'
require 'uri'
email = ARGV[0]
password = ARGV[1]
uri = URI.parse("https://google.com/accounts/ClientLogin")
req = Net::HTTP::Post.new(uri.path)
req.set_form_data({'Email'=> email, 'Passwd' => password,'accountType' => 'GOOGLE', 'service' => 'ac2dm', 'source' => 'myexample'})