Skip to content

Instantly share code, notes, and snippets.

View dtan4's full-sized avatar

Daisuke Fujita dtan4

View GitHub Profile
@dtan4
dtan4 / catch.rb
Last active December 13, 2015 18:59
Post to Catch.com from command line
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'net/http'
require 'uri'
require 'json'
CREATE_NOTE_URI = 'https://api.catch.com/v3/streams/default'
USER = 'username'
PASS = 'password'
# char -> int
p "A".ord
#=> 65
# int -> char
p 1.chr()
#=> "\x01"
@dtan4
dtan4 / bf.rb
Last active December 14, 2015 14:29
Brainf*ck interpreter
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
MEMORY_SIZE = 30000
ASCII_SIZE = 256
def parse(code)
memory = []
MEMORY_SIZE.times do
memory << 0
@dtan4
dtan4 / chapter04.md
Last active June 24, 2018 08:35
「Gitによるバージョン管理」メモ

4. 基本的な Git コマンド

  • git diff
    • -M オプション
      • ファイル名変更のチェック
  • git shortlog
    • コミッタごとにログ表示
    • -s オプション
      • 作成者名とコミット数のみ
    • -n オプション
  • コミット数で降順ソート
@dtan4
dtan4 / eclipse.desktop
Last active December 16, 2015 06:49
Execute Eclipse from Gnome-Do, Unity-Lancher
[Desktop Entry]
Encoding=UTF-8
Name=Eclipse
Comment=Eclipse IDE
Exec=/usr/local/eclipse/eclipse
Icon=/usr/local/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=GNOME;Application;Development;
StartupNotify=true
@dtan4
dtan4 / divider.rb
Created April 17, 2013 18:57
Divide GPX file into segments
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'nokogiri'
def divide(filename)
gpx = Nokogiri::XML(File.read(filename))
segment_count = gpx.xpath('//xmlns:trkseg').length
segment_count.times do |i|
@dtan4
dtan4 / gpx_distance.rb
Last active December 29, 2018 18:13
Calculate distance between all Lat-Lons saved in GPX file.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
module GpxDistance
def calc_gpx_distance(gpx_file)
gpx = File.open(gpx_file) { |f| f.read }
latlons = []
gpx.each_line { |line| latlons << [$1.to_f, $2.to_f] if line =~ /<trkpt lat="([0-9.]+)" lon="([0-9.]+)">/ }
@dtan4
dtan4 / tsutaya.rb
Last active December 18, 2015 14:39
TSUTAYA のレンタル在庫情報を確認
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'open-uri'
require 'nokogiri'
URL_BASE = "http://store.tsutaya.co.jp/item/rental_cd"
def check_stock(product_id, store_id)
url = "#{URL_BASE}/#{product_id}.html?storeId=#{store_id}"
@dtan4
dtan4 / daily.rb
Last active December 24, 2015 17:39
Manage daily memos from console
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require "thor"
require "term/ansicolor"
DAILY_MEMO_DIR = ENV["HOME"] + "/Dropbox/memo/daily/"
class DailyCli < Thor
desc "edit [NAME]", "Edit memo in Emacs", aliases: "e"
@dtan4
dtan4 / unpushed.rb
Created October 11, 2013 08:48
Scan repositories and alert if unpushed commits exist
#!/usr/bin/env ruby
root = Dir.pwd
Dir.glob("*").map { |d| File.expand_path(d, root) }.each do |dir|
next unless File.ftype(dir) == "directory"
Dir.chdir(dir)
unpushed = `git rev-list origin/master..master 2>/dev/null | wc -l | tr -d ' '`.to_i
puts "#{dir} [#{unpushed}]" if unpushed > 0
end