Skip to content

Instantly share code, notes, and snippets.

@jewel12
jewel12 / t.rb
Created March 13, 2014 18:31
1時間単位で開始時間と終了時間が与えられたとき、全ての時間を1時間単位で小さいほうから列挙するリストを返す関数
# -*- coding: utf-8 -*-
# https://twitter.com/katzchang/status/444136941605224448
# is(hoge('2014-01-01 01:00', '2014-01-01 03:00'), ('2014-01-01 01:00', '2014-01-01 02:00', '2014-01-01 03:00')) より
# 1時間単位で開始時間と終了時間が与えられたとき => YYYY-mm-dd HH:00 が入力されるものだと予想
# 寝る
require 'time'
module RefinedTime
@jewel12
jewel12 / Guardfile
Created May 28, 2014 16:30
メモの中にファイル名とカテゴリを書いておくとカテゴリ名のディレクトリを作って勝手にcpしてくれるやつをとりあえず
guard :shell do
watch 'tmp.md' do |f|
lines = open(f.first).readlines
file_name = $~[1] if lines.any?{ |l| l =~ /^__(.+)__$/ }
category = $~[1] if lines.any?{ |l| l =~ /^\[(.+)\]$/ }
if file_name && category
FileUtils.mkdir_p(category)
FileUtils.cp 'tmp.md', category + '/' + file_name
@jewel12
jewel12 / index.html
Created August 2, 2014 08:34
HASH COLOR
<!DOCTYPE html>
<html lang="en">
<head>
<meata charset="UTF-8">
<title>HashColor</title>
<style>
body {
text-align: center;
font-family: arial;
@jewel12
jewel12 / pretty_cure_printer.rb
Created August 23, 2014 07:08
Pretty(Cure)Print
# -*- coding: utf-8 -*-
require 'pp'
require 'rubicure'
module PrettyCurePrinter
# 設定ファイルに書いた方がいい
# precure_name => [foreground, background]
PRECURE_COLOR_SETTING = {
'キュアブラック' => [:white, :black],
'キュアホワイト' => [:black, :white],
@jewel12
jewel12 / kanidouraku.elm
Created March 4, 2015 17:18
kanidouraku.elm
import Keyboard
import Signal (..)
import Time (..)
import Color(rgb)
import Graphics.Element (..)
import Graphics.Collage (..)
import Random
import Time
type ClawPos = Left | Right
@jewel12
jewel12 / midori-chap-9.ipynb
Created May 13, 2015 11:29
みどり本9章
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jewel12
jewel12 / colorer.rb
Created May 19, 2014 16:07
自動でログ色付け君マシーン
require 'rainbow'
class WordFreq < Hash
def initialize
super(0)
end
def add(w)
self[w] += 1
end
# Translation
function gtranslation() {
RESULT=`ruby "gtranslation.rb のパス" "${RBUFFER}"`
zle push-line
echo "${RESULT}"
zle send-break
}
zle -N gtranslation
bindkey "^t" gtranslation
# -*- coding: utf-8 -*-
# Google 翻訳
require 'rubygems'
require 'json'
require 'open-uri'
URL = "http://ajax.googleapis.com/ajax/services/language/translate"
query = ARGV[0]
@jewel12
jewel12 / gist:631569
Created October 18, 2010 01:47
fopner.rb
#!/usr/bin/ruby
# 拡張子が .gz であれば、zlib でオープンする。
require 'zlib'
module FOpener
def self.open( f_name )
f = Filename.extname(f_name) == ".gz" ? Zlib::GzipReader.open( f_name ) : File.open( f_name )
yield( f )
f.close
end