Skip to content

Instantly share code, notes, and snippets.

View cesare's full-sized avatar

SAWADA Tadashi cesare

View GitHub Profile
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]
<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>
@cesare
cesare / rubyist-pics.rb
Created May 25, 2013 06:34
Usage: rubyist-pics.rb LOCAL/PATH/TO/darashi/rubyistokei/data
#!/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) }
for file in `ls rubyists/*.jpg`
do
bname=`basename $file .jpg`
convert $file -sepia-tone '80%' sepiatones/$bname.jpg
done
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
#!/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}
@cesare
cesare / gist:8907390
Created February 9, 2014 22:59
fetch public keys registered on Github
#!/bin/bash
base_url="https://github.com"
while read name
do
wget "${base_url}/${name}.keys"
done
# 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) }
// 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;
TAX_RATE = 1.08
# 「1.08 を掛けて→小数点以下を切り捨てる」という演算で target を超えない最大の数値を求める
# 戻値 [t: Fixnum, d: Fixnum, i: Fixnum, s: Fixnum]
#
# t: 元々の税込み価格 (= target)
# d: 求める税抜き価格
# i: 計算結果の税抜き価格に税を乗せた価格
# s: 差分 (t - i)
#