Skip to content

Instantly share code, notes, and snippets.

View apal21's full-sized avatar
:octocat:
Web development | DevOps

Apal Shah apal21

:octocat:
Web development | DevOps
View GitHub Profile
@apal21
apal21 / extract password protectred zip.js
Created November 22, 2019 09:39
Open Password protected file in Node.js using unzipper
const unzipper = require('unzipper');
(async () => {
try {
const directory = await unzipper.Open.file('path/to/your.zip');
const extracted = await directory.files[0].buffer('PASSWORD');
// If the extracted entity is a file,
// converting the extracted buffer to string would print the file content
console.log(extracted.toString());
} catch(e) {
@apal21
apal21 / index.js
Created October 28, 2019 18:17
Puppeteer + Tor Proxy file entry point.
const puppeteer = require('puppeteer');
const proxy = require('./proxy'); // Our own proxy module
(async () => {
// Connect to the Tor network
const ip = await proxy();
console.log('Connected to IP:', ip);
let browser;
@apal21
apal21 / proxy.js
Last active October 28, 2019 18:14
Minimal Javascript Module to handle Tor network programatically in Node.js.
const { spawn, exec } = require('child_process');
let tor;
const proxy = kill =>
new Promise(resolve => {
if (kill && tor) {
tor.stdin.pause();
tor.kill();
resolve('killed');
return;
'use strict';
/**
* Person class.
*
* @constructor
* @param {String} name - name of a person.
* @param {Number} age - age of a person.
* @param {String} gender - gender of a person.
*/
'use strict';
/**
* Person class.
*
* @constructor
* @param {String} name - name of a person.
* @param {Number} age - age of a person.
* @param {String} gender - gender of a person.
*/
@apal21
apal21 / ES5 class.js
Last active March 7, 2023 08:06
Example for blog to show the difference between ES5 and ES6 javascript classes using inheritance and prototypes use cases.
'use strict';
/**
* Person class.
*
* @constructor
* @param {String} name - name of a person.
* @param {Number} age - age of a person.
* @param {String} gender - gender of a person.
*/
@apal21
apal21 / CloudFront Signed Cookies Custom Policy.js
Created February 6, 2019 10:02
Example to generate Signed Cookies in CloudFront using Custom Policy.
const AWS = require('aws-sdk');
const cloudFront = new AWS.CloudFront.Signer(
process.env.PUBLIC_KEY,
process.env.PRIVATE_KEY
);
const policy = JSON.stringify({
Statement: [
{
@apal21
apal21 / CloudFront Signed Cookies Canned Policy.js
Created February 6, 2019 09:39
Example to generate Signed Cookies in CloudFront using Canned Policy.
const AWS = require('aws-sdk');
const cloudFront = new AWS.CloudFront.Signer(
process.env.PUBLIC_KEY,
process.env.PRIVATE_KEY
);
// Handle Login Route
router.post('/login-route', (req, res) => {
/* Code to Verify the credentials */
@apal21
apal21 / CloudFront Signed URL Custom Policy.js
Created February 5, 2019 09:14
Example to generate Signed URLs in CloudFront using Custom Policy.
const AWS = require('aws-sdk');
// Try to use process.env.PRIVATE_KEY instead of exposing your key
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
-----END RSA PRIVATE KEY-----`
@apal21
apal21 / CloudFront Signed URL Canned Policy.js
Last active February 5, 2019 09:09
Example to generate Signed URLs in CloudFront using Canned Policy.
const AWS = require('aws-sdk');
// Try to use process.env.PRIVATE_KEY instead of exposing your key
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
-----END RSA PRIVATE KEY-----`