Skip to content

Instantly share code, notes, and snippets.

View reu's full-sized avatar

Rodrigo Navarro reu

View GitHub Profile
@reu
reu / README.md
Last active August 29, 2015 14:27
Gulp plugin to pre-process HTML template includes.

Gulp Template

This plugin allows you to directly include HTML templates into a Javascript file.

Example

Given the following template:

template.html

@reu
reu / fib.clj
Created June 21, 2015 04:46
Infinite Fibonacci sequence
(def fib-seq
((fn fib [a b] (cons a (lazy-seq (fib b (+ b a))))) 1 1))
@reu
reu / index.js
Created April 24, 2015 22:06
Node simple static file server.
var http = require("http");
var fs = require("fs");
var mime = require("mime-types");
var server = http.createServer(function(req, res) {
var path = "." + req.url;
fs.stat(path, function(error, stats) {
if (error) {
res.writeHead(404);
@reu
reu / denodify.js
Last active July 11, 2017 09:41
Convert any NodeJS async function into a Promise
module.exports = function denodify(fn) {
return function() {
var self = this;
var args = Array.prototype.slice.call(arguments);
return new Promise(function(resolve, reject) {
args.push(function(error, result) {
error ? reject(error) : resolve(result);
});
@reu
reu / DequeTest.java
Created February 8, 2015 16:08
Princenton University Algorithms Cousera course unit tests
import static org.junit.Assert.*;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.junit.Before;
import org.junit.Test;
public class DequeTest {
private Deque<String> deque;
def luminance(color = "FFFFFF")
r, g, b = color.chars.each_slice(2).map(&:join).map(&:hex)
r * 0.299 + g * 0.587 + b * 0.114
end
#!/usr/bin/env ruby
require "webrick"
unless ARGV[0]
STDERR.puts "Usage: cgiup [PATH TO CGI SCRIPT]"
exit 1
end
cgi_script = File.expand_path(ARGV[0])
@reu
reu / functional.js
Last active August 29, 2015 14:10
Some building blocks for functional programming in Javascript
function curry(fn) {
var arity = fn.length,
args = Array.prototype.slice.call(arguments, 1);
function accumulator() {
var leftArgs = args.concat(Array.prototype.slice.call(arguments, 0));
if (leftArgs.length >= arity) {
return fn.apply(this, leftArgs);
} else {
@reu
reu / array-unique.js
Last active August 29, 2015 14:08
array-unique.js
Array.prototype.unique = function() {
return this.filter(function(value, index, array) {
return array.indexOf(value) === index;
});
}
# This class implements async evaluation by transparently executing the block on a different thread.
class Future < Lazy
def initialize(&block)
@attribute = ::Lazy.new(&block)
@thread = ::Thread.new { @attribute.__send__(:__call__) }
end
private
def __call__