多くの開発者はSQLをうまく書けるわけではないから、DBを簡単に操作するインタフェースを Table Data Gateway で用意する。
# ex.
# Items
# id integer primary key
class Array | |
def to_proc | |
->(this) { this.send(*self) } | |
end | |
end | |
[1,2,3].map(&[:+, 1]) #=> [2,3,4] | |
def apply(sym, args=[]); ->(this) { this.send(sym, *args) }; end | |
alias _ apply |
require 'benchmark' | |
require 'active_support/all' | |
n = ARGV[0]&.to_i || 50000 | |
m = ARGV[1]&.to_i || 20 | |
arr = Array.new(m){|i| [i, [:a, :b, :c, :d].sample] }.shuffle.to_h | |
Benchmark.bmbm do |b| | |
b.report("1:") { n.times{ arr.select{|_,v| v == :a }.max&.first }} | |
b.report("2:") { n.times{ arr.each_with_object([]){|(k,v),o| o << k if v == :a }.max }} |
require 'benchmark' | |
require 'active_support/all' | |
n = 20000 | |
m = 100 | |
arr = Array.new(m){|i| [i, [:a, :b, :c, :d].sample] }.shuffle.to_h | |
Benchmark.bmbm do |b| | |
b.report("1:") { n.times{ arr.select{|_,v| v == :a }.max&.first }} | |
b.report("2:") { n.times{ arr.each_with_object([]){|(k,v),o| o << k if v == :a }.max }} |
require 'sinatra' | |
require 'jwt' | |
require 'json' | |
def get_iap_key(kid) | |
@key_table ||= begin | |
require 'open-uri' | |
resp = open('https://www.gstatic.com/iap/verify/public_key', &:read) | |
JSON.parse(resp) | |
end |
$><<(%<><<(%$%(/</<=)<%~~~/%>>>~<>)/>>)=)/(>%()<>~~~()<=%/=<=>)=(%=<~>(~/><<~)//)</)=$=~/$/)<<(%$<)>><%(>/()(//(=>%~<=((<=((=%/%~(((>//=<=)/=/<>(>~~<)~>~/~=~)~==%)><%=<=~(=/~//>)><%<>((<)/~)<<=>/%=<$=~/$/)<<(%$</)>(=%))%(<)=></<)~<<))/~/<<~/)//=/>~%~)((()>)/=(%)>>~/~<<()(((()<)~>%<)%%~~<%><==(()((/((><%%=%)=<%%=(%~~)$=~/$/)<<(%$=>~~>>/>>><)=<>=~=<(/%>(~%~()(~<>%)()>)(=<%)=%<>()(%==%<>/(>%~=<//%/(~)/<(%(><)>(>=%)>/~(%><=>)>~>))(<<((~%>$=~/$/)<<(%$</=(~>%~~><=~=<))/~()/(~=%(=<()/=/(~)~~~=/><)<<>>>~///=>))=(>>/(())<>/%<<<==/%(<~<~>/(%<()(/=%=))~%~(/%>==)/~>/$=~/$/)) |
# https://github.com/google/google-api-ruby-client/blob/master/samples/cli/lib/samples/bigquery.rb | |
require 'google/apis/bigquery_v2' | |
require 'googleauth' | |
require 'securerandom' | |
# CHANGEME | |
project_id = 'myproject' | |
dataset_id = 'mydataset' | |
table_id = 'mytable' |
function ticketLink() { | |
// configuration | |
var sheetName = 'Sample1'; | |
var redmineUrl = 'http://redmine.example.com/issues/'; | |
var targetRange = 'A2:A'; | |
var doc = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = doc.getSheetByName(sheetName); | |
var all = sheet.getRange(targetRange); | |
var height = all.getHeight(); |
require 'slack-notifier' | |
require 'tweetstream' | |
SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX' | |
TweetStream.configure do |config| | |
config.consumer_key = 'XXXXXXXXXXXXXXXXXXXXXXXXX' | |
config.consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
config.oauth_token = 'XXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' |
#!/usr/bin/env ruby | |
require 'csv' | |
firstline = true | |
io = $stdout | |
while line = ARGF.gets | |
data = line.chomp.split(/\t/).map{|item| item.split(/:/,2) }.to_h | |
if firstline |