Skip to content

Instantly share code, notes, and snippets.

@jcarley
jcarley / gist:1535280
Created December 29, 2011 17:56
Example Paperclip migration file
class AddAttachmentAvatarToUser < ActiveRecord::Migration
def self.up
add_column :users, :avatar_file_name, :string
add_column :users, :avatar_content_type, :string
add_column :users, :avatar_file_size, :integer
add_column :users, :avatar_updated_at, :datetime
end
def self.down
remove_column :users, :avatar_file_name
@jcarley
jcarley / gist:1535346
Created December 29, 2011 18:09
Rails model with paperclip has_attached_file method
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :username, :realname, :email, :password, :password_confirmation, :encrypted_password, :avatar
has_attached_file :avatar,
:storage => :s3,
:bucket => '<s3 bucket name>',
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
@jcarley
jcarley / gist:1535735
Created December 29, 2011 19:19
Gems for AWS with Paperclip
gem 'paperclip'
gem 'aws-s3'
[alias]
stage = !sh -c '[[ -z "$@" ]] && git add -u || git add "$@" && git add -u "$@" ' -
unstage = reset HEAD --
rewind = ![[ -z "$@" ]] && git reset --hard HEAD || git checkout HEAD
@jcarley
jcarley / gist:2045532
Created March 15, 2012 17:38 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p0
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1333785)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p0 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
@jcarley
jcarley / gist:2570296
Created May 1, 2012 18:32 — forked from hipertracker/gist:214210
NGinx -> TorqueBox
/etc/hosts:
127.0.0.1 myhost jboss_server
NGINX:
server {
listen myhost:80;
server_name myhost;
location / {
proxy_set_header X-Real-IP $remote_addr;
@jcarley
jcarley / remote.md
Created November 24, 2012 14:37 — forked from reid/remote.md
Garage door opener with Arduino

iPhone Garage Remote

Instead of buying two door remotes, I bought one and control it with my iPhone.

Parts

First, I stole nearly everything from MyDoorOpener.com. Their version uses parts I could not find and requires a $6 iPhone app. Let's improve on that.

Almost everything can be found at RadioShack.

@jcarley
jcarley / database_setup.sh
Created February 23, 2013 14:44
Setup the minimum database pieces for Postgresql
createuser --echo --createdb --encrypted --pwprompt --no-createrole --no-superuser carleyfamily
createdb --echo --owner=carleyfamily -E utf8 carleyfamily_development
createdb --echo --owner=carleyfamily -E utf8 carleyfamily_test
@jcarley
jcarley / fizzbuzz.rb
Created June 4, 2013 03:09
Refactoring ruby brownbag
class FizzBuzz
def self.evaluate(number)
raise "Not a number" unless number.is_a? Integer
return "fizzbuzz" if number % 5 == 0 && number % 3 == 0
return "fizz" if number % 3 == 0
return "buzz" if number % 5 == 0
number.to_s
end
end
@jcarley
jcarley / app.js
Created July 27, 2013 18:01
Demonstrates an even aggregator with Angular.js. See http://jsfiddle.net/XqDxG/452/ for a working example. Initial code taken from https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js
var myModule = angular.module('myModule', []);
myModule.factory('eventAggregator', function() {
var cache = {};
return {
publish: function(topic, args) {
cache[topic] && $.each(cache[topic], function(func) {
this.apply(null, args || []);
});
},