Skip to content

Instantly share code, notes, and snippets.

View zhentian-wan's full-sized avatar
🇫🇮
Working from home

Zhentian Wan zhentian-wan

🇫🇮
Working from home
View GitHub Profile
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@zhentian-wan
zhentian-wan / machine.js
Created November 24, 2022 09:47
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@zhentian-wan
zhentian-wan / 03.compose-callback
Created October 25, 2020 14:13
Use the Callback and Closure Pattern to Build Advanced Async Behaviors
import { curry, compose, toUpper, pipe } from 'ramda';
// #region listeners
const _log = (value) => console.log(value);
// #endregion
// #region broadcasters
const done = Symbol('done');
const addListener = curry((element, eventType, listener) => {
return element.addEventListener(evenType, listener);
@zhentian-wan
zhentian-wan / README.md
Created April 27, 2020 18:16
Git basic skill tips

Git basic skills

For an empty project

git init git-demo

For an existing project

cd git-demo
@zhentian-wan
zhentian-wan / machine.js
Created January 19, 2020 15:03
Generated by XState Viz: https://xstate.js.org/viz
const doorMachine = Machine({
id: "door",
initial: "locked",
states: {
unlocked: {
initial: "closed",
states: {
open: {
on: {
const { curry, compose, State, mapProps } = require("crocks");
const { modify } = State;
const state = {
left: 8,
moves: 0
};
const inc = x => x + 1;
@zhentian-wan
zhentian-wan / dbl-scroll.js
Created March 3, 2018 15:45
For fixed width table, scroll bar is used for overflow content. One problem is if there are many rows, users need to scroll to the bottom of page to access scroll bar. Created double scroll bar directive for table component.
angular.directive('dblScroll', dblScroll)
dblSroll.$inject = [
'$timeout'
];
function dblScroll($timeout) {
return {
restrict: 'A',
transclude: true,
@zhentian-wan
zhentian-wan / keyof.ts
Created May 24, 2017 06:48
lookup types
function spyOn<O extends object, P extends keyof O>(obj: O, prop: P) {
console.log(obj, prop);
}
interface IPerson {
name: string,
age: number
}
const person: IPerson = {
@zhentian-wan
zhentian-wan / index.js
Created November 11, 2016 13:13
Testing promise with mocha & chai as promised
const chai = require('chai');
const expect = chai.expect;
const chaiAsPromised = require('chai-as-promised');
const index = require('../index.js');
chai.use(chaiAsPromised);
describe('Function foo', () => {
it('should accpet anything but one', () => {
@zhentian-wan
zhentian-wan / index.html
Last active October 8, 2016 08:33
CSS calc
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<nav>
nav