This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Just some helpers to accelerate jQuery object instantiation, when we are using element IDs or classes as references. | |
It seems stupid, but using these helpers actually boosts the performance a lot. | |
Try the code below on the jQuery homepage, and see the results by yourself (must have Firebug installed) | |
*/ | |
// Helper for getting by ID | |
function $id(id, context) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use the code below as a reference if you're sure you're using | |
* elements' ID's. In my system, the pure version ended in 243ms while | |
* the accelerated version ended in 33ms. The speed difference is not | |
* noticeable for a small number of traversals, though. | |
*/ | |
jQuery(function(){ | |
(function($, doc){ | |
var nElements = 100, iterations = 10000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Little trick to list the MP3 paths | |
* from the great Jim Beard's web pages | |
* (one of the best Jazz composers I've known). | |
* Enjoy. | |
*/ | |
var pattern = /Beard\smp3s\/.+\.mp3/, | |
base = "http://www.jimbeard.com/", | |
paths = []; | |
$$('a').forEach(function(el, i){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just a simple array division to share with a friend | |
function divideArray(array, parts) { | |
if (parts == 0) return []; | |
var length = array.length, | |
blockSize = ((length + (length % parts)) / parts), | |
blocks = [], i; | |
for (i = 0; i < length; i += blockSize) { | |
blocks.push(array.slice(i, i + blockSize)); | |
} | |
return blocks; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A simple helper for cleaning MongoDB collections in NodeJS, using mongoose. | |
They act as setup/teardown cleaners | |
*/ | |
// lib/tools.js | |
exports.chainedCalls = function() { | |
var funcs = Array.prototype.slice.call(arguments, 0); | |
function callNext() { | |
if (funcs.length) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import factorial | |
from operator import add | |
def factorial_digits_sum(number): | |
return reduce( | |
add, | |
[int(string_digit) for string_digit in str( | |
factorial(number) | |
)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This was a little experiment I've put together in some minutes while in TDC2011 (The Developers Conference), at São Paulo | |
# It's just a silly almost-Hello-World, just to show the assynchronous communication working with non-blocking I/O through event loops, mixed with a simple HTTP server | |
# First, put this on a file called 'server.py', and run: | |
#$ ./server.py 8001 & | |
#$ ./server.py 8002 & | |
#$ ./server.py 8003 & | |
#!/usr/bin/env python |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
This is an attempt of an alternative to | |
http://code.activestate.com/recipes/577068-floating-point-range/ | |
but generating the expected floating-point elements in the range, | |
avoiding floating-point arithmetic problems. | |
Currently it works rather well, although without the original | |
validation steps (which seem to be overengineering to me), considering |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
Just another quicksort implementation, to see if I memorized the algorithmn. | |
Apparently, yes. :-) | |
Gotchas during the implementation: | |
- forgot to check min and max in the beginning, got IndexError | |
- choosing nonsense as pivot led me to almost-sorted list (worked when | |
I stopped being stupid) | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
Just a silly example for an Observer implementation using the "push event" method. See discussion about it: | |
https://groups.google.com/forum/?fromgroups#!topic/growing-object-oriented-software/KwJPxUZ0l_M | |
''' | |
class OrderTrackingEvent(object): | |
def __init__(self, order_number, status): | |
self.order_number = order_number | |
self.status = status |
OlderNewer