Skip to content

Instantly share code, notes, and snippets.

View akatakritos's full-sized avatar

Matt Burke akatakritos

View GitHub Profile
@akatakritos
akatakritos / AddMassTransitOutboxTablesPostgres.sql
Last active October 6, 2024 21:46
Postgres schema migration script for MassTransit transactional outbox tables
-- https://github.com/MassTransit/MassTransit/discussions/4847
CREATE TABLE inbox_state
(
id bigint GENERATED BY DEFAULT AS IDENTITY,
message_id uuid NOT NULL,
consumer_id uuid NOT NULL,
lock_id uuid NOT NULL,
row_version bytea,
received timestamp with time zone NOT NULL,
receive_count integer NOT NULL,
@akatakritos
akatakritos / AddMassTransitOutboxTables.sql
Last active July 15, 2024 22:01
SQL Server schema migration script for MassTransit's transactional outbox tables
-- https://github.com/MassTransit/MassTransit/discussions/4847
CREATE TABLE [InboxState] (
[Id] bigint NOT NULL IDENTITY,
[MessageId] uniqueidentifier NOT NULL,
[ConsumerId] uniqueidentifier NOT NULL,
[LockId] uniqueidentifier NOT NULL,
[RowVersion] rowversion NULL,
[Received] datetime2 NOT NULL,
[ReceiveCount] int NOT NULL,
[ExpirationTime] datetime2 NULL,
@akatakritos
akatakritos / SimpleLuaSpreadsheet.cs
Created April 12, 2023 15:07
Demo of using lua formulas for a simple spreadsheet app
using System.Text.RegularExpressions;
using NLua;
Dictionary<string, Cell> Spreadsheet = new();
Spreadsheet["EngineeringHours"] = new StaticCell(200);
Spreadsheet["QAMultiplier"] = new StaticCell(0.4);
Spreadsheet["QAHours"] = new FormulaCell("EngineeringHours * QAMultiplier");
Spreadsheet["EngineeringRate"] = new StaticCell(130);
Spreadsheet["QARate"] = new StaticCell(100);
Spreadsheet["TotalCost"] = new FormulaCell("(EngineeringHours * EngineeringRate + QAHours * QARate) * 1.2");
@akatakritos
akatakritos / webview.html
Created January 5, 2022 20:50
Accept.js webview code
<html>
<head>
<script type="text/javascript" src="https://jstest.authorize.net/v1/Accept.js"></script>
<script type="text/javascript">
(function () {
/**
* @param {SecureData} data
*/
function send(data) {
console.log('send', data);
@akatakritos
akatakritos / loading-state.ts
Last active September 27, 2021 19:09
Pattern for tracking loading states. Demo of typescript discriminated union
export type LoadingStatus = 'idle' | 'loading' | 'fulfilled' | 'rejected';
export type LoadingState<T, E = Error> =
| { state: 'idle' }
| { state: 'loading' }
| { state: 'fulfilled'; data: T }
| { state: 'rejected'; error: E };
export const LoadingStates = {
idle<T, E = Error>() {
return { state: 'idle' } as LoadingState<T, E>;
@akatakritos
akatakritos / LookupDataStore.ts
Last active January 28, 2021 16:32
RxJs Data Cache
/**
* Provides a cache of look up data
*
* consumers can subscribe or use async-pipe to get the list of lookup values in each category
*
* shareReplay(1) will make it so that each subscriber gets the last emitted value rather than making
* another API call
* take(1) is just a convenience for the consumers in case they forget to unsubscribe it will
* only emit once and then complete, to avoid a memory leak
*/
@akatakritos
akatakritos / result-operators.ts
Last active November 6, 2020 17:50
rxjs error handling
/**
* rxjs operator to convert a observable to an obserable of Results
*/
export function wrapResult<T>(): UnaryFunction<Observable<T>, Observable<Result<T, Error>>> {
return pipe(
map<T, Ok<T, Error>>((emitted) => new Ok<T, Error>(emitted)),
catchError((error: Error) => of(new Err<T, Error>(error)))
);
}
Clear-Host
Echo "Keep-alive with Scroll Lock..."
$WShell = New-Object -com "Wscript.Shell"
while ($true)
{
$WShell.sendkeys("{SCROLLLOCK}")
Start-Sleep -Milliseconds 100
$WShell.sendkeys("{SCROLLLOCK}")
@akatakritos
akatakritos / debug.ts
Last active January 13, 2021 19:20
rxjs debug operator
export function debug<T>(label: string) {
return tap<T>(
next => console.log(`[${label}]`, next),
err => console.error(`[${label} -- ERR]`, err),
() => console.log(`[${label}]`, 'complete')
);
}
/*
Use:
@akatakritos
akatakritos / .prettierrc
Created March 1, 2020 20:03
.prettierrc
{
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"trailingComma": "es5",
"bracketSpacing": true
}