Skip to content

Instantly share code, notes, and snippets.

@clinyong
clinyong / Layout.jsx
Last active January 16, 2016 11:19
redux-simple-router-sample
import React from 'react'
import { Link } from 'react-router'
export default class Layout extends React.Component {
render () {
return (
<div>
I'm Layout.
<div>
<Link to='/user'> User </Link>
@clinyong
clinyong / clear_and_margin.html
Created March 9, 2016 23:17
清除浮动两种方法的差异
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>clear与margin重叠</title>
</head>
<body>
1.
<div style="background-color: #f5f5f5;">
var audioCtx = new AudioContext();
var source = audioCtx.createBufferSource();
fetch(
'http://7xsym0.com2.z0.glb.qiniucdn.com/%E9%82%93%E7%B4%AB%E6%A3%8B%20-%20A.I.N.Y.%2528%E7%88%B1%E4%BD%A0%2529.mp3', {
})
.then(function(resp){
resp.arrayBuffer().then(function(buffer){
audioCtx.decodeAudioData(buffer, function(decodedData) {
@clinyong
clinyong / php时间差计算
Created August 5, 2014 01:44
php时间差计算
/**
* 时间差计算
*
* @param Timestamp $time 时间差
* @return String Time Elapsed
* @author Shelley Shyan
* @copyright http://phparch.cn (Professional PHP Architecture)
*/
function time2Units ($time)
{
@clinyong
clinyong / checkTS
Last active January 22, 2017 14:07
use tslint to check ts or tsx file before commit
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E "\.tsx?$")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
for file in ${files}; do
@clinyong
clinyong / arguments.js
Created February 24, 2017 00:57
将传入的参数转成数组
var Thunk = function(fn){
return function (){
var args = Array.prototype.slice.call(arguments);
return function (callback){
args.push(callback);
return fn.apply(this, args);
}
};
};
@clinyong
clinyong / walkdir.js
Created February 24, 2017 14:52
walk directory
function walkDir(root) {
const stat = fs.statSync(root);
if (stat.isDirectory()) {
const dirs = fs.readdirSync(root).filter(item => !item.startsWith('.'));
let results = dirs.map(sub => walkDir(`${root}/${sub}`));
return [].concat(...results);
} else {
return root;
}
@clinyong
clinyong / delBom.php
Created August 27, 2014 01:21
I use this script to detect bom file recursively, and delete bom with sublime text.
<?php
/**
* 用法:复制以下代码至新建的php文件中,将该php文件放置项目目录,运行即可。代码来源于网络。
* chenwei 注。
*/
header('content-Type: text/html; charset=utf-8');
$auto=0;/* 设置为1标示检测BOM并去除,设置为0标示只进行BOM检测,不去除 */
$basedir='.';
$loop=true;
echo '当前查找的目录为:'.$basedir.'当前的设置是:';
@clinyong
clinyong / event-pool.js
Last active July 5, 2018 03:48
Minimum react event pool
const eventPool = [];
const EVENT_POOL_SIZE = 10;
function SyntheticEvent(nativeEvent) {
this.nativeEvent = nativeEvent;
}
SyntheticEvent.prototype.persist = function persist() {
this.isPersistent = true;
};
@clinyong
clinyong / Promise.ts
Created July 23, 2018 02:50
Minimal promise implementation for JavaScript
class Promise() {
constructor() {
}
}