Skip to content

Instantly share code, notes, and snippets.

View Dante-101's full-sized avatar

Gaurav Lahoti Dante-101

View GitHub Profile
@Dante-101
Dante-101 / js-to-ts.js
Last active September 9, 2019 09:30
Javascript (JS) to Typescript (TS) File Extension Converter Script
const glob = require("glob")
const fs = require("fs-extra")
const path = require("path")
const globPaths = [
"src/**/*.js",
"test/**/*.js"
]
globPaths.forEach(globPath => {
@Dante-101
Dante-101 / npm-debug-log
Created May 15, 2018 08:24
npm cache verify Crashing
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'cache', 'verify' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 32567c39d9616e2f
5 verbose stack Error: stream.push() after EOF
5 verbose stack at readableAddChunk (/usr/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:264:30)
5 verbose stack at Class.Readable.push (/usr/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:238:10)
5 verbose stack at Array.from.map.entry (/usr/lib/node_modules/npm/node_modules/cacache/lib/entry-index.js:120:29)
5 verbose stack at Array.map (<anonymous>)
@Dante-101
Dante-101 / video-element.tsx
Last active January 20, 2018 19:53
React video element which stops downloading of video on unmount. If the video has been downloaded successfully, there is no effect. It is used to prevent network request backlog of old assets in Single Page Applications (SPA) and Progressive Web Apps (PWA)
import * as React from 'react'
export class VideoComponent extends React.Component<React.HTMLProps<HTMLVideoElement>> {
videoElem: HTMLVideoElement | null
srcElem: HTMLSourceElement | null
componentWillUnmount() {
this.unmountVideo()
}
@Dante-101
Dante-101 / image-element.tsx
Last active January 20, 2018 13:52
React image element which stops downloading of image on unmount. If the image has been downloaded successfully, there is no effect. It is used to prevent network request backlog of old assets in Single Page Applications (SPA) and Progressive Web Apps (PWA)
import * as React from "react"
export class ImageComponent extends React.Component<React.HTMLProps<HTMLImageElement>> {
imgElem: HTMLImageElement | null
componentWillUnmount() {
this.unmountImage()
}
componentWillReceiveProps(nextProps: React.HTMLProps<HTMLImageElement>) {
@Dante-101
Dante-101 / worker-shutdown.ts
Last active October 17, 2024 19:42
Gist for graceful shutdown of workers
gracefulClusterShutdown = (signal: NodeJS.Signals) => async () => {
if (this.shutdownInProgress)
return
this.shutdownInProgress = true
this.hasCleanWorkerExit = true
log.info(`Got ${signal} on ${this.processStr}. Graceful shutdown start at ${new Date().toISOString()}`)
try {
@Dante-101
Dante-101 / master-worker.ts
Last active October 17, 2024 19:42
Master process class managing workers
import * as cluster from 'cluster'
class Master {
private shutdownInProgress: boolean = false
private hasCleanWorkerExit: boolean = true
private processStr = `${cluster.isMaster ? "master" : "worker"} process ${process.pid}`
gracefulClusterShutdown = (signal: NodeJS.Signals) => async () => {
//defined in worker-shutdown.ts (https://gist.github.com/Dante-101/de2fbd5071bec0c0647f5c9fa1cfa179)