Skip to content

Instantly share code, notes, and snippets.

@serjKim
serjKim / create-apply-git-patch.sh
Created October 6, 2022 07:45
Create/Apply git patch
git stash show -p -u stash@{0} > Stash0.patch
git apply Stash0.patch
@serjKim
serjKim / store.ts
Created April 18, 2022 09:08
rxjs storage
class UserStorage {
private readonly reload$ = new Subject<void>();
private readonly userId$ = new ReplaySubject<number>(1);
public readonly user: Observable<string>;
constructor() {
this.user = combineLatest([
this.reload$.pipe(startWith(undefined)),
this.userId$
]).pipe(
switchMap(([_, userId]) => this.loadUser(userId)),
@serjKim
serjKim / nominal-types.ts
Last active May 1, 2021 20:00
Typescript: nominal types
// Nominal types (branding)
module BrandedTypes {
const BRAND = Symbol();
type Branded<T, TBrand> = T & { readonly [BRAND]: TBrand };
export type UserId = Branded<number, 'userId'>;
export type RoleId = Branded<number, 'roleId'>;
@serjKim
serjKim / popup.component.html
Last active January 5, 2021 19:01
cdkPortal: popup
<ng-template cdkPortal>
<div class="popup">
<div class="arrow"></div>
<ng-content></ng-content>
</div>
</ng-template>
@serjKim
serjKim / Directory.Build.Props
Last active February 22, 2022 13:20
MyStylecop
<Project>
<PropertyGroup>
<CodeAnalysisRuleSet>..\MyRuleset.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>
@serjKim
serjKim / reduxbindings.fs
Last active September 27, 2020 12:43
Fable + redux
module Redux =
type Reducer<'S, 'A> = 'S option -> 'A -> 'S
type IRootReducer = interface end
type IStore = interface end
type IDispatch<'A> = 'A -> unit
let combineReducers (reducers: {| listReducer: Reducer<'S, 'A> |}): IRootReducer = importMember "redux"
let createStore (rootReducer: IRootReducer): IStore = importMember "redux"
let useSelector (selector: 'S -> 'TS) : 'TS = importMember "react-redux"
let useDispatch<'A> () : IDispatch<'A> = importMember "react-redux"
@serjKim
serjKim / Folders.fsproj
Created April 23, 2020 15:23
F# Benchmarking: Folders structure walked in parallel
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
@serjKim
serjKim / reduce-deps.fs
Last active March 24, 2020 09:35
F#: Reduce function dependencies
type Entity = { ArrivalDate: DateTime }
type IDb =
abstract member Conn: string
type Workflow<'Result> = Workflow of (IDb -> 'Result)
let db = { new IDb with member x.Conn = "asd" }
let run idb (Workflow fn) = fn idb
@serjKim
serjKim / srtp.fs
Last active February 16, 2020 13:27
F#: SRTP + AP
let inline (|HasLength|) x =
fun () -> (^a: (member Length: int) fst x)
let inline (|HasMethod|) x =
fun () -> (^a: (member Method: int with get) snd x)
let inline length (HasLength f1 & HasMethod f2) =
let a = f1()
let b = f2()
a + b
@echo Deleting old branches...
git branch --merged develop | grep -v 'develop$' | xargs git branch -d