Skip to content

Instantly share code, notes, and snippets.

@jmccartie
jmccartie / gist:1546417
Created January 1, 2012 06:00
Happy new year
$ irb
ruby-1.9.2-p180 :001 > Time.now
=> 2012-01-01 00:00:00 -0600
@jmccartie
jmccartie / translate.rb
Created October 12, 2011 02:55
Use the Google Translate API to translate Babelwith.me strings
#
# Not currently dynamic for a i18n file -- it spits out "en/txt and en/errors"
#
require 'cgi'
require 'yaml'
require 'httparty'
@strings = YAML.load(File.read("")).to_hash
@api_key = ''
##
# Benefits: plain text that can be discussed amongst stakeholders,
# repeatable "steps", Gherkin syntax to define state, more...
##
Feature: Manage Articles
In order to make a blog
As an author
I want to create and manage articles
@jmccartie
jmccartie / device.rb
Created September 1, 2011 15:25
Device model using Device Atlas
class Device
include HTTParty
attr_accessor :mobile_device, :touch, :device_model,
:device_brand, :ua, :device_os, :bb_info, :properties, :mp4, :h264, :stream
def initialize(ua)
if ua.class == Hash
ua.each do |k, v|
send("#{k}=", v)
@jmccartie
jmccartie / upload.rb
Created August 5, 2011 23:59
Upload all files to s3 bucket
require 'rubygems'
require 'aws/s3'
# Change the access key and secret to your amazon credentials
AWS::S3::Base.establish_connection!(
:access_key_id => 'ACCESS_KEY_ID',
:secret_access_key => 'SECRET'
)
# Change this to your S3 bucket name
WEBSITE_BUCKET_NAME = "YOUR_BUCKET_NAME"
# Bundler output
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.pre.5
Running: bundle install --without development:test --path vendor/bundle --deployment
Fetching dependency information from the API at http://rubygems.org/.......
Could not find fastercsv-1.5.4 in any of the sources
!
! Failed to install gems via Bundler.
@jmccartie
jmccartie / gist:1030191
Created June 16, 2011 20:30
Force / unforce SSL based on given hash of pages you with to protect
def force_ssl
pages = {"giving" => ["login", "give"]}
pages.each do |controller, actions|
if params[:controller] == controller && actions.include?(params[:action])
if !request.ssl? && !Rails.env.development?
redirect_to :protocol => 'https://', :status => :moved_permanently
end
elsif request.ssl?
redirect_to :protocol => 'http://', :status => :moved_permanently
end
@jmccartie
jmccartie / gist:994648
Created May 27, 2011 04:43
lazy ways to do things while you're asleep
while Time.now.to_i < 1306476537
puts "not time yet...\n"
sleep 120
end
system "heroku db:push --tables search_terms --confirm myapp"
@jmccartie
jmccartie / strip.rb
Created May 17, 2011 18:45
Strip HTML from ALL item descriptions
Item.all.each {|item| item.update_attributes(description: Nokogiri::HTML(item.description).xpath("//text()").remove.to_s) }
@jmccartie
jmccartie / gist:969736
Created May 13, 2011 00:24
Geocode CLI
$ geocode Oklahoma City, OK
Latitude: 35.4675602
Longitude: -97.5164276
Full address: Oklahoma City, OK, USA
City: Oklahoma City
State/province: Oklahoma
Postal code:
Country: United States
Google map: http://maps.google.com/maps?q=35.4675602,-97.5164276