Skip to content

Instantly share code, notes, and snippets.

View brianjlandau's full-sized avatar

Brian Landau brianjlandau

  • Walnut Creek, CA
  • 23:06 (UTC -07:00)
View GitHub Profile
#!/usr/bin/env bash
gem uninstall rubygems-update
gem install rubygems-update --version $1
update_rubygems
<div id="map"></div>
<div id="map-side-bar">
<div class="map-location" data-jmapping="{id: 1, point: {lng: -122.2678847, lat: 37.8574888}, category: 'market'}">
<a href="#" class="map-link">Berkeley Bowl</a>
<div class="info-box">
<p>A great place to get all your groceries, especially fresh fruits and vegetables.</p>
</div>
</div>
</div>
class ApplicationController < ActionController::Base
rescue_from ActiveRecord::StaleObjectError do |exception|
respond_to do |format|
format.html {
correct_stale_record_version
stale_record_recovery_action
}
format.xml { head :conflict }
format.json { head :conflict }
end
@brianjlandau
brianjlandau / resque_web.rb
Created October 27, 2010 23:54
A piece of Rails metal that allows you to run the Resque web server as part of the application.
# app/metal/resque_web.rb
# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
require 'resque/server'
Resque::Server.use Rack::Auth::Basic do |username, password|
username == 'admin' && password == 'password'
end
ResqueWeb = Rack::URLMap.new("/resque" => Resque::Server.new)
~ $ brew install -v io
==> 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 -march=core2 -w -pipe
CXXFLAGS: -O3 -march=core2 -w -pipe
MAKEFLAGS: -j2
PKG_CONFIG_PATH: /usr/local/lib/pkgconfig
/usr/local/bin/git
@brianjlandau
brianjlandau / extensions.io
Created October 10, 2010 18:53
Just some cool snippets I've found or created for adding syntactical sugar to Io.
File read := method(path,
fileToRead := File with(path) openForReading
content := fileToRead readToEnd
fileToRead close
return content
)
# Pulled from http://iota.flowsnake.org/syntax-extensions.html
Object squareBrackets := method(
r := List clone
#!/usr/bin/env ruby -KU
require 'optparse'
require 'ostruct'
require 'iconv'
SCRIPT_NAME = "File Character Encoding Converter"
SCRIPT_VERSION = "0.1"
class FileEncodingConverterOptionParser
@brianjlandau
brianjlandau / duplicatable.rb
Created July 22, 2010 19:31
ActiveRecord mixin to create a name for a duplicate object when names need to be unique.
module Duplicatable
def duplicate_name(no_spaces = false)
new_name = no_spaces ? "#{self.name}_Copy" : "#{self.name} Copy"
replace_name = no_spaces ? "#{new_name}_" : "#{new_name} "
find_options = {:conditions => ["name LIKE ?", "#{new_name}%"],
:order => "copy_number DESC",
:select => "id, CAST(REPLACE(name, '#{replace_name}', '') AS UNSIGNED INTEGER) AS copy_number"}
last_copy = self.class.respond_to?(:find_with_deleted) ?
self.class.find_with_deleted(:first, find_options) :
self.class.first(find_options)
[master] ~/Projects/rails_app $ script/console
Loading development environment (Rails 2.3.8)
rails_app(development):001:0> m = MyModel.new
=> #<MyModel id: nil, name: nil, date: nil>
rails_app(development):002:0> m.date = "bad date words"
=> "bad date words"
rails_app(development):002:0> m.date
=> nil
# From: http://scie.nti.st/2007/2/1/let-activerecord-observers-see-controller-context
# By Garry Dolley
# MIT / X11 licensed
module EnlightenObservers
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods