Skip to content

Instantly share code, notes, and snippets.

View afeld's full-sized avatar

Aidan Feldman afeld

View GitHub Profile
@afeld
afeld / _body.html.erb
Created December 12, 2011 20:47
using HTML in a RSS feed in Rails
<h1><%= record.name %></h1>
<!-- etc -->
@afeld
afeld / multipass.rb
Created December 24, 2011 23:02
Assistly multipass SSO
multipass = MultiPass.encode(
'jux',
api_key,
:customer_name => current_user.displayname,
:customer_email => current_user.email,
:customer_custom_username => current_user.username,
:uid => current_user.id,
:expires => (Time.now + 120), # Expire two minutes from now
:url_safe => true # Convert unsafe characters
)
@afeld
afeld / gist:1708929
Created January 31, 2012 05:01
photo sizes for various photo APIs

(number is px on longest side, or exact dimensions)

Facebook

A sampling from my personal account.

1/2012

  • 2048
  • 720
@afeld
afeld / deepmerge.js
Created February 20, 2012 05:30
deepMerge function for underscore.js
deepMerge: function(dest){
_.each(_.rest(arguments), function(source){
var sourceVal, destVal;
for (var prop in source){
sourceVal = source[prop];
destVal = dest[prop];
if (prop in dest && _.isObject(sourceVal) && _.isObject(destVal)){
_.deepMerge(destVal, sourceVal);
} else {
dest[prop] = sourceVal;
@afeld
afeld / gist:2286105
Created April 2, 2012 18:29
display all unreleased Git commits by a certain person
git log --branches=* --author=Aidan ^origin/deployed
function foo(){
return 'foo'
}
@afeld
afeld / gist:2911480
Created June 11, 2012 17:35
Jux: remove duplicate custom_links
db.users.find({'custom_links.1': {$exists: true}}).snapshot().forEach(function(user){
var urls = {},
keepLinks = [];
user.custom_links.forEach(function(link){
var url = link.value.toString().toLowerCase().replace(/\/$/, '').replace(/^(https?:?\/\/)?(www\. ?)?/, '');
if (!urls[url]){
keepLinks.push(link);
urls[url] = true;
}
@afeld
afeld / Gemfile
Created June 27, 2012 18:06
Gemfile for Heroku
# ...
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
@afeld
afeld / gist:3074251
Created July 9, 2012 04:49
Jux: import Instagram photos for a user
user = User.find_by_username('catturner')
user_id = user.id
next_max_id = nil
quark_ids = []
picture_ids = []
begin
# instagram limits to 60
query = {access_token: user.instagram_token.token, count: 60}
query[:max_id] = next_max_id if next_max_id
results = HTTParty.get 'https://api.instagram.com/v1/users/self/media/recent', format: :json, query: query
@afeld
afeld / gist:3364792
Created August 15, 2012 23:47
Jux: clean up garbage Twitter usernames
# using Mongoid
# clean up leading/trailing whitespace
User.where(twitter_username: /(\A\s+[A-Za-z0-9_]+\s*\z)|(\A\s*[A-Za-z0-9_]+\s+\z)/).each do |user|
user.twitter_username = user.twitter_username.strip
user.save!
end
# clean up twitter usernames of the format @... or twitter.com/...
link_rx = /(?:\A@|\A\/|twitter\.com\/(?:#!\/)?)([A-Za-z0-9_]+)\s*\z/i