Skip to content

Instantly share code, notes, and snippets.

View cmeiklejohn's full-sized avatar
💭
Always working.

Christopher S. Meiklejohn cmeiklejohn

💭
Always working.
View GitHub Profile
@cmeiklejohn
cmeiklejohn / .vimrc
Created June 1, 2010 21:00
My .vimrc
" Christopher Meiklejohn (cmeiklejohn@devio.us)
" .vimrc -- parts stolen from all over the place.
set nocompatible " We don't want vi compatibility.
set viminfo^=!
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
@cmeiklejohn
cmeiklejohn / perm.rb
Created July 21, 2010 16:00
Threading problems... help?
#!/usr/bin/ruby
require 'openssl'
require 'base64'
require 'rubygems'
require 'aws'
# Open master s3 connection
master_s3 = Aws::S3.new(
'key',
@cmeiklejohn
cmeiklejohn / .tmux.conf
Created July 23, 2010 18:56
My .tmux.conf file
# Setup status bar
set -g status-bg black
set -g status-fg white
set -g message-bg black
set -g message-fg green
set -g status-left '#[fg=green]#H #S'
# Highlight active window
set-window-option -g window-status-current-attr bright
set-window-option -g window-status-current-fg white
def to_key
new_record? ? nil : [self.send(self.class.primary_key)]
end
@cmeiklejohn
cmeiklejohn / mongodb index question
Created February 20, 2011 22:50
Why is this not using the index?
> db.collection.getIndexes();
[
{
"name" : "_id_",
"ns" : "test.collection",
"key" : {
"_id" : 1
}
},
{
@cmeiklejohn
cmeiklejohn / AnotherController.rb
Created February 27, 2011 05:10
Is this really the right way to do this?
# Rails 2 way.
SomeController.new.process( request, response )
# Rails 3 way.
status, headers, body = SomeController.action(:show).call(request.env)
response = ActionDispatch::Response.new(status, headers, body)
self.response_body = response
class MicropostsController < ApplicationController
before_filter :set_micropost, :only => [:show, :edit, :update, :create, :new]
before_filter :authenticate, :only => [:create, :destroy] # Same here?
# Omitted.
def destroy
@micropost.destroy
redirect_back_or root_path
@cmeiklejohn
cmeiklejohn / utf8_header.rb
Created April 24, 2011 00:38 — forked from derencius/utf8_header.rb
thor file to add utf-8 header on ruby files. useful for converting ruby 1.8 projects to 1.9
class Utf8Header < Thor
desc "add", "Add Content UTF-8 on top of all .rb/.feature files"
# copy & pasted from https://gist.github.com/738245
def add
files = Array.new
["*.rb", "*.rake","*.feature"].each do |extension|
files.concat(Dir[ File.join(Dir.getwd.split(/\\/), "**", extension) ])
end
files.each do |file|
@cmeiklejohn
cmeiklejohn / parse-me.rb
Created May 17, 2011 23:11
minimal capybara use outside of rails
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'capybara-webkit'
Capybara.run_server = false
Capybara.current_driver = :webkit
Capybara.app_host = 'http://www.google.com'
module MyCapybaraTest
@cmeiklejohn
cmeiklejohn / array_regexp_match.rb
Created July 13, 2011 16:49
Array of regexp matching with include?
class Array
def include_by_regexp_or_string?(str)
any? do |o|
o.is_a?(Regexp) ? o =~ str : o == str
end
end
end