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 / Dockerfile
Last active December 21, 2015 10:33
Node v4 + npm v3 - Docker Image
# Pull base image.
FROM node:4.2.3
# NPM 3 has better management for peerDependencies
RUN npm install -g npm@3.x
# These 2 guys take a little time and they rarely change...
RUN npm install -g bower forever@0.14.2
// Convert the package versions in package.json to the version of the installed packages
//
// cd your-package
// node fix-package-json.js > package.json
var fs = require("fs");
var contents = fs.readFileSync("package.json");
var json = JSON.parse(contents);
// Get current installed versions
@ChrisCinelli
ChrisCinelli / find-in-json.js
Created April 7, 2017 00:14 — forked from iwek/find-in-json.js
Searching through JSON
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i] == val || i == key && val == '') { //
@ChrisCinelli
ChrisCinelli / diffenv.bash
Created May 17, 2017 15:12
Diff env variables between 2 environment in Amazon Elastic Beanstalk
#!/bin/bash
vim -d <(eb printenv $1) <(eb printenv $2)
@ChrisCinelli
ChrisCinelli / containPhoneNumber.js
Last active May 24, 2017 17:15
Catch phone numbers including (223) four56-7890
var rePhoneNumber = /([2-9]|two|three|four|five|six|seven|eight|nine)[^0-9a-zA-Z]{0,3}([0-9]|zero|o|one|l|i|two|three|four|five|six|seven|eight|nine)[^0-9a-zA-Z]{0,3}([0-9]|zero|o|one|l|i|two|three|four|five|six|seven|eight|nine)[^0-9a-zA-Z]{0,3}([0-9]|zero|o|one|l|i|two|three|four|five|six|seven|eight|nine)[^0-9a-zA-Z]{0,3}([0-9]|zero|o|one|l|i|two|three|four|five|six|seven|eight|nine)[^0-9a-zA-Z]{0,3}([0-9]|zero|o|one|l|i|two|three|four|five|six|seven|eight|nine)[^0-9a-zA-Z]{0,3}([0-9]|zero|o|one|l|i|two|three|four|five|six|seven|eight|nine)[^0-9a-zA-Z]{0,3}([0-9]|zero|o|one|l|i|two|three|four|five|six|seven|eight|nine)[^0-9a-zA-Z]{0,3}([0-9]|zero|o|one|l|i|two|three|four|five|six|seven|eight|nine)[^0-9a-zA-Z]{0,3}([0-9]|zero|o|one|l|i|two|three|four|five|six|seven|eight|nine)/gi
export default function containPhoneNumber(num) {
return !!rePhoneNumber.test(num);
}
@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>
@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 / 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 / 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 / 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