Skip to content

Instantly share code, notes, and snippets.

View allenhwkim's full-sized avatar

Allen Kim allenhwkim

View GitHub Profile
@allenhwkim
allenhwkim / micro-template.js
Created August 12, 2015 14:12
micro template
'use strict';
var _cache = {};
var microTemplate = function(str, data) {
var func = _cache[str];
if (!func) {
var strFunc =
"var p=[],print=function(){p.push.apply(p,arguments);};" +
"with(obj){p.push('" +
//str.replace(/[\r\t\n]/g, " ")
@allenhwkim
allenhwkim / micro-template-test.js
Created August 12, 2015 14:13
micro template test
var microTemplate = require(__dirname + '/micro-template.js');
/*******************************************************
* `<%= %>` expression test
*******************************************************/
var layout = [
'<script type="text/html" id="item_tmpl">',
' <div id="<%=id%>" class="<%=(i % 2 == 1 ? " even" : "")%>">',
' <div class="grid_1 alpha right">',
' <img class="righted" src="<%=profile_image_url%>"/>',
var konsole = {
LOG_LEVELS: {
ALL: parseInt('11111',2),
DEBUG: parseInt('00001',2),
LOG: parseInt('00010',2),
INFO: parseInt('00100',2),
WARN: parseInt('01000',2),
ERROR: parseInt('10000',2),
NONE: parseInt('00000',2)
},
@allenhwkim
allenhwkim / getStyle.js
Created April 3, 2016 15:43
Get real width and height using getComputedStyle
// ref. https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle
function getStyle(elem, prop) {
var styles = window.getComputedStyle(elem, null);
var value = styles.getPropertyValue(prop);
if (!value) {
throw "Could not get style for " + prop;
}
return value
}
@allenhwkim
allenhwkim / .bash_profile
Last active September 24, 2018 20:17
usage of .nvmrc
# To use this, add .nvmrc with contents of 'N.N.N' to your project. e.g. 0.12.7
# Add the following to the end of .bash_profile or .bashrc
#
# if directory is changed
# if `.nvmrc` is found execute `nvm use`
# if `package.json` is round execute `nvm use default`
enter_directory() {
if [ "$PWD" != "$PREV_PWD" ]; then
PREV_PWD="$PWD";
if [ -e ".nvmrc" ]; then
@allenhwkim
allenhwkim / getMousePositionInElement.js
Created July 5, 2016 04:18
Find Mouse Position Within A Div
function getDocumentPosition(oElement) {
var posX=0, posY=0;
if(oElement.offsetParent) {
for(;oElement; oElement = oElement.offsetParent) {
posX += oElement.offsetLeft;
posY += oElement.offsetTop;
}
return {x: posX, y: posY};
} else {
return {x: oElement.x, y: oElement.y};
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script>
var previewFile;
window.onload = function() {
var canvas = document.querySelector("#canvas-to-resize");
#!/usr/bin/env node --harmony
var co = require('co');
var prompt = require('co-prompt');
var program = require('commander');
program
.arguments('<file>')
.option('-u, --username <username>', 'The user to authenticate as')
.option('-p, --password <password>', 'The user\'s password')
.action(function(file) {
{
"name": "nodecmd",
"version": "0.0.3",
"description": "A command-line tool for creating command line tol",
"main": "index.js",
"bin": {
"snippet": "./index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"