Skip to content

Instantly share code, notes, and snippets.

View snewell92's full-sized avatar

Sean Newell snewell92

View GitHub Profile
@snewell92
snewell92 / container_override.py
Last active December 7, 2023 17:06
Wireup DI Override
from typing import (
Any,
Dict,
Generic,
Literal,
Optional,
Tuple,
TypeVar,
)
from wireup import DependencyContainer, container
@snewell92
snewell92 / filtered_to_jq.sh
Last active May 25, 2023 07:42
Conditionally pass to jq if the line looks a bit like jason
#!/bin/zsh
# Conditionally pass line or file data to jq.
#
# First argument is a filter override to jq, default is '.'
# Second argument is a file, otherwise stdin is used
JQ_FILTER=${1:-'.'}
while read line
@snewell92
snewell92 / cli.ts
Created April 3, 2023 20:20
ChatGPT Prompt for overload issue
import cli, { InputQuestion, ListQuestion } from "inquirer";
interface TypeSafeInput<
TValidatedInput,
TName extends string
> extends InputQuestion<{ [name in TName]: TValidatedInput }> {
type: "input";
name: TName;
message: string;
typePredicate: (input: any) => input is TValidatedInput;
@snewell92
snewell92 / my-dict.ts
Last active September 28, 2018 02:19
Typescript Dictionary
type KEY = string | number | symbol;
interface Dictionary<K extends KEY, V> {
getKeys(): K[];
getValues(): V[];
get(key: K): V | null;
put(key: K, val: V): void; // or boolean?
}
class JSDict<K extends KEY, V> implements Dictionary<K, V> {
@snewell92
snewell92 / test-app.docker-compose.yml
Last active March 11, 2018 00:01
basic http traefik
version: "2"
services:
app:
image: crccheck/hello-world
restart: always
networks:
- web
- default
expose:
@snewell92
snewell92 / api-server.js
Last active March 8, 2018 21:21
Feathers JWT doesn't have userID
// CLIENT
import feathers from '@feathersjs/feathers'
import socketio from '@feathersjs/socketio-client'
import auth from '@feathersjs/authentication-client'
import io from 'socket.io-client'
const socket = io('http://localhost:3030')
const app = feathers()
// Set up Socket.io client with the socket
@snewell92
snewell92 / Continuation.js
Created February 28, 2018 16:03
Some thing to map but stop on a failure
class ContinueOnSuccess {
items = [];
length = 0;
constructor(newItems) {
this.items = newItems;
length = this.items.length;
}
@snewell92
snewell92 / ifThen.ts
Created December 18, 2017 20:46
Typescript ifThen pattern
import { curry } from 'lodash';
export type Predicate = () => boolean;
export type Func<a> = () => a;
export interface ThenElse<T = void, E = T> {
t: Func<T>,
e: Func<E>
}
@snewell92
snewell92 / app.ts
Created October 18, 2017 20:46
Context
import { curry, flowRight as compose } from 'lodash';
const Task = require('folktale/concurrency/task');
/* example code, pieces from application */
/* Imagine a functional-progrmaming style Forgot Password workflow */
usernameOrEmailExists = (input: {/*...*/}) => isValid(input)
? Task.of(input.username)
: Task.rejected('Invalid');
@snewell92
snewell92 / fp-test.js
Last active October 17, 2017 20:40
Refactor to task
const crypto = require('crypto');
const util = require('util');
const curry = require('lodash/curry');
const compose = require('lodash/flowRight'); // alias flowRight as compose
const moment = require('moment');
const Task = require('folktale/concurrency/task');
const { fromPromised, waitAll } = require('folktale/concurrency/task');
// isValidForgotPasswordRequest :: ForgotPasswordInput -> boolean