Skip to content

Instantly share code, notes, and snippets.

View joemsak's full-sized avatar

Joe Sak joemsak

View GitHub Profile
@mudge
mudge / en.rb
Last active September 5, 2023 09:32
Using date ordinals in Rails through an I18n time format.
# This goes in config/locales/en.rb (*not* en.yml)
{
:en => {
:time => {
:formats => {
:full => lambda { |time, _| "%H:%M | %A, #{time.day.ordinalize} %B %Y" }
}
}
}
}
/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/
def active_if_selected(path)
'active' if /^\/#{path}/ =~ request.path
end
def active_if_child(path)
'active' if /#{path}$/ =~ request.path
end
@joemsak
joemsak / Gemfile
Created August 14, 2012 18:37
Tire, Bonsai Elastic Search
gem "tire", "~> 0.4.2"
@arches
arches / irbrc.rb
Created July 19, 2012 02:54
Run a project-specific IRB config in Rails 3.1+
if ENV['RAILS_ENV']
rails_env = ENV['RAILS_ENV'].downcase
elsif Rails and Rails.env
rails_env = Rails.env.downcase
end
if rails_env
current_app = "myapp"
black = "\[\033[0;30m\]"
@joemsak
joemsak / spec_no_rails_engines_helper.rb
Created March 17, 2012 17:48
Spec No-Rails: RefineryCMS Engine Helper
require 'active_record'
require 'friendly_id'
db = YAML.load(File.open('config/database.yml'))
ActiveRecord::Base.establish_connection(db['test'])
module Refinery
module Core
class BaseModel < ActiveRecord::Base
self.abstract_class = true
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@joemsak
joemsak / spec_helper.rb
Created January 24, 2012 13:27
Require files in a Dir
Dir.glob("lib/**/*.rb").each { |file| require "./#{file}" }
class CanonicalRedirect
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
#
#
#
curl https://raw.github.com/garybernhardt/destroy-all-software-extras/master/das-0010-fast-tests-with-and-without-rails/test > script/test