Skip to content

Instantly share code, notes, and snippets.

Avatar

Kenichi Nakamura kenichi

  • Portland, Oregon
View GitHub Profile
@kenichi
kenichi / test.rb
Created Aug 17, 2011
sinatra/haml reload templates
View test.rb
require 'sinatra'
require 'haml'
configure do
set :reload_templates, true
end
get '/' do
haml :index, :layout => false
end
@kenichi
kenichi / gist:1309647
Created Oct 24, 2011
basic auth in sinatra
View gist:1309647
use Rack::Auth::Basic, "Nope" do |u, p|
[u, p] == ['user', 'password']
end
@kenichi
kenichi / gist:2040219
Created Mar 14, 2012
dondonp problem
View gist:2040219
<!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 Mar 22, 2012
bizzarro dynamic attributes
View gist:2165047
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?
View gist:2845183
# 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 Jun 6, 2012
kill buffer, keep window (vim)
View gist:2883384
" 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)
View gist:2931996
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
View gist:2969137
#!/usr/bin/env ruby
require 'sinatra'
require 'sinatra/namespace'
configure do
disable :raise_errors
disable :show_exceptions
end
@kenichi
kenichi / gist:3894267
Created Oct 15, 2012
deprecated CLLocationManager didUpdateToLocation:fromLocation
View gist:3894267
- (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 Oct 18, 2012
rfc822 email regex (works in 1.9)
View gist:3913655
# 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]'