Skip to content

Instantly share code, notes, and snippets.

View louisremi's full-sized avatar

Louis-Rémi Babé louisremi

View GitHub Profile
@louisremi
louisremi / machine.js
Last active May 17, 2022 15:37
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
const sequelize = new Sequelize('database', 'username', 'password', {
dialect: 'mysql',
host: "my.server.tld",
port: 9821,
})
const Project = sequelize.define('project', {
title: Sequelize.STRING,
description: Sequelize.TEXT,
});
@louisremi
louisremi / app.js
Last active May 17, 2022 15:30
Get rid of forest/ folder with this one weird trick
const Express = require('express');
const Liana = require('forest-express-sequelize');
const config = require('./config');
const models = require('./models');
const smartCollections = require('./smart-collections');
const app = Express();
const {Schemas} = Liana;
// - Hijack Schemas.perform to load Liana collections ourselves
@louisremi
louisremi / example.component.jsx
Last active October 18, 2020 11:35
react-select-places Address autocomplete component built on top of React-Select and Algolia Places
import React from 'react';
import Places from './places.components.jsx';
export default class Example extends React.Component {
constructor(props) {
super(props);
this.state = {address: {}};
this.handleChange = this.handleChange.bind(this);
@louisremi
louisremi / elizabeth2.js
Last active May 18, 2016 14:27
Recreate Elizabeth
houseWindsor = Object.assign({}, houseWindsor, {
"William": Object.assign({}, houseWindsor["William"], {
life: houseWindsor["William"].life.concat(2016)
}
}));
@louisremi
louisremi / member.js
Last active May 18, 2016 14:23
Family member
houseWindsor = {
"Elizabeth II": {
name: "Elizabeth II",
life: [1926],
marriages: [{
partner: "Philip",
children: [ "Charles", "Anne", ... ]
}]
},
"Philip": { ... },
@louisremi
louisremi / lru.js
Created May 17, 2016 15:38
Last Result Used
function LRU(limit) {
this.limit = limit || 1000;
this.map = new Map();
}
LRU.prototype.has = function(key) {
return this.map.has(key);
}
LRU.prototype.set = function(key, value) {
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Caching strategies</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@louisremi
louisremi / nested-map.js
Last active May 14, 2016 16:57
Nested map
// a memoizer that works with functions that receive two arguments
// of any type (can be generalized to accept more arguments)
function memoize(fn) {
// The first level of our nested-cache
var cacheLevel1 = new Map();
return function(arg1, arg2) {
// Let's check the cache, using one argument at each level
if ( !cacheLevel1.has(arg1) ) {
// and create nested maps as we need them
@louisremi
louisremi / map.js
Created May 14, 2016 16:28
Map example
var key = {a:1};
var value = 123456;
var map = new Map();
map.set(key, value);
map.get(key); // === 123456