Skip to content

Instantly share code, notes, and snippets.

View steverob's full-sized avatar

Steve Robinson steverob

View GitHub Profile
require "money"
class Decorator < BasicObject
undef_method :==
def initialize(component)
@component = component
end
def method_missing(name, *args, &block)
class User < ActiveRecord::Base
alias :devise_valid_password? :valid_password?
def valid_password?(password)
begin
devise_valid_password?(password)
rescue BCrypt::Errors::InvalidHash
return false unless Digest::SHA1.hexdigest(password) == encrypted_password
logger.info "User #{email} is using the old password hashing method, updating attribute."
self.password = password
@RaVbaker
RaVbaker / gist:2967695
Created June 21, 2012 18:44
[HOWTO] Ubuntu 12.04 Ruby on Rails Development Environment

Ubuntu 12.04 Ruby on Rails Development Environment

I haven't set up an install guide for the latest ubuntu release, largely because the last set of instructions worked pretty closely with the latest and greatest Ubuntu, 12.04 Precise Pangolin, however when installing today, I found that there were enough differences in the way that I configure my setup to justify an update, so here it goes. Yes, I'm late to the party, but a quick google search didn't find anything that I felt was as complete for my requirements as my previous install guides, so here I go.

As always with my install guides, I have included here is just about everything you'll need (and then some) to get started with ruby on rails development with Ubuntu 12.04 as a platform. These are my settings and preferences, and this is certainly not the only way of doing things, so keep that in mind.

Step 1: Get the repos ready and run updates.

sudo apt-get update && sudo apt-get upgrade
@macournoyer
macournoyer / Dockerfile
Last active December 14, 2019 16:31
Playing w/ Dockerfile on OS X
FROM base
MAINTAINER Marc-Andre Cournoyer "macournoyer@gmail.com"
RUN apt-get -y update
RUN apt-get install -y -q curl
RUN curl -L https://get.rvm.io | bash -s stable --ruby
RUN /bin/bash -l -c rvm requirements
@xntrik
xntrik / gist:6136703
Last active December 20, 2015 13:09
Deploying Rails to EC2
http://railscasts.com/episodes/347-rubber-and-amazon-ec2?view=asciicast
https://github.com/rubber/rubber/wiki/Commands
cap rubber:create #creates instances - but - sometimes, depending on the AMI, and the *mood* of the EC2 gods, you can't establish that initial SSH session ..
Eventually though, they should be setup.
Good trick, if, you can start the instance creation, but, it times out. You can kill that process, and restart the instance a few times until you can SSH to it standalone.
@steverob
steverob / ambient-display.pde
Last active January 1, 2016 10:49
Automatically adjust Ubuntu monitor brightness based on Ambient lighting
var five = require("johnny-five"),
board, photoresistor;
var exec = require('child_process').exec;
board = new five.Board();
board.on("ready", function() {
// Create a new `photoresistor` hardware instance.
photoresistor = new five.Sensor({
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end

sessions controller

# sessions_controller.rb

class Api::V1::SessionsController < ApplicationController
  def create
    user = User.authenticate(params[:email], params[:password])
    if user
      token = user.generate_token_for("auth_token")
@zerothabhishek
zerothabhishek / gist:11108206
Last active August 29, 2015 14:00
chennai.rb-april-meetup
## open class
class Array
def second_last
self[-2]
end
end
class Array
def first
if Rubber::Util.has_asset_pipeline?
# load 'deploy/assets'
_cset :asset_env, "RAILS_GROUPS=assets"
_cset :assets_prefix, "assets"
_cset :assets_role, [:web]
_cset :normalize_asset_timestamps, false
before 'deploy:finalize_update', 'deploy:assets:symlink'