Skip to content

Instantly share code, notes, and snippets.

View robinsloan's full-sized avatar

Robin Sloan robinsloan

View GitHub Profile
@robinsloan
robinsloan / unbroken-spine-id-notes.txt
Created October 7, 2012 04:39
Unbroken Spine member ID notes
Just a few notes for the curious.
* Every number in Mr. Penumbra's 24-Hour Bookstore is a least a little bit meaningful
* The Unbroken Spine member IDs are extra meaningful
* I checked in the roster and Peter Richardson's member ID is 6K6DV8
* I checked in the roster and Patrick Ewing's member ID is 6L9SN2
* Peter and Patrick had different mentors
* Beware the missing letter
More to come, here and there...
@robinsloan
robinsloan / regex_var.rb
Created October 24, 2012 01:36
Ruby regex tricks
# variables from regex
# must be literal; must be on left side of comparison
if /Robin is (?<adjective>\w+)/ =~ "Robin is awesome" then
puts "#{adjective}"
end
# indexing into a string via regex (whoa)
str = "Robin is awesome"
@robinsloan
robinsloan / ruby_zip.rb
Created October 24, 2012 01:47
Ruby zip
# zip two collections together then iterate in lockstep
first_names = "Clark", "Bruce", "Diana"
last_names = "Kent", "Wayne", "Troy"
first_names.zip(last_names) do |first, last|
puts "#{first} #{last}"
end
@robinsloan
robinsloan / yt-scrap.js
Created November 2, 2012 23:07
YouTube API scraps
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var gYTPlayer;
var onYouTubePlayerAPIReady = function() {
gYTPlayer = new YT.Player('gYTPlayer', {
width: 640,
@robinsloan
robinsloan / cook.md
Created December 6, 2012 18:38
"So, anyway."

This part was charming:

BUSINESSWEEK: Nothing hardens faster than the details of a CEO’s bio. Every story about you mentions the following: You’re a Southern gentleman. An Auburn football fan. Always early to work, always the last one to leave. None of it is negative, but do you recognize yourself in those descriptions or do you find yourself a little bit distorted? If so, would you like to correct a few things?

COOK: I think when you start reading about yourself, it’s almost -- it’s like a caricature. It begins to sound like someone else. That’s probably a better question to ask people that really know me vs. me. I hate talking about me. You know, it’s not something I do well or do a lot. I generally avoid it.

But I would say that the person you read about is robotic. There are some good things about that, perhaps. (Laughs.) Discipline comes to mind. But it sounds like there is just no emotion. People that know me, I don’t think they would say that. I certainly am not a fist-pounder. That isn’t my style.

It was the end of the day and we were off to have a drink in the cafeteria just as a low-flying plane in the distance came zooming our way. As the roar grew louder, people shouted, "It's the president! It's Lindy!" Men, women, and children all ran out onto the great front lawn and began to wave at the approaching plane, which as it crossed over the Potomac tipped its wings. "Hurray!" people shouted. "Hurray for Lindy!" It was the same Lockheed fighter we'd seen in the air over the city the previous afternoon, and we had no choice but to stand there like patriots and watch with the rest of them as it banked and flew back over George Washington's home before it turned to follow the Potomac north.

@robinsloan
robinsloan / save-followings.rb
Created April 6, 2013 16:52
Export IDs of the people you're following on Twitter.
#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'
require 'json'
require 'faraday'
TWITTER_USER = "blahblah"
# get these from dev.twitter.com
CONSUMER_KEY = "blahblah"
#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'
require 'json'
require 'faraday'
TWITTER_USER = "your_username_here"
TIMEOUT = 1 # increment this if you're getting a lot of rate limit errors
# get these from dev.twitter.com
#!/usr/bin/env ruby
require 'rubygems'
require 'numbers_and_words'
VOWELS = ['a','e','i','o','u']
CONSONANTS = ('a'..'z').to_a.delete_if do |char|
VOWELS.include?(char)
end
// this is the part i always use
$.ajax = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onload = callback;
xhr.send();
}