Skip to content

Instantly share code, notes, and snippets.

View abruzzihraig's full-sized avatar
🤢

Yang He abruzzihraig

🤢
  • Melbourne
  • 00:48 (UTC -12:00)
View GitHub Profile
@rankjie
rankjie / gist:7fd60376d88c362b00bc
Created August 25, 2014 05:23
Upload file with XHR
xhr = new XMLHttpRequest()
# 进度
xhr.upload.addEventListener "progress", uploadProgress, false
# 完成
xhr.addEventListener "load", uploadComplete, false
xhr.addEventListener "error", console.log, false
xhr.addEventListener "abort", console.log, false
@changtimwu
changtimwu / fluxpurejs.js
Last active February 4, 2016 07:19
gasolin demonstrates flux concept in only 50 lines of javascript
/* original link http://blog.gasolin.idv.tw/2014/11/flux-javascript.html */
// Renderer.js
var ClickRenderer = {
init: function s_init(element, Store) {
this.element = element;
this.store = Store;
window.addEventListener('render_view1', this);
},
handleEvent: s_handleEvent(evt) {
@abruzzihraig
abruzzihraig / angular-amap.js
Last active July 5, 2016 05:45
AMap/高德地图 module wrapper with angular
/*
* The module amap below is a simplest implementation, there is no any updated or proper libraries when I wrote it.
* Since there is a new full-feature library which wrote by another guy, so I just recommend it below.
* https://github.com/leftstick/angular-amap
*
* If you just want version with a few features like below, you could just build your version on top of it.
*/
angular.module('amap', [])
.constant('amapConstant', {
@billywhizz
billywhizz / script_test.js
Created February 6, 2011 09:42
testing vm script functionality in node.js
var vm = require('vm'),
code = 'var square = n * n;',
fn = new Function('n', code),
script = vm.createScript(code),
sandbox;
n = 5;
sandbox = { n: n };
benchmark = function(title, funk) {
@marco-martins
marco-martins / touch-tooltip-fix.js
Created June 26, 2012 10:31 — forked from slawekkolodziej/touch-tooltip-fix.js
Highcharts tracker now don't prevent default behavior (like scrolling on touch devices).
Highcharts.Chart.prototype.callbacks.push(function(chart) {
var hasTouch = hasTouch = document.documentElement.ontouchstart !== undefined,
mouseTracker = chart.tracker,
container = chart.container,
mouseMove;
mouseMove = function (e) {
// let the system handle multitouch operations like two finger scroll
// and pinching
if (e && e.touches && e.touches.length > 1) {
@yyx990803
yyx990803 / props.md
Last active March 28, 2017 11:39
关于应不应该把属性的默认值放在prototype里

TL,DR: 务必总是在构建函数里定义实例属性。

在小胖的PoorPhy物理库里,有很多类似这样的代码:

function WorldA () {
  // ...
}

WorldA.prototype = {
@idiotWu
idiotWu / themr.js
Last active March 29, 2017 03:22
Another theme-able solution for react reusable components.
/*
* Usage:
*
* As a decorator:
*
* import defaultTheme from './style.scss';
*
* @themr(defaultTheme)
* class Comp extends React.Component { ... }
*
@idiotWu
idiotWu / attach-events.js
Last active October 6, 2017 15:22
attach-events decorator for react
/**
* @decorator
* Attach events to DOM element
*
* @param {Element|Function} elemOrFunc: DOM Element, or a function returns element
* @param {String} events: a list events separated with ','
*
* Usage:
* @attachEvents(window, 'click')
* handleWindowClick(evt) {
@marlun78
marlun78 / $once.js
Last active February 28, 2018 19:19
Angular $rootScope.Scope.$once
/**
* Angular $rootScope.Scope.$once
* Copyright (c) 2014 marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*/
$provide.decorator('$rootScope', function ($delegate) {
var Scope = $delegate.__proto__.constructor;
Scope.prototype.$once = function (name, listener) {
var deregister = this.$on(name, function () {
deregister();
@obenjiro
obenjiro / jsdoit.css
Last active June 25, 2018 00:22
Canvas Conical Gradient
body {
margin: 0;
padding: 0;
background-color: #fff;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAANUlEQVQ4jWM8c+bMfwY8wNjYmBGfPBM+SWLAqAGDwQDG///xJgOGs2fP4lUw8F4YNYAKBgAA2NYKfxDn4ZUAAAAASUVORK5CYII=);
overflow: hidden;
}