Skip to content

Instantly share code, notes, and snippets.

@fxghqc
fxghqc / machine.js
Last active August 13, 2021 09:56
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
Promise.resolve([1,2,3])
.then(call('map', x => 2 * x))
.then(console.log);
const arr = [5, 31, 2, 9];
const maximum = (numbers) => { /* 你的代码 */ };
const condition = ['AND',
['=', 3, 3],
['OR',
['IS_TRUE', true],
['IN', ['5', '6', '7'], '7']
]
];
@fxghqc
fxghqc / main.go
Created January 8, 2018 08:21 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"

Keybase proof

I hereby claim:

  • I am fxghqc on github.
  • I am fanxiao (https://keybase.io/fanxiao) on keybase.
  • I have a public key ASAXI1-LakV_57h2cdYvpMBPkI7DK_w9QI6lGfSDjhOzXQo

To claim this, I am signing this object:

const util = require('util')
const exec = util.promisify(require('child_process').exec)
async function random() {
const { stdout, stderr } = await exec(
`/bin/sh -c "tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 128 | head -n 1"`
// 'head -n 80 /dev/urandom | tr -dc A-Za-z0-9 | head -c 168'
// `tr -dc a-zA-Z0-9 < /dev/urandom | fold -w 128 | head -n 1`
// `ls ~/`
)
const Koa = require('koa')
const koaBody = require('koa-body')()
const Router = require('koa-router')
const session = require('koa-session')
const rp = require('request-promise')
const redis = require('redis')
const bluebird = require('bluebird')
const app = new Koa()
const router = new Router()
@fxghqc
fxghqc / use flow.js in exist react projects
Last active October 26, 2016 12:28
use flow.js in react projects
project use webpack, babel & ...
add // @flow to the top of source files
```bash
touch .flowconfig
npm install -D flow-bin babel-plugin-transform-flow-strip-types eslint-plugin-flowtype
## add this plugin in .babelrc or webpack config file
echo '{"plugins": ["transform-flow-strip-types"]}' > .babelrc
```
var a = { name: 'k2', age: 2};
var b = Object.create(a);
b.age = 5;
console.log(a.age);
console.log(b.age);
delete b.age;
console.log(b.age);
// First lets create our drawing surface out of existing SVG element
// If you want to create new surface just provide dimensions
// like s = Snap(800, 600);
var s = Snap("#svg");
// Lets create big circle in the middle:
var bigCircle = s.circle(150, 150, 100);
// By default its black, lets change its attributes
bigCircle.attr({
fill: "#bada55",
stroke: "#000",