Skip to content

Instantly share code, notes, and snippets.

DEVICE_NAME = ENV["DEVICE_NAME"]
SHARED_ACCESS_KEY = ENV["SHARED_ACCESS_KEY"]
HOST_NAME = ENV["HOST_NAME"]
REQUEST_PATH = "devices/#{DEVICE_NAME}/messages/events?api-version=2015-08-15-preview"
uri_with_port = "https://#{HOST_NAME}:443/#{REQUEST_PATH}"
expiry = Time.now.to_i + 60 * 60
s = "#{HOST_NAME}/devices/#{DEVICE_NAME}"
raw = Digest::HMAC.digest("#{s}\n#{expiry}",
require 'openssl'
require 'cgi'
require 'base64'
require 'time'
# CONNECTION_STRINGはiothub-explorerで生成した値
CONNECTION_STRING = ENV['CONNECTION_STRING']
CONNECTION_STRING.split(";").each do |elm|
key = elm[0, elm.index("=")].gsub(/([A-Z])/, "_\\1").gsub(/^_/, '').downcase
self.instance_variable_set("@#{key}".to_sym, elm[(elm.index('=') + 1), elm.length])
filename = ARGV[0]
lines = File.readlines(filename)
fix_footnote = lines.map { |line|
line.sub(/<div =class'footnotes'><ol>/, '').
gsub(/<a href=.+?>←<\/a><\/p><\/li>/, "\n").
sub(/<\/ol><\/div>/, '').
gsub(/<li id='fn(.+?)'><p>/) { '[^' + $1 + ']: '}.
gsub(/<sup id='fnref(.+?)'>.+<\/sup>/) { '[^' + $1 + ']' }
}
'/Applications/Postgres.app/Contents/Versions/9.3/bin'/psql -p5432
Last login: Thu Nov 3 02:00:37 on ttys000
[~]$ '/Applications/Postgres.app/Contents/Versions/9.3/bin'/psql -p5432
psql (9.3.5)
Type "help" for help.
miyohide=# create role hoge with createdb login password 'password';
CREATE ROLE
miyohide=#
@miyohide
miyohide / yokohamarb_70.rb
Created July 9, 2016 15:50
Yokohama.rb 70回で出題された問題の回答です。
// coding: utf-8
// http://nabetani.sakura.ne.jp/yokohamarb/2016.07.ront/
Tiles = [
{top: :left, left: :top, right: :down, down: :right},
{top: :right, left: :down, right: :top, down: :left},
{top: :down, left: :right, right: :left, down: :top},
{top: :death, left: :death, right: :death, down: :death}
]
def input2tiles(input)
require 'openssl'
require 'cgi'
require 'base64'
require 'time'
require 'net/https'
require 'json'
CONNECTION_STRING = ENV['CONNECTION_STRING']
CONNECTION_STRING.split(";").each do |elm|
@miyohide
miyohide / file_move.rb
Created April 23, 2016 09:04
Markdownファイルをディレクトリごとに移動する
(1..53).each do |i|
issue = "%04d" % i
Dir.glob("#{issue}*.md").each { |filename|
File.rename(filename.to_s, "markdowns/#{issue}/#{filename.to_s}")
}
end
@miyohide
miyohide / class_variable_access_warning.rb
Created May 28, 2015 15:03
class_variable_access_warning.rb
[~/work/tmp]$ cat foo.rb
@@v = 1
class Foo
@@v = 2
end
@@v
## Ruby 1.9.3
@miyohide
miyohide / memo.md
Created April 26, 2015 10:06
bashさんにお聞きしたいこと
  • 所属会社の事業領域に全力で飛び込まれているように見受けられます。その原動力は?モチベーションは?
  • 昨年度は、bashさんがいろんな場で発表されている機会をお見受けしたように思います。
    • Rubyworld ConferenceとかRuby Businessとか渋谷Ruby会議とか。
    • Web上での記事も数多くお見受けした感じがします。
      • たまたま重なっただけですか?
      • 個人の意志ですか?会社が何らかの支援をしてもらっているとか?
  • すごくポジティブなお考えをお持ちのようです。
    • 正直羨ましいです。
  • これから何していきたいですか?
  • 仕事の方向性としてはどのような道を目指したい?
@miyohide
miyohide / nike_json_parser.rb
Created March 5, 2015 13:30
Nikeが提供しているWeb画面でのAPIの結果を解析するスクリプト
require "json"
require "yaml"
def yaml_file_dump(datas)
File.open("nike_run_logs.yml", "a") { |f|
f.write(YAML.dump(datas))
}
end
run_datas = []