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
Created August 17, 2021 08:51 — forked from lesonky/Readme.md
如何使用JavaScript实现纯前端读取和导出excel文件
@hjzheng
hjzheng / download-file.js
Created September 3, 2019 03:23 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@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);
}
@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 / 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 / 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 / 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>
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 / 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]);
}
@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);