Skip to content

Instantly share code, notes, and snippets.

View myeonwoo's full-sized avatar

Myeonwoo Lim myeonwoo

View GitHub Profile
@myeonwoo
myeonwoo / gist:77aff182cf4624fbf3732ef1e12c0a36
Created September 15, 2017 06:38
JavaScript: Sexy PubSub
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind
// Hat tip Paul Irish
var o = $({});
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
@myeonwoo
myeonwoo / gist:1fb4e6d5234cba8fcf64a0b5e6c2d166
Created September 15, 2017 06:40
CSS: Image Replacement
.ir {
boarder:0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@myeonwoo
myeonwoo / gist:2b57e953ff0a14d24d85f35589d49934
Created September 15, 2017 06:43
JavaScript: Jquery PubSub
(function($){
var o = $({});
$.each({
on: 'subscribe',
trigger: 'publish',
off: 'unsubscribe'
}, function(key, api) {
$[api] = function(){
o[key].apply(o, arguments);
}
var IE = (function () {
"use strict";
var ret, isTheBrowser,
actualVersion,
jscriptMap, jscriptVersion;
isTheBrowser = false;
jscriptMap = {
"5.5": "5.5",
@myeonwoo
myeonwoo / gist:899d821166d3bea6451bedba69935d87
Created September 19, 2017 04:01
CSS: Emmet - examples
<!-- Skip The Div #1 -->
div.container
<!-- Skip The Div #2 -->
.container
<!-- Implicit Tag Names -->
.wrap>ul.list>.sites
<!-- Chaining Abbreviations -->
@myeonwoo
myeonwoo / msql_table_size.sql
Created September 19, 2017 04:56
MYSQL: Table Size
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "eng_dangicokr"
AND table_name = "{table_name}";
@myeonwoo
myeonwoo / tableToSql.js
Created September 21, 2017 08:16 — forked from rnaffer/tableToSql.js
Export table to excel with pure javascript
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><?xml version="1.0" encoding="UTF-8" standalone="yes"?><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) };
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table);
var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML };
window.location.href = uri + base64(format(template, ctx));
};
@myeonwoo
myeonwoo / hierarchy.php
Created October 9, 2017 06:18
PHP: Data Structure - Hierarchy
<?
class Hierarchy {
private static $hierarchy;
private static $lookup;
// Nodes can be any objects that have IDs (id) and a parent IDs (parent)
public static function buildTree($nodes){
// Initialize hierarchy and lookup arrays
self::$hierarchy = array();
self::$lookup = array();
// Walk through nodes
@myeonwoo
myeonwoo / queue.js
Created October 9, 2017 06:44
JavaScript: Data Structure - Queue
function Queue() {
this._oldestIndex = 1;
this._newestIndex = 1;
this._storage = {};
}
Queue.prototype.size = function() {
return this._newestIndex - this._oldestIndex;
};
@myeonwoo
myeonwoo / stack.js
Last active September 6, 2018 02:57
JavaScript: Data Structure - Stack
function Stack() {
this._size = 0;
this._storage = {};
}
Stack.prototype.push = function(data) {
var size = ++this._size;
this._storage[size] = data;
};