Skip to content

Instantly share code, notes, and snippets.

View rojotek's full-sized avatar

Rob Dawson rojotek

  • ConsenSys
  • Australia
View GitHub Profile
@rojotek
rojotek / ruby.2.1.0-setup.sh
Last active August 29, 2015 13:56 — forked from mustafaturan/ruby.2.0.0-setup.sh
fork of ruby 2.0.0 setup to make it work with with ruby 2.1 ruby-gems 2.2.2 on centos 6.4
#!/usr/bin/env bash
# repository
cd /tmp
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
# system update
yum -y update
yum -y groupinstall "Development Tools"
yum -y install libxslt-devel libyaml-devel libxml2-devel gdbm-devel libffi-devel zlib-devel openssl-devel libyaml-devel readline-devel curl-devel openssl-devel pcre-devel git memcached-devel valgrind-devel mysql-devel ImageMagick-devel ImageMagick
@rojotek
rojotek / thin_thread.rb
Created March 27, 2014 08:13
Start thin server in a thread.
thin_server = Thread.start do
Thin::Server.start('0.0.0.0', 4567) do
run Rack::Directory.new( File.join(Dir.pwd,"seed-images") )
end
end
@rojotek
rojotek / seed_data.rb
Last active August 29, 2015 13:57
seed data
seed_data = [
{model_name: "somename", image:"my_image.jpg"},
...
]
seed_data.each do |seed|
model = Model.find_by_name(seed[:model_name])
model.remote_image_url="http://localhost:4567/#{model[:image]}"
model.save
end
@rojotek
rojotek / thin_kill.rb
Created March 27, 2014 08:15
kill the thin server thread.
thin_server.kill
@rojotek
rojotek / thin_upload_carrier.rb
Created March 27, 2014 08:17
upload images to carrierwave with a local server.
seed_data = [
{model_name: "somename", image:"my_image.jpg"},
#...
]
thin_server = Thread.start do
Thin::Server.start('0.0.0.0', 4567) do
run Rack::Directory.new( File.join(Dir.pwd,"seed-images") )
end
end
@rojotek
rojotek / has_one_initial.rb
Created May 15, 2014 21:49
Simple model for has_one discussion.
class Employee
belongs_to: :department
end
class Departmet
belongs_to :organization
has_many :employees
end
class Organization
@rojotek
rojotek / gist:1a9ce6559bba979f69b7
Created May 15, 2014 21:51
belongs_to through
belongs_to :organization through: :department # Does not exist
@rojotek
rojotek / employee.rb
Created May 15, 2014 21:53
has_one :through
class Employee
belongs_to: :department
has_one :organization, through: :department
end
@rojotek
rojotek / project_department.rb
Created May 15, 2014 21:54
has_many through
class Project
has_many :project_departments
has_many :departments, through: :project_departments
end
class ProjectDepartment
belongs_to :project
belongs_to :project
end
@rojotek
rojotek / migration.rb
Created September 7, 2014 22:48
rails models in migrations
class ModelClass < ActiveRecord::Base
attr_protected
end
def up
ModelClass.reset_column_information
end