Skip to content

Instantly share code, notes, and snippets.

View hongkheng's full-sized avatar
🐢
doing hobby stuff

HongKheng Yap hongkheng

🐢
doing hobby stuff
View GitHub Profile
@hongkheng
hongkheng / SassMeister-input.scss
Created May 18, 2014 06:15
Generated by SassMeister.com.
// ----
// Sass (v3.3.4)
// Compass (v1.0.0.alpha.18)
// ----
// A Sass walk function,
// Calling a given function to each member of a list
// ---
// @param [list] $list: list to walk through
// @param [string] $function: function to apply to all members
@hongkheng
hongkheng / SassMeister-input.scss
Created May 18, 2014 13:01
Generated by SassMeister.com.
// ----
// Sass (v3.3.7)
// Compass (v1.0.0.alpha.18)
// ----
//// Fibonacci Function
@function fibonacci($n) {
$fib: 0 1;
@for $i from 1 through nth($n,1) {
$new: nth($fib, length($fib)) + nth($fib, length($fib) - 1);
@hongkheng
hongkheng / tapfix.js
Last active August 29, 2015 14:03
Touch event with mousedown fix
/**
http://www.gianlucaguarini.com/blog/detecting-the-tap-event-on-a-mobile-touch-device-using-javascript/
**/
// jQuery
var getPointerEvent = function(event) {
return event.originalEvent.targetTouches ? event.originalEvent.targetTouches[0] : event;
};
var $touchArea = $('#touchArea'),
touchStarted = false, // detect if a touch event is sarted
@hongkheng
hongkheng / Gruntfile.js
Created July 28, 2014 14:37
grunt dynamic task
// Grunt dynamic tasks examples
// Example 1
https://oncletom.io/2013/dynamic-grunt-targets-using-templates/
// Example 2
// Call grunt release:target where target is the name of the subtask
grunt.registerTask('release', function(target) {
if (target === null) {
return grunt.warn("Build target must be specified, e.g. release:hover");
@hongkheng
hongkheng / Clamp.as
Last active August 29, 2015 14:06
Clamping
function clamp(val:Number, min:Number = MIN, max:Number = MAX){
return Math.max(min, Math.min(max, val))
}
@hongkheng
hongkheng / Rounding.as
Created October 1, 2014 02:48
Round number to specific number of decimal places
// Rounds a target number to a specific number of decimal places.
function roundToPrecision(numberVal:Number, precision:int = 0):Number
{
var decimalPlaces:Number = Math.pow(10, precision);
return Math.round(decimalPlaces * numberVal) / decimalPlaces;
}
@hongkheng
hongkheng / LinearInterpolate.as
Last active August 29, 2015 14:07
Linear Interpolation formula
// Linear interpolation
function interpolateVal(y0:Number, y1:Number, x:Number, x1:Number, x0:Number):Number
{
//y = y0 + (x - x0) * (y1 - y0) / (x1 - x0);
return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
}
@hongkheng
hongkheng / ui.customselectmenu.js
Created December 26, 2014 09:04
Using AMD for custom jqueryUI widget
/* A small jqueryui widget for extending selectmenu */
(function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define([
"jquery"
], factory );
} else {
// Browser globals
@hongkheng
hongkheng / SassMeister-input.scss
Created March 4, 2015 03:47
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
@mixin keyframe ($animation_name) {
@-webkit-keyframes #{$animation_name} {
@content;
}
@hongkheng
hongkheng / longpress
Created May 7, 2015 03:46
Long press jquery
var timeoutId = 0;
$('#myElement').mousedown(function() {
timeoutId = setTimeout(myFunction, 1000);
}).bind('mouseup mouseleave', function() {
clearTimeout(timeoutId);
});