Skip to content

Instantly share code, notes, and snippets.

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

Dann Luciano dannluciano

🏠
Working from home
View GitHub Profile
@dannluciano
dannluciano / user.rb
Created September 6, 2014 04:19
The Best Way to Test the Validations on Models in ActiveRecord
class User < ActiveRecord::Base
validates :username, presence: :true
validates :password_digest, presence: :true
has_secure_password
end
@dannluciano
dannluciano / links
Last active August 29, 2015 14:13
Links
@dannluciano
dannluciano / happy_numbers.go
Last active August 29, 2015 14:20
HappyNumbers
package main
import (
"fmt"
)
func is_happy_number(number int) bool {
if number < 10 {
return (number == 1 || number == 7)
} else {
$source = 'http://gemcutter.org/'
gem 'will_paginate', :lib => 'will_paginate', :source => $source
gem 'annotate', :lib => 'annotate', :source => $source
gem 'kete-tiny_mce', :lib => "tiny_mce", :source => $source
gem 'paperclip', :lib => "paperclip", :source => $source
gem 'searchlogic', :lib => "searchlogic", :source => $source
gem 'authlogic', :lib => "authlogic", :source => $source
gem 'cancan', :lib => "cancan", :source => $source

Rails Dev Stack on Snow Leopard

(from a scratch install). Kinda, I imported my user home (~) from a Time Machine backup.

Homebrew

sudo mkdir /usr/local
sudo chown -R `whoami` /usr/local
curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local
def interesting_tables
ActiveRecord::Base.connection.tables
end
class BackupDB < ActiveRecord::Base
end
destination_db = 'new'
BackupDB.establish_connection destination_db.intern
require 'rubygems'
require 'active_record'
require 'net/http'
require 'uri'
email = "YOUR_EMAIL_HERE"
password = "YOUR_PASSWORD_HERE"
ActiveRecord::Base.establish_connection(:adapter => "mysql", :socket => "/tmp/mysql.sock", :user => "root", :password => "root", :database => "YOUR_DATABASE_HERE")
results = ActiveRecord::Base.connection.execute("SELECT * FROM `wp_posts` WHERE post_type = 'post' and post_status='publish' order by post_date asc;")
This example shows how to setup an environment running Rails 3 beta 3 under 1.9.2-head with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell)) or do 'rvm reload'
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.2-head
# Switch to 1.9.2-head and gemset rails3, create if it doesn't exist.
∴ rvm --create use 1.9.2-head@rails3
# include at least one source and the rails gem
source :gemcutter
gem 'rails', '~> 2.3.5', :require => nil
gem 'sqlite3-ruby', :require => 'sqlite3'
# Devise 1.0.2 is not a valid gem plugin for Rails, so use git until 1.0.3
# gem 'devise', :git => 'git://github.com/plataformatec/devise.git', :ref => 'v1.0'
group :development do
# bundler requires these gems in development

(a gist based on the old toolmantim article on setting up remote repos)

To collaborate in a distributed development process you’ll need to push code to remotely accessible repositories.

This is somewhat of a follow-up to the previous article setting up a new rails app with git.

For the impatient

Set up the new bare repo on the server: