Skip to content

Instantly share code, notes, and snippets.

Louis-Rémi Babé louisremi

Block or report user

Report or block louisremi

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
View test.js
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 Jul 13, 2017
Get rid of forest/ folder with this one weird trick
View app.js
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 Apr 12, 2019
react-select-places Address autocomplete component built on top of React-Select and Algolia Places
View example.component.jsx
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
Recreate Elizabeth
View elizabeth2.js
houseWindsor = Object.assign({}, houseWindsor, {
"William": Object.assign({}, houseWindsor["William"], {
life: houseWindsor["William"].life.concat(2016)
}
}));
@louisremi
louisremi / member.js
Last active May 18, 2016
Family member
View member.js
houseWindsor = {
"Elizabeth II": {
name: "Elizabeth II",
life: [1926],
marriages: [{
partner: "Philip",
children: [ "Charles", "Anne", ... ]
}]
},
"Philip": { ... },
@louisremi
louisremi / lru.js
Created May 17, 2016
Last Result Used
View lru.js
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) {
View index.html
<!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>
View nested-map.js
// 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
View map.js
var key = {a:1};
var value = 123456;
var map = new Map();
map.set(key, value);
map.get(key); // === 123456
View stupid-memoize.js
function memoize(fn) {
var cache = {};
// return a memoized version of the function
return function(arg) {
// intercept the argument
if ( !(arg in cache) ) {
// if it's not in cache, execute the original function and
// cache the result, using the argument as the cache key.
cache[arg] = fn.call(this, arg);
You can’t perform that action at this time.