Skip to content

Instantly share code, notes, and snippets.

View mattiaerre's full-sized avatar
`yarn prettier:fix`

Mattia Richetto mattiaerre

`yarn prettier:fix`
View GitHub Profile
@mattiaerre
mattiaerre / generic-component-tests.js
Last active September 6, 2015 18:27
Dependency injection in Node.js
var chai = require('chai'),
expect = chai.expect,
should = chai.should();
describe('unit-tests', function () {
'use strict'
describe('generic-component-tests', function () {
describe('given a component', function () {
describe('when initialized w/ dependency', function () {
@mattiaerre
mattiaerre / handle-change-with-debounce.js
Created July 29, 2016 19:08
handle-change-with-debounce.js
handleChange(e) {
e.persist();
// info: "this.debounced" is defined at the class level
if (!this.debounced) {
this.debounced = _.debounce(() => {
console.log('YATTA!');
this.debounced.cancel();
this.debounced = undefined;
}, 500);
this.debounced();
/* eslint no-console: off */
const http = require('http');
const _ = require('lodash');
const randomHttpStatusCode = _.sample(_.invert(http.STATUS_CODES));
console.log('randomHttpStatusCode:', randomHttpStatusCode);

pre-release

-alpha.1

-alpha.2

-beta.1

-beta.2
@mattiaerre
mattiaerre / package.json
Last active April 3, 2017 08:52
How to run a CRA in Heroku w/ Express and Node.js build pack
/* info: the original "start" from CRA has been renamed to dev and a new "start" that points to server.js has been added */
{
"scripts": {
"start": "node server.js",
"dev": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
@mattiaerre
mattiaerre / open-component-renderer.js
Last active August 20, 2017 22:45
how to client side render an OpenComponents component using the Console (Developer Tools)
((oc, $) => {
// see: https://github.com/opentable/oc/wiki/Browser-client#ocbuild-options
const html = oc.build({
baseUrl: 'http://localhost:3030',
name: 'pi-baltimore-special-offers-promo-banners',
version: '1.X.X',
parameters: {
banner: 'purple-pasta'
}
});
@mattiaerre
mattiaerre / index.js
Last active August 20, 2017 22:46
Load the OpenComponents client then render a component.
(() => {
const script = document.createElement('script');
script.type = 'application/javascript';
script.src = '//s3.amazonaws.com/oc-registry-dc/components/oc-client/0.40.7/src/oc-client.min.js';
script.onload = () => {
const html = window.oc.build({
baseUrl: '//oc.registry.dc',
name: 'oc-superman',
version: '1.0.0',
parameters: {
(function() {
var you = true;
const MATTIA = 'Mattia';
var myName = {
is: function(name) {
return name == MATTIA
}
};
var to = {
call: {
@mattiaerre
mattiaerre / .prettierrc
Created August 21, 2018 11:27
prettier configuration file
{
"singleQuote": true,
"trailingComma": "none"
}
@mattiaerre
mattiaerre / ForStatement.json
Created September 29, 2018 19:40
ForStatement AST part
{
"type": "ForStatement",
"initExpression": {
"type": "VariableDeclarationStatement",
"variables": [
{
"type": "VariableDeclaration",
"typeName": {
"type": "ElementaryTypeName",
"name": "uint",