Skip to content

Instantly share code, notes, and snippets.

View samthecodingman's full-sized avatar

Samuel Jones samthecodingman

View GitHub Profile
@samthecodingman
samthecodingman / stackexchange-max-login-streak.js
Created December 19, 2022 13:42
Discover your longest StackOverflow/StackExchange login streak
/*! stackexchange-max-login-streak.js | Samuel Jones 2022 | MIT License | gist.github.com/samthecodingman */
/*
* == USAGE ==
* 1. Review and vet the below code
* 2. Open your profile page on the relevant SE site (e.g. https://stackoverflow.com/users/3068190/samthecodingman)
* 3. Open your Browser's JavaScript console (usually Ctrl+Shift+J or F12)
* 4. Paste and execute this helper script
* 5. Take note of the stats logged to the console
*/
@samthecodingman
samthecodingman / cesium-navigation.d.ts
Created May 12, 2021 10:55
Typescript declaration file for @znemz/cesium-navigation
// Requires these modules to be installed:
// - @turf/helpers (dev dependency, compiled and exported by this module)
// - cesium (dependency)
declare module "@znemz/cesium-navigation" {
import { Cartographic, Rectangle, Viewer } from "cesium";
import { Units } from "@turf/helpers";
export {
Units,
@samthecodingman
samthecodingman / firestore-fetch-documents-by-id.js
Last active April 7, 2021 04:22
Drop-in TypeScript & JavaScript helper functions to help fetch a list of Cloud Firestore documents by their IDs.
/*! firestore-fetch-documents-by-id.js | Samuel Jones 2021 | MIT License | gist.github.com/samthecodingman */
// on server:
import * as firebase from "firebase-admin";
// on client:
// import firebase from "firebase/app";
// import "firebase/firestore";
@samthecodingman
samthecodingman / firestore-multi-batch.ts
Last active September 19, 2022 16:11
A helper object used for managing large batch write operations on Cloud Firestore.
/*! firestore-multi-batch.ts | Samuel Jones 2021 | MIT License | gist.github.com/samthecodingman */
import { firestore } from "firebase-admin";
/**
* Helper class to compile an expanding `firestore.WriteBatch`.
*
* Using an internal operations counter, this class will automatically start a
* new `firestore.WriteBatch` instance when it detects it has hit the operations
* limit of 500. Once prepared, you can commit the batches together.
@samthecodingman
samthecodingman / bookmarklet-gh-pages-switch.js
Last active August 22, 2020 19:15
Switch between the current GitHub repo & it's GitHub pages URL [Javascript Bookmarklet] [CC-BY License]
javascript:{let regex;window.location.href.indexOf("/github.com")>-1?(regex=new RegExp("/(\\w+)/([^/?]+)").exec(window.location.pathname))!=null?window.location.assign("https://"+regex[1]+".github.io/"+regex[2]):alert("Error: RegExp couldn't identify user and repo."):window.location.href.indexOf("github.io")>-1?(regex=new RegExp("/(\\w+).github.io/([^/?]+)").exec(window.location.href))!=null?window.location.assign("https://github.com/"+regex[1]+"/"+regex[2]):alert("Error: RegExp couldn't identify user and repo."):alert("Error: Not a GitHub page or repo.");}
@samthecodingman
samthecodingman / firestoreTransforms.js
Created January 1, 2020 04:48
A collection of helper functions for transforming the results of Firebase Cloud Firestore Queries.
/*! firestoreTransforms.js | Samuel Jones 2019 | MIT License | gist.github.com/samthecodingman */
/**
* @file A file containing common firestore idioms used with queries
* @author Samuel Jones 2017 (github.com/samthecodingman)
* @license MIT
* @module firestore-transforms
*/
/**
@samthecodingman
samthecodingman / extendGetter.js
Created December 22, 2019 13:31
Defines a function that allows you to overwrite/extend an existing accessor in JavaScript. Particularly useful for extending properties of Request/Response objects based on optional headers..
/*! extendGetter.js | Samuel Jones 2017 | MIT License | gist.github.com/samthecodingman */
/**
* @file Extends built-in getter functions
* @author Samuel Jones 2017 (github.com/samthecodingman)
*/
// Example usage: Overwrite `req.protocol` when behind a Google App Engine CDN/proxy
// extendGetter(req, 'protocol', function() {
// let xHttps = this.get('x-appengine-https'); // eslint-disable-line
// if (!xHttps) return; // header not present - fallback to internal getter
@samthecodingman
samthecodingman / databaseExportBundler.js
Created December 17, 2019 16:17
Defines two Cloud Functions for Firebase to bundle data from the Realtime Database for export to Cloud Storage for Firebase.
/**
* Copyright 2019 Samuel Jones (@samthecodingman). All Rights Reserved.
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@samthecodingman
samthecodingman / AutoHotkey-Function-GetArgsArray.ahk
Created November 21, 2018 19:02
AutoHotkey function to create an array of command line arguments whilst maintaining compatibility with AHK v1.0.90+
; [COMPATIBILITY FUNCTION] Get command line arguments as an array (AHK v1.0.90+)
; by @samthecodingman [MIT License]
; You can use A_Args directly if using AHK v1.1.27 or later.
GetArgsArray() {
static _arr
global ; Give access to %0%, %1%, %2%, etc. for before v1.1.27
if (not _arr)
_arr := A_Args ; shortcut for v1.1.27+
@samthecodingman
samthecodingman / AutoHotkey-ShadedIconsForListView.ahk
Last active March 30, 2022 21:56
Working AutoHotkey Example - Shaded Icons in a ListView: Demonstrates the use of icons in a ListView to show shading for a row
; [DEMO] Shaded Icons in a ListView
; Description: Demonstrates the use of icons in a ListView to show shading for a row
; Author: Samuel Jones (@samthecodingman)
; Created: 21 NOV 2018
; Last-Modified: 21 NOV 2018
; License: MIT (https://opensource.org/licenses/MIT)
; URL: https://gist.github.com/samthecodingman/44e58a47a0b2d07c8553f036285f5c4b
; Requires AHK v1.0.46 or later. Demo itself not compatible with AHK v2, but concept is.