This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _request = require('request'); | |
const { stringify } = require('flatted/cjs'); | |
const LRU = require('lru-cache'); | |
const crypto = require('crypto'); | |
// Interface for cached requests | |
class Cache { | |
// opt to pass to LRU, h hash function for the key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# See https://gist.github.com/db1af03d007d2f64a44ff22f4633fe74 for more info | |
# This script backup data from a ES instance to disk and create a xz archive with the command to restore it | |
# You need to have jq ( https://stedolan.github.io/jq/ ) and elasticdump ( https://www.npmjs.com/package/elasticdump ) installed | |
# source ES instance | |
DEFAULT_ESR='http://source:9200' # Edit this | |
ESR=${1:-$DEFAULT_ESR} # Or just use $1 to add the Elastic Search url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Split files in a bunch of 10Mb files and add .zip (even if they are not zip) | |
# Why? They can be attached to a issue in Github and overcoming the ;-) | |
# Use: split10m file | |
# or tar cJf - folder_to_compress | split10m | |
gsplit -b 10m -d --additional-suffix=.zip ${1:--} ${2:-archive} | |
# It can be reconstructed with just: | |
# $ cat archive*.zip > originalfile | |
# Or assuming that the file was a .tar.xz file, it can be extract directly: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# See https://gist.github.com/593100533a7dbb4474612f9adb8f8ff6 for more info | |
# This script backup data from a ES instance to disk and create a xz archive with the command to restore it | |
# You need to have jq ( https://stedolan.github.io/jq/ ) and elasticdump ( https://www.npmjs.com/package/elasticdump ) installed | |
# source ES instance | |
DEFAULT_ESR='http://locahost:9200' # Edit this | |
ESR=${1:-$DEFAULT_ESR} # Or just use $1 to add the Elastic Search url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _get = require('lodash/get'); | |
const regEx = /\{\s*([a-zA-Z0-9\[\]\._]+)(\s*\|\s*['"]([^\}\s]+)['"])?\s*\}/g; | |
/* | |
f({a: 1, b: { c: 2, d: 3}}, '({a}, {b.c}, {c.d})') will output (1, 2, 3) | |
*/ | |
module.exports = (obj, str) => str.replace(regEx, (match, p1, p2, p3) => _get(obj, p1) || p3 || ''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Flame graph on EB AWS machines: | |
# Check http://www.brendangregg.com/blog/2014-09-17/node-flame-graphs-on-linux.html | |
# Change the run command to run the node process with: | |
# $ node --perf_basic_prof_only_functions index.js | |
ssh your.machine.net | |
sudo yum install perf | |
sudo sysctl kernel.kptr_restrict=0 | |
sudo sysctl kernel.perf_event_paranoid=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Related tp: https://github.com/visionmedia/superagent/issues/1263 | |
const agent = require("superagent"); | |
const express = require('express') | |
const app = express() | |
app.get('/', function (req, res) { | |
res.status(400).end("not good"); | |
}) | |
var mockPort; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: node fromTextToOneWordForLine.js < infile >outfile | |
// You can then use opendiff to find the real differences | |
var fs = require('fs'); | |
var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0 | |
var text = stdinBuffer.toString(); | |
console.log(text.replace(/(\s|[^a-z])+/gi, '\n')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert video to gif file. See:https://superuser.com/a/1154859 | |
# Usage: video2gif video_file (scale) (fps) | |
video2gif() { | |
ffmpeg -y -i "${1}" -vf fps=${3:-10},scale=${2:-320}:-1:flags=lanczos,palettegen "${1}.png" | |
ffmpeg -i "${1}" -i "${1}.png" -filter_complex "fps=${3:-10},scale=${2:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${1}".gif | |
rm "${1}.png" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="root"></div> |
NewerOlder