Skip to content

Instantly share code, notes, and snippets.

View code-later's full-sized avatar

Dirk Breuer code-later

View GitHub Profile
#!/usr/bin/env ruby
require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb"
require "#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb"
result = TextMate::UI.request_string(
:title => 'Open Rubygem',
:prompt => 'Name of the gem to open',
:default => ENV['TM_CURRENT_WORD'] || "",
:button1 => 'Open'
@code-later
code-later / gist:719848
Created November 29, 2010 11:25
Load a project specific .irbrc in your Rails 3 project
# Add this method the MyApp::Application class (in config/application.rb)
def load_console(sandbox=false)
super
project_specific_irbrc = File.join(Rails.root, ".irbrc")
puts "Loading project specific .irbrc ..."
load(project_specific_irbrc) if File.exists?(project_specific_irbrc)
end
class HouseDetail
def foo
return [1,2,3]
end
end
class KeyInvoker
instance_methods.reject {|meth| meth.to_s =~ /^_/ }.each { |meth| undef_method(meth.to_sym) }
acf, x = [], []
time_val = 0.002
i = time_val
# init function 'x[i] = A0 * cos(2*pi*f*i); f = 100Hz'
freq = 100.0 # Hz
sample_window = (freq/time_val).to_i+1
(freq*2/time_val).to_i.times do
# puts "#{i}: #{2.0*Math::PI*f*i}"
#!/bin/zsh
bindkey -e '^[[3~' delete-char
# bindkey -v "^[Od" backward-word
# bindkey -v "^[Oc" forward-word
bindkey -e "^A" beginning-of-line
bindkey -e "^E" end-of-line
bindkey -e "^K" kill-line
bindkey -e "^L" clear-screen
@code-later
code-later / fwatch.rb
Created August 23, 2011 19:49
watch with fsevent
#! /usr/bin/env ruby
require 'rubygems'
require 'rb-fsevent'
command = ARGV[0]
fsevent = FSEvent.new
fsevent.watch Dir.pwd do |directories|
system command
@code-later
code-later / app-in-a-tweet.rb
Created September 13, 2011 17:13
Heroku deployable app to retrieve the Twitter-ID for a Twitter-Name
run->(e){`curl twitter.com#{e['PATH_INFO']}`=~/_(\d+)"/;[200,{'Content-Type'=>''},[$1]]}
@code-later
code-later / pbcopy.rb
Created October 14, 2011 13:05
Put something in OS X system clipboard from your IRB session
def pbcopy(input)
IO.popen("pbcopy", "r+") do |clipboard|
clipboard << input
end
return input
end
@code-later
code-later / change_ar_records.rb
Created November 24, 2011 16:51
Apply arbitrary changes to a bunch of ActiveRecord entities
changes = {
"Boooking:234" => lambda { |record| record.some_attribute = "new_value" }
}
changes.each do |model_class_and_id, change|
begin
klass = model_class_and_id.split(":").first.constantize
id = model_class_and_id.split(":").last.to_i
print "== Changing #{klass} '#{id}' ... "
@code-later
code-later / spec_helper_no_rails.rb
Created December 2, 2011 12:05
A spec_helper to run your specs without Rails but blazing fast!
ENV["RAILS_ENV"] ||= 'test'
if defined?(Bundler)
Bundler.setup(*%w(development test))
end
require 'rspec'
require 'renum'
require 'active_model'