Skip to content

Instantly share code, notes, and snippets.

View joker1007's full-sized avatar

Tomohiro Hashidate joker1007

View GitHub Profile
module Foo
def bar
puts "bar"
end
end
class Hoge
include Foo
def bar
puts "hoge"
require "rubygems"
require "bundler/setup"
require "tapp"
class Regexp
def self.build(*numbers)
nums = []
numbers.each do |num|
if num.is_a? Range
nums.concat(num.to_a)
@joker1007
joker1007 / roman_number.rb
Created April 25, 2012 15:09
Fixnum convert to Roman Number String
class Fixnum
def to_roman
return "" unless (1..3999).include?(self)
digit_count = Math.log(self, 10).to_i
case digit_count
when 0
minor = "I"
major = "V"
@joker1007
joker1007 / Gemfile
Created June 1, 2012 08:03
Get github activity from atom feed, and notify to Skype.
source "https://rubygems.org"
gem "actionpack"
gem "rype"
gem "awesome_print"
gem "simple-rss"
@joker1007
joker1007 / amida.hs
Created June 10, 2012 07:19
Amida Generator
import System.Environment
import System.Random
import Control.Monad
import Data.List
import Data.List.Split
data Amida = Amida { amidaRow :: Int, amidaCol :: Int, amidaMap :: [[Bool]] } deriving (Show)
main :: IO ()
main = do (r:c:[]) <- getArgs
import System.Environment
main :: IO()
main = do a <- getArgs
putStrLn $ digitToEng $ read $ head a
digitToEng :: Int -> String
digitToEng n
| n == 0 = "zero"
| n == 1 = "one"
Earthquake.init do
output do |item|
next unless item["_stream"] && item["user"]
if item["user"]["screen_name"] =~ /usagee_audio/i
notify item["text"], :title => "#{item["user"]["screen_name"]}"
end
end
end
class User < ActiveRecord::Base
attr_accessible :image, :name, :provider, :screen_name, :uid
def self.find_or_create_with_omniauth(auth)
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"])
unless user
user = User.new
user[:provider] = auth["provider"]
user[:uid] = auth["uid"]
class SessionsController < ApplicationController
def callback
auth = request.env["omniauth.auth"]
user = User.find_or_create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to posts_url, :notice => "Signed in!"
end
def failure
end
<h1>Listing posts</h1>
<% if current_user %>
login user: <%= current_user.screen_name %>
<% end %>
<table>
<tr>
<th>Title</th>
<th>Body</th>
<th></th>