Skip to content

Instantly share code, notes, and snippets.

View madelinecameron's full-sized avatar

Madeline madelinecameron

View GitHub Profile
@madelinecameron
madelinecameron / delete-branches.js
Last active December 2, 2021 15:55
Delete git branches from file because I am a wimp and want to check my work
const { exec } = require('child_process');
const fs = require('fs/promises');
;(async () => {
const rawBranchList = await fs.readFile('./delete', 'utf8');
const branchesToDelete = rawBranchList.split('\n').filter(Boolean);
const promises = branchesToDelete.map(async (branch) => {
return new Promise((resolve, reject) => {
@madelinecameron
madelinecameron / provision
Created January 19, 2021 15:29
Provision a new project on my VPS
#!/bin/bash
rsync -rave "ssh -i ~/.ssh/key" infra/[project name].conf root@[IP]:/etc/supervisor/conf.d;
rsync -rave "ssh -i ~/.ssh/key" infra/[project name]_http root@[IP]:/etc/nginx/sites-available;
ssh root@[IP] -i ~/.ssh/key "ln -s /etc/nginx/sites-available/[project name]_http /etc/nginx/sites-enabled/ && sudo service nginx reload && sudo service nginx restart && sudo supervisorctl reload && sudo supervisorctl restart [project name] && certbot --nginx"
@madelinecameron
madelinecameron / deploy
Created January 19, 2021 15:27
Deploy to my VPS
#!/bin/bash
echo 'Hash-busting index.html'
./scripts/rewriteIndex
echo 'Syncing files to server'
rsync --exclude=node_modules/ -rave "ssh -i ~/.ssh/key -A" * root@[IP]:[project folder];
echo 'SSHing in and restarting the server'
ssh root@[IP] -i ~/.ssh/qnzl "cd [project name] && npm install && sudo supervisorctl restart [project name]"
@madelinecameron
madelinecameron / sneaky-server.js
Created January 15, 2021 20:36
Example of using symbols to hide data on a request and make sure it can never get returned to a user
const express = require('express')
const app = express()
const doStuff = (req, res, next) => {
// Symbols are like objects in that even if their contents are equal, they aren't.
// You have to pass symbols around to use them to access data.
const $superSecret = Symbol('superSecret')
const $dontTellAnyone = Symbol('dontTellAnyone')
@madelinecameron
madelinecameron / run-out.js
Created January 14, 2021 22:09
Making sure you can't cause max stack with Promise.all
// ~10,000,000+ on 16GB of RAM causes out of memory
const PROMISE_COUNT = 1000000
const doStuff = (index) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
return resolve(index)
}, (Math.random() * index) / 100)
})
}
const { PerformanceObserver, performance } = require('perf_hooks');
let avgCallTime = 0
const obs = new PerformanceObserver((list, observer) => {
const callTime = list.getEntries()[0].duration
avgCallTime += callTime
})
obs.observe({ entryTypes: ['measure'] })
@madelinecameron
madelinecameron / redirect.js
Created September 11, 2019 01:36
Redirect incoming phone call to SIM
const accountId = process.env.TWILIO_ACCT_ID
const token = process.env.TWILIO_TOKEN
const mongoose = require('mongoose')
const express = require('express')
const client = require('twilio')(accountId, token)
const debug = require('debug')('rprivacy:bounceCalls')
// Model of User
const User = {}
#!/usr/bin/env node
// v1.0.0 - Nov 13th, 2018
// Disclaimer: This doesn't create the CLI docs without fault,
// it's simply to get most of the work done.
// You will still need to read and check the resulting docs.
const { execFile } = require('child_process')
const { resolve } = require('path')
@madelinecameron
madelinecameron / tackyer.js
Last active August 28, 2018 01:25
Reduce the size of your CSS file by only taking what you use
const { resolve } = require('path')
const request = require('superagent')
const globby = require('globby')
const css = require('css')
const fs = require('fs')
const flattenArray = (arr) => [].concat(...arr)
const rulesToString = (rules) => {
return rules.map(rule => {

Keybase proof

I hereby claim:

  • I am madelinecameron on github.
  • I am madeline (https://keybase.io/madeline) on keybase.
  • I have a public key ASDWBpDpooC65e7-82QPWNfYhOdo-S48Pc7sDnK2vMch3wo

To claim this, I am signing this object: