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
if $0.end_with?('/rake') && ARGV[0].start_with?('db:migrate') && Rails.env.development? | |
#require 'active_record/migration' | |
klass = | |
case (adapter_class = ActiveRecord::Base.connection.class.to_s) | |
when 'ActiveRecord::ConnectionAdapters::SQLite3Adapter' | |
require 'active_record/connection_adapters/sqlite_adapter' | |
ActiveRecord::ConnectionAdapters::SQLiteAdapter | |
when 'ActiveRecord::ConnectionAdapters::Mysql2Adapter' | |
require 'active_record/connection_adapters/mysql2_adapter' |
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
# TODO : | |
# 1 : return the attributes that are missing | |
# 2 : in views, also test presence of documents | |
# | |
require_relative 'completeness_measure' | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
describe CompletenessMeasure do |
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
slip() { | |
sleep 1 | |
} | |
rm -rf contents | |
mkdir contents | |
cd contents | |
git init |
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 Fixnum | |
def to_roman | |
[].tap do |res| | |
a, b = self.divmod(10) ; res << ([''] + %w(I II III IV V VI VII VIII IX))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(X XX XXX XL L LX LXX LXXX XC))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(C CC CCC CD D DC DCC DCCC CM))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(M MM MMM Mv v vM vMM vMMM Mx))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(x xx xxx xl l lx lxx lxxx xc))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(c cc ccc cd d dc dcc dccc cm))[b] | |
end.reverse.join |
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
# what: a Regexp-based parser. alainravet - 2016 jan | |
SYNTAX_RULES = { | |
/^PRINT\b/ => { | |
/^PRINT\s*\z/ => :new_line_command, | |
/^PRINT (.*)/ => :print_command, | |
}, | |
/HELP/i => :help_command, | |
} |
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
# Usage : | |
# EnvVarsChecker.new do | |
# env_includes 'USER' | |
# env_includes 'USER', in: -> { `echo $USER`.chomp} | |
# env_includes 'USER', in: %w(deployer deploy rails) | |
# end | |
class EnvVarsChecker | |
class Error < RuntimeError ; 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
# Ad-hoc code (no library) | |
# | |
module GemUtils | |
def self.gem_names # version 1 : 1st call | |
GEM_NAMES_PRELOADER.join.value # **1 : wait and return this if the cache is not ready | |
end | |
private |
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
# response to http://jumpstartlab.com/news/archives/2013/04/23/the-death-of-ifs | |
#----------------- | |
# Commands : | |
#----------------- | |
class Command | |
class Quit ; def execute ; exit end end | |
class Invalid ; def execute ; puts 'invalid command' end end | |
class Tweeting ; def execute ; puts "tweeting" 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
module BinaryFileStringUtils | |
def byte_to_int | |
self.unpack('U').first | |
end | |
def little_endian_to_int | |
# source : http://stackoverflow.com/questions/5236059/unpack-signed-little-endian-in-ruby | |
arr, bits, num = self.unpack('V*'), 0, 0 | |
arr.each do |int| | |
num += int << bits |
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 Hash | |
def diff(other) | |
(self.keys + other.keys).uniq.inject({}) do |memo, key| | |
unless self[key] == other[key] | |
if self[key].kind_of?(Hash) && other[key].kind_of?(Hash) | |
memo[key] = self[key].diff(other[key]) | |
else | |
memo[key] = [self[key], other[key]] | |
end | |
end |
NewerOlder