Skip to content

Instantly share code, notes, and snippets.

View katoy's full-sized avatar

revers katoy

  • japan/tokyo
View GitHub Profile
@katoy
katoy / get_opencv3.sh
Created April 21, 2018 22:20 — forked from n8henrie/get_opencv3.sh
Download, build, and install opencv on Raspberry Pi 3
#! /bin/bash
set -euf -o pipefail
function cleanup {
for pid in "${opencv_download_pid:-''}" "${contrib_download_pid:-''}" "${pip_install_pid:-''}"; do
if [ -z "${pid}" ]; then
kill "${pid}"
fi
done
class ChangeColumnToUser < ActiveRecord::Migration[5.0]
def change
# 追加
add_column :users, :piyo, :string
add_column :users, :piyo2, :string
# 削除
remove_column :users, :piyo2, :string
# rename
rename_column :users, :name_x, :name
end
@katoy
katoy / sampe_spec.rb
Last active June 15, 2016 22:51
rspec の mock の例
# See
# http://qiita.com/jnchito/items/640f17e124ab263a54dd
require 'spec_helper'
class WeatherBot
def tweet_forecast
twitter_client.update '今日は晴れです'
rescue => e
@katoy
katoy / 1.txt
Last active August 29, 2015 14:18
camunda の rest api を呼び出してみる
# ------ 実行例
$ ruby rest.rb
id:064c0150-db48-11e4-835e-12f5ba1407e2, name:"ローン申請の 審査"
id:073f66b2-db36-11e4-bc81-12f5ba1407e2, name:"Assign Approver"
id:077a4cf8-db36-11e4-bc81-12f5ba1407e2, name:"Review Invoice"
id:0bd16b17-db39-11e4-b167-12f5ba1407e2, name:"Assign Approver"
id:0bf6a67d-db39-11e4-b167-12f5ba1407e2, name:"Review Invoice"
id:247d07d5-db14-11e4-9656-12f5ba1407e2, name:"Prepare Bank Transfer"
id:304be6fb-db4e-11e4-b444-12f5ba1407e2, name:"Assign Approver"
id:3079fbeb-db4e-11e4-b444-12f5ba1407e2, name:"Approve Invoice"
@katoy
katoy / output.txt
Last active April 6, 2020 05:25
Rails の routes 情報を csv 書式で出力する。 (rake routes:csv)
$ rake -T routes
rake routes # Print out all defined routes in match order, with names
rake routes:csv # Print out all defined routes in CSV format
$ rake routes:csv
Prefix, Verb, URI Pattern, Controller#Action
data, GET, /data(.:format), data#index
, POST, /data(.:format), data#create
new_datum, GET, /data/new(.:format), data#new
edit_datum, GET, /data/:id/edit(.:format), data#edit
@katoy
katoy / kditta.rb
Created April 7, 2015 22:01
plantuml の ditaa モードの日本語対応版 (in progress ...)
# coding: utf-8
File.open(ARGV[0], "r:utf-8" ) do |f|
while line = f.gets
line2 = ''
line.chars do |c|
line2 += c
code = c.ord
line2 += ' ' unless 0 <= code && code <= 255
end
@katoy
katoy / pr0201.rb
Created February 15, 2015 11:16
From Mathematics to Generic Programming
# coding: utf-8
# See Book "http://ptgmedia.pearsoncmg.com/images/9780321942043/samplepages/9780321942043.pdf"
# "From Mathematics to Generic Programming"
def odd?(n)
(n & 1) == 1
end
def half(n)
n >> 1
end
@katoy
katoy / pi1.rb
Last active August 29, 2015 14:14
ruby で円周率
# See http://keibakuroku.jp/category/brain-teaser
def pi_1(len)
count = 0
k, a, b, a1, b1 = 2, 4, 1, 12, 4
while TRUE
# Next approximation
p, q, k = k*k, 2*k+1, k+1
a, b, a1, b1 = a1, b1, p * a + q * a1, p * b + q * b1
@katoy
katoy / tree.rb
Last active August 29, 2015 14:14
二分木のAA
# coding: utf-8
# See http://ja.stackoverflow.com/questions/4739
# https://gist.github.com/snipsnipsnip/0e267f6a39cc2397da3d
#
# 2 分木をコンソールにアスキーアートで出力する。
#
require 'gviz' # gem install gviz
@katoy
katoy / rational.swift
Last active August 29, 2015 14:13
Swift での 分数 (Rational number)
#!/usr/bin/xcrun swift
// See https://gist.github.com/kristopherjohnson/eb7dc5b6af06eb42ef38
// http://codereview.stackexchange.com/questions/56872/fraction-rational-number-structure-with-custom-operators
import Cocoa
public struct Rational {
let numer: Int
let denom: Int