Skip to content

Instantly share code, notes, and snippets.

@johnholdun
johnholdun / tumblr-archive.rb
Last active August 29, 2015 14:02
Get all your dang tumblr posts
require 'json'
require 'open-uri'
hostname = 'irc'
posts = []
page = 1
pages = 1
per_page = 20
begin
@johnholdun
johnholdun / spirit-locations.rb
Created September 26, 2014 12:21
Scrape the Spirit Halloween store locator and return a sensible array of hashes
require 'open-uri'
require 'nokogiri'
require 'yaml'
def aggressive_strip text
text.strip.gsub(/[\s\r\n]+/, ' ')
end
postal_code = 10003
url = "http://checkout.spirithalloween.com/storelocation.aspx?zipPostalCode=#{ postal_code }"
@johnholdun
johnholdun / sinatra-rails.rb
Last active December 18, 2022 06:59
Using ActionController inside a Sinatra App
require 'rubygems'
require 'sinatra/base'
# ActionPack is a gem that is part of Rails. It includes ActionController and ActionView
require 'action_pack'
# Rack::Test is not used in this file but ActionController will yell if we don't require it
require 'rack/test'
# This is part of the ActionPack gem
@johnholdun
johnholdun / crew.rb
Last active August 29, 2015 14:22 — forked from Will-Sommers/gist:4fe13e7a9383318f4bcd
An okay way to interleave names
FOLKS = %w(
Caroline
Chris
Dave
Devin
Hindi
John
Kai
Nizar
Pat
@johnholdun
johnholdun / Rakefile
Last active August 29, 2015 14:26
commit, build, and publish a new version of your gem
namespace :gem do
task publish: [:commit, :build, :fury]
task :commit do
current_branch = %x(git rev-parse --abbrev-ref HEAD).strip
git_status = %x(git status --short --untracked-files=no)
unless current_branch == 'master'
puts 'Only run this task with master checked out!'
return
@johnholdun
johnholdun / cookie_test.rb
Last active November 13, 2015 18:27
Cookie Test: Given the same cookie set to different values on different domains, what persists?
@johnholdun
johnholdun / scrobbles.rb
Created November 17, 2015 05:51
download all your tracks from last.fm
require 'active_support/all'
require 'open-uri'
require 'nokogiri'
require 'csv'
require 'pry'
LAST_FM_ENDPOINT = 'http://ws.audioscrobbler.com/2.0/'
PAGE_SIZE = 200
def result(username, api_key, page)
@johnholdun
johnholdun / index.js
Created November 24, 2015 23:14
fake redux simulator
/** @jsx React.DOM */
var store = {
name: "Chris",
position: "there"
};
var reduce = function (state, action) {
if (action.type === "CHANGE_NAME") {
state.name = action.payload;
@johnholdun
johnholdun / fake-jsx.js
Created December 9, 2016 21:58
render html with javascript?
var objectToAttributes = function (object) {
var output = "";
var keyTranslations = {
className: "class",
htmlFor: "for"
};
Object.keys(object).forEach(function (key) {
var value = object[key];
@johnholdun
johnholdun / lateset_browser_versions.rb
Created January 20, 2017 16:48
Find the latest browser versions from the caniuse db
require 'json'
require 'net/https'
require 'uri'
def latest_browser_versions
uri = URI.parse('https://cdn.rawgit.com/Fyrd/caniuse/master/data.json')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE