Skip to content

Instantly share code, notes, and snippets.

View wonglok's full-sized avatar
🙏
Thank you Jesus for the new life

Wong Lok wonglok

🙏
Thank you Jesus for the new life
View GitHub Profile
// relies on Date.now() which has been supported everywhere modern for years.
// as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values
// if you want values similar to what you'd get with real perf.now, place this towards the head of the page
// but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed
(function(){
// prepare base perf object
@wonglok
wonglok / consoleLogo.js
Last active August 29, 2015 13:57
Console Image lgoo
function consoleLogo(width,height,url,comment){
'use strict';
//config
var lineHeight = 14;
//build string
var str = '';
@wonglok
wonglok / wildcard_search.dart
Last active August 29, 2015 14:02
AngularDart WildCardFilter :)
library wildcard_filter;
import 'package:angular/angular.dart';
class WildcardFilter{
static final String DEFAULT_SEPARATOR = ' ';
/*
* AngularJS Filter fnc "call"
@steveblue
steveblue / ScrollHandler.js
Last active November 1, 2015 04:36
ScrollHandler, a layout agnostic Famo.us module for scrolling.
/* global famous */
define(function(require, exports, module) {
var Utility = famous.utilities.Utility;
var MouseSync = famous.inputs.MouseSync;
var TouchSync = famous.inputs.TouchSync;
var ScrollSync = famous.inputs.ScrollSync;
var GenericSync = famous.inputs.GenericSync;
var Transitionable = famous.transitions.Transitionable;
var Easing = famous.transitions.Easing;
@wonglok
wonglok / connectHTMLelements_SVG.png
Created November 26, 2017 10:07 — forked from alojzije/connectHTMLelements_SVG.png
Connect two elements / draw a path between two elements with SVG path (using jQuery)
connectHTMLelements_SVG.png
@loo2k
loo2k / wechat-browser-detect.js
Last active March 14, 2019 02:08
JavaScript 判断是否微信内置浏览器
var isWeixin = false;
if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
isWeixin = true;
} else {
if (document.addEventListener) {
document.addEventListener("WeixinJSBridgeReady", function() { isWeixin = true; }, false);
} else if (document.attachEvent) {
document.attachEvent("WeixinJSBridgeReady", function() { isWeixin = true; });
document.attachEvent("onWeixinJSBridgeReady", function() { isWeixin = true; });
@stevekinney
stevekinney / _.md
Created March 25, 2014 18:10
Lorenz Curve
@wonglok
wonglok / loadExt.js
Created January 28, 2020 00:37 — forked from Aymkdn/loadExt.js
To load JS and CSS files with vanilla JavaScript
// long version
function loadExt(files, after) {
var _this=this;
_this.files = files;
_this.js = [];
_this.head = document.getElementsByTagName("head")[0];
_this.after = after || function(){};
_this.loadStyle = function(file) {
var link = document.createElement("link");
link.rel = "stylesheet";
/**
* parseTemplate takes a string and a JS Object and returns a string with template
* replaced with content you provided. Template tags look like: {{tag}}
* @param {String} s This is the string to search for tags in.
* @param {Object} j This is the JS object that contains a key=>value pair for the tag and what to be replaced
* @returns {String} returns the modified string with the content you provided in replacement of the tags
* @example var html = parseTemplate('Hey, {{name}}',{ name:'John' }); //returns "Hey, John"
*/
var parseTemplate = function(s,j){
for(x in j){ var r = new RegExp('{{'+x+'}}','g'); s = s.replace(r,j[x]); }
@JedWatson
JedWatson / KeystoneApiExample.md
Last active July 26, 2021 11:29
Example of how to scaffold API endpoints for Posts in a Keystone project (based on the yo keystone example).

This is an example of how to scaffold API endpoints to list / get / create / update / delete Posts in a Keystone website.

It's a modification of the default project created with the yo keystone generator (see https://github.com/JedWatson/generator-keystone)

Gists don't let you specify full paths, so in the project structure the files would be:

routes-index.js        -->    /routes/index.js         // modified to add the api endpoints
routes-api-posts.js    -->    /routes/api/posts.js     // new file containing the Post API route controllers