Skip to content

Instantly share code, notes, and snippets.

Avatar
🔷

Santiago Palladino spalladino

🔷
View GitHub Profile
@spalladino
spalladino / main.py
Created May 1, 2011
Asignacion de gastos en publicidad oficial de un organismo a un proveedor por rubro en base a vistas agregadas
View main.py
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 Jun 13, 2011
Add reset function to jquery wrapped forms
View jquery-form-reset.js
$.fn.extend({
reset: function(){
return this.each(function(){
$(this).is('form') && this.reset();
})
}
});
@spalladino
spalladino / devisetesting.rb
Created Aug 3, 2011
Disable password hashing in devise for testing
View devisetesting.rb
module Devise
module Models
module DatabaseAuthenticatable
protected
def password_digest(password)
password
end
end
end
View EventThreadListModel.java
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 Dec 2, 2011
Default request parameters in Rails functional tests
View default_request_params.rb
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 Dec 16, 2011
Delayed change jquery plugin
View jquery.delayedChange.js
(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 Jan 31, 2012
How to check if object can be destroyed if it has dependent restrict associations
View can_destroy.rb
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 Apr 17, 2012
Knockout js binding handler for reapplying instedd initializer when the object is created
View instedd_init.js.coffee
ko.bindingHandlers.instedd_init =
init: (element, valueAccessor, allBindingsAccessor, viewModel) ->
$.instedd.init_components($(element))
@spalladino
spalladino / cover.py
Created May 21, 2012
Heuristic for calculating edge clique cover in a graph
View cover.py
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
Organizing coffeescript code in a Rails 3 app
View blog01.js.coffee
if $('#my_div_in_complex_page').length > 0
class Foo
...
You can’t perform that action at this time.