Skip to content

Instantly share code, notes, and snippets.

Avatar

Rafael Hengles rhengles

View GitHub Profile
@rhengles
rhengles / index.js
Last active Aug 29, 2015
Node server that save POSTs to a file
View index.js
var http = require('http')
, fs = require('fs');
var save = fs.createWriteStream('save.txt')
, server = http.createServer(function(req, resp) {
resp.setHeader('Access-Control-Allow-Origin', '*');
var url = req.url;
console.log(url);
if ( '/exit' === url ) {
resp.end('BYE');
@rhengles
rhengles / mmdp-example.js
Last active Aug 29, 2015
mmdp - packaged (or namespaced) AMD loader
View mmdp-example.js
(function() {
var define = mmd.package('core').define;
define('core/1', function(){/*...*/});
define('core/2', ['core/1'], function(){/*...*/});
})();
(function() {
var define = mmd.package('lib1', ['core']).define;
define('lib1/file-a', ['core/1'], function(){/*...*/});
define('lib1/file-b', ['core/2', 'lib1/file-a'], function(){/*...*/});
@rhengles
rhengles / random.js
Created Nov 27, 2015
setTimeout-based entropy
View random.js
// please forgive the one letter variables, this is a gist
// the setTimeout must be called sequentially, or else the
// runtime will execute all of them at the same time,
// giving the same value
function random(m, cb) {
var t = Date.now();
setTimeout(function() {
cb(Date.now()-t);
@rhengles
rhengles / node-reverse-proxy.js
Created Mar 30, 2016
Node Reverse Proxy with Express
View node-reverse-proxy.js
var fs = require('fs');
var express = require('express');
var request = require('request');
var apiUrl = 'http://example.com'; // remote host
var app = express();
// replace specific requests
app.get('/Scripts/js.js', function(req, res, next) {
@rhengles
rhengles / README.md
Created Jun 7, 2016
Nunjucks - minimal precompiled templates for Node
View README.md

Usage:

npm install nunjucks nunjucks-cjs

node precompile.js

node render.js

View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Canvas Rainbow</title>
</head>
<body>
<canvas></canvas>
<script src="index.js"></script>
</body>
@rhengles
rhengles / line-splitter.js
Created May 21, 2018
Node Split Lines Transform Stream
View line-splitter.js
var strDec = require('string_decoder');
var StringDecoder = strDec.StringDecoder;
var stream = require('stream');
var Transform = stream.Transform;
var util = require('util');
function LineSplitter(options) {
if (!(this instanceof LineSplitter)) {
return new LineSplitter(options);
}
You can’t perform that action at this time.