Skip to content

Instantly share code, notes, and snippets.

View ToastShaman's full-sized avatar

Kevin Denver ToastShaman

View GitHub Profile
package com.github.toastshaman.json.reader;
import io.vavr.Function0;
import io.vavr.Function1;
import io.vavr.Function2;
import io.vavr.Function3;
import io.vavr.Function4;
import org.json.JSONObject;
import java.util.Arrays;
@ToastShaman
ToastShaman / SpringJdbcAction.java
Last active December 9, 2023 21:18
Spring JDBC Monad
package com.example.demo.fp;
import io.vavr.control.Try;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.transaction.support.TransactionTemplate;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.*;
@ToastShaman
ToastShaman / BookBuddy.py
Last active January 1, 2023 12:10
BookBuddy: My Library Manager to Markdown
#!/usr/bin/env python3
# pip3 install pathvalidate
# pip3 install pillow
# brew install libffi libheif
# pip3 install pyheif
import sqlite3
import base64
import io
@ToastShaman
ToastShaman / install.sh
Last active September 12, 2022 19:25
Mac provisioning with Brew
#!/bin/bash
set -euxo pipefail
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install --cask alacritty
brew install --cask iterm2
brew install --cask visual-studio-code
brew install --cask cyberduck
@ToastShaman
ToastShaman / Dockerfile
Last active April 29, 2022 13:45
PlantUML CLI
FROM openjdk:14-jdk-alpine3.10
ENV PLANTUML_VERSION=1.2022.4
ENV LANG en_US.UTF-8
RUN \
apk add --no-cache graphviz wget ca-certificates && \
apk add --no-cache graphviz wget ca-certificates ttf-dejavu fontconfig && \
mkdir /app && \
wget "https://github.com/plantuml/plantuml/releases/download/v${PLANTUML_VERSION}/plantuml-${PLANTUML_VERSION}.jar" -O /app/plantuml.jar && \
apk del wget ca-certificates
RUN ["java", "-Djava.awt.headless=true", "-jar", "/app/plantuml.jar", "-version"]
@ToastShaman
ToastShaman / random-git-branch.sh
Created January 24, 2022 11:45
Create a git branch with a random name (OSX)
function git_random_branch() {
randomword=`shuf /usr/share/dict/words | head -1 | awk '{print tolower($0)}'`
branchname="kevin_${randomword}"
git create-branch -r ${branchname}
}
git_random_branch()
@ToastShaman
ToastShaman / PagedResults.kt
Created October 15, 2021 06:21
DynamoDB Pagination
// uses value4k: https://github.com/fork-handles/forkhandles/tree/trunk/values4k
class PaginationToken private constructor(value: String) : StringValue(value) {
companion object : NonBlankStringValueFactory<PaginationToken>(::PaginationToken)
}
data class PagedResult<T>(
private val result: List<T> = emptyList(),
val token: PaginationToken? = null
) : List<T> by result {
companion object
@ToastShaman
ToastShaman / Retry.kt
Last active October 18, 2022 21:12
A simple retry mechanism in Kotlin
fun <R> retry(
maxAttempts: Int,
action: () -> R
): R {
require(maxAttempts > 0) { "maxAttempts must be greater than 0" }
return runCatching(action).getOrElse {
val leftAttempts = maxAttempts.dec()
if (leftAttempts == 0) throw it
retry(leftAttempts, action)
}
@ToastShaman
ToastShaman / active-record-pattern.js
Created February 25, 2016 18:06
Active Record Pattern (ngEurope 2014)
function OrderFactory($http) {
function Order(order) {
angular.extend(this, order || {});
this.toppings = this.toppings || {};
}
Order.prototype.addTopping = function(topping) {
this.toppings.push(topping);
};
@ToastShaman
ToastShaman / index.html
Last active August 29, 2015 14:07 — forked from anonymous/index.html
AngularJS directive that allows you to subtract money from a total amount in pounds or percentages
<html ng-app="app">
<head>
<meta charset="utf-8">
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/1.0.1/math.js"></script>
</head>
<body ng-controller="MoneyController as ctrl">
<p>
Total: <input type="number" ng-model="ctrl.total">
</p>