Skip to content

Instantly share code, notes, and snippets.

View treble37's full-sized avatar
🏠
Working from home

Bruce Park treble37

🏠
Working from home
View GitHub Profile
source: http://avdi.org/devblog/2009/11/20/hash-transforms-in-ruby/
def transform_hash(original, options={}, &block)
original.inject({}){|result, (key,value)|
value = if (options[:deep] && Hash === value)
transform_hash(value, options, &block)
else
value
end
block.call(result,key,value)
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@treble37
treble37 / db.rake
Created February 21, 2014 05:06 — forked from tehpeh/db.rake
namespace :db do
namespace :enable do
desc "enable hstore extension"
task :hstore => [:environment, :load_config] do
ActiveRecord::Base.connection.execute('CREATE EXTENSION IF NOT EXISTS hstore;')
end
end
Rake::Task['db:schema:load'].enhance ['db:enable:hstore']
end
RAILS_ENV=production rake db:setup
# produces the error below.....hmmm.....it's a no-worky
psql:/yourprojectpath/yourproject/db/structure.sql:29: ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/hstore.control": No such file or directory
# hstore postgresql extension needs to be installed, so....
sudo apt-get install postgresql-contrib
# now your extension should be available to enable so log in with psql
psql -d yourproject_production -U yourdbuser -W
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install postgresql-9.2 postgresql-server-dev-9.2 postgresql-contrib-9.2
sudo su -l postgres
psql -d template1 -p 5433
CREATE EXTENSION IF NOT EXISTS hstore;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
service postgresql stop
/usr/lib/postgresql/9.2/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.2/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.2/main/ -O "-c config_file=/etc/postgresql/9.2/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"
require 'artoo'
connection :sphero, :adaptor => :sphero, :port => '127.0.0.1:4560'
device :sphero, :driver => :sphero
work do
every(3.seconds) do
if @color == :green
@color = :blue
else
@treble37
treble37 / rails4-gemfile-template
Last active December 29, 2015 09:19
Rails app Gemfile starter template
source 'https://rubygems.org'
# # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
# gem 'rails', '4.0.1'
@treble37
treble37 / rvm-cheatsheet
Last active December 29, 2015 09:09
rvm cheatsheet
rvm get stable
rvm list known
rvm install 2.1.0
rvm gemset create mountainlion_rails4
gemset created mountainlion_rails4 => /home/bruce/.rvm/gems/ruby-2.0.0-p247@mountainlion_rails4
rvm use ruby-2.0.0-p247@mountainlion_rails4
rvm --ruby-version use 1.9.3@my_app
The second form will create both .ruby-version and .ruby-gemset.
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@treble37
treble37 / rails-console-tricks
Created October 14, 2013 23:24
rails console tricks
## Generating url paths
app.users_path --> app is an object, users_path is the URL helper for your User model