Skip to content

Instantly share code, notes, and snippets.

View sonhanguyen's full-sized avatar

Harry sonhanguyen

  • Melbourne, Australia
View GitHub Profile
@sonhanguyen
sonhanguyen / nwb.config.js
Last active November 12, 2017 12:27
react typescript scratchpad
module.exports = {
type: 'react-app',
webpack: {
extra: {
resolve: {
extensions: ['.js', '.jsx', '.json', '.tsx', '.ts' ]
},
module: {
rules: [
{ test: /\.jsx|tsx?$/, exclude: /node_modules/,
/*
## NexusFolder.ahk
##
## Switch default filemanager by launching this script without
## commandline parameters. If you send a file or folder as a
@sonhanguyen
sonhanguyen / mobX.md
Last active October 6, 2022 01:50
use revealjs to view

MobX


  • What it is
  • Why do we need it
  • How do we use it
  • How it works


@sonhanguyen
sonhanguyen / App.tsx
Last active January 18, 2018 12:36
typed grid
import * as React from 'react'
import Grid from './Grid'
import './App.css'
interface BaseLineItem {
id: string
name: string
cost: number
}
@sonhanguyen
sonhanguyen / userChrome.css
Last active December 6, 2021 05:03
side panel style for using with Tree Tabs
#!/usr/bin/env bash {} /*
cd ~/.mozilla/firefox || cd ~/Library/Application\ Support/Firefox*
source <(grep Default= profiles.ini)
mkdir $Default/chrome
tee $Default/chrome/userChrome.css <<EOF
/*#region Firefox */
#browser,
@sonhanguyen
sonhanguyen / app.tsx
Last active September 7, 2018 02:22
Services in React's new context API
import * as React from 'react'
import { render } from 'react-dom'
import { compose, fromRenderProps } from 'recompose'
import { identity, pick, mapValues } from 'lodash'
const withDependencies = (...services: Array<[any, Function]>) => {
const enhance = compose(
...services.map(([service, mapProps]) => fromRenderProps(
Service.contextFor(service).Consumer,
mapProps
@sonhanguyen
sonhanguyen / Default.bttpreset
Created July 20, 2019 02:35
Better touch tool setup for window management
{
"BTTPresetName" : "Default",
"BTTGeneralSettings" : {
"disableScrollingIf3" : true,
"BTTPasteWhenTriggeringClipboardAgain" : true,
"BTTForceNormalClickPressure5F" : 200,
"disableScrollingIf2" : true,
"BTTDidRegisterForUpdateStats" : "3.140",
"BTTShowControlStrip" : true,
"BTTShowControlStripItem" : true,
@sonhanguyen
sonhanguyen / overload.ts
Last active September 20, 2019 01:31
OverloadBuilder
type Func = (..._) => any
const overload = <Default extends Func>(defaultFunc: Default): OverloadBuilder<Default> => {
// @ts-ignore
const match = cases => Object.assign(
(...args) => {
const matcher = cases.find(([ guard ]) => guard(args))
const func = matcher
? matcher[1]
: defaultFunc
@sonhanguyen
sonhanguyen / cache.js
Last active January 30, 2024 03:59
File system-based memoization
/**
* @template [T=any]
* @property {{ (_: T): Promise<void>} & { pending?: Promise<T> }} put
*/
class CacheIOError extends Error {
constructor(cause, context) {
Object.assign(this, context, { cause })
}
}
@sonhanguyen
sonhanguyen / cache.py
Last active October 17, 2020 03:03
A filesystem-based memoization decorator
import os
import collections
import pickle
import json
import urllib.parse
import re
from functools import wraps
from typing import Callable, Any
from dataclasses import dataclass, fields