Skip to content

Instantly share code, notes, and snippets.


Eric Miller SimplGy

View GitHub Profile
SimplGy / generate-index-from-config.js
Created Aug 3, 2020
For every website folder that contains a certain file, autogen an index.html landing page for it.
View generate-index-from-config.js
// For every website folder that contains a certain file, autogen an index.html landing page for it.
const { readdirSync, statSync, writeFileSync, existsSync, readFileSync } = require('fs');
const { join } = require('path');
// ----------------------------------------- Config
const DIR = '/home/deploy/www';
const CONFIG_FILE = 'logo/info.txt';
SimplGy / generate-nginx-config.js
Last active Aug 2, 2020
script that makes an nginx config for every folder in a certain dir
View generate-nginx-config.js
const { readdirSync, statSync, writeFileSync } = require('fs')
const { join } = require('path')
// ----------------------------------------- Config
const DIR = '/home/deploy/www';
const TARGET = '/home/deploy/deployNginxConfig';
const HEADER = `
# Config generated by 'generate-nginx-config.js', do not hand-edit
SimplGy /
Last active Jul 20, 2020
Rename files with a hash based on their contents. eg: `abc.jpg` to `3101ace8db9f.jpg`. Useful for detecting duplicates.
# TODO: skip tiny files (so small they couldn't be photos)
# TODO: make sure sym links and other file system oddities are handled
# TODO: look at paralellization for perf boost
# Constants
# Update the system's packages
apt-get update
apt-get upgrade
# Set up the `deploy` user
useradd deploy
mkdir /home/deploy
mkdir /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
usermod -s /bin/bash deploy
SimplGy / promise.js
Last active Apr 17, 2020
Sample Promise Implementation. Wrote in
View promise.js
// --------------------------------------------- Promise Implementation
Promise = function () {
this._stack = [];
this._isResolved = false;
Promise.prototype = {
success: function(callback){
// Is the promise already resolved?
if(this._isResolved) {
callback( this._result );
SimplGy / addFileToGit.js
Last active Dec 8, 2019
Usage: `addFileToGit(foo.txt, "some file contents")`. Uses the "octokit" to add a single file to your gitub repo. Adapted from a Ruby guide by
View addFileToGit.js
const Octokit = require('@octokit/rest'); //
// Customize this stuff:
const auth = 'your-key-generated-in-github-ui'; // PRIVATE!
const owner = 'repo-owner';
const repo = 'your-repo-name';
// Constants
const userAgent = 'git commiter v1';
const ref = 'heads/master';
SimplGy / node-get-file-contents.js
Last active May 4, 2019
Node - get the contents of all the files in DIR
View node-get-file-contents.js
const fs = require('fs')
const path = require('path')
const DIR = 'input/';
const readFile = name => fs.readFileSync(name);
(async () => {
const files = fs.readdirSync(DIR)
.filter(s => s.match(/\.csv$/)) // only .csv files -- change to whatever you want.
SimplGy / sort-object-keys.ts
Last active Mar 16, 2019
sort keys of an object using an array index as rank, with TypeScript
View sort-object-keys.ts
export interface SomeShape {
b: string,
c: string,
a: string,
// Specify your sort order here
const rank: Array<keyof SomeShape> = ['a', 'b', 'c'];
export function sortedKvpString(obj: SomeShape) {
SimplGy / keybindings.json
Created Nov 11, 2018
VSCode keybindings
View keybindings.json
// Place your key bindings in this file to overwrite the defaults
"key": "cmd+d",
"command": "editor.action.copyLinesDownAction",
"when": "editorTextFocus && !editorReadonly"
"key": "shift+alt+down",
"command": "-editor.action.copyLinesDownAction",
SimplGy / count-dom-words.js
Last active Nov 5, 2018
This counts up all the words (innerText) at each level of the dom tree.
View count-dom-words.js
// Procedure:
* Count the text inside each element.
* Parents include all the words of their children.
You can’t perform that action at this time.