Skip to content

Instantly share code, notes, and snippets.

View jmgarnier's full-sized avatar
💭
❤️🚲

Jean-Michel Garnier jmgarnier

💭
❤️🚲
View GitHub Profile
# Monday is 26/01/2009, Sunday is 01/02/2009
# I have to use a constand because RSpec can not access variables outside of "it" blocks ...
TWENTY_SIX_OF_JANUARY_20009 = "26/01/2009".to_date_with_european_date_format
describe "On going events" do
before :each do
@event = create_ongoing_event_for_barcelona(
:starts_at => TWENTY_SIX_OF_JANUARY_20009,
:ends_at => "01/02/2009".to_date_with_european_date_format)
script/cucumber features/_balloon_day/a_register_campaign.feature --drb
/Library/Ruby/Gems/1.8/gems/cucumber-0.3.9.3/lib/cucumber/rails/world.rb:97: undefined method `World' for main:Object (NoMethodError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from /Users/jeanmichel/Projects/betterplace/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:496:in `require'
from /Users/jeanmichel/Projects/betterplace/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /Users/jeanmichel/Projects/betterplace/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:496:in `require'
from /Users/jeanmichel/Projects/betterplace/trunk/features/support/env.rb:18
from /Library/Ruby/Gems/1.8/gems/bmabey-spork-0.4.4/bin/../lib/spork.rb:15:in `each_run'
from /Users/jeanmichel/P
/* Mozilla Ubiquity Command for Diigo, currently only support add bookmark.
* Some code from https://ubiquity.mozilla.com/standard-feeds/social.js
*/
var store = Application.storage;
const DIIGO_CUR_LOGIN = "ubiquity_diigo_cur_login";
var Choices = {"yes": "yes", "no": "no"};
var noun_type_share = {
_name: "yes/no",
require 'benchmark'
$require_level = 0
module Kernel
alias require_without_timing require
def require(path)
result = seconds = nil
begin
$require_level += 1
@jmgarnier
jmgarnier / stats.rake
Created November 7, 2011 14:10
rails statistics hacked to get gross LOC of Views, css, js, coffeescript, RSpec and cucumber
# Note THIS IS some hackety hack code without tests. CodeStatistics class could be rewritten to be more configurable ...
task :stats => [:statsetup, :stats_assets]
# Setup specs / cuke & js for stats
task :statsetup do
require 'code_statistics'
class CodeStatistics
alias calculate_statistics_orig calculate_statistics
@jmgarnier
jmgarnier / active_record_migration_ext.rb
Created February 17, 2012 10:16
Fast rename columns for MYSQL, very handy for huge tables
class ActiveRecord::Migration
def self.fast_add_columns(table_name, new_columns_count)
tmp_table_name = "#{table_name}_tmp"
execute "DROP TABLE IF EXISTS #{tmp_table_name}"
execute "CREATE TABLE #{tmp_table_name} LIKE #{table_name}"
yield tmp_table_name
execute("INSERT INTO #{tmp_table_name} SELECT * #{', NULL' * new_columns_count} FROM #{table_name}")
@jmgarnier
jmgarnier / gist:2251117
Created March 30, 2012 12:16
Remove unused images
require "fileutils"
img =Dir.glob("**/*.jpg")+Dir.glob("**/*.png")+Dir.glob("**/*.gif")
data=Dir.glob("**/*.htm*")+Dir.glob("**/*.css")+Dir.glob("**/*.js")
puts "#{img.size} images found & #{data.size} files found to search against"
content=""
data.each do |f|
content+=File.open(f, 'r').read
@jmgarnier
jmgarnier / statistics.rb
Created August 6, 2012 13:34
Inner classes to implement SRP in ruby
class Statistics
def initialize
@configuration = Configuration.new(self)
end
delegate :for_caller,
:rtp_errors,
to: :@configuration
@jmgarnier
jmgarnier / spec.rake
Created September 4, 2012 08:42
spec.rake
if defined? RSpec
task(:spec).clear
desc "Run all specs in spec directory starting with js specs"
RSpec::Core::RakeTask.new(:spec => ['konacha:run', 'db:test:prepare']) do |t|
t.pattern = './spec/**/*{_spec.rb,.feature}'
end
namespace :spec do
desc "Run the code examples in spec/acceptance"
@jmgarnier
jmgarnier / fast_presenter_spec.rb
Created December 6, 2012 10:24
How to unit test a presenter using rails i18n and ActionView helpers *without* loading the spec_helper, hence keeping the tests fast?
require 'action_view/helpers/number_helper'
require 'rails-i18n'
class FastPresenter
include ActionView::Helpers::NumberHelper
def initialize(value)
@value = value
end