Skip to content

Instantly share code, notes, and snippets.

View adamabernathy's full-sized avatar
👋

Adam C. Abernathy adamabernathy

👋
View GitHub Profile
@adamabernathy
adamabernathy / array.js
Created December 26, 2017 15:20
Array tricks
// Create array of n length
const range = n => Array.from({ length: n }, (v, i) => i);
@adamabernathy
adamabernathy / parseQueryStatement.js
Last active January 10, 2018 17:15
Parse string with "parameter:value" style search syntax to object.
/**
* Parse string with `parameter:value` style search syntax to object.
*
* Examples:
* state:ut --> {state: ['ut']}
* state:ut,az,id --> {state: ['ut', 'az', 'id]}
* complete --> {complete: 1} // defaults to value of 1
* {air_temp > 10} --> {filter_on: '(air_temp > 10)'} // explicit statement
*
* @param {string} blob, query
@adamabernathy
adamabernathy / randomKey.js
Last active January 10, 2018 10:22
Generates a random key name such as "yfva-pyxd-qxfv-ftjr"
/**
* Generates a random key name such as "yfva-pyxd-qxfv-ftjr"
* @param {number} quartets
* @returns {string}
*
* (C) 2018 Adam C. Abernathy, [email protected]. Licence MIT
* https://gist.github.com/adamabernathy/4047f2e79b05af2d5f8b23e0748ac1a2
*/
const randomKey = (quartets = 4) => {
const f = () => Math.floor(Math.random() * 26) + 97; // Lowercase charcodes: 97->122
@adamabernathy
adamabernathy / removing-js-labeled-statement-pt-1.js
Last active February 9, 2018 16:54
Removing JS "labelled" statement part 1
'use strict';
// The basic idea
let keepRunning = true;
for (let i = 0, li = 5; i < li; i++) {
if (!keepRunning) break;
for (let j = 0, lj = 5; j < lj; j++) {
if (!keepRunning) break;
for (let k = 0, lk = 5; k < lk; k++) {
@adamabernathy
adamabernathy / removing-js-labeled-statement-pt-2.js
Last active February 9, 2018 16:54
Removing JS "labelled" statement part 2
// A bit cleaner now
let keepRunning = true;
for (let i = 0, li = 5; keepRunning && i < li; i++) {
for (let j = 0, lj = 5; keepRunning && j < lj; j++) {
for (let k = 0, lk = 5; keepRunning && k < lk; k++) {
if (k == 3) {
keepRunning = false;
break;
}
for (let m = 0, lm = 5; m < lm; m++) {
@adamabernathy
adamabernathy / parsecli.py
Last active March 17, 2018 16:55
Simple CLI arguments parser
'''Simple CLI arguments parser
Requires the `--key=value` format. Defaults to True if value is omitted.
(C) 2018 Adam C. Abernathy, [email protected]
'''
import sys
def coerce_value(value=None):
@adamabernathy
adamabernathy / alpha_columns.py
Last active August 12, 2018 02:54
Convert Excel columns to index and back
# coding: utf-8
'''Excel Column Conversion, (C) 2018 Adam C. Abernathy, Lic. MIT'''
def excel_alpha_to_index(column_name, alphabet='abcdefghijklmnopqrstuvwxyz'):
return sum([(alphabet.find(column_name[-i - 1].lower()) + 1) * pow(len(alphabet), i)
for i in reversed(xrange(len(column_name)))])
def excel_index_to_alpha(postion, alphabet='abcdefghijklmnopqrstuvwxyz'):
column_name = ''
while postion > 0:
@adamabernathy
adamabernathy / remove-all-service-workers.js
Created November 12, 2018 01:32
Removes all services workers from browser via JS
navigator.serviceWorker.getRegistrations().then(registrations => registrations.map(k => k.unregister()));
@adamabernathy
adamabernathy / git-and-gpg.md
Created April 23, 2019 19:23
Git and GPG

GitHub and GPG Signing

Create GPG key pair

gpg --full-generate-key

Assign Key to GH

gpg --list-secret-keys --keyid-format LONG
@adamabernathy
adamabernathy / ec2-iam-s3.yaml
Created June 25, 2019 14:13
Create EC2 with IAM role that can read S3 bucket.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: >-
Creates EC2 instance with an IAM role that can access an S3 Bucket (also created).
Parameters:
KeyPairName:
Description: EC2 Instance SSH Key
Type: AWS::EC2::KeyPair::KeyName