Skip to content

Instantly share code, notes, and snippets.

View beattyml1's full-sized avatar

Matthew Beatty beattyml1

View GitHub Profile
@beattyml1
beattyml1 / READEM.md
Last active October 20, 2023 17:52
Web Storm TypeScript Bug

In the above file the first two types work in both ts compiler and webstorm. The final type works in ts compiler but fails in Web Storm

@beattyml1
beattyml1 / session.py
Last active October 28, 2020 19:31
Converting static sql alchemy global session db session to thread safe/per thread session
class Module:
@property
def session(self):
local = threading.local()
_session = getattr(local, 'session', None)
if _session is None:
local.session = build_session()
return _session
sys.modules[__name__] = Module()
@beattyml1
beattyml1 / combine
Created March 1, 2019 20:09
ts operators
import {and as bool_and} from 'boolean'
import {and as num_and} from 'number'
@operator
export const and = overload(bool_and, num_and)
@beattyml1
beattyml1 / Contextual Best Practices.md
Last active June 6, 2018 15:01
Contextual Best Practices

As engineers we often hear about best practices, but we also see so many smart people disagree about what is or isn't best practice. While some things seem relatively clear and agreed upon many aren't. Many are often vigorously disagreed upon. These disagreements often happend between people at the top of their field. So what's the deal? Is one group just wrong?

I would like to posit that they can both be right but in different contexts. When you put a bunch of smart, motivated, passionate, and caring people together and give them a task to solve it is reasonable that they will do a good job within the context and constraints that they are working. Context and constraints being the key words there.

We all come from different places and are trying to solve different problems. To think that all our problems are the same and thus have the same solution is just as silly as to think that all our problems are completely unique. So many incredible people have come before us and we should learn from them and what

@beattyml1
beattyml1 / fixAsyncJestErrors.ts
Created March 5, 2018 23:18
fixAsyncJestErrors
// this doesn't work just yet but I'm trying to figure out the idea because async testing in jest is driving me nuts
async function fixAsyncErrors(action: (expect: (x) => Matchers) => Promise<any>|void) {
let errors = new Array();
await (action(x => {
let matchers = expect(x);
let matcherProps = Object.getOwnPropertyNames(matchers);
let safeMatchers = matcherProps.reduce((safeMatchers, p) => {
let safe = typeof matchers[p] === 'function' ? (...args) => {
try { matchers[p](...args); }
catch (e) { errors.push(e); console.error(e) }
@beattyml1
beattyml1 / Record Editor.ts
Last active January 28, 2018 02:55
Record Editor Example
@editorFor("record", FieldSet, {isDefault: true})
export class RecordEditor extends BaseEditorModel<{[key:string]:any}, RecordSchemaType, BaseEditorModel<RecordSchemaType>, void> {
render() {
let recordType = this.props.field.typeParameters.typeParams as SchemaRecordType;
let fields = recordType.fields;
return (<>{
fields.map(field =>
<FieldEditor value={this.props.value[field.name]} field={field} context={createContext(field, this.props.context)}/>
)}
</>)
@beattyml1
beattyml1 / Metatonic Field Model.ts
Created January 27, 2018 23:24
Metatonic Field Model
@model
export class Field {
@field("text", "Name", SchemaEntryType.entry, { required: true })
name: string;
@field("text", "Label", SchemaEntryType.entry, { required: true })
label: string;
@field("code", "Type", SchemaEntryType.selection, { required: true })
typeName: string;
@beattyml1
beattyml1 / Metatonic Custom Editor Example.ts
Created January 27, 2018 22:29
Metatonic Custom Editor Example
@editorFor("numeric", InputBoxLabelContainer, { isDefault: true })
export class NumericEditor extends BaseEditor<Numeric, NumericTypeInfo, BaseEditorModel<Numeric>, void> {
render() {
return (
<input type="number"
id={this.uniqueId()}
value={this.value().toEditorString()}
required={this.field().required}
max={this.props.field.max || undefined}
min={this.props.field.min || undefined}
@beattyml1
beattyml1 / Rest.ts
Last active January 24, 2018 02:37
import {Maybe, Nothing} from "CoreTypes";
export type IdTypes = string|number;
export type IdRequest<TId extends IdTypes> = { id?: Maybe<TId> };
export type QueryRequest<TQuery> = { query?: Maybe<TQuery> };
export type ActionRequest = { action?: Maybe<string>; };
export interface RestfulClient {
Get<TResult, TQuery, TId extends IdTypes>(
resourceUrl: string,
requestParams?: IdRequest<TId> & QueryRequest<TQuery> & ActionRequest): Promise<TResult>
@beattyml1
beattyml1 / Technical Debt Metrics.md
Last active June 6, 2018 15:29
Technical Debt Metrics

Given

time_cost = person months spent on fix/refactor/project total including training and any temporary lost efficiency

total_improvement = specific to scenario

Then