start new:
tmux
start new with session name:
tmux new -s myname
A quick overview of the node.js streams interface with basic examples.
This is based on @brycebaril's presentation, Node.js Streams2 Demystified
Streams are a first-class construct in Node.js for handling data.
Think of them as as lazy evaluation applied to data.
# first we download the list of IP ranges from CloudFlare | |
wget https://www.cloudflare.com/ips-v4 | |
# set the security group ID | |
SG_ID="sg-00000000000000" | |
# iterate over the IP ranges in the downloaded file | |
# and allow access to ports 80 and 443 | |
while read p | |
do |
Not all random values are created equal - for security-related code, you need a specific kind of random value.
A summary of this article, if you don't want to read the entire thing:
Math.random()
. There are extremely few cases where Math.random()
is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.crypto.getRandomBytes
directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.uuid
, specifically the uuid.v4()
method. Avoid node-uuid
- it's not the same package, and doesn't produce reliably secure random values.random-number-csprng
.You should seriously consider reading the entire article, though - it's
'use strict'; | |
const crypto = require('crypto'); | |
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters) | |
const IV_LENGTH = 16; // For AES, this is always 16 | |
function encrypt(text) { | |
let iv = crypto.randomBytes(IV_LENGTH); | |
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv); |
module.exports = { | |
config: { | |
// default font size in pixels for all tabs | |
fontSize: 12, | |
// font family with optional fallbacks | |
fontFamily: 'Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace', | |
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk) | |
cursorColor: 'rgba(248,28,229,0.8)', |
-- Retrieve descendants | |
-- ==================== | |
-- retrieve descendants of #4 | |
SELECT c.* | |
FROM Comments AS c | |
JOIN TreePaths AS t ON c.comment_id = t.descendant | |
WHERE t.ancestor = 4; | |
-- Retrieve ancestors |
db.getCollection('fs.chunks').aggregate([ | |
{ $lookup: { from: 'fs.files', localField: 'files_id', foreignField: '_id', as: 'file' } }, | |
{ $unwind: { path:'$file', preserveNullAndEmptyArrays: true } }, | |
{ $match: { file: { $exists: false } } }, | |
{ $project: { _id: 1, files_id: 1 } }, | |
]).forEach(function(chunk) { | |
printjson(chunk); | |
// db.getCollection('fs.chunks').remove({ _id: chunk._id }); | |
}); |
import customModuleLoader = require('module'); | |
export class CustomModuleLoader { | |
public cOptions: any = require('../tsconfig.json').compilerOptions; | |
public replacePaths: any = {}; | |
constructor() { | |
Object.keys(this.cOptions.paths).forEach(alias => { | |
this.replacePaths[alias.replace(/\*.?/, '(.*)')] = this.cOptions.paths[alias][0].replace(/\*.?/, '$1'); |
const { pbkdf2: deriveKey } = require("pbkdf2"); | |
const crypto = require("crypto"); | |
const DERIVATION_ROUNDS = 200000; | |
const HMAC_KEY_SIZE = 32; | |
const PASSWORD_KEY_SIZE = 32; | |
function pbkdf2(password, salt, rounds, bits) { | |
return new Promise((resolve, reject) => { | |
deriveKey(password, salt, rounds, bits / 8, "sha256", (err, key) => { |