Skip to content

Instantly share code, notes, and snippets.


Rafael Hengles rhengles

View GitHub Profile
View convert-jdl-to-gql.js
import jhipster from "jhipster-core";
import url from "url";
import path from "path";
import util from "util";
import * as graphql from "graphql";
import {
LocalDateTypeDefinition as GraphQLLocalDate
} from "graphql-scalars";
const __dirname = url.fileURLToPath(new URL('./', import.meta.url));
rhengles / example-using.jsx
Created Mar 18, 2021
Parse HTML string into React Elements
View example-using.jsx
import React from "react";
import { htmlFragmentToReact } from "./html-to-element";
import { allowTag, parserModify } from "./html-post-parse-fns";
export default function Component(props) {
return <div className="component-example">
{htmlFragmentToReact(postNode.html, null, React.createElement, allowTag, parserModify)}
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);
View index.html
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Canvas Rainbow</title>
<script src="index.js"></script>
rhengles /
Created Jun 7, 2016
Nunjucks - minimal precompiled templates for Node


npm install nunjucks nunjucks-cjs

node precompile.js

node render.js

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 = ''; // remote host
var app = express();
// replace specific requests
app.get('/Scripts/js.js', function(req, res, next) {
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 =;
setTimeout(function() {
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 / 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;
if ( '/exit' === url ) {