Skip to content

Instantly share code, notes, and snippets.

@jmccartie
jmccartie / gist:5730171
Created June 7, 2013 15:36
migrate forums from one Zendesk account to another
forum.topics.each do |topic|
topic_hash = topic.to_hash
["url", "created_at", "updated_at", "id", "topic_type", "attachments", "comments_count", "fourm_id"].each { |k| topic_hash.delete(k) }
old_submitter = ZendeskAPI::User.find(chop, id: topic.submitter_id)
new_submitter = find_user_by_email(digerati, old_submitter.email)
topic_hash["submitter_id"] = new_submitter.id rescue next
topic_hash["updater_id"] = new_submitter.id
@jmccartie
jmccartie / easter2013.yml
Last active December 14, 2015 02:59
LifeChurch Easter 2013 service times (physical campuses)
ALB:
-
day_of_week: 6
time_of_day: "17:00:00"
-
day_of_week: 6
time_of_day: "18:30:00"
-
day_of_week: 0
time_of_day: "08:30:00"
@jmccartie
jmccartie / gist:4489565
Last active December 10, 2015 20:38
Rails 3.2.11 --> Empty arrays being parsed as "nil" instead of empty array

Rails 3.2.10

Post JSON with nested attributes:

> RestClient.post "http://localhost:3000/users.json", {"users" => [] }.to_json, { 'Content-Type' => 'application/json'}

Dump params from controller:

{"users"=>[], "action"=>"create", "controller"=>"users", "format"=>"json"}
@jmccartie
jmccartie / unsubscribe.rb
Created September 23, 2012 22:53
Don't deliver email if the address is on a blacklist
class EmailAddressFilter
def self.delivering_email(message)
message.perform_deliveries = false
# Remove email from message.to if email is on the unsubscribe list
tos = message.to.to_a
message.to.each do |email|
tos.delete(email) if Unsubscribe.find_by_email(email)
end
message.to = tos # can't delete directly from message.to. probably a better way to do this...
@jmccartie
jmccartie / gist:3051086
Created July 5, 2012 03:35
"Hallelujah" by The Digital Age (tab)
Song repeats the same theme.
Notes: keep your ring finger on the G-string. Mute the A-string with your index as you hit the low-E notes. Enjoy!
E |-- X--X---X-X---X-X---X-X
B |-- X--X---X-X---X-X---X-X
G |--12-11---7-6---2-4---2-7
D |-- 0--0---0-0---0-0---0-0
A |-- X--X---X-X---X-X---X-X
@jmccartie
jmccartie / css2sass.rb
Created May 15, 2012 22:49
Convert all your css files to sass
require 'rubygems'
require 'sass/css'
Dir["/PATH/TO/YOUR/PROJECT/app/assets/stylesheets/**/*.css"].each do |file|
puts "==> Starting #{file}..."
# file properties
basename = File.basename(file, ".css")
dir = File.dirname(file)
@jmccartie
jmccartie / lunchme.coffee
Created April 11, 2012 16:10
Lunchme hubot script
# Where we gonna go for lunch?
#
# lunch me <zipcode> - get a random lunch result based on your zipcode
module.exports = (robot) ->
robot.respond /lunch me( (\d+))/i, (msg) ->
zipcode = msg.match[2]
msg.http("http://lunchme.herokuapp.com/?zipcode=" + zipcode)
@jmccartie
jmccartie / signed_request.rb
Created March 6, 2012 19:59
Parse the Facebook "signed_request" param
# Found here: http://stackoverflow.com/questions/4987772/decoding-facebooks-signed-request-in-ruby-sinatra
require 'base64'
require 'openssl'
require 'crack/json'
def base64_url_decode str
encoded_str = str.gsub('-','+').gsub('_','/')
encoded_str += '=' while !(encoded_str.size % 4).zero?
Base64.decode64(encoded_str)
@jmccartie
jmccartie / mobile_device.rb
Created February 15, 2012 21:50
Determines whether or not the user is a mobile device
def prepare_for_mobile
session[:mobile_param] = params[:mobile] if params[:mobile]
request.format = :mobile if mobile_device?
end
def mobile_device?
return (session[:mobile_param] == "1") if session[:mobile_param]
request.user_agent.to_s.downcase =~ Regexp.new(
'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
@jmccartie
jmccartie / gist:1562007
Created January 4, 2012 20:36
Getting started with rbenv
$ brew update
$ brew install rbenv
$ brew install ruby-build
$ rbenv install 1.9.2-p290