Skip to content

Instantly share code, notes, and snippets.

@arches
arches / unified social media access
Created March 5, 2011 03:53
console output showing unified access to multiple 3rd-party services. In the output, we see my personal albums/images from these services.
>> albums = Album.find(user, {:services => [:flickr, :facebook]})
=> [#<Buffet::Album:0x1024deee8 @remote_id="72157625131396492", @title="set2", @service="flickr">,
#<Buffet::Album:0x1024df1e0 @remote_id="72157625006674119", @title="set1", @service="flickr">,
#<Buffet::Album:0x1024deec0 @title="Photostream", @service="flickr">,
#<Buffet::Album:0x1024d4330 @remote_id="505294201356", @title="Christmas 2010", @service="facebook">,
#<Buffet::Album:0x1024d4380 @remote_id="504864193096", @title="Profile Pictures", @service="facebook">,
#<Buffet::Album:0x1024d4358 @remote_id="504697162826", @title="A Retrospective", @service="facebook">,
.
.
.
@arches
arches / pre-commit-jammit
Created October 31, 2011 19:48
Git commit hook to package assets using Jammit
#!/bin/bash
# to install, replace your .git/hooks/pre-commit with this file
if [ $staged_asset_count -gt 0 ]; then
if [ $changed_asset_count -eq 0 ]; then
echo "Packaging css/js assets with jammit..."
jammit -f
git add public/packaged # you might need to change this based on the package_path you use in your assets.yml
else
@arches
arches / app.rb
Created February 13, 2012 00:57
News articles with voting
# Entities
class Post
attr_accessor :id, :title, :link, :summary
attr_accessor :reactions
def score
self.reactions.inject(0){|r, sum| sum += r.score }
end
end
@arches
arches / namespace.js
Created March 4, 2012 23:39
Namespacing syntax
var Foo; if (!Foo) Foo = {};
// Then you can safely define things on Foobar:
Foo.Bar = function(){};
@arches
arches / public-javascripts-base-flash.js
Created March 5, 2012 05:05
Javascript for Flash Messages
var Arch; if (!Arch) Arch = {}; // set up custom namespace 'arch'
Arch.Flash = {
showError: function(message) {
if (message == "") return;
$('#flash-msg .user-msg-detail').removeClass('notice');
$('#flash-msg .user-msg-detail').addClass('error');
$('#flash-msg .user-msg-detail span').html(message);
$('#flash-msg').show();
},
var Arch; if (!Arch) Arch = {}; // set up custom namespace 'Arch'
Arch.AjaxPagination = function(paginationContainer, storiesContainer, filtersContainer) {
// Only html5 browsers can use ajax pagination. We don't want no stinkin' hashbang URLs.
if (!history.pushState) {
return;
}
this.$paginationContainer = $(paginationContainer);
@arches
arches / run_bot.rb
Created March 17, 2012 19:24
Chat client for dogs
require 'iron_mq'
# IronMQ credentials
token = asdf
project_id = asdf
# each chatter needs their own queue
@fido = IronMQ::Client.new('token' => token, 'project_id' => project_id, :queue_name => "fido")
@red_rover = IronMQ::Client.new('token' => token, 'project_id' => project_id, :queue_name => "red_rover")
@arches
arches / sandbox.rb
Created April 1, 2012 03:35
Create and manipulate arbitrary classes with attributes and inheritance inside the safety of a module namespace
module Sandbox
def self.add_class(klass)
const_set_from_string(klass)
end
def self.add_attributes(klass, *attrs)
self.const_get_from_string(klass).class_eval do
attr_accessor *attrs
# set up the 'initialize' method to assign the attributes
@arches
arches / gist:3054004
Created July 5, 2012 14:29
HTML Curriculum

Lesson 1 - Pulling Back the Curtain

  • A web page is just a text file
  • html > body > hello world
  • definition of markup
  • the HTML is invisible

Lesson 2 - Tags are the Building Blocks of Life

  • heading
@arches
arches / irbrc.rb
Created July 19, 2012 02:54
Run a project-specific IRB config in Rails 3.1+
if ENV['RAILS_ENV']
rails_env = ENV['RAILS_ENV'].downcase
elsif Rails and Rails.env
rails_env = Rails.env.downcase
end
if rails_env
current_app = "myapp"
black = "\[\033[0;30m\]"