Skip to content

Instantly share code, notes, and snippets.

describe Hoge do
before do
@h = Hoge.new
end
describe Hoge, "メソッドAについて" do
it "0には1を返す" do
@h.method_a(0).should == 1
end
end
end
#include <iostream>
using namespace std;
class TEST1{
typedef int id;
public:
A(){};
void set(id n){
x = n;
};
def fact(x)
x > 1 ? x * fact(x-1) : 1
end
def f(x)
return fact(x).to_s.reverse.scan(/^0+/).to_s.size
end
if $0 == __FILE__
p f(ARGV[0].to_i)
require 'rubygems'
require 'mechanize'
require 'hpricot'
require 'open-uri'
agent = Mechanize.new
agent.user_agent_alias = 'Windows IE 7'
page = agent.get("https://twitter.com/login")
f = page.forms[0]
f["session[username_or_email]"] = "username"
# -*- coding: utf-8 -*-
$KCODE='u'
t_a = "釣りゲームはGree".split(//)
s = t_a.size
c = ""
ARGV[0].to_i.times do |i|
c += t_a[0..rand(s).to_i].join("")
end
c += "、無料です"
puts c
class Object
def to_i_or_nil
if self.nil?
return nil
else
return self.to_i
end
end
end
#include <unordered_map>
#include <map>
#include <iostream>
using namespace std;
struct myeq : std::binary_function<pair<int , int> , pair<int , int> , bool>{
bool operator() (const pair<int , int> & x , const pair<int , int> & y) const{
//keyの一致って普通これですよね
return x.first == y.first && x.second == y.second;
#include <unordered_map>
#include <map>
#include <iostream>
using namespace std;
struct myeq : std::binary_function<pair<int , int> , pair<int , int> , bool>{
bool operator() (const pair<int , int> & x , const pair<int , int> & y) const{
//keyの一致って普通これですよね
return x.first == y.first && x.second == y.second;
@ybenjo
ybenjo / google_tex.rb
Created January 1, 2011 15:31
convert hatena-tex to google chart api's tex
require 'cgi'
google_url = "http://chart.apis.google.com/chart?cht=tx&chl="
$<.each{|l|
l.chomp!
l.scan(/(\[tex:(.*?)\]){1,}/).each do |e|
math = e[1]
url_math = CGI.escape(math)
l.sub!(/#{Regexp.quote(e[0])}/,"<img src=\"#{google_url}#{url_math}\">")
end
puts l
@ybenjo
ybenjo / one
Created March 14, 2011 14:03
aaa
cat f_1.csv|ruby -e '$<.each{|l|ary = l.chomp.split(",");3.upto(4){|i|ary[i]=0 if ary.include?("未満");if ary[i] != "-";ary[i]=ary[i].gsub(/[^0-9\.]/,"");end;};puts ary.join(",")}' | less