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
brew install cowsay | |
x = (<<'END') | |
don't escape the backslash, f.ex /\:/\ | |
END | |
IO.popen(['cowsay', message]) do |process| | |
process.read | |
end | |
$ bundle 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_lcd_matrix(sep=' ') | |
segments_per_row_per_digit=[ | |
' ._. ._. __. ._. ._. __. ._. ._.' .scan(/ (...)/).flatten, | |
' | | | ._| __| |_| |_. |_. _| |_| |_|' .scan(/ (...)/).flatten, | |
' |_| | |_. __| | ._| |_| ..| |_| ._|' .scan(/ (...)/).flatten | |
] | |
lcd_rows = [[],[],[]] | |
self.to_s.chars.each do |s| | |
digit = s.to_i |
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
i - OUTSIDE CALL (calling this private method is normally forbidden) | |
a_method was called | |
i - INSIDE CALL | |
a_method was called | |
Process finished with exit code 0 |
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
#!/bin/sh | |
bundle install | tail -1 | |
rm log/test.lo* 2> /dev/null | |
rm log/cucumber.lo* 2> /dev/null | |
echo ----------------------------- | |
echo TEST UNIT ... | |
echo ----------------------------- |
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
$(document).ready(function() { | |
$('textarea.word_count').each(function(){ | |
var maxlimit = parseInt($(this).attr('maxlength')); | |
// ...on page load | |
var length = $(this).val().length; | |
if(length >= maxlimit) { | |
$(this).val($(this).val().substring(0, maxlimit)); |
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
require 'test_helper' | |
module ActiveSupport | |
class TestCase < Test::Unit::TestCase | |
# Correct Usage : | |
# def test_ok_pending_1 | |
# pending "feature 1 should do this ..." | |
# end |