Skip to content

Instantly share code, notes, and snippets.

View michaeldv's full-sized avatar

Michael Dvorkin michaeldv

  • Cupertino, California
View GitHub Profile
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,
// 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);
#!/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
# 0.4.0 TODO
#
# - merge Windows fix
# - merge Stephan's ap/object
# - merge Mongo(?)
# - specs for arbitrary Obj
# - rescue LoadError if in specs if Rails is not installed
# - require unless defined?(::AwesomePrint) (when required from .irbrc)
# - Obj overrides :send
# - Obj overrides :method
# Original
Dir.glob("./commands/*.rb").each do |command|
$commands << command.split("/").last.split('.rb').first
end
# Refactored
Dir.glob("./commands/*.rb").each do |command|
$commands << File.basename(command, '.*')
end
@michaeldv
michaeldv / console.coffee
Created May 22, 2012 01:17
Make IE shut up when encountering console calls
window.console or do ->
window.console = {}
for method in [ "log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd" ]
window.console[method] = ->
return
@michaeldv
michaeldv / sort.rb
Created June 5, 2012 02:03
Various sort algorithms in Ruby
# Plain bubble sort.
def bubble_sort(array)
loop do
swapped = false
(array.size - 1).times do |i|
if array[i] > array[i+1]
array[i], array[i+1] = array[i+1], array[i]
swapped = true
end
end
function k() {
kill -9 $(ps ax | grep $1 | grep -v grep | awk '{print $1}')
}
@michaeldv
michaeldv / Rakefile
Created September 21, 2012 00:21
AwesomePrint::Painter.red("x") crashes RubyMotion 1.24
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require '~/Source/Ruby/Motion/motion_awesome_print/lib/awesome_print'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'hello'
end
class Alert
def initialize(title, message, *buttons)
#
# Delegating to self.
#
@alert = UIAlertView.alloc.initWithTitle(title, message:message, delegate:self, cancelButtonTitle:"Cancel", otherButtonTitles:"OK", nil)
@alert.show
self
end