Skip to content

Instantly share code, notes, and snippets.

View afeld's full-sized avatar

Aidan Feldman afeld

View GitHub Profile
@afeld
afeld / ride4ruby.rb
Created January 12, 2011 02:52
solution for Ride4Ruby
# Ride4Ruby solution by Aidan Feldman
# aidan.feldman@gmail.com
# contest: http://www.engineyard.com/blog/2011/january-contest-ride4ruby/
# 1/11/10
require 'rubygems'
require 'rest_client'
require 'active_support'
require 'active_support/core_ext'
@afeld
afeld / countries.rb
Created February 7, 2011 18:54
A nested array of country names with their ISO country codes, useful for select fields in Rails
# this is useful inside of an initializer
COUNTRIES = [
["United States", "US"],
["Afghanistan", "AF"],
["Albania", "AL"],
["Algeria", "DZ"],
["American Samoa", "AS"],
["Andorra", "AD"],
["Angola", "AO"],
@afeld
afeld / jquery-clearinput_empty_submit.js
Created March 16, 2011 21:05
when the form is submitted, the form should submit empty values for the input elements with empty values
// note: this is not tested, but gives you the idea :-)
// for a normal html form:
$('form').submit(function(){
$(this).find('input.clear-input').each(function(i, elt){
// for each clear-input field
if ($(elt).val() === $(elt).initialValue()) {
// value has not changed
// empty the value
$(elt).val('');
@afeld
afeld / gist:1254889
Created September 30, 2011 20:28
YouTube video ID regex
# Parses YouTube URLs directly or from iframe code. Handles:
# * Address bar on YouTube url (ex: http://www.youtube.com/watch?v=ZFqlHhCNBOI)
# * Direct http://youtu.be/ url (ex: http://youtu.be/ZFqlHhCNBOI)
# * Full iframe embed code (ex: <iframe src="http://www.youtube.com/embed/ZFqlHhCNBOI">)
# * Old <object> tag embed code (ex: <object><param name="movie" value="http://www.youtube.com/v/ZFqlHhCNBOI">...)
/(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/
$5 #=> the video ID
# test it on Rubular: http://rubular.com/r/eaJeSMkJvo
@afeld
afeld / soloistrc
Created October 26, 2011 05:08
dev machine setup with pivotal_workstation and soloist
# Using soloist to set up a new Lion machine
# http://pivotallabs.com/users/cunnie/blog/articles/1872-got-lion-now-get-everything-else-
cookbook_paths:
- ./workspace
recipes:
- pivotal_workstation::bash_profile-git_completion
- pivotal_workstation::bash_profile-ps1
- pivotal_workstation::dropbox
- pivotal_workstation::firefox
@afeld
afeld / 01.rb
Created November 14, 2011 03:33
99 bottles using PDD
# sing "99 bottles of beer on the wall..."
# sing "98 bottles of beer on the wall..."
# ...keep counting down...
@afeld
afeld / encapsulate.js
Created November 17, 2011 18:40
code to encapsulate CSS with a class name
/**
* Encapsulates the css for a given bit. Prepends the bit name as an ancestor selector,
* as well as a "self" selector for each element and class selector found in a sheet.<br><br>
*
* For example, given a bit with name "myBit", the sheet:
* <pre><code>
.myClass { color: blue; }
.myOtherClass { color: red; }
* </pre></code>
* would be converted to:
@afeld
afeld / gist:1419298
Created December 1, 2011 19:44
check if custom domains valid
num_ok = 0
users = User.where(:custom_domain => /\S/)
users.each do |u|
begin
records = Net::DNS::Resolver.start(u.custom_domain).answer
rescue Net::DNS::Resolver::NoResponseError
records = []
end
@afeld
afeld / gist:1427799
Created December 3, 2011 18:42
jitsu set env
Aidans-MacBook-Pro:faacelift (master)$ jitsu env set FAACELIFT_FB_APP_ID XXXXXXX
info: Welcome to Nodejitsu
info: It worked if it ends with Nodejitsu ok
info: Executing command env set FAACELIFT_FB_APP_ID XXXXXXX
info: Authenticated as aidanfeldman
error: Error running command env set FAACELIFT_FB_APP_ID XXXXXXX
error: Nodejitsu Error (404): Item not found
error: request not found
info: Nodejitsu not ok
@afeld
afeld / gist:1452292
Created December 9, 2011 16:42
h.264 video sizes
very rough estimates - measured with a Canon Rebel T3i
-------------------------------
bit rates:
640x480 30fps -> 1.27 MB/s
1920x1080 24fps -> 5.91 MB/s
8GB card capacity: