Skip to content

Instantly share code, notes, and snippets.

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 / 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
@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 / 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 / .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 / 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 / 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 / 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
var page = require('webpage').create();
var args = require('system').args;
page.viewportSize = {
width: 1200,
height: 780
};
page.open(args[1], function (status) {
if (status !== 'success') {
# ~/.config/fish/config.fish
## peco ##
function fish_user_key_bindings
bind \cr peco_select_history
end
## rbenv ##
set -x PATH $HOME/.rbenv/bin $PATH
rbenv init - | source