Skip to content

Instantly share code, notes, and snippets.

View rhengles's full-sized avatar

Rafael Hengles rhengles

View GitHub Profile
@rhengles
rhengles / example-using.jsx
Created March 18, 2021 21:21
Parse HTML string into React Elements
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)}
</div>;
}
@rhengles
rhengles / convert-jdl-to-gql.js
Last active April 24, 2021 23:23
Convert JDL to GQL
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
rhengles / line-splitter.js
Created May 21, 2018 21:48
Node Split Lines Transform Stream
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);
}
@rhengles
rhengles / index.html
Created August 24, 2017 16:23
Canvas Rainbow
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Canvas Rainbow</title>
</head>
<body>
<canvas></canvas>
<script src="index.js"></script>
</body>
@rhengles
rhengles / README.md
Created June 7, 2016 16:00
Nunjucks - minimal precompiled templates for Node

Usage:

npm install nunjucks nunjucks-cjs

node precompile.js

node render.js

@rhengles
rhengles / node-reverse-proxy.js
Created March 30, 2016 14:42
Node Reverse Proxy with Express
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 / random.js
Created November 27, 2015 21:49
setTimeout-based entropy
// 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 / mmdp-example.js
Last active August 29, 2015 14:11
mmdp - packaged (or namespaced) AMD loader
(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 / index.js
Last active August 29, 2015 14:09
Node server that save POSTs to a file
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');