Skip to content

Instantly share code, notes, and snippets.

Toshiyuki Masui masui

Block or report user

Report or block masui

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@masui
masui / gyazo.rb
Created Dec 28, 2015
gyazoコマンド
View gyazo.rb
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
#
require 'shellwords'
if ARGV.length == 0
STDERR.puts "% gyazo query"
STDERR.puts "% gyazo -f uploadfile1 uploadfile2"
exit
end
View gyazofull.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# 全画面Gyazoると同時にファイル情報/アプリ情報のメタデータをアップする
#
require 'net/http'
require 'json'
require 'digest/md5'
View register.sh
#!/bin/sh
pushd /var/www/html/master.gyazo.com/current/; RAILS_ENV=staging bundle exec rails runner /home/nota/masui/register.rb $1 $2 $3; popd
View register.rb
id = ARGV[0]
time = ARGV[1]
url = ARGV[2]
exit unless id && time && url
time = time.gsub(/_/,' ')
d = Image.find_by(image_id: id)
d.date = Time.zone.parse(time).utc
d.metadata = { 'url' => url }
@masui
masui / promise.coffee
Last active Aug 29, 2015
Promiseの例
View promise.coffee
fs = require 'fs'
readFile = (filename, enc) ->
new Promise (fulfill, reject) ->
fs.readFile filename, enc, (err, res) -> # readFile()は非同期関数
if err
reject err
else
fulfill res
@masui
masui / gist:8a5a6ae7e5bb7acf83ee
Last active Aug 29, 2015
1時間以内に解けなければプログラマ失格となってしまう5つの問題(3)
View gist:8a5a6ae7e5bb7acf83ee
#
# https://blog.svpino.com/2015/05/08/solution-to-problem-5-and-some-other-thoughts-about-this-type-of-questions
#
def power(len, sels, arr=[], &block)
if len == 0 then
yield arr
else
sels.to_a.each { |sel|
power len-1, sels, arr + [sel], &block
}
@masui
masui / slow.rb
Created May 26, 2015
a^2 + b^2 == c^2 かつ a+b+c=1000, a < b < c となる a, b, c を求める
View slow.rb
1.upto(1000) do |c|
1.upto(c-1) do |b|
1.upto(b-1) do |a|
next if a + b + c != 1000
next if a * a + b * b != c * c
puts "#{a}^2 == #{b}^2 + #{c}^2"
end
end
end
@masui
masui / gist:89fa67d47c1925f89329
Last active Aug 29, 2015
1時間以内に解けなければプログラマ失格となってしまう5つの問題(2)
View gist:89fa67d47c1925f89329
#
# https://blog.svpino.com/2015/05/08/solution-to-problem-5-and-some-other-thoughts-about-this-type-of-questions
#
def power(n, alts, &block)
_power(n, 0, [], alts, &block)
end
def _power(total, level, res, alts, &block)
if level < total then
alts.each { |op|
@masui
masui / gist:b688b4275f5d59fea6ec
Created May 25, 2015
1時間以内に解けなければプログラマ失格となってしまう5つの問題
View gist:b688b4275f5d59fea6ec
#
# https://blog.svpino.com/2015/05/08/solution-to-problem-5-and-some-other-thoughts-about-this-type-of-questions
#
def power(level, a, &block)
if level > 0 then
['+', '-', ''].each { |op|
a[level-1] = op
power level-1, a, &block
}
else
@masui
masui / problem9-slow.rb
Created May 25, 2015
a^2 + b^2 == c^2 かつ a+b+c=1000, a < b < c となる a, b, c を求める (流石にナイーブすぎて遅いバージョン)
View problem9-slow.rb
(1..1000).each { |i|
(1..1000).each { |j|
(1..1000).each { |k|
next if j <= i
next if k <= j
next if i+j+k != 1000
puts "#{i}, #{j}, #{k}" if i*i + j*j == k*k
}
}
}
You can’t perform that action at this time.