Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
JogoShugh / README.md
Last active October 23, 2024 19:14
Starborn AG Prototype

Goal

Leverage AI for building a prototype of a VUI / GUI for logging home gardening activities: planting, mulching, watering, weeding, harvesting, etc

image

Tools

  • Spring Boot with Spring AI, leveraging OpenAI's chat completions API
@JogoShugh
JogoShugh / Chapter 4 Quicksort.md
Last active June 26, 2024 15:51
Grokking Algorithms 2nd Ed Notes

The book provides this first implementation, which as written traverses each element past i two times per recursion:

def qsort(arr):
  if len(arr) < 2:
    return arr
  pivot = arr[0]
  less = [i for i in arr[1:] if i <= pivot]
  # NOTE: this traverses all N elements twice in the list.    
  greater = [i for i in arr[1:] if i > pivot]  
@JogoShugh
JogoShugh / 07-Event-Sourced Domain Model.md
Last active April 24, 2024 13:45
Learning Domain-Driven Design book notes
image
  • Storing only "current state" completely loses all business value of "how things got this way over time" (time traveling lost)
  • Think about showing how event-sourced projections do the same level of work that is traditionally done by complicated SQL queries and graph building from disparate data sources -- but when combined with read-models they do them ahead of query time so as to optimize the retrieval of such data when it's used.

Disadvantages

Learning curve

  • Different thinking
@JogoShugh
JogoShugh / KotlinOnly.md
Last active September 13, 2022 11:18
Stateful vs Eventful

Calculating current state

When storing events to track the complete path of state transitions for an aggregate, it is always possible to also store a projection of the current state, but this is usually only necessary for aggregates that have large numbers of events. Since each SCA Transaction will not have a large number of events, that is probably overkill. Instead, a simple process of reading the list of past events and flowing them through a function that is capable of producing, or projecting, a model is rather straight forward. The most important part is to design this such that it only operates on the events, not on the original requests of "commands" since these often have side-effects like calling APIs, saving data, etc.

In Kotlin, this is easily achieved with a left fold over the set of events. For illustration purposes, consider the following simple illustration. You can run and edit the sample online here in the Kotlin Playground.

class Statef
@JogoShugh
JogoShugh / ScreenCapture.sh
Last active February 7, 2021 03:48
Screen capture and convert to Data URI from command line in windows
./MiniCapPortable/MiniCap.exe -save C:\\Users\\Josh\\cap.jpg -captureactivewin -exit
certutil -encode cap.jpg cap.txt
(lines=$(wc -l < cap.txt); tail -n +2 cap.txt | head -n $(($lines-2)) | tr -d '\n') | awk '{ print "data:image/jpg;charset=utf-8;base64,"$1 }' >data.url
@JogoShugh
JogoShugh / Create single asset.md
Created December 18, 2019 16:15
V1 Enterprise Bulk API

Request

JSON

{
  "AssetType": "Story",
  "Scope": "Scope:0",
  "Name": "First Story"
}
@JogoShugh
JogoShugh / sample.md
Last active November 14, 2019 19:52
Api with next / prev links
@JogoShugh
JogoShugh / AssignMemberWithRoleJson.md
Last active November 5, 2019 20:34
Auto generated docs from tests

Execute AssignMemberWithRole Operation upon a Scope for list of Members by OID Token

Demonstrates how to use a single command to assign multiple Members to a Scope along with Scope-specific roles each Member will have for the target Scope.

Setup

For the context of this example, the following request will setup the instance with the needed starting conditions:

POST http://host/instance/api/asset

@JogoShugh
JogoShugh / errors.md
Last active September 16, 2019 16:26
Bulk Error Handling

The following input payload specifies an array with 9 commands. These nine commands expand to 13 concrete actions for the backend API processor to execute. However, 12 of these actions are erroneous! Only one of them will succeed against the database running on the instance.

[
  {
    "from": "Animal"
  },
  {
    "from": "Scope",
    "where": {
@JogoShugh
JogoShugh / hack.js
Last active April 29, 2019 19:41
Card aging with duration in each status stint
$(document).arrive('.story-card', function() {
const story = $(this);
const applyStatusAging = () => {
const number = story.find('.number').text().trim();
const title = story.find('.title');
const query = `
from: PrimaryWorkitem
where:
Number: ${number}