This file contains hidden or 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 useFocus = (count: number) => { | |
const refsArr: Array<React.RefObject<HTMLInputElement>> = []; | |
for (let index = 0; index < count; index++) { | |
const htmlElRef: React.RefObject<HTMLInputElement> = useRef(null); | |
refsArr[index] = htmlElRef; | |
} | |
const setFocus = (index: number): void => { | |
refsArr[index].current && refsArr[index].current.focus(); |
This file contains hidden or 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
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "Run ts-mocha File", | |
"type": "node", | |
"request": "launch", | |
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/ts-mocha", | |
"runtimeArgs": [ | |
"${file}" |
This file contains hidden or 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
app.get('/video', function(req, res) { | |
const path = 'assets/sample.mp4' | |
const stat = fs.statSync(path) | |
const fileSize = stat.size | |
const range = req.headers.range | |
if (range) { | |
const parts = range.replace(/bytes=/, "").split("-") | |
const start = parseInt(parts[0], 10) | |
const end = parts[1] | |
? parseInt(parts[1], 10) |
This file contains hidden or 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
import cluster from "cluster"; | |
import { cpus } from "os"; | |
const NUM_WORKERS = cpus().length; | |
const PATH_TO_SERVER_APP = __dirname + '/app.ts'; | |
cluster.setupMaster({ | |
execArgv: ['-r', 'tsconfig-paths/register', '-r', 'ts-node/register'], | |
exec: PATH_TO_SERVER_APP | |
} as cluster.ClusterSettings) |
This file contains hidden or 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
// Nodejs encryption with GCM | |
// Does not work with nodejs v0.10.31 | |
// Part of https://github.com/chris-rock/node-crypto-examples | |
var crypto = require('crypto'), | |
algorithm = 'aes-256-gcm', | |
password = '3zTvzr3p67VC61jmV54rIYu1545x4TlY', | |
// do not use a global iv for production, | |
// generate a new one for each encryption | |
iv = '60iP0h6vJoEa' |
This file contains hidden or 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
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"type": "node", | |
"request": "launch", | |
"name": "Launch Program", |
This file contains hidden or 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 net = require('net'); | |
var client = new net.Socket(); | |
client.connect(1337, '127.0.0.1', function() { | |
console.log('Connected'); | |
client.write('Hello, server! Love, Client.'); | |
}); | |
client.on('data', function(data) { | |
console.log('Received: ' + data); |
This file contains hidden or 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 | |
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do | |
git branch --track ${branch#remotes/origin/} $branch | |
done |
This file contains hidden or 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 fs = require('fs'); | |
var readStream = fs.createReadStream('bigfilelogs.txt'); | |
var stream = require('stream'); | |
var xtream = new stream.Transform( { objectMode: true } ); | |
xtream._transform = function(chunk, encoding, done) { | |
var strData = chunk.toString(); | |
if (this._invalidLine) { |
This file contains hidden or 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
// Log incoming traffic | |
var metricStore = new Map(); | |
/** | |
* | |
* @param {string} key | |
* @returns {void} | |
*/ | |
const getCount = (key) => metricStore.has(key) ? metricStore.get(key) + 1 : 1; |