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
# | |
# extension for rspec | |
# this extension enables to check should_receive in stub_chain | |
# you must require this file in 'spec/spec_helper.rb' | |
# | |
# | |
# Example: | |
# in controller, | |
# | |
# def index |
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
# | |
# write it in the bottom of spec/spec_helper.rb | |
# | |
def method_missing(name, *args) | |
if matched = name.to_s.match(/mock_(.*)/) | |
klass = matched[1].classify.constantize | |
var_name = "@#{name.to_s}" | |
self.class.send(:define_method, name) do |*stubs| | |
stubs = stubs.try(:first) || {} | |
instance_variable_get(var_name) || |
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
class BaseClass | |
def self.find | |
"find" | |
end | |
end | |
# in class definition | |
class ClassA < BaseClass | |
def self.find_with_my_name | |
find_without_my_name + " ClassA" |
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
#include <stdio.h> | |
void main(int argc, char** argv){ | |
int i, a = atoi(argv[1]), b = atoi(argv[2]), sum = 0; | |
for(i = (a > 0 ? a : 0); i <= b && i <= 100; i ++){ | |
sum += (1 - i % 2) * i; | |
} | |
printf("sum = %d\n", sum); | |
} |
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 'net/http' | |
require 'uri' | |
require 'kconv' | |
Net::HTTP.version_1_2 | |
puts 'require url' and exit if ARGV[0].nil? |
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
# -*- coding: utf-8 -*- | |
# | |
# Earthquakeを実況モードにするプラグインです | |
# 普通に起動した後 | |
# :tsunami #K-ON #tbs | |
# のようにして実況モードに入ります | |
# | |
# すると #K-ON (空白区切りで最初のキーワードのみ) で検索した結果が | |
# リアルタイムに更新されます | |
# |
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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
miko = Fiber.new do | |
cnt = 0 | |
puts "みなさーん 元気ですかー!" | |
Fiber.yield | |
puts "それでは早速、いってみよー!" | |
Fiber.yield |
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 Earthquake | |
attr_accessor :ng_list | |
def self.ng_list | |
@ng_list ||= [] | |
end | |
def self.ng_list=(ng_list) | |
@ng_list = ng_list | |
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
# -*- coding: utf-8 -*- | |
Earthquake.init do | |
output :tweet do |item| | |
next unless item["text"] | |
info = [] | |
if item["in_reply_to_status_id"] | |
info << "(reply to #{id2var(item["in_reply_to_status_id"])})" | |
elsif item["retweeted_status"] | |
info << "(retweet of #{id2var(item["retweeted_status"]["id"])})" |
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
class Integer | |
def sample(num = 1) | |
to_a.sample(num) | |
end | |
def to_a | |
@to_a ||= self.times.map{|i| i + 1} | |
end | |
end |
OlderNewer