Skip to content

Instantly share code, notes, and snippets.

View hjzheng's full-sized avatar
💭
I may be slow to respond.

HaoJu Zheng hjzheng

💭
I may be slow to respond.
View GitHub Profile
@hjzheng
hjzheng / README.md
Last active August 29, 2015 14:07 — forked from addyosmani/README.md

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@hjzheng
hjzheng / .zshrc
Last active August 29, 2015 14:26 — forked from puzza007/.zshrc
zsh config changes (override stuff set in oh my zsh)
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.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="robbyrussell"
ZSH_THEME="gentoo"
# Example aliases
@hjzheng
hjzheng / advice.js
Created March 15, 2016 03:13 — forked from angus-c/advice.js
an advice functional mixin
//usage
withAdvice.call(targetObject);
//mixin augments target object with around, before and after methods
//method is the base method, advice is the augmenting function
withAdvice: function() {
['before', 'after', 'around'].forEach(function(m) {
this[m] = function(method, advice) {
if (typeof this[method] == 'function') {
return this[method] = fn[m](this[method], advice);
@hjzheng
hjzheng / ResLoader.js
Created March 29, 2016 04:26 — forked from willerce/ResLoader.js
保存 Javascript 和 CSS 到 LocalStorage 中
var Loader = (function () {
function Loader(options) {
this.options = options;
if (resource.scripts && resource.baseUrl) {
for (var i = 0; i < this.options.scripts.length; i++) {
this.load('js', this.options.scripts[i]);
}
for (var i = 0; i < this.options.stylesheets.length; i++) {
this.load('css', this.options.stylesheets[i]);
}
var gulp = require('gulp');
var source = require('vinyl-source-stream'); // Used to stream bundle for further handling
var browserify = require('browserify');
var watchify = require('watchify');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
var notify = require('gulp-notify');
var concat = require('gulp-concat');
var cssmin = require('gulp-cssmin');
@hjzheng
hjzheng / angularjs_directive_attribute_explanation.md
Created July 6, 2016 17:20 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@hjzheng
hjzheng / flyweight.js
Created September 14, 2016 02:27 — forked from addyosmani/flyweight.js
The Flyweight pattern
// Flyweight.js - Copyright Addy Osmani, 2012.
// Consider public domain
// My implementation in JS of this:
// http://en.wikipedia.org/wiki/Flyweight_pattern
// Simulate pure virtual inheritance/'implement' keyword for JS
Function.prototype.implementsFor = function (parentClassOrObject) {
if (parentClassOrObject.constructor == Function) {
// Normal Inheritance
this.prototype = new parentClassOrObject;
@hjzheng
hjzheng / git-stash.md
Created April 26, 2017 05:34 — forked from subchen/git-stash.md
Git Stash 用法

git stash用于保存和恢复工作进度

  • git stash

    保存当前的工作进度。会分别对暂存区和工作区的状态进行保存

  • git stash save "message..."

这条命令实际上是第一条 git stash 命令的完整版

@hjzheng
hjzheng / service_spec.js
Created August 11, 2017 21:45 — forked from paulsturgess/service_spec.js
Test Axios promise with jasmine-ajax
import Service from 'path/to/service';
import 'jasmine-ajax'
describe('Service', () => {
let request, promise;
let instance = Service;
let payload = {foo:'bar'};
let path = '/path';
let callback = jasmine.createSpy('callback');
@hjzheng
hjzheng / PromiseSimpleExample.js
Created October 14, 2017 16:38 — forked from treyhuffine/PromiseSimpleExample.js
An example using a simple promise implementation
class PromiseSimple {
constructor(executionFunction) {
this.promiseChain = [];
this.handleError = () => {};
this.onResolve = this.onResolve.bind(this);
this.onReject = this.onReject.bind(this);
executionFunction(this.onResolve, this.onReject);
}