Skip to content

Instantly share code, notes, and snippets.

@nysalor
nysalor / const_test.rb
Last active August 29, 2015 14:03
const and class
class Foo
attr_accessor :me
def initialize(arg)
@me = arg
end
end
class Bar
def execute
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
# 超簡易webサーバ
require "webrick"
include WEBrick
HTTPServer.new(Port: 8888, DocumentRoot: ".").start
ruby -r 'webrick' -e 'include WEBrick;HTTPServer.new(Port: 8888, DocumentRoot: "public_html/").start'
(Date.new(2001,1,1)..Date.new(2019,12,31)).select { |x|
str = x.to_s.gsub('-0','')
str.split('').uniq.size == str.size
}.size
=> 210
@nysalor
nysalor / .zshenv.sh
Created November 24, 2012 15:36
zsh settings for non-interactive shell with rvm
PATH=$HOME/.rvm/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
@nysalor
nysalor / rails_app.yml
Created August 2, 2012 17:02
tmuxinator sample settings
# ~/.tmuxinator/rails_app.yml
# you can make as many tabs as you wish...
project_name: rails_app
project_root: ~/src/rails/rails_app
tabs:
- main:
layout: even-horizontal
panes:
- #shell
@nysalor
nysalor / age_calc.rb
Created July 27, 2012 11:21
TDD sample production code
class AgeCalc
attr_accessor :birthday
def age
@age ||= calculate_age
end
def calculate_age
if @birthday
(Time.now.strftime("%Y%m%d").to_i - @birthday.strftime("%Y%m%d").to_i) / 10000
# -*- coding: utf-8 -*-
require './age_calc'
require 'date'
describe AgeCalc do
before do
@age_calc = AgeCalc.new
end
it "birthdayで誕生日が設定できること" do
@nysalor
nysalor / rspec_crash_report.log
Created May 11, 2012 07:33
rspec crash report on MacOS 10.7.3
Process: ruby [60151]
Path: /Users/USER/*/ruby
Identifier: ruby
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: ruby [60090]
Date/Time: 2012-05-11 16:15:34.942 +0900
OS Version: Mac OS X 10.7.3 (11D50b)
Report Version: 9