Skip to content

Instantly share code, notes, and snippets.

View 2get's full-sized avatar
😌
Think

Mayoto Yoshida 2get

😌
Think
  • GMO Pepabo, Inc.
  • Tokyo, Japan
View GitHub Profile
@2get
2get / add_role_attribute_to_the_form_tag_in_simple_form.html.erb
Created May 30, 2014 06:38
How to add attribute to the form tag in simple_form
<%= simple_form_for(@user, html: { role: 'form' }) do |f| %>
<% end %>
@2get
2get / mountable engine into application development.md
Created June 3, 2014 07:32
mountable engine into application development
$ bundle config local.GEM_NAME /path/to/local/git/repository

Gemfile

gem 'GEM_NAME', git: '[email protected]:GEM_NAME', branch: 'master'
@2get
2get / ruby_private_and_protected.rb
Created June 18, 2014 03:51
ruby private and protected
class C1
def method
protected_method
self.protected_method
C1.new.protected_method
private_method
self.private_method rescue puts "ERROR self.private_method #{self.class.name}"
C1.new.private_method rescue puts "ERROR C1.new.private_method #{self.class.name}"
end
@2get
2get / date comparison in python.md
Created June 18, 2014 07:29
date comparision in python
Python 3.4.0 (default, Mar 26 2014, 11:08:39)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from time import time
>>> time()
1403076335.497517
>>> time() == time()
False
&gt;&gt;&gt; time() is time()
@2get
2get / konami.coffee
Last active August 29, 2015 14:02
konami.coffee
showKonami = ->
alert 'KONAMI'
inputs = []
input = (e) ->
inputs.push(e.keyCode)
if e.keyCode is 65
len = inputs.length
if inputs[len - 10] is 38 and inputs[len - 1] is 65
if [38, 38, 40, 40, 37, 39, 37, 39, 66, 65].join('') is inputs.slice(len - 10, len).join('')
@2get
2get / ga_link_track_event.html
Last active August 29, 2015 14:03
analytics link track event ( hitCallback )
@2get
2get / ruby_===.rb
Last active August 29, 2015 14:04
Ruby ===
p (1..5) === 3 #=> true レシーバは Range クラスのインスタンスだから、=== 演算子は引数が自身の範囲内に含まれるかを判定
p 3 === (1..5) #=> false レシーバは Fixnum クラスのインスタンスだから、=== 演算子は数値として等しいかを判定
p /おつかれ/ === 'おつかれさまです' #=> true レシーバは Regexp クラスのインスタンスだから、=== 演算子は引数の文字列がマッチするか判定
p 'おつかれさまです' === /おつかれ/ #=> false レシーバは String クラスのインスタンスだから、=== 演算子は同値判定
@2get
2get / config.ru
Created December 17, 2014 13:51
Hello Rack
require 'rack'
class HelloRack
def call(env)
[200, { 'Content-Type' => 'text/html' }, ['Hello Rack!']]
end
end
run HelloRack.new
@2get
2get / config.ru
Created December 17, 2014 13:58
The Single-File Rails Application
require 'rubygems'
require 'rails'
require 'active_support/railtie'
require 'action_dispatch/railtie'
require 'action_controller/railtie'
class SingleFile < Rails::Application
config.eager_load = true
config.cache_classes = true
@2get
2get / case_return.rb
Created February 5, 2015 06:11
case 式の返り値に対しての処理
def case1
i = 1
case i
when 1
5
end + 10
end
def case2