Skip to content

Instantly share code, notes, and snippets.

View fayimora's full-sized avatar
🕺

Fayi FB fayimora

🕺
  • London, England
View GitHub Profile
@fayimora
fayimora / gfm.rb
Created February 26, 2012 15:57 — forked from mojombo/gfm.rb
require 'digest/md5'
def gfm(text)
# Extract pre blocks
extractions = {}
text.gsub!(%r{<pre>.*?</pre>}m) do |match|
md5 = Digest::MD5.hexdigest(match)
extractions[md5] = match
"{gfm-extraction-#{md5}}"
end
@fayimora
fayimora / post.rb
Created February 23, 2012 01:04 — forked from davidcelis/post.rb
Polymorphism 101
class Post < ActiveRecord::Base
has_many :tag_links
has_many :tags, :through => :tag_links
# ...
end
@fayimora
fayimora / post.rb
Created February 20, 2012 20:46 — forked from davidcelis/post.rb
Polymorphism 101
class Post < ActiveRecord::Base
has_many :tag_links, :as => :tags
# ...
end
@fayimora
fayimora / role.rb
Created February 12, 2012 18:19 — forked from mongrelion/role.rb
Dynamic Role methods for Role and User models
class Role < ActiveRecord::Base
ROLES = [ :group_admin, :agency_admin ]
# - Relationships -
has_many :user_roles
has_many :users, :through => :user_roles
# - Class Methods -
class << self
@fayimora
fayimora / gist:1094465
Created July 20, 2011 06:40 — forked from JosephPecoraro/shell-execution.rb
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111