Skip to content

Instantly share code, notes, and snippets.

View RaffaeleSgarro's full-sized avatar

Raffaele Sgarro RaffaeleSgarro

View GitHub Profile
@RaffaeleSgarro
RaffaeleSgarro / gist:4539279
Created January 15, 2013 15:07
Rake task to fill the database of a Rails app with fake data
# Run it with rake db:populate
namespace :db do
desc "Empty the db and fill it with fake data"
task :populate => :environment do
require 'faker'
Rake::Task['db:reset'].invoke
def time_rand from = 0.0, to = Time.now
Time.at(from + rand * (to.to_f - from.to_f))
@RaffaeleSgarro
RaffaeleSgarro / StringsContainingCharacters.java
Created November 17, 2012 00:55
Benchmark for StackOverflow
package stackoverflow;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class StringsContainingCharacters {
public static void main(String[] args) {
@RaffaeleSgarro
RaffaeleSgarro / Pollycoke Buddypress fix.js
Created August 29, 2012 08:46
Disable Buddypress callbacks on elements flagged with "button" class
// Elements having "button" class will not fire the buddypress callbacks
$.each( $( ".item-list-tabs" ).data( "events" ).click, function ( i, obj ) {
var oldHandler = obj.handler;
obj.handler = function ( event ) {
if ( $( event.target ).hasClass( "button" ) )
return true;
else
return oldHandler( event );
}
}