Skip to content

Instantly share code, notes, and snippets.

@scpike
scpike / sortlines.js
Last active October 17, 2015 22:34
Sorts the lines in your input.
(function(x) {
return x.split("\n").sort().join("\n");
})
(defn wrap-token
[handler & [{:as options}]]
(fn [request]
(let [token (:token (:params request))]
(if (= token "MAGIC-KEY")
(handler request)
{ :status 403 :body "Forbidden" }))))
@scpike
scpike / gist:a72a748126cbb4359c03
Created December 8, 2014 20:06
Namecheap hosts file => Route 53
File.readlines(ARGV[0]).each do |l|
l.chomp!
xs = l.split("\t")
"@ MX ALT1.ASPMX.L.GOOGLE.COM. 20 1800"
if xs.count == 5
owner, rtype, tdata, pref, ttl = xs
pref = nil if pref.strip == "0"
next if rtype.strip == 'URL'
puts [owner, ttl, "IN", rtype, pref, tdata].compact.join("\t")
# example.com. IN MX 10 mail.example.com. ; mail.example.com is the mailserver for example.com
@scpike
scpike / grab_venues.rb
Created September 19, 2012 05:21
Grab a list of all the foursquare venues
# ruby grab_venues.rb will print a csv of all the foursquare venue types
# flattens the nested hash of venues
url = "https://api.foursquare.com/v2/venues/categories?oauth_token=your_token&v=20120828"
require 'json'
# hashes are nested, containing arrays of hashes of category information
def print_hash(hash)
# We've found a category
@scpike
scpike / gen_token.rb
Created September 19, 2012 03:53
generate at token
token = SecureRandom.urlsafe_base64
# Naive, but with ~64^16 possibilities conflicts aren't a worry yet
# > 5,000,000.times {x << SecureRandom.urlsafe_base64}; puts x.uniq.count
# 5000000
while Checkin.where(:token => token).any?
token = SecureRandom.urlsafe_base64
end
@scpike
scpike / add_4sq_reply.rb
Created September 19, 2012 02:44
Reply to a foursquare checkin
def create_reply(message)
reply_url = "https://api.foursquare.com/v2/checkins/#{checkin_id}/reply"
url = URI.parse(reply_url)
req = Net::HTTP::Post.new(url.path)
# token is a one time use secure random string
params = { :url => "http://www.hashtagmom.com/notify_mom/#{token}/",
:text => message,
:oauth_token => user.foursquare_access_token,
:v => "20120827" }
req.set_form_data(params)
@scpike
scpike / create_4sq_post.rb
Created September 19, 2012 02:41
Add a post to a foursquare checkin
def create_post
url = URI.parse("https://api.foursquare.com/v2/checkins/#{checkin_id}/addpost")
req = Net::HTTP::Post.new(url.path)
params = { :url => "http://www.hashtagmom.com",
:text => message,
:oauth_token => user.foursquare_access_token,
:v => "20120827" }
req.set_form_data(params)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
@scpike
scpike / copy-s3-bucket.rb
Created September 18, 2012 20:29 — forked from scharfie/copy-s3-bucket.rb
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Maintains acl
require 'rubygems'
require 'right_aws'
aws_access_key_id = ''
aws_secret_access_key = ''
target_bucket = 'bucket_with_data_to_copy'
destination_bucket = 'to_copy_into'
s3 = RightAws::S3Interface.new(aws_access_key_id, aws_secret_access_key)
@scpike
scpike / copy-s3-bucket.rb
Created September 18, 2012 20:26 — forked from scharfie/copy-s3-bucket.rb
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Useful for transferring large amounts of data and will work across geographic regions.
require 'rubygems'
require 'right_aws'
require 'yaml'
filename = ENV['FILE'].to_s
source = ENV['FROM'].to_s
destination = ENV['TO'].to_s
dry_run = true
puts "Please provide filename of s3 configuration" and exit(1) if filename == ""
@scpike
scpike / copy-s3-bucket.rb
Created September 18, 2012 20:26 — forked from scharfie/copy-s3-bucket.rb
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Useful for transferring large amounts of data and will work across geographic regions.
require 'rubygems'
require 'right_aws'
require 'yaml'
filename = ENV['FILE'].to_s
source = ENV['FROM'].to_s
destination = ENV['TO'].to_s
dry_run = true
puts "Please provide filename of s3 configuration" and exit(1) if filename == ""