Skip to content

Instantly share code, notes, and snippets.

View MatthieuLemoine's full-sized avatar

Matthieu Lemoine MatthieuLemoine

View GitHub Profile
@MatthieuLemoine
MatthieuLemoine / install-deps.js
Created May 19, 2018 12:22
Install dependencies for all projects in current dir
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const { exec: childExec } = require('child_process');
const ProgressBar = require('ascii-progress');
const readDir = promisify(fs.readdir);
const exec = promisify(childExec);
const workingDir = process.cwd();
@MatthieuLemoine
MatthieuLemoine / index.js
Last active May 10, 2018 22:03
Parse RATP stops data & dump in an Algolia index
const { promises: fs, createReadStream } = require('fs');
const { Transform } = require('stream');
const path = require('path');
const uuid = require('uuid/v4');
const ProgressBar = require('ascii-progress');
const algolia = require('algoliasearch');
const { ALGOLIA_APP_ID, ALGOLIA_API_KEY } = process.env;
const client = algolia(ALGOLIA_APP_ID, ALGOLIA_API_KEY);
@MatthieuLemoine
MatthieuLemoine / junk.js
Created January 10, 2018 15:52
Sync settings
//
@MatthieuLemoine
MatthieuLemoine / find-repo-dependencies.js
Created December 27, 2017 13:25
Find repository dependencies in all your projects
// Usage : node find-repo-dependencies /path/to/projects/folder
const path = require('path');
const fs = require('fs');
const folder = path.resolve(process.argv[2]);
fs
.readdirSync(folder)
// Absolute path
.map(item => path.join(folder, item))
@MatthieuLemoine
MatthieuLemoine / refactor.js
Last active August 9, 2017 08:53
Refactor from dirname/filename(.test).js to dirname/filename/index(.test).js
/*
node refactor.js --dirs src/actions src/components
Before :
- src
- actions
messenger.js
messenger.test.js
login.js
npm init --scope=<orgName>
npm publish --access public
@MatthieuLemoine
MatthieuLemoine / index.js
Last active April 10, 2017 15:57
Mediasoup : Link audio/video streams with participants
// You need to setup a working mediasoup SFU server first
// see : https://mediasoup.org/api/#webrtc
// Map userId => streamId
// Local to a room
const userStreams = {};
// Mediasoup peer
const mediaPeer = mediaRoom.Peer(participant.id);
@MatthieuLemoine
MatthieuLemoine / postbuild.js
Last active February 6, 2017 10:21
Post babel build. Copy missing files.
#!/usr/bin/env node
const glob = require('glob');
const fs = require('fs');
const sh = require('shelljs');
const SRC_DIR = 'src';
const DEST_DIR = 'build';
glob(`${SRC_DIR}/**/*(*.json|!(*.js))`, (err, files) => {
if (err) {
@MatthieuLemoine
MatthieuLemoine / crypto.js
Created January 23, 2017 14:36
Node crypto sign & verify
const id = '__JUNK__';
// Public key need to be in PKCS8 format
// ssh-keygen -e -m PKCS8 -f id_rsa.pub > id_rsa.pkcs8
const publicKey = fs.readFileSync(path.join(__dirname, 'id_rsa.pkcs8'), { encoding : 'utf8' });
const privateKey = fs.readFileSync(path.join(__dirname, 'id_rsa'), { encoding : 'utf8' });
// Sign
const signer = crypto.createSign('RSA-SHA512');
signer.update(id);
const signature = signer.sign(privateKey, 'hex');
@MatthieuLemoine
MatthieuLemoine / .hyper.js
Last active February 20, 2017 17:06
Hyperterm sync settings
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 12,
// font family with optional fallbacks
fontFamily: 'Menlo, "DejaVu Sans Mono", "Lucida Console", monospace',
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
cursorColor: '#fff',