Skip to content

Instantly share code, notes, and snippets.

View aq2bq's full-sized avatar

aq2bq aq2bq

  • YUKASHIKADO Inc.
  • Japan
  • X @aq2bq
View GitHub Profile
@aq2bq
aq2bq / spree_state_create.rb
Last active December 19, 2015 05:49
Spree::Stateの初期データ投入。/ ありがとうございます: https://gist.github.com/koseki/38926
# encoding: utf-8
Spree::Country.create!({"name"=>"日本", "iso3"=>"JPN", "iso"=>"JP", "iso_name"=>"JAPAN", "numcode"=>"392"}, :without_protection => true)
country = Spree::Country.find_by_name('日本')
Spree::State.create!({"name"=>"北海道", "abbr"=>"hokkaido", :country=>country}, :without_protection => true)
Spree::State.create!({"name"=>"青森県", "abbr"=>"aomori", :country=>country}, :without_protection => true)
Spree::State.create!({"name"=>"岩手県", "abbr"=>"iwate", :country=>country}, :without_protection => true)
Spree::State.create!({"name"=>"宮城県", "abbr"=>"miyagi", :country=>country}, :without_protection => true)
Spree::State.create!({"name"=>"秋田県", "abbr"=>"akita", :country=>country}, :without_protection => true)
Spree::State.create!({"name"=>"山形県", "abbr"=>"yamagata", :country=>country}, :without_protection => true)
@aq2bq
aq2bq / StudyingGit.sh
Last active July 19, 2017 10:12
StudyingGit:復習メモ
# ブランチ
## リモートのgitブランチをローカルにチェックアウトする
$ git checkout -b branch_name origin/branch_name
## - http://sessan.hatenablog.com/entry/2012/11/04/132746
## masterブランチに加えられた変更をトピックブランチへマージする
$ git checkout topic_branch
$ git merge master

Rubyもくもく会 2013/07/20

先週末、神戸東灘区の区民会館で開催された「西脇.rb & 東灘.rb もくもく会」へ参加してきました。

もくもく会とは?

もくもく会は今年3月から始まって5回目の開催で、自分自身は4回目の参加です。内容はシンプルで、もくもく会でやりたいこと(普段開発しているもや調べたいこと)を互いに紹介したものを2,3時間やってみて、それに質問したり、コードレビューしたりするというものです。

これはこの地域での、プレゼンを見るだけだったりや研究会のようなメジャーなプログラミングイベントとは大いに違う点です。もくもく会は実際にコードを書いて、他の開発者からフィードバックをもらって学習することに重きをおいています。本で読んでいるだけでは得られない効果があります。

@aq2bq
aq2bq / seeds.rb
Last active July 28, 2016 01:41
[JPローカライズ] Spree 2.0.x 向け seeds.rb (Spree 2.1.1 with Rails4 用は https://gist.github.com/aq2bq/6790523 )
# encoding: utf-8
Rails.application.config.active_record.whitelist_attributes = false
ActiveRecord::Base.class_eval do
class << self
def create_or_update! attrs={}
instance = first_or_initialize(attrs, :without_protection => true)
instance.save!
end
@aq2bq
aq2bq / seeds.rb
Last active July 28, 2016 01:42
[JPローカライズ]Spree 2.1.1 with Rails4 用シードファイル
# encoding: utf-8
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
@aq2bq
aq2bq / heroku.sh
Last active August 29, 2015 14:00
Deploy Lokka to Heroku
# Regist public-key
$ heroku login
# => input heroku account, email and password
# Remove registered public-key
$ heroku keys:clear
# => All keys removed.
# Reregist public-key
$ heroku keys:add
@aq2bq
aq2bq / fizzbuzz.js
Created July 10, 2015 02:36
Fizz Buzz on Javascript
// Logic 1: The shortest
(function(i,c){while(i<=100){if(i%15==0){c("FizzBuzz")}else if(i%3==0){c("Fizz")}else if(i%5==0){c("Buzz")}else{c(i)}i++}})(1,console.log.bind(console));
// Logic 2: Use Array#forEach
(function(i,a){while(i<=100){a.push(i);i++}return a;})(1,[]).forEach(function(i){
if(i % 15 == 0){
console.log("FizzBuzz");
} else if(i % 3 == 0) {
console.log("Fizz");
} else if(i % 5 == 0){
@aq2bq
aq2bq / konami_command.js
Last active April 14, 2016 05:00
KONAMI Command
var konamiCommand = (function(i, commands){
function keyDown(e) {
e.keyCode == commands[i] ? i++ : i = 0;
if (i == commands.length) alert('KONAMI!');
}
window.addEventListener('keydown', keyDown);
})(0, [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]);
@aq2bq
aq2bq / build.rb
Last active June 9, 2016 10:28
Summary Generator for mdBook
require 'pathname'
PATHS = Pathname.glob('./src/**/[^SUMMARY]*.md')
paths = PATHS.each_with_object({}) do |path, dirs|
unless dirs[path.parent]
dirs[path.parent] = []
end
dirs[path.parent] << path
end
@aq2bq
aq2bq / natural_or_zero.rb
Last active January 23, 2020 06:01
[Benchmark] f(int) returns natural number or zero - ruby
require 'benchmark'
q = 10000000
Benchmark.bm 10 do |r|
r.report "IF" do
f = ->(i){ i < 0 ? 0 : i }
q.times {|i| f.call(i) }
end
r.report "ABS" do
f = ->(i){ (i + i.abs) / 2 }