Skip to content

Instantly share code, notes, and snippets.

View mackato's full-sized avatar

Masakuni Kato mackato

View GitHub Profile
@mackato
mackato / rails_guides_to_epub.rb
Created June 4, 2010 03:24
Ruby on Rails Guides ePub convert ruby script
require 'rubygems'
require 'nokogiri'
require 'eeepub'
DOC_TITLE = 'Ruby on Rails Guides'
def get_pages(src_dir)
index_file = File.join(src_dir, 'index.html')
section = nil
pages = [{ :section => section, :title => DOC_TITLE, :path => index_file }]
@mackato
mackato / timeago_japanese.js
Created November 12, 2010 07:05
timeago a jQuery plugin Japanese enhancement
function convertWithLang(timeAgo, lang) {
if (lang == "ja")
return toJa(timeAgo);
return timeAgo;
}
function convert(timeAgo, dict, strip) {
var delim = " ";
var arr = timeAgo.split(delim);
@mackato
mackato / have_store_accessor_matcher.rb
Last active December 25, 2015 11:59
Rails 4 Postgresql store accessor matcher
module Shoulda
module Matchers
module ActiveRecord
def have_store_accessor(key)
HaveStoreAccessor.new(key)
end
class HaveStoreAccessor
def initialize(key)
@key = key
@mackato
mackato / closure_singleton.as
Created March 26, 2010 01:19
ActionScript Singleton pattern
public class Singleton {
public static var getInstance:Function = function():Singleton {
var instance:Singleton = new Singleton();
getInstance = function():Singleton {
return instance;
};
return getInstance();
@mackato
mackato / rbenv-1.8.7-bundle-install-libv8
Created August 9, 2012 15:58
rbenv exec bundle install with libv8 (1.8.7)
RUBYOPT="-r rubygems" rbenv exec bundle install --path vendor/bundle
@mackato
mackato / homebrew.mxcl.jenkins.plist
Created August 9, 2012 08:05
Jenkins plist for Mac OS X
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.jenkins</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
<string>-Dfile.encoding=UTF-8</string>
@mackato
mackato / create-daily-blog
Created March 30, 2012 09:19
日報起動スクリプト
#!/bin/bash -e
NAME="YOUR JAPANESE LAST NAME"
DATE=`date '+%Y-%m-%d'`
URL="https://airshq.atlassian.net/wiki/pages/createblogpost.action?spaceKey=AIRS&title=$DATE+$NAME"
open $URL
@mackato
mackato / filter_with_module.rb
Created March 26, 2012 07:15
declare filter when module is included
module Foo
def self.included(base)
base.class_eval do
before_filter :admin_required
end
end
end
@mackato
mackato / add_git_remote_repository.sh
Created February 14, 2012 04:13
add git remote repository
git remote add origin my://server/repo.git
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
@mackato
mackato / mapview_contains_location.m
Created January 25, 2012 02:07
Check MKMapView contains CLLocationCoordinate2D
MKCoordinateRegion region = mapView.region;
CLLocationCoordinate2D topLeftCoordinate =
CLLocationCoordinate2DMake(region.center.latitude + (region.span.latitudeDelta / 2.0),
region.center.longitude - (region.span.longitudeDelta / 2.0));
CLLocationCoordinate2D bottomRightCoordinate =
CLLocationCoordinate2DMake(region.center.latitude - (region.span.latitudeDelta / 2.0),
region.center.longitude + (region.span.longitudeDelta / 2.0));
MKMapPoint topLeftMapPoint = MKMapPointForCoordinate(topLeftCoordinate);