This file contains hidden or 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
r = Random.new(19930224); (1..22).sort_by { r.rand } | |
# => [4, 10, 13, 18, 7, 16, 20, 15, 22, 2, 19, 5, 17, 14, 8, 6, 9, 1, 11, 3, 21, 12] |
This file contains hidden or 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
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<title>Raphael</title> | |
<style type="text/css"> | |
</style> | |
</head> | |
<body> | |
<div id="holder"> | |
</div> |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'fileutils' | |
require 'net/https' | |
require 'yaml' | |
datadir = ARGV.shift | |
filenames = Dir.entries(datadir).select {|name| name =~ /\.(yml|yaml)$/} | |
rubyists = filenames.map {|filename| YAML.load_file(File.join(datadir, filename)).merge('filename' => filename) } |
This file contains hidden or 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
for file in `ls rubyists/*.jpg` | |
do | |
bname=`basename $file .jpg` | |
convert $file -sepia-tone '80%' sepiatones/$bname.jpg | |
done |
This file contains hidden or 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
puts 'Hello! May I help you?' | |
$stdin.lazy.reduce(Array.new 3) do |history, message| | |
history = ([message.strip!] + history).take 3 | |
break if history.all? {|msg| msg == 'BYE' } | |
reply = | |
case message | |
when 'BYE' | |
nil |
This file contains hidden or 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
#!/bin/bash | |
srcdir="${HOME}/svn/pjproject" | |
devpath="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer" | |
arch="i386" | |
cflags="-O2 -m32 -miphoneos-version-min=4.0" | |
ldflags="-O2 -m32 -miphoneos-version-min=4.0" | |
cd ${srcdir} |
This file contains hidden or 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
#!/bin/bash | |
base_url="https://github.com" | |
while read name | |
do | |
wget "${base_url}/${name}.keys" | |
done |
This file contains hidden or 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
# Example Answer to http://qiita.com/jnchito/items/c4a56046be1096c19b1c | |
def count_by_word(str) | |
raise ArgumentError, 'str should be a string' unless str.is_a? String | |
str.split.reduce(Hash.new(0)) {|rs, w| rs.merge(w => rs[w] + 1) } | |
end | |
describe "count_by_word" do | |
let(:results) { count_by_word(string) } |
This file contains hidden or 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
// http://qiita.com/t_uda/items/1969e09a970d71e4cfd6 | |
function hoge(x) { | |
switch (true) { | |
case x < 0: | |
console.log(x + " は自然数ではありません."); | |
break; | |
case x === 0: | |
console.log("ここでは 0 は自然数です."); | |
break; |
This file contains hidden or 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
TAX_RATE = 1.08 | |
# 「1.08 を掛けて→小数点以下を切り捨てる」という演算で target を超えない最大の数値を求める | |
# 戻値 [t: Fixnum, d: Fixnum, i: Fixnum, s: Fixnum] | |
# | |
# t: 元々の税込み価格 (= target) | |
# d: 求める税抜き価格 | |
# i: 計算結果の税抜き価格に税を乗せた価格 | |
# s: 差分 (t - i) | |
# |