Skip to content

Instantly share code, notes, and snippets.

View kenichi's full-sized avatar

Kenichi Nakamura kenichi

  • Portland, Oregon
View GitHub Profile
@kenichi
kenichi / test.rb
Created August 17, 2011 22:29
sinatra/haml reload templates
require 'sinatra'
require 'haml'
configure do
set :reload_templates, true
end
get '/' do
haml :index, :layout => false
end
@kenichi
kenichi / gist:1309647
Created October 24, 2011 17:55
basic auth in sinatra
use Rack::Auth::Basic, "Nope" do |u, p|
[u, p] == ['user', 'password']
end
@kenichi
kenichi / gist:2040219
Created March 14, 2012 22:54
dondonp problem
<!doctype html>
<html lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
console.log($('#new_patent'));
$('#new_patent').css('background','blue');
});
</script>
@kenichi
kenichi / gist:2165047
Created March 22, 2012 22:19
bizzarro dynamic attributes
def method_missing(meth, *args)
meth_s = meth.to_s
key = meth_s.sub(/=$/,'')
aattr = self.account_attributes.find_by_key key
if aattr
case meth_s
when aattr.key
aattr.value
when "#{aattr.key}="
if args[0].nil?
@kenichi
kenichi / gist:2845183
Created May 31, 2012 18:18
who needs rvm?
# actually, fuck rvm...
OPT_RUBY_CURRENT=/opt/ruby/current
function opt_ruby_clear_current {
rm ${OPT_RUBY_CURRENT}
}
function opt_ruby_187 {
opt_ruby_clear_current
ln -s /opt/ruby/1.8.7-p358 ${OPT_RUBY_CURRENT}
hash -r
}
@kenichi
kenichi / gist:2883384
Created June 6, 2012 17:17
kill buffer, keep window (vim)
" delete buffer, keep window
function Kwbd(kwbdStage)
if(a:kwbdStage == 1)
let g:kwbdBufNum = bufnr("%")
let g:kwbdWinNum = winnr()
windo call Kwbd(2)
execute "bd! " . g:kwbdBufNum
execute "normal " . g:kwbdWinNum . ""
else
if(bufnr("%") == g:kwbdBufNum)
class String
def base60_decode
n = 0
self.each_byte do |c|
case
when c >= 48 && c <= 57
c -= 48
when c >= 65 && c <= 72
c -= 55
when c == 73 || c == 108
@kenichi
kenichi / gist:2969137
Created June 21, 2012 23:02
error catching
#!/usr/bin/env ruby
require 'sinatra'
require 'sinatra/namespace'
configure do
disable :raise_errors
disable :show_exceptions
end
@kenichi
kenichi / gist:3894267
Created October 15, 2012 18:40
deprecated CLLocationManager didUpdateToLocation:fromLocation
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSMutableArray *locations = [NSMutableArray arrayWithObject:newLocation];
if (oldLocation) [locations insertObject:oldLocation atIndex:0];
[self locationManager:locationManager didUpdateLocations:locations];
}
// --- or the other way around
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
@kenichi
kenichi / gist:3913655
Created October 18, 2012 17:44
rfc822 email regex (works in 1.9)
# RFC822 Email Address Regex
# Originally written by Cal Henderson
# c.f. http://iamcal.com/publish/articles/php/parsing_email/
# Translated to Ruby by Tim Fletcher, with changes suggested by Dan Kubb.
# Licensed under a Creative Commons Attribution-ShareAlike 2.5 License
# http://creativecommons.org/licenses/by-sa/2.5/
module RFC822
EmailAddress = begin
qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'