Skip to content

Instantly share code, notes, and snippets.

View ChrisCinelli's full-sized avatar

Chris Cinelli ChrisCinelli

  • Close5
  • San Francisco, CA, United States
View GitHub Profile
@ChrisCinelli
ChrisCinelli / cachedRequest.js
Last active November 20, 2018 00:09
cache for npm request and elastic search
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
@ChrisCinelli
ChrisCinelli / migrate-data.sh
Last active November 10, 2018 01:02
Migrate all indexes of Elastic Search from a cluster to another - It has less limirations then reindex when runinng with differnt ES versions
#!/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
@ChrisCinelli
ChrisCinelli / split10m
Last active November 10, 2018 00:43
Split a file in pieces of 10Mb that can be easily reassembled with 'cat'
#!/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:
@ChrisCinelli
ChrisCinelli / backup-data.sh
Last active September 29, 2023 16:30
Backup all indexes in Elastic Search (ES) in an archive
#!/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
@ChrisCinelli
ChrisCinelli / index.js
Last active December 19, 2017 01:56
Fast string template with tolerance to undefined
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 || '');
@ChrisCinelli
ChrisCinelli / create-flame-graph-on-elb-aws.sh
Last active November 9, 2021 05:56
Flame graphs on AWS on a ELB
# 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
@ChrisCinelli
ChrisCinelli / superagent.test.js
Created August 16, 2017 21:02
Superagent fail on 4xx with content-type:"text/plain" and a body
// 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;
@ChrisCinelli
ChrisCinelli / fromTextToOneWordForLine.js
Created August 9, 2017 20:41
Convert text in one line of text for each line for faster comparison
// 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'));
@ChrisCinelli
ChrisCinelli / video2gif.sh
Created July 19, 2017 16:52
video2gif with ffmpeg
# 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"
}
@ChrisCinelli
ChrisCinelli / index.html
Created May 26, 2017 19:17
A good testing boilerplate with console for React (Ex: with react-waypoint) - See https://codesandbox.io/s/qxyRGMlp3
<div id="root"></div>