Skip to content

Instantly share code, notes, and snippets.

Hi there! I am using WhatsApp

Ricardo Magalhães magalhini

Hi there! I am using WhatsApp
Block or report user

Report or block magalhini

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
magalhini / mochachaisinon.js
Created Oct 5, 2018 — forked from eswak/mochachaisinon.js
An example of asynchronous JavaScript testing using Mocha + Chai + Sinon
View mochachaisinon.js
var chai = require('chai');
var assert = chai.assert;
var expect = chai.expect;
var should = chai.should();
var sinon = require('sinon');
function myAsyncFunction(callback) {
// 50ms delay before callback
setTimeout(function() {
magalhini / synaptic-shape-training.js
Created Sep 6, 2017
Training a neural network to recognise 15 inputs worth of Shapes
View synaptic-shape-training.js
const Layer = require('synaptic').Layer;
const Network = require('synaptic').Network;
const Trainer = require('synaptic').Trainer;
const inputLayer = new Layer(15);
const hiddenLayer = new Layer(40);
const outputLayer = new Layer(4);
magalhini / pre-commit
Last active May 8, 2017
Git pre-commit hook to check against accidental describe.only() in tests
View pre-commit
# Check for .only() in this path
if git rev-parse --verify HEAD >/dev/null 2>&1
# Initial commit: diff against an empty tree object
magalhini / node-multiple-calls-render.js
Last active Jun 8, 2019
Example on how to render multiple responses into a route in node.js
View node-multiple-calls-render.js
const express = require('express')
const app = express()
const path = require('path')
const fetch = require('node-fetch')
const PORT = process.env.PORT || 3000
app.get('/api/user', (req, res) => {
res.json({ name: 'Richard' });
magalhini / Enhance.js
Created Sep 5, 2016 — forked from sebmarkbage/Enhance.js
Higher-order Components
View Enhance.js
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
componentDidMount() {
this.setState({ data: 'Hello' });
render() {
View advent-day1.js
const fs = require('fs');
const file = fs.readFileSync('./1.txt').toString('utf8');
let level = 0;
let findWay = (char) => {
if (char === '(') return 1;
else if (char === ')') return -1;
magalhini / TemplateStore.js
Last active Oct 27, 2015
Testing a Flux Store using Mocha and Sinon. It uses rewire to fetch a new copy of the Store every time, as to maintain a clean state before each test. Also includes a sample for the Gulp task to run it in proper TDD fashion.
View TemplateStore.js
// Mock our global environment using JSDOM
let jsdom = require('mocha-jsdom');
import {
magalhini / webpack.js
Created Oct 14, 2015 — forked from Couto/webpack.js
Fetch polyfill with webpack
View webpack.js
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var folders = {
APP: path.resolve(__dirname, '../app'),
BUILD: path.resolve(__dirname, '../build'),
BOWER: path.resolve(__dirname, '../bower_components'),
NPM: path.resolve(__dirname, '../node_modules')
View sequentialPromise.js
// Kinda pseudo code
// This script will download and resize each image to half
// Because the images can be RRREAAALLY big
// the download and resize is done sequentially (in my case, inside a child_process)
// to ensure that memory is released after each image.
// We dont know how many images there are
let images = [
You can’t perform that action at this time.