Skip to content

Instantly share code, notes, and snippets.

View z2015's full-sized avatar
🎯
Focusing

William Zhou z2015

🎯
Focusing
View GitHub Profile
@z2015
z2015 / handleEvent.md
Last active June 7, 2016 05:11
addEventListener, handleEvent and passing objects

Addeventlistener passed obj with handleevent to fn

  var obj = {
    handleEvent: function() {
        alert(this.dude);
    },
    dude: "holla"
  };
@z2015
z2015 / Register.md
Last active June 6, 2016 10:05
Vim 101: Register

###:reg To see all of the current registers tha are in use.

  1. '*' register is system clipboard
  2. '.' register stores what just typed , it's read-only.
  3. typing 'yy' will 'yank' this line .
  4. type ':reg' will show the 'yank' line in register 0

###Unnamed Register 1.'""'register will show the delete element. 2.'0' register will always show the last yank command. 3.p will put delete element rather than the yank element.

@z2015
z2015 / blurfocus.js
Created June 2, 2016 08:59
remove the focus from a text input
document.activeElement.blur();
@z2015
z2015 / horizontalScroll.js
Created May 30, 2016 09:11
Horizontal Touch Scroll Animation
var jzhg = (function(){
let navDom = document.querySelector('.zyee-jzhg-nav');
let nav = $('.zyee-jzhg-nav');
let navWidth = nav.width(),
domWidth = $(document).width(),
maxTransformX = navWidth - domWidth;
let touchStartX,
touchMoveX,
moveX,
@z2015
z2015 / listentransitionend.js
Last active May 30, 2016 06:28
Detecting CSS Animation Completion with JavaScript
/* From Modernizr */
function whichTransitionEvent(){
var t;
var el = document.createElement('fakeelement');
var transitions = {
'transition':'transitionend',
'OTransition':'oTransitionEnd',
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
}
@z2015
z2015 / scrollbar.css
Created May 27, 2016 03:02
css control scrolbar
//Internet Explorer 5.5+
body, html { /* these are default, can be replaced by hex color values */
scrollbar-base-color: aqua;
scrollbar-face-color: ThreeDFace;
scrollbar-highlight-color: ThreeDHighlight;
scrollbar-3dlight-color: ThreeDLightShadow;
scrollbar-shadow-color: ThreeDDarkShadow;
scrollbar-darkshadow-color: ThreeDDarkShadow;
scrollbar-track-color: Scrollbar;
@z2015
z2015 / package.md
Created May 25, 2016 03:24
hot module replacement with webpack

/* style.css */ body { background: red; }

/* entry.js */ require("./style.css"); document.write("");

npm install webpack webpack-dev-server -g

@z2015
z2015 / immutable.js
Created May 21, 2016 09:03
Immutable and Mocha and Chai Pure Function Test
import {expect} from 'chai';
import {List, Map} from 'immutable';
//set Entries function
function setEntries(state, entries){
return state.set('entries', List(entries));
}
//get Winners
function getWinners(vote){
if (!vote) return [];
@z2015
z2015 / deletecookie.js
Created May 20, 2016 02:22
Delete Cookie
document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); });
javascript:(function(){document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); }); })();
@z2015
z2015 / flyweight.js
Created May 20, 2016 02:16 — 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;