Skip to content

Instantly share code, notes, and snippets.

View katoy's full-sized avatar

revers katoy

  • japan/tokyo
View GitHub Profile
@katoy
katoy / draw.swift
Last active October 28, 2016 09:48
draw line in playground (Xcode 6.1)
// See http://techlife.cookpad.com/entry/2014/11/12/170041
//
// 本来はplayground用に用意されているXCPlaygroundフレームワークのXCPShowViewを使って
// Timelineに表示することが可能ですが、現行のXcode6.1でiOS用にUIKitを使って表示した場合
// コンソールにエラーが出てしまうため使用していません。
//
import UIKit
// ビューのサイズ
@katoy
katoy / fukumen.rb
Created December 13, 2014 13:49
覆面算を ruby で解く。
# encoding: utf-8
# See http://web-salad.hateblo.jp/entry/2014/04/06/164312
# このコードを元に、少し変更して、全解を得るようにした。
# 文字に日本語もあつかえるようにした。
#
# 覆面算の例: http://ja.wikipedia.org/wiki/%E8%A6%86%E9%9D%A2%E7%AE%97
#
DOCUMENT = <<EOS
Find solutions to alphametic equations.
@katoy
katoy / client.rb
Created December 13, 2014 01:28
druby のサンプル (remote のファイル内容を得る)
# coding: utf-8
# See http://docs.ruby-lang.org/ja/2.0.0/library/drb.html
require 'pp'
require 'drb/drb'
# 接続先の URI
SERVER_URI="druby://localhost:8787"
# DRbサーバを起動する
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Canvas でお絵描き</title>
<style>
#mycanvas {
border: 3px solid #999;
cursor: crosshair;
}
@katoy
katoy / yes-no.sh
Created March 12, 2014 14:23
yes/no を聞く bash スクリプト
#!/bin/bash
# bash で yes/no を聞く。
#
# See http://yuki.silk.to/2006/04/000161.html
# http://usaturn.net/memo/shell_tech_yesorno.html
function yes_no() {
echo "-------------------------------------------"
echo "よろしいですか?(yes/no)"
@katoy
katoy / num10.rb
Last active January 1, 2016 02:39
puzzle for 4-numbers. 4 つの数字から四則演算して 10 になるような計算式を得る。(num10.rb) 指定した個数の数字から四則演算して、指定した値になるような計算式を得る。(num10ex.rb)
# -*- coding: utf-8 -*-
# 演算子の優先度を返す
OP_INFO = {
# 演算子 => [優先度、演算]
'+' => { priority: 1, func: 'func_add' },
'-' => { priority: 1, func: 'func_sub' },
'*' => { priority: 2, func: 'func_mul' },
'/' => { priority: 2, func: 'func_div' },
# '**' => { priority: 3, func: 'func_exp' },
@katoy
katoy / test.rb
Created November 30, 2013 12:57
using daemons.
# -*- coding: utf-8 -*-
require 'logger'
STDOUT.sync = true
STDERR.sync = true
def get_logger
ret = Logger.new(File.join(File.dirname(File.expand_path(__FILE__)), 'test.log'))
ret.level = Logger::INFO
@katoy
katoy / run.rb
Created October 10, 2013 12:43
ruby で外部プログラムを実行する例
# See http://refm.rubicle.net/sp/1.9.3/class/Open3
require 'open3'
puts "====== system ======"
ret = system('ps > /tmp/1')
puts ret
puts File.read('/tmp/1')
puts "====== Open3.capture3 ======"
@katoy
katoy / 1.rb
Created October 8, 2013 15:10
erb の利用例
# -*- coding: utf-8 -*-
require 'erb'
require 'time'
def make_body(template, name, time, params)
erb = ERB.new(template)
result = erb.result(binding)
end
@katoy
katoy / gist:6809787
Created October 3, 2013 13:25
ruby の Net::SCP でプログレスバーを出す。 See https://gist.github.com/drfeelngood/3784077
require 'rubygems'
require 'net/scp'
host = "xxxxxxx.ne.jp"
user = "youichikato"
src_path = "/tmp/1"
dest_path = "/tmp/2"
opts = {:password => "xxxxxxxx"}
Net::SCP.start(host, user, opts){|scp|