Skip to content

Instantly share code, notes, and snippets.

View anuragteapot's full-sized avatar
🔥
try {} catch(err) {}

Anurag Kumar anuragteapot

🔥
try {} catch(err) {}
View GitHub Profile
@anuragteapot
anuragteapot / VideoProcessing.js
Created December 12, 2020 07:37
Video Processing helper code
import FfmpegCommand from "fluent-ffmpeg";
const spawn = require("child_process").spawn;
const exec = require("child_process").exec;
// const execFile = require("child_process").execFile;
import * as path from "path";
import * as fs from "fs-extra";
import moment from "moment";
import { HttpStatus, Util, Logs } from "./../index";
/**
@anuragteapot
anuragteapot / app.js
Created May 14, 2020 17:09 — forked from joshnuss/app.js
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./permission"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
import * as Sentry from "@sentry/node";
import imagemin from "imagemin";
import mozjpeg from "imagemin-mozjpeg";
import sharp from "sharp";
import isJpg from "is-jpg";
import * as aws from "aws-sdk";
import { Upload } from "../../types/graphqlUtils";
import { generateFilename } from "./generateFilename";
export const s3 = new aws.S3({
@anuragteapot
anuragteapot / Drupal.txt
Last active May 7, 2020 16:11
Install Drupal AWS
// Install Mysql server
sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation // Now Set your passsword
// Install PHP 7.2
sudo apt install php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl
// Check PHP status make sure running
sudo apt-get install php libapache2-mod-php
@anuragteapot
anuragteapot / media_source_engine.js
Last active March 29, 2020 16:10
Media Source Extension
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this;
var args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
@anuragteapot
anuragteapot / ffmpeg.md
Created December 27, 2019 00:42 — forked from protrolium/ffmpeg.md
using ffmpeg to extract audio from video files

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:

const FfmpegCommand = require('fluent-ffmpeg');
const spawn = require('child_process').spawn;
const path = require('path');
const fs = require('fs-extra');
const Promise = require('bluebird');
const _ = require('lodash');
const del = require('del');
/**
 * @class ThumbnailGenerator
@anuragteapot
anuragteapot / STL_javascript.js
Created October 27, 2019 11:51
STL Javascript for competitive programming.
class Stack {
constructor() {
this.stack = [];
}
print() {
return this.stack;
}
top() {
return this.stack[this.stack.length - 1];
}
@anuragteapot
anuragteapot / nginxproxy.md
Created October 9, 2019 20:45 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers