Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / bible-doge.rb
Last active December 26, 2015 19:49
wow. so minister. much earth. many angels.
require 'open-uri'
puts open('http://johnholdun.com/wardrobe/bible-doge.txt').read.split("\n").sample(1 + (rand * 2).round).shuffle.send((rand < 0.5 ? :unshift : :push), 'wow').join('. ') + '.'
ids = [329740082619772928, 329918487558504451, 330280700072833026, 330651260321669121, 331023740257325057, 331355726356291585, 331747132803518465, 332093606355664896, 332458504747110401, 332817496753184768, 333183149867667458, 333542218503696384, 333921623436574721, 334270156035469314, 334632030774099969, 335013040451891200, 335369313466871808, 335719753299685376, 336094052749565952, 336461902785966081, 336790999277916162, 337173236968210432, 337529860106878976, 337875782665912320, 338255438862766080, 338630809231708160, 338988045032370177, 339350345010536448, 339714371792035841, 340065176281837569, 340451705298771968]
ids.each do |id|
method = :post
uri = URI "https://api.twitter.com/1.1/favorites/create.json"
params = { id: id, include_entities: false }
request = Net::HTTP::Post.new uri.request_uri
request.set_form_data params
request['Authorization'] = SimpleOAuth::Header.new(method, uri, params, {
consumer_key: CONSUMER_KEY,