This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Node.js勉強中...HTTPリクエストをオウム返しするサーバを作ってみた | |
// http://qiita.com/manuluu/items/dd871a5a98e695b9129e | |
var http = require('http'); | |
// サーバ作る | |
var server = http.createServer(function(req, res) { // HTTPリクエスト受けたら実行されるメソッド | |
var req_str = ""; | |
// 読む (リクエスト行) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 36進数でちょっと遊ぶ (簡単な英文を書く) | |
# http://qiita.com/manuluu/items/ad2c471a1a1c6fd91a63 | |
module Base36Utils | |
def get_symbols(str) | |
syms = str.scan(/[^a-zA-Z]/).uniq.sort.join | |
end | |
def to_base36(base10, symbols="") | |
base10.to_s(36).gsub(/\d/){|d|symbols[d.to_i]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AAUtils | |
def get_chars(aa) | |
aa.chars.uniq.sort.join | |
end | |
def to_num(aa, chars) | |
aa.tr(chars, "0-9a-z").to_i(chars.size) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# シェルで比叡と対話する (hieisay) | |
# http://qiita.com/manuluu/items/90d867025cc617a29f5a | |
require 'optparse' | |
Version = '214.6' | |
DEFAULT = :default | |
class Hiei |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fibonacci(num) | |
[1,1].tap{|a|(num-2).times{a<<a[-2,2].inject(:+)}}[0,num] | |
end | |
#p fibonacci 10 #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mechanize' | |
name = "foo.html" | |
path = File.expand_path(name, __FILE__) | |
agent = Mechanize.new | |
page = agent.get("file://#{path}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def notification(message, title:"Ruby", subtitle:"", sound:"") | |
[message, title, subtitle, sound].each{|arg| arg.gsub!(/"/, '\\\\\"')} | |
scpt = 'display notification "%s"' % message | |
scpt << ' with title "%s"' % title | |
scpt << ' subtitle "%s"' % subtitle unless subtitle.empty? | |
scpt << ' sound name "%s"' % sound unless sound.empty? | |
system %|osascript -e "#{scpt.gsub(/"/, '\"')}"| | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File.expand_path(File.dirname(__FILE__)) | |
# スクリプトのパスからの相対パスを使いたいとき | |
# "./foo.rb"みたいにするとカレントフォルダによって変わってしまうので |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
@dir = Dir.home # home dir | |
# @dir = File.expand_path(File.dirname(__FILE__)) # script dir | |
def download(url, name) | |
open("#{@dir}/#{name}", "wb"){|file|file.write(open(url).read)} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
last = Date.new(Time.now.year, Time.now.month, -1) | |
days = (1..last.day).map{|d| '%2d' % d} | |
days.unshift *[nil] * (last + 1 << 1).wday | |
puts last.strftime "%B %Y" | |
puts days.each_slice(7).map{|week| week * "\t"} |
OlderNewer