Skip to content

Instantly share code, notes, and snippets.

View sonhanguyen's full-sized avatar

Harry sonhanguyen

  • Melbourne, Australia
View GitHub Profile
@sonhanguyen
sonhanguyen / mixin_delegate_decorator.ts
Last active October 31, 2022 13:44
kotlin's style delegate in typescript
function delegateTo(prop: string) {
const { __proto__ } = this
Object.setPrototypeOf(this,
new Proxy({}, {
get: (target, name) => {
target = this[prop]
if (name === prop) return target
if (name in __proto__) return __proto__[name]
return target ? target[name] : undefined
@sonhanguyen
sonhanguyen / index.html
Last active March 17, 2023 00:08
resume
<head>
<style>
@media print { body { height: 297mm } }
body {
width: 210mm;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
margin: 0;
display: flex;
}
@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 })
}
}