Skip to content

Instantly share code, notes, and snippets.

View spalladino's full-sized avatar
🔷

Santiago Palladino spalladino

🔷
View GitHub Profile
@spalladino
spalladino / main.py
Created May 1, 2011 20:21
Asignacion de gastos en publicidad oficial de un organismo a un proveedor por rubro en base a vistas agregadas
import csv
import networkx as nx
from decimal import *
from itertools import *
FILE_SALIDA = 'output.csv'
FILE_PROVEEDOR = 'ocrtest_segundo_semestre_prov_rubro CORREGIDO.csv'
FILE_ORGANISMO = 'ocrtest_segundo_semestre_organismo_rubro CORREGIDO.csv'
class Data:
@spalladino
spalladino / jquery-form-reset.js
Created June 13, 2011 18:58
Add reset function to jquery wrapped forms
$.fn.extend({
reset: function(){
return this.each(function(){
$(this).is('form') && this.reset();
})
}
});
@spalladino
spalladino / devisetesting.rb
Created August 3, 2011 13:46
Disable password hashing in devise for testing
module Devise
module Models
module DatabaseAuthenticatable
protected
def password_digest(password)
password
end
end
end
@spalladino
spalladino / EventThreadListModel.java
Created October 27, 2011 22:15
EventThreadListModel
public class EventThreadListModel extends DefaultListModel {
private static final long serialVersionUID = -4389671662282607290L;
private void invokeOnEventThread(Runnable r) {
try {
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeAndWait(r);
} else {
r.run();
}
@spalladino
spalladino / default_request_params.rb
Created December 2, 2011 16:03
Default request parameters in Rails functional tests
class ActionController::TestCase < ActiveSupport::TestCase
module Behavior
def process_with_default_params(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
default_params = {:locale => :en}
parameters ||= {}
parameters.reverse_merge! default_params
process_without_default_params(action, parameters, session, flash, http_method)
end
alias_method_chain :process, :default_params
end
@spalladino
spalladino / jquery.delayedChange.js
Created December 16, 2011 23:36
Delayed change jquery plugin
(function($){
$.delayedChangeDelay = 1000;
$.checkUpdateTime = 500;
// Special event definition.
$.event.special.delayedChange = {
setup: function( params ) {
// Add data and handlers to other events
@spalladino
spalladino / can_destroy.rb
Created January 31, 2012 14:42
How to check if object can be destroyed if it has dependent restrict associations
class ActiveRecord::Base
def can_destroy?
self.class.reflect_on_all_associations.all? do |assoc|
assoc.options[:dependent] != :restrict || (assoc.macro == :has_one && self.send(assoc.name).nil?) || (assoc.macro == :has_many && self.send(assoc.name).empty?)
end
end
end
@spalladino
spalladino / instedd_init.js.coffee
Created April 17, 2012 16:15
Knockout js binding handler for reapplying instedd initializer when the object is created
ko.bindingHandlers.instedd_init =
init: (element, valueAccessor, allBindingsAccessor, viewModel) ->
$.instedd.init_components($(element))
@spalladino
spalladino / cover.py
Created May 21, 2012 01:09
Heuristic for calculating edge clique cover in a graph
class Graph:
def __init__(self, n):
self.n = n
self.adjs = []
self.edges = set()
for i in range(n):
self.adjs.append(set())
def add_edge(self, v, w):
@spalladino
spalladino / blog01.js.coffee
Created May 23, 2012 11:45
Organizing coffeescript code in a Rails 3 app
if $('#my_div_in_complex_page').length > 0
class Foo
...