Skip to content

Instantly share code, notes, and snippets.

View gouf's full-sized avatar
😇
I don't know how my life work with.

Go Furuya gouf

😇
I don't know how my life work with.
View GitHub Profile
@gouf
gouf / C:\Ruby200-x64\bin\setrbvars
Created December 2, 2013 03:33
筆圧検知が有効になったら(ペンタブのドライバが起動したら) SAI を起動する。
@ECHO OFF
REM Determine where is RUBY_BIN (where this script is)
PUSHD %~dp0.
SET RUBY_BIN=%CD%
POPD
REM Add RUBY_BIN to the PATH
REM RUBY_BIN takes higher priority to avoid other tools
REM conflict with our own (mainly the DevKit)
SET PATH=%RUBY_BIN%;%PATH%
@gouf
gouf / mechanize_link_getter.rb
Created December 11, 2013 13:45
2015年 就職情報サイトから、企業名で検索して紹介ページURL を取得する。
@gouf
gouf / new_gist_file_0.js
Created December 17, 2013 13:14
JavaScript の破壊的ソート問題と、その対策 From http://d.hatena.ne.jp/kitokitoki/20110615/p1
var a = ["aa", "cc", "bb"];
result = a.slice().sort();
console.log(a); //=> ["aa", "cc", "bb"] // a は変更されない
console.log(result); //=> ["aa", "bb", "cc"]
var b = ["aa", "cc", "bb"];
result = b.sort();
console.log(b); //=> ["aa", "bb", "cc"] // b も変更されている
console.log(result); //=> ["aa", "bb", "cc"]
@gouf
gouf / paste_and_remove.rb
Created December 20, 2013 09:29
ターミナルとかでファイルの削除リストを提示された時に使う。
str = <<PASTE
/usr/local/lib/pkgconfig/libcdt.pc
/usr/local/lib/pkgconfig/libcgraph.pc
/usr/local/lib/pkgconfig/libgvc.pc
/usr/local/lib/pkgconfig/libgvpr.pc
/usr/local/lib/pkgconfig/libpathplan.pc
/usr/local/lib/pkgconfig/libxdot.pc
/usr/local/lib/pkgconfig/osxfuse.pc
/usr/local/lib/pkgconfig/tcl.pc
/usr/local/lib/pkgconfig/tk.pc
@gouf
gouf / al.rb
Created December 20, 2013 15:27
bowser search angular の結果を加工してファイルに保存する1行スクリプト。
open('al', 'w').write %x{bower search angular}.to_s.split(/\n/).to_a.drop(2).map{|x| x.gsub /^\s+/, ''}.inject(''){|re, x| re += "#{x}\n"}
@gouf
gouf / pop.rb
Created December 24, 2013 08:24
DRB によるオブジェクトサーバ
require 'drb'
require 'eventmachine'
require 'pp'
EM.run do
DRb.start_service()
obj = DRbObject.new(nil, 'druby://localhost:9000')
EM.add_periodic_timer(2) do
3.times{pp obj.pop}
end
@gouf
gouf / clipboard_watch_and_download.rb
Created January 9, 2014 18:31
Mac のクリップボードを監視して、設定されたファイル拡張子をwget で実行フォルダにダウンロード。
require 'pp'
require 'clipboard'
module Downloader
@@target_file_exts = [:jpg, :png, :gif, :bmp, :doc, :pdf]
@@cache = []
def clipboard_text
#%x(pbpaste).scrub
Clipboard.paste.scrub
require 'pp'
max = 100
first_prime = 2
prime = [2]
list = (2..max).to_a
i = 2
while list.size > 1 do
list = list.select{|x| x % i != 0}
@gouf
gouf / code.rb
Created January 15, 2014 08:51
stupid coding. cypher encode / decode program. if you have boring, try refactoring.
def decrypt cypher
decoder = cypher.to_s.split('.').last.split(//).map{|x| x.to_i}
code = cypher.to_s.split('.').first.split(//)
decoder.inject("") {|res, x|
res += proc {|x|
if x == 0 then
" "
else
proc {|x| z = 'a'; x.times{z = z.succ}; z}.call(
code.shift(x).inject(:+).to_i
@gouf
gouf / launch_aws_ec2_instance.rb
Last active January 3, 2016 10:59
AWS EC2 インスタンスをRuby から立ち上げ。SSH キーを用意させるので、立ち上げたあとにそのまま利用できる。
require 'aws-sdk'
require 'pp'
# if not set region, it will set us-east by default
ec2 = AWS::EC2.new(region: 'ap-northeast-1')
# List up key pairs you have
#pp ec2.key_pairs.map(&:name)
# Available Regions