Skip to content

Instantly share code, notes, and snippets.

@bf4
bf4 / Gemfile
Created September 7, 2012 18:20
Ruby Time and Timezone walkthrough
source "https://rubygems.org"
gem "rack"
gem "tzinfo"
@bf4
bf4 / Gemfile
Last active November 11, 2017 22:18
Download my destroyallsoftware videos
# A sample Gemfile
source "https://rubygems.org"
gem 'mechanize'
# method to evaluate the block for a default value if the
# conversion to date fails
# string.to_date return nil if the string is blank
# so we yield to get the default value from the block there
# or on a parse error
def string_to_date(string,&block)
string.to_date || yield
rescue => e
block_given? ? yield : raise
end
@bf4
bf4 / child_index.html.haml
Created December 24, 2012 17:30
Rails template / layout inheritance
-content_for :title do
Child Title
The rest of the page goes here
@bf4
bf4 / lib_user_cache.rb
Created December 24, 2012 17:48
Two ways of clearing the cache in rails... needs work
module UserCache
def self.expire_cache(id)
@base ||= ActionController::Base.new
fragments = [ "user_#{id}", "mini_user_#{id}",
"admin_user_#{id}", "admin_mini_user_#{id}",
"admin_video_user_#{id}", "video_user_#{id}",
"archive_column", "archive",
"admin_archive_column", "admin_archive",
"embedded_video_#{id}"]
fragments.each do |fragment|
@bf4
bf4 / notes.rb
Created December 26, 2012 15:53
Rails error handling for the view
# sources:
# http://www.igodigital.com/blog/blog/notes-on-cyber-weekend-targeted-email-campaigns/custom-error-handling-in-rails-303
# To test in dev, use the production setting below
# config/environments/development.rb
config.consider_all_requests_local = false
# delete the 404.html, and 500.html files.
# generate an error controller
`rails g controller Errors 404 500`
@bf4
bf4 / build.sh
Created December 27, 2012 17:14 — forked from anonymous/build.sh
#!/usr/bin/env bash
export PATH="$PATH:/usr/texbin/"
which pandoc &>/dev/null
if [ $? -eq 0 ]
then
if [ ! -n "$1" ]
then
echo 'defaulting to pdf'
file_name='scalingphp.pdf'
else
@bf4
bf4 / Rakefile
Last active December 11, 2015 02:48 — forked from anonymous/bootstrap.rb
gem 'rake', '=0.8.7'
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
#TODO don't shell out quite as much
namespace :bootstrap do
task :dev => ['bootstrap:copy_configs', 'bootstrap:bundle_gems', 'bootstrap:database'] do
run_cmd "bundle exec rake db:test:prepare"
end
require 'action_view'
require 'ostruct'
require 'erb'
require 'flog'
require 'ruby_parser'
require 'sexp_processor'
ERBHandler = ActionView::Template::Handlers::ERB.new
def new_template(body, details={format: :html})
require 'action_view'
require 'ostruct'
require 'erb'
require 'flog'
require 'ruby_parser'
require 'sexp_processor'
ERBHandler = ActionView::Template::Handlers::ERB.new
def new_template(body, details={format: :html})