Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
zakuroishikuro / file0.txt
Last active August 29, 2015 14:12
Hashのキーを文字列からシンボルに変換する ref: http://qiita.com/zakuroishikuro/items/5b08d65d4fef79982f19
def symbolize_keys(hash)
hash.map{|k,v| [k.to_sym, v] }.to_h
end
hash = {'key':'value', 'key2':'value2'}
symbolize_keys(hash) #=> {:key=>"value", :key2=>"value2"}
@zakuroishikuro
zakuroishikuro / cal.rb
Created January 9, 2015 05:16
Calendar
# Twitterに投稿できるくらい短くしたかったけど無理で諦めた。
# 捨てるのももったいないのでここにメモっておく
require'date'
n = Time.now
l = Date.new(n.year,n.month,-1)
puts l.strftime("%B %Y");
puts "ver. 1"
@zakuroishikuro
zakuroishikuro / file1.txt
Last active August 29, 2015 14:14
例のゲームの都市伝説を再現したかった ref: http://qiita.com/zakuroishikuro/items/8cbb0f4948b70dcd06cd
ruby -e 's=%|すぐに消せ |;v,h=`stty size`.split.map(&:to_i);puts [s.ljust(h/2,s)]*v'
{
"Sequential Inputs of numbers with 8"=>
(1..9).map{|n|"#{[*1..n] * ''} * 8 + #{n}"},
"Sequential 1's with 9"=>
(1..9).map{|n|"#{[*1..n] * ''} * 9 + %2d" % (n + 1)},
"Sequential 8's with 9"=>
9.downto(2).map{|n|"#{[*9.downto(n)] * ''} * 9 + #{n - 2}"},
@zakuroishikuro
zakuroishikuro / get_all_scriptable_apps.js
Last active August 29, 2015 14:15
(Apple|Java)Scriptから操作可能なアプリのパスを全て取得 (JXA) ref: http://qiita.com/zakuroishikuro/items/b5a77ad4f3885c8ed93a
function run(){
var SystemEvents = Application("System Events");
// GUIスクリプティングが有効になってなければエラー投げて終了
if (!SystemEvents.uiElementsEnabled()) {
throw "GUIにアクセスできないよ。「システム環境設定 > セキュリティとプライバシー > プライバシー > アクセシビリティ」から許可を与えてね。";
// 「スクリプトで開けよ」とか言わない
};
// スクリプトエディタを開く
@zakuroishikuro
zakuroishikuro / gist:f360d332d30b496b51f4
Created February 17, 2015 19:41
一気にrequireするメソッド ついでにシンボルも可
// require [String, Symbol, Array]
def req(*f)
f.flatten.map{|s| require s.to_s }
end
// usage
req :yaml
req :date, :uri
req [:zlib, "open-uri"]
@zakuroishikuro
zakuroishikuro / gist:045944bb3a1a650351db
Created February 18, 2015 20:17
Scriptable Mac Application - each sdef sizes
Screen Sharing.app sdef: 487 bytes
Bluetooth File Exchange.app sdef: 860 bytes
Digital Hub Scripting.osax sdef: 1153 bytes
AppleScript Utility.app sdef: 1958 bytes
Instruments.app sdef: 3048 bytes
Folder Actions Dispatcher.app sdef: 3283 bytes
Folder Actions Setup.app sdef: 3361 bytes
System Preferences.app sdef: 4049 bytes
Notes.app sdef: 5224 bytes
Reminders.app sdef: 7094 bytes
@zakuroishikuro
zakuroishikuro / gist:fc5a63c7c7aebd3d7294
Created February 18, 2015 20:41
全角半角を考慮して文字列の幅を取得するモンキーパッチ
class String
def width
length * 2 - chars.count(&:ascii_only?)
end
end
Safari.doJavaScript("location.reload()", {in:tab});
@zakuroishikuro
zakuroishikuro / Qiitaのユーザーページで「投稿タイプ」に出てるタグをクリックしたらそのユーザーがそのタグで投稿した記事を検索するやつ.js
Last active August 29, 2015 14:15
Qiitaのユーザーページで「投稿タイプ」に出てるタグをクリックしたらそのユーザーがそのタグで投稿した記事を検索するやつ ref: http://qiita.com/zakuroishikuro/items/e136480a019ac11d0a15
var tags = $("#piechart text:not(:contains('Others'))");
tags.hover(
function(){ $(this).css({"font-weight":"bold", "text-decoration":"underline", cursor:"pointer"}) },
function(){ $(this).css({"font-weight":"normal", "text-decoration":"none"}) }
);
tags.click(function(){
var user = location.href.match(/[^\/]+$/),
tag = $(this).text().match(/\S+$/),