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 } |
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 |
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 | |
} |
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 |
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| |
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 |
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 | |
} | |
} | |
} |
NewerOlder