This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env escript | |
%% -*- erlang -*- | |
main([]) -> | |
main([100]); | |
main([Limit|_]) when is_list(Limit) -> | |
main([list_to_integer(Limit)]); | |
main([Limit|_]) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Helper | |
def smash_whitespaces(&block) | |
capture(&block).lines.lazy.map(&:strip).reduce(StringIO.new, :<<).string | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |