Skip to content

Instantly share code, notes, and snippets.

View aileron's full-sized avatar

AILERON aileron

View GitHub Profile
class Array
def eql_all? &block
block = lambda {|a|a} unless block
max=self.length
i=0
c = block.( self[i] )
n = nil
result = while i+1<max
n=block.(self[i+1])
break false unless c == n
@aileron
aileron / gist:1183652
Created August 31, 2011 14:18
pixiv member
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'open-uri'
check = lambda {|i| open("http://www.pixiv.net/member.php?id=#{i}").read.index("該当ユーザーは既に退会したか、存在しないユーザーIDです")}
i=3600000
loop do
print "#{i-=1000} "
break unless check.(i)
@aileron
aileron / gist:1194834
Created September 5, 2011 12:23 — forked from yamitake/gist:1194813
美人時計の地域ベストを表示するスクリプト。
var tiiki = ["hokkaido",
"aomori",
"iwate",
"miyagi",
"akita",
"yamagata",
"fukushima",
"ibaraki",
"tochigi",
"gunma",
@aileron
aileron / gist:1641421
Created January 19, 2012 17:48
sexy hash
class Hash; def &(x) self.merge(x) end end
@aileron
aileron / gist:2152307
Created March 21, 2012 20:09
なんでオブジェクト指向の説明って、へんてなサンプルコードをむりやりクラスにするのだろう。って思って無駄にリファクタリングしてみた。
<?php
function getLabel($opt)
{
$colors = Array(1=> "blue", 0=> "pink" );
$namings = Array( "ちゃん", "くん", "さん", "君" );
extract( array_merge(Array( "name"=> "", "sex"=> 0, "suffix"=>"", "coloring"=>"","school"=>false ), $opt) );
$color = $colors[ $sex ];
$naming = $names[ ($sex | (($age >= 12)*2)) ];
@aileron
aileron / gist:2156651
Created March 22, 2012 06:31
ruby のインストール方法 ( rbenv + ruby-build )
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zprofile
echo 'eval "$(rbenv init -)"' >> ~/.zprofile
git clone git://github.com/sstephenson/ruby-build.git
cd ruby-build
./install.sh
CONFIGURE_OPTS="--with-readline-dir=/usr/local" rbenv install 1.9.3-p0
rbenv global 1.9.3-p0
rbenv rehash
@aileron
aileron / gist:2300796
Created April 4, 2012 12:30
短縮URLとか展開する
def extract_tiny_url(url)
url = URI.parse(url) if url.is_a?String
TCPSocket.open(url.host, url.port) do|s|
s.write("GET #{url.path} HTTP/1.1")
s.write("\nHost: #{url.host}")
s.write("\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:11.0) Gecko/20100101 Firefox/11.0")
s.write("\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
s.write("\nAccept-Language: ja-JP-mac,ja;q=0.8,en-US;q=0.5,en;q=0.3")
s.write("\n\n")
text = (s.readlines.join('').scan /URL=([a-z:\/\.\_0-9]*)/).flatten.first
@aileron
aileron / gist:2305094
Created April 4, 2012 19:50
sexy enumerator
class Enumerator
def filter(c=nil,&b)
s = self
e = ::Enumerator.new do |y|
s.each do |x|
y << (c||b).call(x)
end
end
return e unless c
e.each &b
@aileron
aileron / gist:2347987
Created April 10, 2012 02:31
てすと

Hello

@aileron
aileron / gist:2464233
Created April 22, 2012 13:58
accesslog rack モジュール
class AccessLog
class Handler
def initialize(app)
@app = app
end
def call(env)
session = env["rack.session"] && user_id = session["user_id"]
ipaddress = env["REMOTE_ADDR"]
user_agent = env["HTTP_USER_AGENT"]
referer = env["HTTP_REFERER"]