View humanize-words.js
['hey_you', 'hey-you', 'hey-You', 'heyYou'].map(txt => {
let result = txt.replace(/[a-z][A-Z]/, (val, i) => {
return `${val[0]} ${val[1]}`;
}).replace(/[-|_]/, ' ').toLowerCase();
return result;
});
View runawayDomElems.js
doc = angular.element(document);
bounds = [];
doc.find('button,.button,a,input,select,.creative-item-wrapper').each((index, btn) => {
let $btn = angular.element(btn);
if (!$btn.is(':visible'))
return;
let pos = $btn.offset();
let width = $btn.outerWidth();
let height = $btn.outerHeight();
View languageSyntax.md

Syntax

Javascript ES6

/**
 * @see {@link https:/https://gist.github.com/jsbin.com/?js,console}
 * @see ES5 vs ES6: {@link https://medium.com/@manojsinghnegi/es5-vs-es6-with-example-code-9901fa0136fc}
 */
let name = 'Eddy';
let born = 2010;
View git-update.sh
#!/usr/local/bin/bash
function git_update {
local RED="\e[31m"
local GREEN="\e[32m"
local WHITE="\e[1m"
local RESET="\e[m"
local branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
local num=1
local has_stash=true
View BigDelete.sql
/**
* When database is more 10 million rows
* [!IMPORTANT] Foreign key reference will be changed to `table_old` after renaming the tables
*/
/* Don't do this. It will create undo log (innoDB) and makes the database sluggish. And it takes forever to complete */
DELETE FROM `table` WHERE `column` = 'such';
/* Do this instead */
CREATE TABLE `table_new` LIKE `table`;
View fbDocsTableToTypeDef.js
function fbDocsTableToTypeDef(tbodyIds) {
let lines = [];
let initialIndent = ' ';
tbodyIds.forEach((tbodyId) => {
tbody = document.getElementById(tbodyId);
tbody.childNodes.forEach((row) => {
let cols = row.getElementsByTagName('td');
let nameCol = cols[0];
let descCol = cols[1];
View nice-dimension-from-ratio.js
/**
* Calculate a set of nice to use dimension for interface design & styling
* *Its rules*
* - No fraction on both width & height
* - Both width & height must end with zero
*
* @param {float|int} ratio The ratio you intend to have.
* @param {int} startWidth The starting width you intend to have (it will decrement)
* @param {int} minWidth The smallest width you want
* @return {[[int,int]]} An array of width & height set
View video-thumbnail-animate.js
/**
* Play a few seconds of video when user hover the mouse over the video element
*
* @param {int} secToPlay number of seconds to preview
*/
function videoAutoPlay(secToPlay = 3) {
let currentlyPlaying;
$('.video-wrapper').each(function () {
let wrapper = $(this);
let button = $('.play-button', wrapper);
View Facebook Post Source Image.php
<?php
// Initialize Facebook PHP SDK
require_once Kohana::find_file('vendor', 'facebook/facebook', 'php');
$config = Kohana::config('lux.facebook');
$facebook = new Facebook($config);
// Load post
$post = new Model_Facebook_Page_Posts($_POST['id']);
if ( $post->loaded() )