Skip to content

Instantly share code, notes, and snippets.

View Qquanwei's full-sized avatar
💭
Busyman

李权威 Qquanwei

💭
Busyman
View GitHub Profile
@Qquanwei
Qquanwei / Koa video stream server
Last active November 26, 2018 01:21
video stream server
"use strict"
let koa = require('koa');
let Router = require('koa-router');
let fs = require('fs');
let assert = require('http-assert');
let sscanf = require('scanf').sscanf;
let app = new koa();
let router = new Router();
@Qquanwei
Qquanwei / react-mode.el
Created September 12, 2016 06:21
emacs react mode by web-mode and ycmd
; autocomplete as javascript
(add-to-list 'ycmd-file-type-map '(react-mode . ("javascript")))
(define-derived-mode react-mode web-mode "React-IDE"
"Major mode for react/jsx")
(add-hook 'react-mode-hook 'ycmd-mode)
(add-to-list 'auto-mode-alist '("\\.jsx" . react-mode))
@Qquanwei
Qquanwei / withTitle.js
Created May 12, 2017 09:30
react withTitle. change title when switch component
import React from 'react'
import createReactClass from 'create-react-class'
import cu from 'lodash/curry'
export default cu(function (title, Component) {
let oriTitle = document.title
return createReactClass({
componentWillMount () {
oriTitle = document.title
@Qquanwei
Qquanwei / app.jsx
Last active August 7, 2017 08:58
trackpoint-demo
import React from 'react';
import '../styles/index.scss';
import { track, before, after, composeWith, evolve, time, identity, createCounter} from 'trackpoint-tools'
export default class App extends React.Component {
constructor () {
super()
this.name = 'app'
}
@Qquanwei
Qquanwei / gist1.js
Last active March 14, 2019 09:16
OverAssert
function submit(data) {
let errorMessage = '';
if (!data.name) {
errorMessage = 'please input name';
} else if (data.lastName && data.lastName.length > 10) {
errorMessage = 'length of lastName should less than 10 ';
} else if (data.age < 80) {
import { of, itShouldProp, large, always } from 'OverAssert'
const data = {
age: 20
};
of(data)
.map(itShouldProp('age', large(10), always('age should large than 10')))
.map(itShouldProp('age', less(80), always('age should less than 80')))
.validation((success, reason) => {
import { of, itShouldPath, itShouldProp, equals, allPass, large, less, always } from 'OverAssert';
const data = {
user: {
name: 'Alice',
id: 200
},
expireTime: 200,
import { of, always } from 'OverAssert';
function asyncCheckValidate(value) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (value > 10) {
resolve();
} else {
reject();
}
function imageMatch(file) {
return readImageAsPromise(file).then(image => {
return of(image).map(itShouldProp('width', large(10), always('image width should large 10, now is ' + image.width)))
})
}
of({ filename: 'c:/fakepath/file.txt'})
.map(itShould(imageMatch, always('image not exists')))
.validate(( success, reason) => {
// async validation just fun
const shouldSizeMatch = compact(
itShouldProp('width', large(20), always('width should large 20')),
itShouldProp('height', large(20), always('height should large 20'))
);
of({ width: 10, height: 30})
.map(shouldSizeMatch)
.validate((success, reason) => {
// reuse rules
})