Skip to content

Instantly share code, notes, and snippets.

View ssoper's full-sized avatar
👨‍💻

Sean Soper ssoper

👨‍💻
View GitHub Profile
@ssoper
ssoper / failsafe.kt
Last active December 29, 2021 21:39
Use Failsafe to clone an OkHttp/Retrofit call in Kotlin on the 2nd attempt
// Assumes a long running process where the session keys need to be renewed or possibly even re-created
var session: Session = authorization.renewSession() ?: authorization.createSession()
val retryPolicy = RetryPolicy.builder<Any>()
.handle(ExpiredTokenError::class.java, InvalidTokenError::class.java)
.withDelay(Duration.ofSeconds(1))
.withMaxRetries(1)
.onRetry {
authorization.renewSession()?.let {
println("Re-authorization of session succeeded")
@ssoper
ssoper / mac-clean.sh
Created November 13, 2020 19:23
My homegrown attempt to figure out what’s going on when OSX claims “Other” is taking up half my HDD
#!/usr/bin/env bash
# Root folder
echo "Largest folders at /"
du -hs /* 2>&1 | grep -v 'permitted' | sort -hr | grep '^\s\?\d\+\(\.\d\+\)\?G'
# /private/var temp
echo "Largest temporary folders"
du -hs $TMPDIR../C/* 2>&1 | grep -v 'permitted' | sort -hr | grep '^\s\?\d\+\(\.\d\+\)\?G'
@ssoper
ssoper / gh-clean.sh
Last active October 20, 2020 13:21
Review and remove merged git branches, works on OSX
#!/bin/sh
git branch --merged | sed '$d' >/tmp/merged-branches && \
vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches
@ssoper
ssoper / EtradeInterceptor.kt
Last active October 12, 2020 20:08 — forked from polson/Oauth1SigningInterceptor.kt
An OkHttp interceptor written in Kotlin that supports connecting to the E*TRADE API
/*
* Copyright (C) 2015 Jake Wharton
* Modified work Copyright 2019 Phil Olson
* Modified work Copyright 2020 Sean Soper
*
* 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
@ssoper
ssoper / report.json
Last active March 6, 2021 17:01
Zebec Test Coverage Results
{"instruction": {"missed": 5572, "covered": 100, "ratio": 0.017946877243359655, "ratioStr": "2%"}, "branch": {"missed": 363, "covered": 100, "ratio": 0.27548209366391185, "ratioStr": "28%"}, "line": {"missed": 561, "covered": 100, "ratio": 0.17825311942959002, "ratioStr": "18%"}, "complexity": {"missed": 400, "covered": 100, "ratio": 0.25, "ratioStr": "25%"}, "method": {"missed": 179, "covered": 100, "ratio": 0.5586592178770949, "ratioStr": "56%"}, "class": {"missed": 42, "covered": 57, "ratio": 1.3571428571428572, "ratioStr": "136%"}, "total": "44%", "color": "yellow"}
# use color, even if piping to a another program
--color
# sort files
--sort-files
# only search with case sensitivity if there is mixed case
--smart-case
# follow symlinks
@ssoper
ssoper / housecleaning
Last active December 27, 2017 21:20
Remove merged git branches
#!/usr/bin/env bash
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -D
var distributedThruTestFlight: Bool {
if let sandboxReceiptHasSuffix = Bundle.main.appStoreReceiptURL?.path.hasSuffix("sandboxReceipt"),
sandboxReceiptHasSuffix == true {
return true
}
return false
}
@ssoper
ssoper / read_file.swift
Last active January 18, 2016 21:28
Cross-platform file reader in Swift
// Latest snapshot, 01-11-2016, seems to have fixed the missing SEEK_END pointer yet
// made NSData(contentsOfFile:) a missing symbol on Linux
func contents(path: String) -> String? {
let fp: UnsafeMutablePointer<FILE> = fopen(path, "r")
defer { fclose(fp) }
fseek(fp, 0, SEEK_END)
let fileSize = ftell(fp)
rewind(fp)
@ssoper
ssoper / Promise.first
Last active November 10, 2015 16:41
Extension for Promises which gets the result of the first Promise that passes
/**
* Promise.first
* Get the result of the first Promise that passes
* If none of the Promises pass then it is rejected
* Doesn’t short-circuit like Promise.race
* Requires ES6
*/
if (Promise.first === undefined) {
Promise.first = (promises) => {