Skip to content

Instantly share code, notes, and snippets.

@naoty
naoty / pre-commit
Created August 26, 2015 10:46
コミット前にrubocop適用して自動修正するフック
#!/usr/bin/env ruby
files = `git diff --cached --name-only | grep .rb`.split
exit 0 if files.empty?
ok = true
files.each do |file|
next unless File.exist?(file)
result = system "rubocop", "--auto-correct", file
ok = false if result == false
@naoty
naoty / pagerank.rb
Last active August 29, 2015 13:56
ページランクのRuby実装
require "matrix"
class Graph
D = 0.85
EPS = 1 * 10 ** -5
def initialize(matrix)
@dimension = matrix.row_size
elements = []
@naoty
naoty / .gitignore
Created March 2, 2014 15:16
.gitignore for Android project
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class

hr


hr

#import <Foundation/Foundation.h>
@interface NSString (Snakecase)
@property (nonatomic, readonly) NSString *snakecaseString;
@end
@naoty
naoty / sample.md
Last active August 29, 2015 14:02

naoty

@naoty
naoty / .zlogout
Created June 23, 2014 02:53
change directory selected on peco
# ディレクトリスタックを重複を省いてファイルに保存する
dirs -lp > $HOME/.dirs.tmp
cat $HOME/.dirs.tmp | sort | uniq > $HOME/.dirs
rm $HOME/.dirs.tmp
import Cocoa
extension Int {
var seconds: NSTimeInterval {
return NSTimeInterval(self)
}
var minutes: NSTimeInterval {
return self.seconds * 60
}
@naoty
naoty / gist:eabc657918469f4af0b1
Created July 23, 2014 05:25
タイムゾーンこわい
[7] pry(main)> Delorean.time_travel_to("10 hour ago") do
[7] pry(main)* DateTime.yesterday.beginning_of_day
[7] pry(main)* end
=> Tue, 22 Jul 2014 00:00:00 JST +09:00
[8] pry(main)> Delorean.time_travel_to("10 hour ago") do
[8] pry(main)* DateTime.current.utc.yesterday.beginning_of_day
[8] pry(main)* end
=> Mon, 21 Jul 2014 00:00:00 +0000
@naoty
naoty / gist:0aff43e98f866ac9bdad
Created August 13, 2014 13:32
推奨されてるシングルトンパターンの実装、structのネストの位置を変えても動いた
import UIKit
class Manager {
struct Singleton {
static let instance = Manager()
}
class var sharedInstance: Manager {
println("sharedInstance called")