Skip to content

Instantly share code, notes, and snippets.

View jpablo's full-sized avatar

juan pablo romero jpablo

View GitHub Profile
@jpablo
jpablo / partial.js
Created April 28, 2011 00:15
Partial function application with javascript
/*
* taken from
* http://www.webreference.com/programming/javascript/rg17/
* */
Function.prototype.partial = function () {
var method = this;
var args = Array.prototype.slice.call(arguments);
return function() {
var allArguments = args.concat(Array.prototype.slice.call(arguments));
return method.apply(this, allArguments);
@jpablo
jpablo / gist:946582
Created April 28, 2011 15:32
Monads in python using generic functions from peak.rules
__author__ = 'jpablo'
##
import operator
from peak.rules import when, abstract
@abstract
def bind(obj, func):
'do something with obj and func'
@jpablo
jpablo / gist:947937
Created April 29, 2011 06:21
Stereographic projection script for MathMap filter (Gimp)
filter inv_stereo2 (image in,
float zoom:1-20(10),
float warp:-5-5(1),
float altura:1-20(2),
float rotx:0-6.2839(0),
float roty:0-6.2839(0),
float rotz:0-6.2839(0)
)
# mathmap: http://www.complang.tuwien.ac.at/schani/mathmap/
@jpablo
jpablo / gist:947944
Created April 29, 2011 06:28
bootstrap in R
# Los datos (ejemplo)
d = c(2,4,6,6,7,11,13,13,14,15,19,23,24,27,28,28,28,30,31,43)
####
dm <- mean(d)
ds <- sd(d)
@jpablo
jpablo / eps2frag.rb
Created April 29, 2011 06:42
Convert inkscape files into eps converting the embeded strings into latex formulas
#! /usr/bin/env ruby
# has problems with spaces
# depends on:
# pstotext
# http://pages.cs.wisc.edu/~ghost/doc/pstotext.htm
def procesa(file)
p file
@jpablo
jpablo / ogg2mp3.rb
Created April 29, 2011 06:46
transcode an ogg file into mp3
#!/usr/bin/env ruby
## depends on:
## oggdec, lame, mp3info
def procesa(file)
base = `basename "#{file}" .ogg`.chop
tags = `vorbiscomment "#{file}"`.split("\n")
tags.collect! {|t| t.split("=")}
@jpablo
jpablo / create_lazy_var.py
Created July 1, 2011 20:27
lazy class variables
# first, subclass property:
class ClassProperty(property):
def __get__(self, cls, owner):
return self.fget.__get__(None, owner)()
# then, define create_lazy_var
def create_lazy_var(cls,name, func):
private = '_'+name
@jpablo
jpablo / proxy_logger.py
Created September 8, 2011 17:49
Logger Proxy class
from django.db import models
## given a Log container class, for example:
class MethodLog(models.Model):
occurred = models.DateTimeField(auto_now_add=True)
method = models.CharField(max_length=100)
## here's a class which logs all method calls and passes it
## to the contained object
@jpablo
jpablo / async_map.js
Created July 16, 2012 02:20
async map
function asyncMap(promises, callback) {
var results = [];
for(var p in promises) {
if(!promises.hasOwnProperty(p)) { continue; }
promises[p].done(function(result) {
results.push(callback(result))
})
}
return $.when.apply(null,promises).pipe(function() { return results });
}​
@jpablo
jpablo / gist:3885136
Created October 13, 2012 16:04
java "map"
import com.google.common.collect.Iterables;
// ...
Iterable<String> items = Iterables.transform(getNodes("/List/Item", document),
new Function<Node, String>() {
public String apply(@Nullable Node node) {
//noinspection ConstantConditions
return node.getTextContent();
}
});