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
# 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 |
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 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 |
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
//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 == '') { // |
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 | |
vim -d <(eb printenv $1) <(eb printenv $2) |
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 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); | |
} |
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> |
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
// 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
// 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
# 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 |