Skip to content

Instantly share code, notes, and snippets.

View alainravet's full-sized avatar

Alain Ravet alainravet

  • Braine l'Alleud, Belgium
View GitHub Profile
@alainravet
alainravet / aync_preloader.rb
Last active December 17, 2015 09:59
async preloading cache with code rewriting
# 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
# 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
@alainravet
alainravet / binary_file_string_utils.rb
Last active December 14, 2015 04:49
extract POIs from a TomTom *.ov2 file (in Ruby)
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
@alainravet
alainravet / cowsay_video_notes.txt
Created September 2, 2012 17:27
cowsay video notes
brew install cowsay
x = (<<'END')
don't escape the backslash, f.ex /\:/\
END
IO.popen(['cowsay', message]) do |process|
process.read
end
$ bundle init
@alainravet
alainravet / fixnum_to_lcd_matrix.rb
Created August 15, 2012 13:06
Fixnum#to_lcd_matrix
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
@alainravet
alainravet / output.txt
Created July 22, 2012 19:14
private_please : detect if a method can be made private
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
@alainravet
alainravet / config_initializers_export_migrations_as_ddl.rb
Created June 3, 2012 01:18
have `rake db:migrate` export the matching DDL to a file in db/migrate
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'
@alainravet
alainravet / test_parallel_8core_iMac
Created September 9, 2011 22:34
test_parallel_8core_iMac
#!/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 -----------------------------
@alainravet
alainravet / the_jquer_code.js
Created February 9, 2011 18:14
limit the characters in a textarea + display 'n characters left'
$(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));
@alainravet
alainravet / bug_or_pending_test_case.rb
Created May 5, 2010 21:22
add pending tests to TestCAse
require 'test_helper'
module ActiveSupport
class TestCase < Test::Unit::TestCase
# Correct Usage :
# def test_ok_pending_1
# pending "feature 1 should do this ..."
# end