View README.md

scan-dependencies

Usage : node scan-dependencies.js <path>

  • will find every root project inside <path> (a project is a folder with package.json file, himself not inside a node_modules directory)
  • will npm install then npm outdated from project
  • will list all *.js files and check for missing require(…) for every dependency
View README.md

Shitty code, version 1:

const concat = s => s.reduce((r,s) => r + s)
const mult = (a, b) => a * b
const foo = a => b => c => concat([c, ' = ', mult(a, b)])
const bar = a => Number(a) + 1
const baz = b => b ? 42 : 33
const res = foo(1)('bar')('baz')
console.log(res)
View promise-all.js
// ( T1 => Promise<T2> ) => Array<T1> => Promise<Array<T2>>
export const concurrent = foo => vals =>
Promise.all(vals.map(foo))
export const series = foo => vals =>
vals.reduce((p, val) => p.then(rs => foo(val).then(r => rs.concat([val]))), Promise.resolve([]))
// Usage: promiseOfValues.then(promiseAll.concurrent(functionReturningAPromiseFromAValue))
View index.js
"use strict";
const { readFileSync } = require("fs")
const { parse } = require("json5")
const { merge } = require("lodash")
module.exports = merge({},
// Global defaults
requireConfig("defaults"),
// Environment defaults
View npm-check-used.sh
#!/bin/bash
# Run from your project's root
# Run "npm install" or "npm update" before
# Requirement: jq (https://stedolan.github.io/jq/)
required () {
grep -R "from ['\"]${1}[\\/'\"]\|require(['\"]${1}[\\/'\"]" --exclude-dir=node_modules --include='*.js' > /dev/null
}
View .zshrc
# Requires zsh
# Requires xdotool
the_command="?????"
preexec()
{
if [ "x$TTY" != "x" ]; then
the_command="$2"
fi
View cache.js
import config from ''
import Redis from 'ioredis'
const client = new Redis(config.redis)
const cachePrefix = config.cache.prefix
const cacheDefaultTTL = config.cache.defaultTTL
// (string) => Promise<any>
export function get (key /* string */) {
return client.get(cachePrefix + key)
View app1.js
// generic reusable
app.use(timeMiddleware('session', session));
//
function timeMiddleware (description, middleware) {
return function (req, res, next) {
var start = process.hrtime();
middleware(req, res, function (err) {
View client.js
var Promise = require('bluebird');
var request = require('request-promise');
var io = require('socket.io-client');
var jar = request.jar();
/**
* Connect to web interface
*/
request({
uri: loginActionUrl,
View index.js
// foo() fait une opération compliquée
// mais c'est codé un peu avec les pieds et un des EventEmitter déclaré (et non exposé)
// dans la fonction émet parfois un "error" non catché qui pète mon application :(
var foo = require("./module-pourri");
// Ça fait parfois péter mon app :(
//foo();