Skip to content

Instantly share code, notes, and snippets.

View jkeefe's full-sized avatar

John Keefe jkeefe

View GitHub Profile
@jkeefe
jkeefe / access.json
Last active May 3, 2024 19:22
Access One Bucket Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets"
],
"Resource": "arn:aws:s3:::*"
},
@jkeefe
jkeefe / example.js
Last active January 25, 2024 23:12
Adding text to images in Node
const fs = require('fs')
const gm = require('gm').subClass({ imageMagick: '7+' });
WIDTH = 1138
HEIGHT = 50
X = 0
Y = 0
gm('./images/us_at_bottom.png')
.region(WIDTH, HEIGHT, X, Y)
@jkeefe
jkeefe / cors.json
Last active October 25, 2023 22:38
Open CORS policy for AWS S3
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD"
],
"AllowedOrigins": [
@jkeefe
jkeefe / raspberry-pi-ble-sniffer.md
Last active September 16, 2023 14:33
Notes on using Adafruit's "Bluefruit" BLE sniffer with a Raspberry Pi

BLUETOOTH SNIFFER

Working to sniff Bluetooth Low Energy with the adafruit sniffer

For more information, see this blog post

Going the python route, as described here

before installing pySerial, did ...

@jkeefe
jkeefe / round.js
Created August 3, 2023 18:00
Sweet dayjs rounding function
// from https://github.com/iamkun/dayjs/issues/1619#issuecomment-1185714859
const round: PluginFunc = (option, dayjsClass) => {
dayjsClass.prototype.round = function (amount, unit) {
const mod = this.get(unit as UnitType) % amount;
if(mod < amount / 2) {
return this.subtract(mod, unit).startOf(unit);
}
@jkeefe
jkeefe / import_mapshaper.js
Created July 12, 2023 21:09
Importing mapshaper in ES6
// npm install mapshaper --save
import mapshaper from 'mapshaper'
// Example: converting a directory of Shapefiles to GeoJSON
mapshaper.runCommands('-i shapefiles/*.shp -o geojson/ format=geojson');
@jkeefe
jkeefe / date-to-eastern.js
Last active May 12, 2023 19:50
Parse current date to U.S. Eastern time + customize short months & a.m./p.m.
// installation:
// npm install dayjs dayjs-plugin-utc --save
// note: if not already a module, in package.json add "type":"module",
import dayjs from 'dayjs';
import updateLocale from 'dayjs/plugin/updateLocale.js';
import utc from 'dayjs/plugin/utc.js';
import timezone from 'dayjs/plugin/timezone.js';
// set up the as-of date
@jkeefe
jkeefe / time_hash.js
Last active April 20, 2023 14:14
Cool hex time hash for cache busting, unique, etc.
const time_hash = Date.now().toString(36);
// reverse it for more wordiness:
const time_hash2 = Date.now().toString(36).split("").reverse().join("")
@jkeefe
jkeefe / delay.js
Created January 29, 2023 21:23
Node delay function
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
// usage:
console.log("Thing one")
await delay(2000)
console.log("Thing two, two seconds later")
@jkeefe
jkeefe / get_history.sh
Created September 9, 2021 01:55
Load all of the previous versions of a file in git from earlier commits
#!/bin/sh
# copied from https://github.com/truist/settings/blob/master/bin/git_export_all_file_versions
# more details here: https://stackoverflow.com/questions/12850030/git-getting-all-previous-version-of-a-specific-file-folder
# based on script provided by Dmitry Shevkoplyas at http://stackoverflow.com/questions/12850030/git-getting-all-previous-version-of-a-specific-file-folder
set -e
if ! git rev-parse --show-toplevel >/dev/null 2>&1 ; then
echo "Error: you must run this from within a git working directory" >&2