Skip to content

Instantly share code, notes, and snippets.

@quanon
quanon / enum_value_getter.rb
Created May 13, 2016 09:21
enum の整数値をゲットするマン
# enum 定義の後で include すること。
module EnumValueGetter
extend ActiveSupport::Concern
included do
defined_enums.keys.each do |name|
define_method("#{name}_value") { self[name] }
end
end
end
@quanon
quanon / Gemfile
Created February 6, 2016 04:39
Rails 5.0.0.beta2 をインストールした際のログ
ruby '2.3.0'
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0.beta2'
@quanon
quanon / binary_number_counter.ino
Created January 6, 2016 16:25
2 進数カウンター
const int LED4 = 13;
const int LED3 = 12;
const int LED2 = 11;
const int LED1 = 10;
const int BTN1 = 7;
int old_input = LOW;
int new_input = LOW;
int count = 0;
@quanon
quanon / .zshrc
Last active August 29, 2015 14:26
ターミナルを可愛くする
export PROMPT=$'%{$fg[magenta]%}|%c|*\'-\'\) %{$reset_color%}'
export PROMPT=$'|%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[red]%}%30<...<%~%<<%{$reset_color%}|*\'-\'\) %(!.#.$) '
@quanon
quanon / highlight_followers.js
Last active August 29, 2015 14:23
「フォローされています」をハイライトして両思いを見つけやすくするためのスクリプト
// ==UserScript==
// @name Highlight followers
// @namespace quanon
// @version 0.1
// @author QUANON
// @match https://twitter.com/following
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @grant none
// ==/UserScript==
@quanon
quanon / fizzbuzz.ex
Created June 24, 2015 09:50
Elixir で FizzBuzz
calc_rems = fn (n) -> {rem(n, 3), rem(n, 5), n} end
fizzbuzz = fn
{0, 0, _} -> "FizzBuzz"
{0, _, _} -> "Fizz"
{_, 0, _} -> "Buzz"
{_, _, n} -> n
end
IO.inspect(1..50 |> Enum.map(calc_rems) |> Enum.map(fizzbuzz))
@quanon
quanon / array_extention.rb
Created June 18, 2015 08:50
reject_if (delete_if の返り値を削除後の self ではなく、削除した要素に変更したバージョン)
module ArrayExtention
def reject_if(&block)
rejected = []
delete_if do |value|
if block.call(value) # or if yield
rejected << value
true # なくてもいいけど僕の好み的に明示的に true を返したかった。
end
end
module Extension::ActiveRecordExtension
extend ActiveSupport::Concern
included do
# (参考)
# OR operator in WHERE clause with Arel in Rails 4.2
# http://stackoverflow.com/questions/27627390/or-operator-in-where-clause-with-arel-in-rails-4-2
#
# ActiveRecord::QueryMethods::WhereChain
# https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/relation/query_methods.rb
@quanon
quanon / jmotto.js
Last active August 29, 2015 14:20
j-motto のタイムカードに就業時間の列を追加するための user script
// ==UserScript==
// @name j-motto Userscript
// @namespace quanon
// @version 0.1.0
// @author QUANON
// @include https://gws45.j-motto.co.jp/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @grant none
// ==/UserScript==
@quanon
quanon / question.md
Last active August 29, 2015 14:19
集合から要素を n 回取り出した際に重複あり/重複なしがちょうど半々となるには?

問題

x 面のダイスがある。それを n 回振り、ダイスの数ごとに出た回数をカウントする。
この時、出た回数が 1 回の目の種類と 2 回以上の目の種類の比率が
1:1 となるには x は何である必要があるか。n を使って表せ。

出た回数が 1 回の目の数、2 回以上の目の数の比率が 1:1 となるってどういうこと?

x = 12 (12 面ダイス)
n = 10 (10 回振った)