Skip to content

Instantly share code, notes, and snippets.

View code-later's full-sized avatar

Dirk Breuer code-later

View GitHub Profile
@code-later
code-later / gist:2780882
Created May 24, 2012 11:23
Search & Replace across files in Vim
" Select files to work on with :args
:args app/views/*/*
" Perform any action on the previous selected files
:argdo %s/search/replace/gec | update
@code-later
code-later / mt_to_markdown.rb
Created April 10, 2012 12:28
Convert a MovableType export to single Markdown posts to use with Octopress
#!/usr/bin/env ruby
require 'date'
require 'mustache'
require 'stringex'
require 'cgi'
export = File.open(ARGV[0])
target_dir = ARGV[1]
[color]
diff = auto
status = auto
branch = auto
interactive = auto
[alias]
br = branch
st = status
ci = commit -m
ca = commit -a -m
@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'
@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 / 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 / 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 / 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
#!/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
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}"