Skip to content

Instantly share code, notes, and snippets.

@meltedice
meltedice / application.rb
Created November 22, 2013 07:59
rails 4.0.1 + rails_admin 0.5.0 (sass-rails 4.0.1) + less-rails 2.4.2 sass-rails will overwrite stylesheet_engine setting in config/application.rb via initializer hook. So rails g scaffold and other generators use :scss instead of :less Force set :less as stylesheet_engine via initializer hook to use :less.
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
@meltedice
meltedice / feature_spec_helper.rb
Created July 22, 2016 02:52
Wait for dynamic content with capybara feature spec
# wait_for_content 'Submit'
# wait_for_content 'Submit', selector: '.super-button'
# wait_for_content 'Submit', selector: 'form .super-button'
# wait_for_content 'Message', timeout_s: 5
# wait_for_content 'Messages?', timeout_s: 5
# wait_for_content '[ck]lass(es)?'
# wait_for_content 'Thanks' do
# puts 'Waiting...'
# end
#
@meltedice
meltedice / class-new-test.rb
Created September 5, 2016 02:32
How to pass value to a class that generated by Class.new in ruby
# How to pass value to a class that generated by Class.new in ruby
# ruby で Class.new で生成した class に値を渡す方法
def ClassTemplate(name)
Class.new do |klass|
klass.instance_variable_set :@my_name, name
def hello
puts "Hello, #{self.class.instance_variable_get(:@my_name)}!"
end
end
end
@meltedice
meltedice / pic-with-slices.go
Created October 2, 2017 04:55
A Tour of Go: Exercise: Slices
// https://go-tour-jp.appspot.com/moretypes/18
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for y, _ := range pic {
pic[y] = make([]uint8, dx)
@meltedice
meltedice / wordcount.go
Created October 2, 2017 05:29
A Tour of Go: Exercise: Maps
package main
import (
"strings"
"golang.org/x/tour/wc"
)
func WordCount(s string) map[string]int {
wordCount := make(map[string]int)
for _, word := range strings.Fields(s) {
@meltedice
meltedice / fibonacci-closure
Created October 2, 2017 05:52
A Tour of Go: Exercise: Fibonacci closure
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
f0 := 0
f1 := 1
return func() int {
@meltedice
meltedice / bookmarklet-jump-to-askens-this-morning.js
Created January 11, 2018 05:03
Jump to Asken's this morning page
javascript:var d=new Date();location.href='https://www.asken.jp/wsp/meal/breakfast/'+d.getFullYear()+'-'+('0'+(d.getMonth()+1)).slice(-2)+'-'+('0'+d.getDate()).slice(-2)