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 / simple-template-func.js
Last active August 29, 2015 14:05
A really simple template function
/**
* A really simple template function.
*
* USAGE:
*
* 1. Ivoke `prepareTemplate(template)` by provide template string as an argument
* 2. The above invocation returns another function which called by with data argument
**/
function prepareTemplate(template) {
@phalkunz
phalkunz / echoc.sh
Last active August 29, 2015 14:05
Echo string in color based on `--type`
###
#
# Echo string in color based on `--type`.
# Read `colorEcho()` funncton for more info on type.
#
# AUTHOR:
#
# Saophalkun Ponlu (phalkunz@gmail.com)
#
###
@phalkunz
phalkunz / git-origin-branch-sync-status.sh
Last active August 29, 2015 14:03
Script to check whether local branch and the origin's counterpart are in sync
###
# Returns a code that determine whether local branch and its origin's counterpart
# are in sync. In sync, in this case, means there's no commits in local branch
# that have not been pushed to the origin. In short, it means the following
# command returns nothing.
#
# git log {branch} --not origin/{branch}
#
# The code will be be in `$?` variable after the funciton call.
# The status code can be:
@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/
@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 */
}
# 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 / 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'"
@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 / 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-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();
};