Skip to content

Instantly share code, notes, and snippets.

View sgonyea's full-sized avatar

Scott Gonyea sgonyea

  • Google
  • Mountain View, CA
View GitHub Profile
@sgonyea
sgonyea / gist:3896429
Created October 15, 2012 23:52 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

@sgonyea
sgonyea / comma-ize.rb
Created September 25, 2012 22:29
comma-delimit a number
"12345678".gsub!(/(?=(\d\d\d)+$)(?<=\d)/, ',')

The following works:

openssl s_client -key private_key.key -cert cert.crt -connect "client-auth.myhost.com:443"

wget --no-check-certificate --certificate=cert.crt --private-key=private_key.key https://client-auth.myhost.com:443/path

Yet curl does not seem to work:

curl -v -s -k --key private_key.key --cert cert.crt "https://client-auth.myhost.com:443/path"
@sgonyea
sgonyea / renew_dhcp_until_ip.rb
Created July 29, 2012 22:05
Renews your DHCP Lease every 30-seconds, until an IP Address is assigned. Fight crappy WAPs!
#!/usr/bin/env ruby
# I believe 'en1' is the default WiFi device name on Mac OS X. It's what mine is set to.
def device; @device ||= ARGV[0] || "en1" end
def ip_set?
ip = `ipconfig getifaddr #{device}`
return false if ip.empty?
return false if ip.start_with?("169")
@sgonyea
sgonyea / infinite_cache.py
Created July 18, 2012 03:28
Infinite Cache: Python vs. Ruby
# In Python:
from collections import defaultdict
def infinite_cache():
cache = lambda: defaultdict(cache)
return cache()
cache = infinite_cache()
def hash_counter(default=nil)
Hash.new{ |k,v| k[v] = block_given? ? yield : default }
end
counts = {
:sl => {
:absent => hash_counter(0),
:missing_data => hash_counter { hash_counter(0) },
:present_data => hash_counter { hash_counter(0) },
},
Padrino::Logger::Config[:production][:log_level] = :info
Padrino::Logger::Config[:production][:stream] = :to_file
Padrino::Logger::Config[:production][:format_datetime] = " [%Y-%m-%d %H:%M:%S] "
Padrino::Logger::Config[:development][:stream] = :to_file
Padrino::Logger::Config[:development][:format_datetime] = " [%Y-%m-%d %H:%M:%S] "
Padrino::Logger::Config[:uat] = Padrino::Logger::Config[:production]
Padrino::Logger::Config[:staging] = Padrino::Logger::Config[:production]
Padrino::Logger::Config[:qa] = Padrino::Logger::Config[:production]
platform :jruby do
gem 'jruby-openssl'
gem 'ffi-ncurses'
gem 'activerecord-jdbcsqlite3-adapter'
end
@sgonyea
sgonyea / gist:2484827
Created April 25, 2012 00:19
How to test if there are non-ASCII characters in a file.
# Surely there is a better way than this. You can do grep:
# grep --color='auto' -P -n "[\x80-\xFF]"
def string_has_non_ascii_chars?(string)
begin
string.encode("US-ASCII")
return false
rescue Encoding::InvalidByteSequenceError => e
return true
@sgonyea
sgonyea / gist:2475444
Created April 24, 2012 01:46
How to find non-ASCII characters in a file
grep --color='auto' -P -n "[\x80-\xFF]"