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
| // 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
| 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
| 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
| { | |
| "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
| 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
| openssl req -new -x509 -nodes -newkey rsa:1024 -keyout server.key -out server.crt |
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
| type Constructor<T> = new (...args: any[]) => T; | |
| type ModelType<T extends Model<T>> = Constructor<T> & typeof Model; | |
| export interface IRepository<T extends Model> { | |
| get(id: string): Promise<T| null>; | |
| find(where: FindOptions<T>): Promise<T>; | |
| create(model: T): Promise<T>; | |
| update(key: any, model: T): Promise<T>; | |
| } |
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 nextChar = c=>c?String.fromCharCode(c.charCodeAt(0)+1):'A'; | |
| var nextCol = s=>s.replace(/([^Z]?)(Z*)$/, (_,a,z)=>nextChar(a) + z.replace(/Z/g,'A')); | |
| //test: | |
| nextCol(''); //A | |
| nextCol('A'); //B | |
| nextCol('Z'); //AA | |
| nextCol('AA'); //AB | |
| nextCol('XYZ'); //XZA |