Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env escript
%% -*- erlang -*-
main([]) ->
main([100]);
main([Limit|_]) when is_list(Limit) ->
main([list_to_integer(Limit)]);
main([Limit|_]) ->
module Helper
def smash_whitespaces(&block)
capture(&block).lines.lazy.map(&:strip).reduce(StringIO.new, :<<).string
end
end
@takkkun
takkkun / unicorn.cap
Last active December 25, 2015 10:59
lib/capistrano/tasksにでも置いて使う
set :unicorn_config_path, -> { current_path.join('config', 'unicorn.rb') }
set :unicorn_pid_path, -> { current_path.join('tmp', 'pids', 'unicorn.pid') }
set :unicorn_env, -> { fetch(:rails_env) || fetch(:stage) }
SSHKit.config.command_map[:unicorn_stop] = 'kill -QUIT'
SSHKit.config.command_map[:unicorn_restart] = 'kill -USR2'
namespace :deploy do
def unicorn_running?
trait Expression {
def +(right: Expression) = Addition(this, right)
def *(right: Expression) = Multiplication(this, right)
def **(right: Expression) = Exponential(this, right)
}
object Expression {
implicit def intToConst(value: Int) = Const(value)
}
var Color = function() {
if (arguments.length == 1)
[this.r, this.g, this.b] = Color.parse(arguments[0]);
else if (arguments.length == 3)
[this.r, this.g, this.b] = arguments;
else
throw 'invalid number of arguments, takes one or three arguments';
};
Color.parse = function(color) {
@takkkun
takkkun / user.rb
Last active December 19, 2015 01:19
class User < ActiveRecord::Base
attr_accessor :current_phase
def self.thereafter(phase)
-> do
current_phase.nil? or current_phase >= phase
end
end
validates :email, presence: true, if: thereafter(1)
module Definable
def self.redefine(object, method_name, &process)
original_method = object.method(method_name)
object.define_singleton_method(method_name) do |*args, &block|
process[*args, &block]
original_method[*args, &block]
end
end
import org.atilika.kuromoji._
import collection.JavaConversions._
class Word(surface: String) {
override val toString = surface
}
object Word {
def fromToken(token: Token): Word = {
val surface = token.getSurfaceForm
case class Nyan(name:String, age:Int)
val nyans:List[Nyan] = List(Nyan("ねこがた", 2), Nyan("うーねこ", 4))
val has_wneko: PartialFunction[List[Nyan], Unit] = {
case Nil => println("うーねこのっといんざりすとなうよー")
case Nyan("うーねこ", _) :: _ => println("うーねこいんざりすとなうよー")
case _ :: rest => has_wneko(rest)
}
module Arel::AliasAttribute
def alias_attribute(new_name, old_name)
attribute_aliases.update(new_name.to_s => old_name.to_s)
end
def [](name)
super attribute_aliases[name.to_s] || name
end
def attribute_aliases