Skip to content

Instantly share code, notes, and snippets.

View zaaack's full-sized avatar
Nothing is an absolute reality; all is permitted

Zack Young zaaack

Nothing is an absolute reality; all is permitted
View GitHub Profile
@zaaack
zaaack / .zshrc
Created June 16, 2016 01:41
My Dot Files
# Path to your oh-my-zsh installation.
export ZSH=/home/z/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="steeef"
# Uncomment the following line to use case-sensitive completion.
var _CommentInput = React.createClass({
propTypes: {
atUser: PropTypes.string,
placeholder: PropTypes.string,
focus: false,
onEnter: PropTypes.func,
onChange: PropTypes.func
},
getDefaultProps: function () {
@zaaack
zaaack / trunc_html.js
Last active September 21, 2016 01:51
safe truncate html, without broken any tags
function truncHtml(html, truncNum) {
if (!truncNum) {
return 0
}
let sum = 0, index = 0
;('>'+html+'<').replace(/>([^<>]*)</g, (ma, g1, offset, str) => {
g1 = g1.trim()
if (sum - 1 < truncNum && sum + g1.length - 1 >= truncNum) {
index = offset + (truncNum - sum) - 1
console.log(index, offset, sum)
@zaaack
zaaack / koa-sync-middleware.js
Created October 31, 2016 05:47
koa-sync-middleware.js
let syncPromise
export default function syncMiddleware () {
return async (ctx, next) => {
if (ctx.isSync) { // 可以通过 decorator 实现
if (!syncPromise) {
syncPromise = next()
await syncPromise
} else {
syncPromise = syncPromise.then(next)
@zaaack
zaaack / StoreUtil.js
Created November 21, 2016 03:33
localStorage wrapper with right expire and exceed handling, using jsonh to compress json array
// @import './jsonh.es6';
const StoreUtil = (function () {
// http://crocodillon.com/blog/always-catch-localstorage-security-and-quota-exceeded-errors
function isQuotaExceeded(e) {
var quotaExceeded = false
if (e) {
if (e.code) {
switch (e.code) {
case 22:
@zaaack
zaaack / SimpleRouter.js
Created November 23, 2016 08:16
SimpleReactRouter using hash
/**
* SimpleRouter
*
*```js
* const routes = [{
* path: '/',
* component: Main,
* }, {
* path: '/user/:id',
* component: User,
@zaaack
zaaack / update_git_author_and_mail.sh
Created March 10, 2017 06:29
update_git_author_and_mail.sh
#!/bin/sh
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
old_mail="[Your Old Mail]"
@zaaack
zaaack / file
Created April 27, 2017 02:20
freedom_public
{"0.3984699617225185":"-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nCharset: UTF-8\r\n\r\nxv8AAABSBAAAAAATCCqGSM49AwEHAgME4JCeuCGhYIjKLhTDOXe1o8KbD0OgTBUy\r\nN2tFDZHROjL+ZRIPeqCym03m+iiTysgp71Qszl764+nlI5u4sSyqZ83/AAAACDxn\r\naXRodWI+wv8AAACOBBATCABA/wAAAAWCWQFVXv8AAAACiwn/AAAACZCUFR1PQAQi\r\ntv8AAAAFlQgJCgv/AAAABJYDAQL/AAAAApsD/wAAAAKeAQAAXXYBANoYKPXoiTbd\r\nY56ithXekpS18vVi0zR6J/VtiT5+of+GAP9VgVUTKk/19vBityNvHxh198iqShSu\r\nlC66kj3niDwPgs7/AAAAVgQAAAAAEggqhkjOPQMBBwIDBJkY2u9+S26cM0/cvRP+\r\nEpMzoxOdK3N8jeqhC2y1dRzLl2ZiB5OtrG3m1mB8GhmxeQwM2/qk+/YTohPAh6oH\r\nF04DAQgHwv8AAABtBBgTCAAf/wAAAAWCWQFVXv8AAAAJkJQVHU9ABCK2/wAAAAKb\r\nDAAA7ygA+gLSZjpYh6iTUdf8hI59KBYxyIaKoDlK1l3xiYzyO/8CAQCpoC5jrAs2\r\nu8tKlJEmChqWKPeKGJp+J6MUFn6TCnHO0g==\r\n=tu8N\r\n-----END PGP PUBLIC KEY BLOCK-----\r\n"}
function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
var k = UInt32(str, currentIndex);
import { Struct } from 'immuter'
const struct = Struct({
title: {
zh: '哈利·波特与魔法石',
en: 'Harry Potter and the Philosopher\'s Stone',
},
author: 'J. k. rowling',
tags: ['novel', 'magic'],
})