Skip to content

Instantly share code, notes, and snippets.

View zaaack's full-sized avatar
🏠
Working from home

Zack Young zaaack

🏠
Working from home
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.
@zaaack
zaaack / update-resolv-conf
Created July 8, 2016 13:23
update-resolv-conf for openvpn in deepinlinux 15.2 x64(Debian sid)
#!/bin/bash
#
# Parses DHCP options from openvpn to update resolv.conf
# To use set as 'up' and 'down' script in your openvpn *.conf:
# up /etc/openvpn/update-resolv-conf
# down /etc/openvpn/update-resolv-conf
#
# Used snippets of resolvconf script by Thomas Hood and Chris Hanson.
# Licensed under the GNU GPL. See /usr/share/common-licenses/GPL.
#
var _CommentInput = React.createClass({
propTypes: {
atUser: PropTypes.string,
placeholder: PropTypes.string,
focus: false,
onEnter: PropTypes.func,
onChange: PropTypes.func
},
getDefaultProps: function () {
const EventEmitter = require('events')
const electron = require('electron')
export default class EventBus extends EventEmitter {
constructor(name='default') {
super()
this._name = name
this._baseEventKey = `EventBus-${name}:`
}
@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 / react-shave.js
Last active October 6, 2022 14:08
react-shave.js (ellipsis)
// @flow
import shave from 'shave'
import { h, Component } from 'preact'
import shallowCompare from 'shallow-compare'
type Props = {
line?: number,
text: string,
ellipsis?: string,
onEllipsisClick?: ?MouseEventListener,