Skip to content

Instantly share code, notes, and snippets.

@weikinhuang
weikinhuang / php-js-post-checkout-merge-hook
Last active May 2, 2020 12:41
post-checkout/post-merge hook to automate npm/yarn/bower/composer install only when they change
#!/bin/bash
#
# A hook to update files for package managers
# bin/post-checkout-merge-hook
#
# This is a post-merge/post-checkout/post-rewrite hook.
#
#set -x
if [[ "$SKIP_COM_GIT_HOOK" == '1' ]]; then
@weikinhuang
weikinhuang / js-pre-commit-hook.sh
Last active August 29, 2015 14:13
Javascript linting precommit hook with jscs and jshint
#!/bin/bash
#
# A hook to disallow js lint errors to be committed
#
# This is a pre-commit hook.
#
# To install this you can either copy or symlink it to
# $GIT_DIR/hooks/pre-commit
#
# Set up with npm install --save-dev jshint jscs
'use strict';
var AngularPage = function () {
browser.get('http://www.angularjs.org');
};
AngularPage.prototype = Object.create({}, {
todoText: { get: function () { return element(by.model('todoText')); }},
addButton: { get: function () { return element(by.css('[value="add"]')); }},
yourName: { get: function () { return element(by.model('yourName')); }},
@weikinhuang
weikinhuang / gist:6b7f11b59d4a08e35f83
Created October 20, 2014 19:24
Count angular watchers within an element
(function (window) {
var slice = [].slice;
window.ngWatchCount = function(base) {
var elems;
if (base && typeof base !== "string") {
elems = slice.call(base.querySelectorAll("*"));
elems.unshift(base);
} else if (typeof base === "string") {
elems = slice.call(document.querySelectorAll(base + ", " + base + " *"));
} else {
@weikinhuang
weikinhuang / app.js
Created August 7, 2014 19:35
Express 4 and socket.io share sessions
var express = require("express");
var path = require("path");
var favicon = require("serve-favicon");
var logger = require("morgan");
var cookieParser = require("cookie-parser");
var bodyParser = require("body-parser");
var session = require("express-session");
var cookie = require("cookie");
var q = require("q");
@weikinhuang
weikinhuang / gist:3876951
Created October 12, 2012 02:05
Click capturing functionality for delaying all clicks until all events have been bound
/*!
* preload-clicks.js v0.1.0
* http://www.closedinterval.com/
*
* Click capturing functionality for delaying all clicks until all events have been bound
*
* Copyright 2011-2012, Wei Kin Huang
* Classify is freely distributable under the MIT license.
*/
var releaseClicks = (function(document) {
@weikinhuang
weikinhuang / gist:3266794
Created August 5, 2012 19:25
Get true viewport height in mobile browsers
var getUsableHeight = function() {
"use strict";
// check if this page is within a app frame
var isInAppMode = ("standalone" in navigator && navigator.standalone) || (window.chrome && window.top.chrome.app && window.top.chrome.app.isInstalled);
var ua = navigator.userAgent;
// memoized values
var isIphone = ua.indexOf('iPhone') !== -1 || ua.indexOf('iPod') !== -1;
@weikinhuang
weikinhuang / gist:2004856
Created March 9, 2012 03:28
Bash PS1 git and svn repo info
# Special repo status function for git and svn
__repo_ps1 () {
local info=$(svn info 2> /dev/null)
# if not a svn repo, then try the git method
if [[ -z "$info" ]] ; then
echo -n "$(__git_ps1)"
return
fi
@weikinhuang
weikinhuang / mobile-meta-links.html
Created August 6, 2011 00:52
iOS Web App Configuration