Skip to content

Instantly share code, notes, and snippets.

View michaeldv's full-sized avatar

Michael Dvorkin michaeldv

  • Cupertino, California
View GitHub Profile
#!/usr/bin/env ruby
# Usage:
# $ ./script/railssh
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require APP_PATH
Rails.application.require_environment!
module Kernel
// Generic version of the waiting-for-pause trick:
// execute callback only after a pause in user input; the function returned
// can be used to handle an event type that tightly repeats (such as typing
// or scrolling events); it will execute the callback only if the given timout
// period has passed since the last time the same event fired
function createOnPause(callback, timeout, _this) {
return function(e) {
var _that = this;
if (arguments.callee.timer)
clearTimeout(arguments.callee.timer);
20:22 1.9.2@r3 [~/Source/Rails/fat_free_crm.r3] (rails3)$ rails c
Loading development environment (Rails 3.0.3)
ruby-1.9.2-p0 > ActiveRecord::Base.time_zone_aware_attributes
true
ruby-1.9.2-p0 > Time.zone = "Pacific Time (US & Canada)"
"Pacific Time (US & Canada)"
ruby-1.9.2-p0 > x1 = Account.create(:name => "x1", :updated_at => 1.day.ago)
#<Account:0x0000010476b218> {
:id => 131,
:user_id => nil,
@michaeldv
michaeldv / xml.rb
Created December 1, 2010 03:36
activerecord/test/cases/xml_serialization_test.rb
module ActiveModel
# == Active Model XML Serializer
module Serializers
module Xml
extend ActiveSupport::Concern
include ActiveModel::Serialization
class Serializer #:nodoc:
class Attribute #:nodoc:
attr_reader :name, :value, :type
@michaeldv
michaeldv / regression
Created November 30, 2010 00:10
Regression between Rails 3.0.3 and 3.0.0
### 1) Added $stderr tracing in gems/activesupport-3.0.3/lib/active_support/xml_mini.rb
###
FORMATTING = {
"symbol" => Proc.new { |symbol| symbol.to_s },
"date" => Proc.new { |date| date.to_s(:db) },
"datetime" => Proc.new { |time| $stderr.puts "3.0.3: time.xmlschema for <#{time.class.inspect}>"; time.xmlschema },
"binary" => Proc.new { |binary| ActiveSupport::Base64.encode64(binary) },
"yaml" => Proc.new { |yaml| yaml.to_yaml }
} unless defined?(FORMATTING)
require "rubygems"
require "ap"
unless IRB.version.include?('DietRB')
IRB::Irb.class_eval do
def output_value
ap @context.last_value
end
end
else # MacRuby
function detect_rvm {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
[ "$gemset" != "" ] && gemset="@$gemset"
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
[ "$version" != "" ] && version="$version"
local full="$version$gemset"
[ "$full" != "" ] && echo "$full"
}
function git_deleted {
function git_deleted {
[[ $(git status 2> /dev/null | grep deleted:) != "" ]] && echo "-"
}
function git_added {
[[ $(git status 2> /dev/null | grep "Untracked files:") != "" ]] && echo '+'
}
function git_modified {
[[ $(git status 2> /dev/null | grep modified:) != "" ]] && echo "*"
# Everything you need to do to get started with Rails 2.3.8
#
# As of June 14th, 2010 @ 2:30 p.m. MST
#
# This gist now features instructions to get Rails 3 up and running with:
# - Ruby 1.8.7-p174
# - Bundler 0.9.26
# - Cucumber 0.8.0
# - Rspec 1.3.0 + Rspec-Rails 1.3.2
# - RVM
t = Thread.start do
l = '/ - \ |'.split
print "\e[?25l"
loop do
c = l.shift
print "\r#{c}"
STDOUT.flush
sleep 0.1
l.push c
end