Skip to content

Instantly share code, notes, and snippets.

View phalkunz's full-sized avatar
🏠
Working from home

Saophalkun Ponlu phalkunz

🏠
Working from home
  • Wellington, New Zealand
View GitHub Profile
@phalkunz
phalkunz / gist:2411184
Created April 18, 2012 04:56 — forked from stojg/async-social-load.js
Async loading of javascript with callback
(function(d, s) {
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id, callback) {
if (d.getElementById(id)) {return;}
js = d.createElement(s);js.src = url;js.id = id;js.async=true;
fjs.parentNode.insertBefore(js,fjs);
if(callback!=undefined) {
js.onload=callback;
//Extra for internet explorer
js.onreadystatechange = function () { if(this.readyState == 'complete' || this.readyState == 'loaded') { callback(); } }
}
@phalkunz
phalkunz / ps-rotating-sprite.js
Created April 26, 2012 02:32
Photoshop script for preparing a sprite for rotating animation
/**
* Photoshop script for preparing a sprite for rotating animation.
* Input : a starting sprite and number of frames
* Output: the specified number of layers ready to be used in the PS animation tool
*/
var docRef = app.activeDocument;
var activeLayer = docRef.activeLayer;
var degToRotate = null;
var newLayer = null;
@phalkunz
phalkunz / js-func-url-vars.js
Created May 16, 2012 04:51
Function for extracting url query string variables from the `window.location`
/**
* Returns a literal object with properties mapped to the query string variables
* For example:
* input (page url): http://www.test.com/index?one=1&two=2
* value: { 'one': 1, 'two': 2 }
*/
function urlVars() {
var search = window.location.search;
if(search === '' || !search || search === '?') {
@phalkunz
phalkunz / js-time-profiler.js
Created June 19, 2012 02:11
Simple JS running time profiler
/**
* Profiling (running time). For dev purpose only.
*/
(function() {
window._profiler = {
'profiles': []
};
_profiler.time = function(name) {
_profiler.profiles[name] = new Date();
};
@phalkunz
phalkunz / mountain-lion-brew-setup.markdown
Created July 30, 2012 10:22 — forked from myobie/mountain-lion-brew-setup.markdown
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from http://developer.apple.com. You will not be able to submit apps to any stores using this XCode version, so turn away if that is something you might want to do.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

@phalkunz
phalkunz / js-flash-detection.js
Created March 18, 2013 21:59
JavaScript: Flash detection
function isFlashInstalled() {
try {
if(new ActiveXObject('ShockwaveFlash.ShockwaveFlash')) return true;
}catch(e){
if(navigator.mimeTypes["application/x-shockwave-flash"] !== undefined) return true;
}
return false;
}
@phalkunz
phalkunz / git-log-today-by-self.bash
Last active December 19, 2015 15:09
Git report today with yourself an author If you want (or you are asked) to review what you have done today the following command does just that.
git log --since='1am' --author=$(git config user.email) --format='%h — %an (%ar) %s'
# Output with colors
# $ git log --since='1am' --author=$(git config user.email) --format='%Cred%h%Creset — %an (%ar) %Cgreen%s%Creset'
# To set up git alias, run the following command once
# $ git config --global alias.log-today "log --since='1am' --author=$(git config user.email) --format='%h — %an (%ar) %s'"
# Mac OS X Lion introduced a new, iOS-like context menu when you press and hold a key
# that enables you to choose a character from a menu of options. If you are on Lion
# try it by pressing and holding down 'e' in any app that uses the default NSTextField
# for input.
#
# It's a nice feature and continues the blending of Mac OS X and iOS features. However,
# it's a nightmare to deal with in Sublime Text 2 if you're running Vintage (Vim) mode,
# as it means you cannot press and hold h/j/k/l to move through your file. You have
# to repeatedly press the keys to navigate.
@phalkunz
phalkunz / touch-event-detection.js
Created October 8, 2013 09:32
Touch event detection
// Source: https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/
if (
('ontouchstart' in window) ||
(navigator.maxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0)
) {
/* browser with either Touch Events of Pointer Events
running on touch-capable device */
}
@phalkunz
phalkunz / ctags definitions for Javascript
Last active December 27, 2015 03:09 — forked from tim-smart/ctags definitions for Javascript
Ctags for Javascript lang. It goes in `~/.ctags`
--langdef=js
--langmap=js:.js
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*\{/\5/,object/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*function[ \t]*\(/\5/,function/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*\[/\5/,array/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*[^"]'[^']*/\5/,string/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*(true|false)/\5/,boolean/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*[0-9]+/\5/,number/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*.+([,;=]|$)/\5/,variable/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*[ \t]*([,;]|$)/\5/,variable/