Skip to content

Instantly share code, notes, and snippets.

View tanhauhau's full-sized avatar

Tan Li Hau tanhauhau

View GitHub Profile
@tanhauhau
tanhauhau / Component.svelte
Created May 30, 2021 15:30
svelte/register
<script>
let name = 'world';
</script>
<h1>Hello {name}!</h1>
@tanhauhau
tanhauhau / Component.svelte
Created May 26, 2021 15:04
Server-side rendering Component API
<script>
import { createEventDispatcher } from 'svelte';
import { getContext } from 'svelte';
const dispatch = createEventDispatcher();
export let a = 1;
export let b = 1;
export let title = 'xxx';
$: product = a * b;
@tanhauhau
tanhauhau / Component.svelte
Created May 26, 2021 14:32
Svelte Component API
<script>
import { createEventDispatcher } from 'svelte';
import { getContext } from 'svelte';
import { fade } from 'svelte/transition';
const dispatch = createEventDispatcher();
export let a = 1;
export let b = 1;
@tanhauhau
tanhauhau / lihautan.itermcolors
Created December 16, 2020 13:48
iTerm2 Theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.0</real>
@tanhauhau
tanhauhau / machine.js
Created June 28, 2020 07:30
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@tanhauhau
tanhauhau / my-webpack-plugin.js
Created February 20, 2020 00:55
Webpack additional compilation pass
const PLUGIN_NAME = 'MY_WEBPACK_PLUGIN';
class MyWebpackPlugin {
constructor() {
this.cssReady = false;
this.cssFiles = [];
}
apply(compiler) {
compiler.hooks.watchRun.tap(PLUGIN_NAME, () => {
this.cssReady = false;
@tanhauhau
tanhauhau / SetModuleTemplatePlugin.js
Last active January 22, 2020 14:50
SetModuleTemplatePlugin
const { ConcatSource } = require('webpack-sources');
const RuntimeGlobals = require('webpack/lib/RuntimeGlobals');
const JavascriptModulesPlugin = require('webpack/lib/javascript/JavascriptModulesPlugin');
/** @typedef {import("./Compiler")} Compiler */
class SetModuleTemplatePlugin {
/**
* @param {string} moduleMethod the accessor where the library is exported
* @param {boolean} moduleName specify copying the exports
@tanhauhau
tanhauhau / webpack.config.js
Created October 3, 2019 14:42
Declarative webpack config
const FILE_TYPES = {
JS: /\.js$/,
CSS: /\.css$/,
SCSS: /\.scss$/,
TS: /\.tsx?$/,
};
const FOLDERS = {
APP: path.join(__dirname, './src'),
NODE_MODULES: path.join(__dirname, './node_modules'),
};
@tanhauhau
tanhauhau / index.js
Created March 24, 2019 12:02
setting a scope
// setting a property in the `$scope` object triggers
// the framework to update the model and the DOM
$scope.name = 'Hello';
@tanhauhau
tanhauhau / index.js
Created March 24, 2019 12:01
throw an error to get stack
let _value;
Object.defineProperty(obj, 'awesome', {
get: () => {
try {
// intentionally throw an Error to get the call stack
throw new Error();
} catch (error) {
// stack is the stack trace,
// containing error message and the stack
const stack = error.stack;