Skip to content

Instantly share code, notes, and snippets.

@devdoomari3
devdoomari3 / readme.md
Last active August 27, 2020 09:46
On Code Complexity, Types, and Protobuf

https://blog.codacy.com/an-in-depth-explanation-of-code-complexity/

I think a lot of people don't know these simple things:

  1. key to reducing source-code complexity = reducing number of possible cases
  • reduce number of cases to think about
  • reduce number of 'what-can-go-wrong?' scenarios
  1. number-of-cases are usually multiplicative between function-calls
@devdoomari3
devdoomari3 / check_keys_match.ts
Created July 17, 2020 07:00
typescript type-level example: check keys match
import { Equals } from 'typelevel-ts';
export const __KEYS_MATCH_OK_STRING = 'Keys Match!'
export type isMatch<TType> = TType extends 'T' ?
typeof __KEYS_MATCH_OK_STRING : never;
export type RequireSameKeys<
A extends object,
B extends object
> = {
@devdoomari3
devdoomari3 / gist:eb3036a93dbaffe34fc3a70cc44bf07b
Last active March 5, 2020 02:32
intellij-rust set up stuff
solution for https://github.com/intellij-rust/intellij-rust/issues/4817:
--> https://github.com/intellij-rust/intellij-rust/issues/3628
@devdoomari3
devdoomari3 / InTeResTing.txt
Created February 18, 2020 11:17
interesting Typescript stuffs
https://stackoverflow.com/questions/57016728/is-there-a-way-to-define-type-for-array-with-unique-items-in-typescript
( https://www.typescriptlang.org/play/#code/MYewdgzgLgBFCuAHANgUwPIDMAyBLKqATgIbIQBcMA2gIwA0MATA4wLowC819TLrA3AFgAUKEiwEKDJgBy4PARJlKVMPAC2AIyIM1WnTD3bC7LrRZ8ho8NBjFCJAJ5YFRUhRgAKGjAA+TAEoqU24LJgERMVt7Jyw5MFclDyMiYM5Q3nCrEShHRFQYAEkwADdSXAATAB4AFQA+dIBRBxBCGAAyGABvGAB9XqJCVoBZVAgIYgBzVEoamABfDsNUEqJs4Vz8mABBCABVMFwAR3hUbYdiRyqRGB2YVAAPAjAKiBgAJVRiCvBkR3OnFViGBHHU6DcYAAhe5PVAvN6fb6-f4XK7A0EiBpcLoQqiFGC4MAwADWqEcIEwO1YlHgYGJYBAAHciY9nq9uhDblQAFIEomk8mUyHUmC81lw9n4gD8y1WbUokJ57HF8J2ePYMtp9KZRMoYBWRAh81UGmMrE5MBlxTKyEqVSo23VDAARLg3oRUPliAQKs7WHULZRHYVzcJ5utNgUZDEmcRNGhOBD-NBCITJknDKbDcJbv5NCAQGhgRmQJoAFaoYBQDNqZDIDO0iqoTCE1AVDMQRxaQvrKKwYj7Q4nM6o9LXHMwGQwtlvaMtRlxtDgifbacSt5pfyIn5gP4Ay5VGQNTq7A7HU77q7bBjbAPCOqeCHEIMiAKcBrEXs2WAgYmXdIDmew6Xp45iZAAzKwAT8DAAD0sEwL+lyRN+hggFA6B-o4AGDueI5OKBPDMOE0FwQhgytAAhCI8G3HR9EMYxTEMQAfrcLE0QhKRtG6aH9uMuCTGAi4FFAIBFKU5TVFQxGuu6npfD6foNP4jbNq27bCJxMAAMLbAAao02w1AAy
@devdoomari3
devdoomari3 / InTeResTing.txt
Created February 18, 2020 11:17
interesting Typescript stuffs
https://stackoverflow.com/questions/57016728/is-there-a-way-to-define-type-for-array-with-unique-items-in-typescript
( https://www.typescriptlang.org/play/#code/MYewdgzgLgBFCuAHANgUwPIDMAyBLKqATgIbIQBcMA2gIwA0MATA4wLowC819TLrA3AFgAUKEiwEKDJgBy4PARJlKVMPAC2AIyIM1WnTD3bC7LrRZ8ho8NBjFCJAJ5YFRUhRgAKGjAA+TAEoqU24LJgERMVt7Jyw5MFclDyMiYM5Q3nCrEShHRFQYAEkwADdSXAATAB4AFQA+dIBRBxBCGAAyGABvGAB9XqJCVoBZVAgIYgBzVEoamABfDsNUEqJs4Vz8mABBCABVMFwAR3hUbYdiRyqRGB2YVAAPAjAKiBgAJVRiCvBkR3OnFViGBHHU6DcYAAhe5PVAvN6fb6-f4XK7A0EiBpcLoQqiFGC4MAwADWqEcIEwO1YlHgYGJYBAAHciY9nq9uhDblQAFIEomk8mUyHUmC81lw9n4gD8y1WbUokJ57HF8J2ePYMtp9KZRMoYBWRAh81UGmMrE5MBlxTKyEqVSo23VDAARLg3oRUPliAQKs7WHULZRHYVzcJ5utNgUZDEmcRNGhOBD-NBCITJknDKbDcJbv5NCAQGhgRmQJoAFaoYBQDNqZDIDO0iqoTCE1AVDMQRxaQvrKKwYj7Q4nM6o9LXHMwGQwtlvaMtRlxtDgifbacSt5pfyIn5gP4Ay5VGQNTq7A7HU77q7bBjbAPCOqeCHEIMiAKcBrEXs2WAgYmXdIDmew6Xp45iZAAzKwAT8DAAD0sEwL+lyRN+hggFA6B-o4AGDueI5OKBPDMOE0FwQhgytAAhCI8G3HR9EMYxTEMQAfrcLE0QhKRtG6aH9uMuCTGAi4FFAIBFKU5TVFQxGuu6npfD6foNP4jbNq27bCJxMAAMLbAAao02w1AAy
@devdoomari3
devdoomari3 / typescript_ramda_pipe.ts
Created February 17, 2020 02:41
typescript_ramda_pipe.ts
import { pipe } from 'ramda'
export function addB<T>(i: T) {
return {
...i,
b: 2,
}
}
export function addC<T>(i: T) {
@devdoomari3
devdoomari3 / del_remote_branch_by_pattern.sh
Created November 12, 2019 11:57
delete remote branch by pattern
// from https://stackoverflow.com/questions/10555136/delete-multiple-remote-branches-in-git
// TODO - define bash/zsh func
@devdoomari3
devdoomari3 / pack_unpack_generics.ts
Created August 21, 2019 01:48
pack_unpack_generics.ts
export type PackedGenerics<A,B,C> = {
a: A,
b: B,
c: C
}
type testType = PackedGenerics<number, boolean, string>
type unpack2nd<T extends PackedGenerics<any, any, any>> = T extends PackedGenerics<infer A2, infer B2, infer C2> ? {
a2: A2,
@devdoomari3
devdoomari3 / typescript-string-enums_iots.ts
Last active June 18, 2019 02:00
typescript-string-enums with iots
import * as t from 'io-ts'
export class FromTsStringEnumType<T extends object> extends t.Type<T[keyof T]> {
constructor (public enumObject: T, name?: string) {
super(
name || `fromTsStringEnum: ${enumObject}`,
(u): u is T[keyof T] => Object
.values(enumObject)
.some(v => v === u),
(u, c) => (this.is(u) ? t.success(u) : t.failure(u, c)),
t.identity,
@devdoomari3
devdoomari3 / TypedDictPlaceHolder.py
Created December 3, 2018 06:52
TypedDictPlaceHolder.py
# for https://github.com/Instagram/MonkeyType/issues/105
class TypedDictPlaceHolder(dict):
def __init__(self, **kwargs):
super().__init__(**kwargs)
for (key, value) in kwargs.items():
self.__dict__[key] = value
def __setitem__(self, key, item):
self.__dict__[key] = item