Skip to content

Instantly share code, notes, and snippets.

@mmay
mmay / configdatabase.yml
Created June 3, 2012 18:31
Rails config/database.yml for postgres and utf8
development:
adapter: postgresql
encoding: utf8
database: <app_name>_development
pool: 5
timeout: 5000
host: localhost
test:
adapter: postgresql
# Adds minutes to the time string
# @param time [String] of format "[H]H:MM {AM|PM}"
# @param minutes [Integer] the number of minutes to add to the time
def add_minutes(time, minutes)
hours, min, am_pm = time.match(/(\d+):(\d+)\s(\w\w)/).captures
hours = hours.to_i
min = min.to_i + minutes
if hours == 11 && min > 59
am_pm = am_pm == "PM" ? "AM" : "PM"
# "Stuff" is a java object with a default constructor
# In the style of ruby open struct
stuff = Stuff.new(attr1: "value1", attr2: "value2")
# VS
# typcial get/set style
stuff = Stuff.new
stuff.attr1 = "value1"
@mmay
mmay / gist:6873007
Last active December 24, 2015 22:29
srsly?
mmay$ rake assets:clean
Booted rails in 0.83
Included bundled gems in 5.738
/Users/mmay/.rvm/rubies/jruby-1.7.3/bin/jruby /Users/mmay/.rvm/gems/jruby-1.7.3/bin/rake assets:clean:all RAILS_ENV=production RAILS_GROUPS=assets
Booted rails in 0.802
Included bundled gems in 5.209
Loading java environment from /Users/mmay/dev/.../src/main/rails/.../../../../../pom.xml
Built effective-pom.xml in 0.0s
Built build-classpath.txt in 0.0s
Added java paths to $CLASSPATH in 0.023
@mmay
mmay / gist:9906606
Created April 1, 2014 02:29
heroku push wut
-----> Ruby app detected
<internal:prelude>:8:in `lock': deadlock detected (fatal)
from <internal:prelude>:8:in `synchronize'
from /usr/local/lib/ruby/1.9.1/thread.rb:293:in `push'
from /app/vendor/lpxc/lpxc.rb:39:in `puts'
from /app/slug-compiler/lib/utils.rb:173:in `log_write'
from /app/lib/loggable.rb:137:in `log_hash'
from /app/lib/loggable.rb:100:in `l2metfmt'
from /app/lib/loggable.rb:72:in `count'
from /app/lib/loggable.rb:47:in `monitor'
fastly = Fastly.new(api_key: FASTLY_API_KEY)
# Site wide purge
s = fastly.get_service service_id
s.purge_all
# URL Purge
# "www.cool.com/blah.json"
fastly.purge("/blah.json")
@mmay
mmay / fastly_create_domain
Last active August 29, 2015 14:04
ruby script to create a fastly domain
#!/bin/env ruby
##
# fastly_upload_vcl - upload raw VCL files to Fastly
#
# Author:: Fastly Inc <[email protected]>
# Copyright:: Copyright (c) 2011 Fastly Inc
# License:: Distributes under the same terms as Ruby
#
# = USAGE
@mmay
mmay / gist:5eaa4d3c2fb942f3d000
Last active August 29, 2015 14:07
asset caching config
# config/environments/production.rb
config.serve_static_assets = false
config.assets.compress = true
config.assets.digest = true
config.action_controller.asset_host = ENV['FASTLY_CDN_URL']
config.static_cache_control = 'public, s-maxage=15552000, maxage=2592000'