Skip to content

Instantly share code, notes, and snippets.

@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")
@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
import Cocoa
extension Int {
var seconds: NSTimeInterval {
return NSTimeInterval(self)
}
var minutes: NSTimeInterval {
return self.seconds * 60
}
@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
@naoty
naoty / sample.md
Last active August 29, 2015 14:02

naoty

#import <Foundation/Foundation.h>
@interface NSString (Snakecase)
@property (nonatomic, readonly) NSString *snakecaseString;
@end

hr


hr

@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
@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 / parser.rb
Last active January 4, 2016 16:19
paragraph parse sample
require "redcarpet"
require "pathname"
require "cgi"
class MyRenderer < Redcarpet::Render::HTML
def paragraph(text)
if text =~ /^\s?\[.+\]\s?$/
puts "parses:"
lines = text.split("\n")
lines.each do |line|