Skip to content

Instantly share code, notes, and snippets.

#coding:utf-8
def fuga(n, i, n_max)
kugiru = 2 ** (i+1)
tonari = 2 ** i
if(n % kugiru < kugiru/2)
n + tonari
else
n - tonari
@mtsmfm
mtsmfm / template.rb
Created April 19, 2013 03:57
Rails Application Template for Rails Tutorial Chapter 3
run 'echo "" > Gemfile'
add_source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem_group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
end
require "spring/watcher/abstract"
require "spring/watcher/listen"
require "spring/watcher/polling"
module Spring
class << self
attr_accessor :watch_interval
attr_writer :watcher
end
@mtsmfm
mtsmfm / Rakefile
Created April 24, 2013 08:26
qwik2md
task :default => :convert
desc "convert qwik to markdown (using pbcopy/pbpaste for osx)"
task :convert do
file = IO.popen('pbpaste', 'r+')
str = file.map do |s|
s.gsub!(/^(\*+)/){ '#' * $1.length }
s.gsub!(/^(-++)/){ ' ' * ($1.length - 1) + '-' }
s.gsub!(/\[\[(.*?)\|(.*?)\]\]/){ "[#{$1}](#{$2})" }
s
@mtsmfm
mtsmfm / utilities.rb
Created May 15, 2013 00:52
feature spec でも request spec でも controller spec でも 同様にログインしたい
def sign_in(user)
case example.metadata[:type]
when :controller, :request
cookies[:remember_token] = user.remember_token
when :feature
visit signin_path
fill_in "Email", with: user.email.upcase
fill_in "Password", with: user.password
click_button "Sign in"
else
@mtsmfm
mtsmfm / Rakefile
Last active December 17, 2015 09:49
にっぽーさくせー
#coding:utf-8
require 'fileutils'
task :default => :create_todays_report
desc "create today's almost daily report"
task :create_todays_report do
report = Report.new
report.create_dir
report.create_file
@mtsmfm
mtsmfm / template.rb
Created June 30, 2013 15:58
Rails application template
gem 'haml-rails'
gem 'omniauth'
gem_group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'guard-rspec'
gem 'database_cleaner'
gem 'erb2haml'
end
@mtsmfm
mtsmfm / 1.9.2-p136
Created July 4, 2013 10:48
ruby-build custom definition 1.9.2-p136
require_gcc
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz#36c852831d02cf90508c29852361d01b"
install_package "ruby-1.9.2-p136" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p136.tar.gz#6e17b200b907244478582b7d06cd512e"
install_package "rubygems-1.8.23" "http://production.cf.rubygems.org/rubygems/rubygems-1.8.23.tgz#178b0ebae78dbb46963c51ad29bb6bd9" ruby
@mtsmfm
mtsmfm / file1.txt
Created December 26, 2013 08:46
Markdown記法チートシート ref: http://qiita.com/mtsmfm/items/9e611b9aba3494d6ce78
| Left align | Right align | Center align |
|:-----------|------------:|:------------:|
| This | This | This |
| column | column | column |
| will | will | will |
| be | be | be |
| left | right | center |
| aligned | aligned | aligned |
@mtsmfm
mtsmfm / test.hs
Last active January 2, 2016 01:59
greet :: String -> String
greet name
| name == "Juan" = niceGreeting ++ " " ++ name
| otherwise = badGreeting ++ " " ++ name
where niceGreeting = "Hello! So very nice to see you,"
badGreeting = "Oh! Pfft. It's you."
greet' :: String -> String
greet' "Juan" = niceGreeting ++ " " ++ "Juan"
where niceGreeting = "Hello! So very nice to see you,"