Skip to content

Instantly share code, notes, and snippets.

View listrophy's full-sized avatar

Brad Grzesiak listrophy

View GitHub Profile
@listrophy
listrophy / create_join_table_for_domains_and_users.rb
Created October 15, 2011 23:32
simple has_and_belongs_to_many example (from memory...)
class CreateJoinTableForDomainsAndUsers < ActiveRecord::Migration
def change
create_table :domains_users, id: false do |t|
t.integer :user_id
t.integer :domain_id
end
add_index :domains_users, [:user_id, :domain_id]
add_index :domains_users, [:domain_id, :user_id]
end
end
@listrophy
listrophy / gist:1065746
Created July 5, 2011 19:55
Using AES in Ruby
require 'openssl'
require 'base64'
secret_message = 'foo!'
aes = OpenSSL::Cipher.new 'AES-256-CBC'
aes.encrypt
iv = aes.random_iv # never EVER use the same IV if you're reusing a key
rnd = aes.random_key
:%s/{/(/g|%s/}/)/g
jr}w./[
r{jj.kF(r[f)r]ZZ
@listrophy
listrophy / gist:669821
Created November 9, 2010 21:11
brew install -v povray
### Without libpng installed
$ brew install -v povray
==> Build Environment
CC: /usr/bin/cc => /usr/bin/gcc-4.2
CXX: /usr/bin/c++ => /usr/bin/c++-4.2
LD: /usr/bin/cc => /usr/bin/gcc-4.2
CFLAGS: -O3 -w -pipe
CXXFLAGS: -O3 -w -pipe
MAKEFLAGS: -j4
scope :latest_by_hashtag, lambda {|hashtag| {
:where => { :hashtags => hashtag },
:order_by => :tweeted_at.desc,
:limit => 20 }
}
# OR #
module MyModelModules
module Scopes
source :rubygems
gem 'rails'
# Or find something else that returns true
# locally, but false on heroku
if RbConfig::CONFIG['host_os'] =~ /darwin/
group :test do
# heroku fails hard on this gem
gem 'specjour'
source :rubygems
gem 'activerecord', '2.3.5'
gem 'sqlite3-ruby'
STRIPPED_PS1="$(echo "$PS1" | sed -e 's/\$ $//')"
function prompt_with_success {
previous_return_value=$?
RED="\[\033[0;31m\]"
GREEN="\[\033[0;32m\]"
COLOR_NONE="\[\e[0m\]"
if [ $previous_return_value -eq 0 ]
module Submethods
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def submethods type = :public
if self.class.name == "Object"
return nil
end
Shoes.setup do
gem 'activeresource'
end
require 'activeresource'
class Person < ActiveResource::Base
self.site = 'http://0.0.0.0:3000'
end