Skip to content

Instantly share code, notes, and snippets.

@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 / resource.js
Created August 11, 2017 15:56
axios-resource
import axios from 'axios';
function mixParams(url, params) {
let copyParams = Object.assign({}, params);
let urls = url.replace(/\:([^/:?&]+)/g, ($0, $1) => {
delete copyParams[$1];
return params[$1];
});
urls.includes('?') ? urls = urls + '&' : urls = urls + '?';
@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 命令的完整版

//::LICENSE:://
(function(global){

//::SIGNAL_BINDING_JS:://

//::SIGNAL_JS:://

    //exports to multiple environments
 if(typeof define === 'function' && define.amd){ //AMD
@hjzheng
hjzheng / $resource.md
Last active January 23, 2017 08:56
同时 使用拦截器拦截 response 和 transformResponse

当单独使用 transformResponse 时: 如下,当然不推荐这样做, 最好是参考官方例子,将自己的 transformResponse 作为默认 transformResponse 的数组的一个成员,自己参见官网

export const MenuResource = genResource('/menus', null, null, {
	query: {
		isArray: true,
		method: 'GET',
		transformResponse: (result) => {
			const res = angular.fromJson(result);
 return res;
/**
* Fire an event handler to the specified node. Event handlers can detect that the event was fired programatically
* by testing for a 'synthetic=true' property on the event object
* @param {HTMLNode} node The node to fire the event handler on.
* @param {String} eventName The name of the event without the "on" (e.g., "focus")
*/
function fireEvent(node, eventName) {
// Make sure we use the ownerDocument from the provided node to avoid cross-window problems
var doc;
if (node.ownerDocument) {
@hjzheng
hjzheng / isContentOverflow.js
Created October 21, 2016 04:27
判断内容是否溢出
const chopStyle2Num = style => Number(style.substr(0, style.length - 2));
const closestParent = (element, tagName) => {
let parentNode = element.parentNode;
while (parentNode.nodeName.toLowerCase() !== tagName) {
parentNode = parentNode.parentNode;
if (parentNode === document.body) {
@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>