Skip to content

Instantly share code, notes, and snippets.

@erikologic
erikologic / CONFIGURATION.md
Last active June 19, 2026 16:09
Restish + Gmail CLI - OAuth pagination tools (no secrets exposed)

Restish + Gmail Configuration

Setup

Google Cloud OAuth app with redirect URI http://localhost:8080.

Restish Config (~/.config/restish/restish.json)

{
@erikologic
erikologic / restish-content
Created June 19, 2026 16:08
Restish + Gmail CLI - OAuth pagination tools
# Restish + Gmail CLI
Complete setup for using restish CLI with Gmail API.
## Files
- `restish` - This overview
- `paginate` - Pagination handler
- `CONFIGURATION.md` - OAuth setup
#! /bin/bash
set -eo pipefail
AWS_PARAMS=("$@")
NEXT_TOKEN=""
OUTPUT="{}"
deep_merge() {
@erikologic
erikologic / extract.js
Created March 2, 2023 22:42
Calculate border crosses with Google Maps Timeline data
/*
I need to monitor my UK border crosses for residential purposes.
This script will calculate whenever I moved more than 5 degrees, either on lat or long, from one datapoint to the other, since the start of 2017.
*/
// First of all, go to Google Takeout and fetch your Location data.
// Then, for each day, extract the last position for the day with the following command (using gojq)
// cat Records.json | gojq -r '[.locations[] | select((.timestamp | sub("\\.[0-9]+";"") | strptime("%Y-%m-%dT%H:%M:%SZ")) | mktime >= 1483228800) | {latitudeE7, longitudeE7, accuracy, source, timestamp}] | group_by(.timestamp[:10]) | map(max_by(.timestamp)) | map({latitude: (.latitudeE7 / 10000000), longitude: (.longitudeE7 / 10000000), accuracy: .accuracy, source: .source, timestamp: .timestamp})' > grouped.json
// *** You might want to change the Unix timestamp after mktime to filter on your needs
@erikologic
erikologic / inject_behaviour.js
Last active July 25, 2023 21:02
Jest: mocking externally dependencies
// TestSubject.js
const ExternalDependency = require('./ExternalDependency')
module.exports = class TestSubject {
constructor () {
this.externalDependency = new ExternalDependency()
}
isExternalDependencyMocked () {
return this.externalDependency.isMocked
@erikologic
erikologic / Error.js
Created August 12, 2017 02:41
CustomError in NodeJS
module.exports = function CustomError(message) {
this.name = this.constructor.name
this.message = message
Error.captureStackTrace(this, this.constructor)
}
module.exports.prototype.inspect = function () {
return this.stack
}
//file substack.js
module.exports = function() {
console.log('main entry point');
};
module.exports.details = function() {
console.log('more detailed functionality');
};
function getDatasetfromJsonData(jsonData){
return jsonData[0].scores;
};
function getLabels(dataset) {
return Object.keys(dataset)
};
function getData(dataset) {
return Object.keys(dataset).map(function(key) {
// ...IN THE CALLER
import JSONDataConverter from './JSONDataConverter';
<RadarChart data={JSONDataConverter(data)} width={width} height={height} redraw />
var JSONDataConverter = (function () {
var getDatasetfromJsonData = function(jsonData){
return jsonData[0].scores;
};
var getLabels = function(dataset) {
return Object.keys(dataset)
};
var getData = function(dataset) {