Skip to content

Instantly share code, notes, and snippets.

data = [
# [ id, input, expected ],
[ 0, "4*5+6&7|8", "44" ],
[ 1, "15*5", "75" ],
[ 2, "15+5", "20" ],
[ 3, "15&5", "5" ],
[ 4, "15|5", "15" ],
[ 5, "30*15*5", "2250" ],
[ 6, "30*15+5", "600" ],
[ 7, "30*15&5", "150" ],
# -*- coding: utf-8 -*-
require 'cgi'
require 'rexml/document'
require 'open-uri'
class Suggest
attr_reader :response
def initialize
@query_base = "http://www.google.co.jp/complete/search?output=toolbar&hl=ja&q=%s"
# coding: utf-8
require 'test/unit'
require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'lib', 'zenra')
class ZenraTest < Test::Unit::TestCase
def setup
@appid = ENV['YAHOO_APPID']
end
require 'formula'
<<-COMMENTS
This is the Homebrew formula for Python.
Versions
--------
This formula is currently tracking version 2.6.x.
@kwappa
kwappa / emacs.rb
Created March 9, 2011 07:25
emacs 23.2 formula for homebrew with `fix-shiftmodifier-with-ime.patch`
require 'formula'
class Emacs <Formula
url 'http://ftp.gnu.org/pub/gnu/emacs/emacs-23.2.tar.bz2'
md5 '057a0379f2f6b85fb114d8c723c79ce2'
homepage 'http://www.gnu.org/software/emacs/'
if ARGV.include? "--use-git-head"
head 'git://repo.or.cz/emacs.git'
else
@kwappa
kwappa / emacs.rb
Created July 26, 2011 09:09
emacs 23.3a formula for homebrew with Xcode4.1 / Lion / --cocoa
require 'formula'
class Emacs < Formula
url 'http://ftp.gnu.org/pub/gnu/emacs/emacs-23.3a.tar.bz2'
md5 'f2cf8dc6f28f8ae59bc695b4ddda339c'
homepage 'http://www.gnu.org/software/emacs/'
skip_clean :all
if ARGV.include? "--use-git-head"
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
file_name = ARGV[0]
if !file_name || !File.exists?(file_name)
puts "file not found."
exit
end
File.open(file_name) { |f|
@kwappa
kwappa / comp_gacha_oneliner.rb
Created May 10, 2012 11:14
コンプガチャをシミュレートしてみよう
r = Array.new(12).fill(0) ; while (r.include?(0)) do r[rand(r.count)] += 1 ; end ; puts "#{r.count}個のガチャをコンプするために #{r.inject(:+)}回抽選しました。"
@kwappa
kwappa / mb_width.rb
Created June 19, 2012 06:13
マルチバイト文字まじりの文字列を等幅フォントで表示するために文字数を数える
# -*- coding: utf-8 -*-
require 'rspec'
class String
def mb_width
self.split('').inject(0) { |r, c| c =~ /^[ -~。-゚]*$/ ? r += 1 : r += 2 ; r }
end
end
describe String do
@kwappa
kwappa / Guardfile
Created June 21, 2012 05:36
guard-rspec, guard-spork, guard-livereload を使うための最低限のGuardfileをメモっておく
# https://github.com/guard/guard-rspec
guard 'rspec', :version => 2, :all_after_pass => false, :all_on_start => false, :cli => '--color --format nested --fail-fast --drb' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
# https://github.com/guard/guard-spork
guard 'spork', :rspec_env => { 'PADRINO_ENV' => 'test' } do
watch('Gemfile')