Skip to content

Instantly share code, notes, and snippets.

View akatakritos's full-sized avatar

Matt Burke akatakritos

View GitHub Profile
@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
}
@akatakritos
akatakritos / angularjs-rxjs-utils.ts
Created February 14, 2020 16:06
angular.js rxjs misc
/** AngularJS function to unsubscribe from observables when scope destroyed.
* @param $scope - Scope that is listening to an observable.
*/
export function registerDestroyedObservable($scope: any) {
if($scope.destroyed$) {
return;
}
$scope.destroyed$ = new Subject();
$scope.$on('$destroy', () => {
@akatakritos
akatakritos / injectables.ts
Created January 14, 2020 20:03
angular.js injectables and dependencies
function getInjectables(appName) {
const queue = (angular.module(appName) as any)._invokeQueue;
const injectables = [];
function injectable(type, name, deps) {
return { name, type, deps, depsCount: deps.length, depsJoin: deps.join() };
}
queue.forEach(q => {