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 / express-passport-local.md
Last active April 25, 2023 13:15
Setup local (username/password) authentication in express.js (using passport.js)

Setup the project folder

    mkdir passport-local
    npm init
    # Use default values for npm init prompts

Install required packages

function getQueryParam(name) {
window.location.search
const paramStr = window.location.search.substr(1).split('&').find(param => param.includes(`${name}=`));
const nameValue = paramStr.split('=');
if (nameValue.length === 2) {
return nameValue[1];
}
return null;
@phalkunz
phalkunz / latest-checkouts.sh
Last active September 3, 2019 11:47
Get latest git checkout
history | grep -e "\d\+\s\+git checkout [^-.]\+" | awk '{ print $NF }' | tail -n 10
@phalkunz
phalkunz / sass-spacing-helper.scss
Last active September 3, 2019 11:47
Sass spacing helper
/**
* This is based on https://getbootstrap.com/docs/4.1/utilities/spacing/
*/
$directioMap: (
top: t,
right: r,
left: l,
bottom: b
);
@phalkunz
phalkunz / composer.json
Created April 13, 2018 02:57
Git pre-commit hook with PHPCS
{
...
"scripts": {
"post-install-cmd": "(cd .git/hooks/; ln -s -f ../../mysite/tools/git-pre-commit-hook ./pre-commit)"
},

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@phalkunz
phalkunz / callback-threshold.js
Last active July 12, 2016 04:50
Make sure a callback won't run more than once during a specified duration
(function() {
var __timerIDs = {};
/**
* Make sure the callback won't run more than once
* during a specified duration.
*
* This function relies on variable __timerIDs
* in outer scope.
*
@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.