Skip to content

Instantly share code, notes, and snippets.

View RaffaeleSgarro's full-sized avatar

Raffaele Sgarro RaffaeleSgarro

View GitHub Profile
@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 );
}
}
@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 / 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 / gist:4635795
Created January 25, 2013 16:30
Distribute tasks among assignees
# Python 2.x
import random
import itertools
tasks = ['account', 'gestione classi', 'registro insegnanti',
'registro di classe', 'corsi di studio', 'gestione materie', 'bacheca',
'giornalino', 'pon', 'gestione circolari', 'gestione locali',
'inventario', 'viaggi', 'tasse']
assignees = ["Marco", "Gabriele", "Raffaele"]
@RaffaeleSgarro
RaffaeleSgarro / gist:4652027
Last active August 6, 2016 14:10
Test random generation when reseeding each iteration
# Requires python-imaging on Ubuntu
import PIL.Image, random, time
class AlexRand(random.Random):
'''This replicates how PHP does randint()'''
def randint(self, a, b):
self.seed()
return super(AlexRand, self).randint(a, b)
image = PIL.Image.new("1",(512,512)) # Creates a 512x512 bitmap
trait MyOption[A] { outer =>
import MyOption._
def fold[B](map: A => B, getOrElse: => B): B
}
object MyOption {
def none[A]: MyOption[A] =
@RaffaeleSgarro
RaffaeleSgarro / gist:4747371
Created February 9, 2013 22:23
Telnet D-Link DSL-2640B available commands
?
help
logout
reboot
adsl
atm
brctl
cat
ethctl
ddns
import commands, re
import pprint
class Engine:
def __init__(self):
self.data = dict()
def updateSourceEvent(self):
self.updateData()
@RaffaeleSgarro
RaffaeleSgarro / YahooURI.java
Last active December 15, 2015 14:19
Encode/decode parameters in a format that is suitable to be sent as the encoded query string to Yahoo services with a HTTP API
package stackoverflow;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@RaffaeleSgarro
RaffaeleSgarro / GetImageColorComponents.java
Last active December 15, 2015 21:28
Save color components of an image separately in a MySQL database
package stackoverflow;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Arrays;