Skip to content

Instantly share code, notes, and snippets.

View h2non's full-sized avatar

Tom h2non

  • Dissident
  • Decentralized
View GitHub Profile
@h2non
h2non / Makefile
Created December 15, 2013 16:46
Makefile for node projects. Requires semver package $ npm install semver --save-dev
LIB = $(SRC:src/%.js=lib/%.js)
build: $(LIB)
define release
VERSION=`node -pe "require('./package.json').version"` && \
NEXT_VERSION=`node -pe "require('semver').inc(\"$$VERSION\", '$(1)')"` && \
node -e "\
var j = require('./package.json');\
j.version = \"$$NEXT_VERSION\";\
@h2non
h2non / croak-project-example.md
Last active December 30, 2015 06:09
Croak example project structure

Croak example project structure and configuration scenario

$HOME
├── .croakrc
└── workspace
    ├── builder
    │   ├── tasks
    │   ├── node_modules
    │   ├── .jshintrc
@h2non
h2non / component-layout.md
Last active December 29, 2015 13:29
Web Component general purpose organization layout structure
component
├── src
│   ├── scripts
│   │   ├── module.js
│   │   ├── services
│   │   │   └── cache.js
│   │   ├── directives
│   │   │   └── login.js
│ │ └── filters
@mixin make-grid-columns($cols: $cols-all) {
// Common styles for all sizes of grid columns, widths 1-12
@debug #{$cols};
#{$cols} {
position: relative;
// Prevent columns from collapsing when empty
min-height: 1px;
// Inner gutter via padding
padding-left: ($grid-gutter-width / 2);
padding-right: ($grid-gutter-width / 2);
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
#!/usr/bin/env node
/**
* A very basic Node.js Bower installer replacement for download private hosted components
* @version 0.1
* @license WTFPL
*
* Usage:
* node bower-private-install.js -u username -p password -f ../bower.json
*
* TODO:
@h2non
h2non / wget_download.sh
Last active December 23, 2015 15:59
wget output simple parsing to show the download process
#!/bin/bash
download_status() {
if [ -f $1 ]; then
while : ; do
sleep 1
local speed=$(echo `cat $1 | grep -oh '\([0-9.]\+[%].*[0-9.][s|m|h|d]\)' | tail -1`)
echo -n "Downloading... $speed"
echo -n R | tr 'R' '\r'
@h2non
h2non / jade.min.js
Created August 1, 2013 10:50
Adapted Jade library to compile in the browser
(function(){function require(p){var path=require.resolve(p),mod=require.modules[path];if(!mod)throw new Error('failed to require "'+p+'"');return mod.exports||(mod.exports={},mod.call(mod.exports,mod,mod.exports,require.relative(path))),mod.exports}require.modules={},require.resolve=function(path){var orig=path,reg=path+".js",index=path+"/index.js";return require.modules[reg]&&reg||require.modules[index]&&index||orig},require.register=function(path,fn){require.modules[path]=fn},require.relative=function(parent){return function(p){if("."!=p.charAt(0))return require(p);var path=parent.split("/"),segs=p.split("/");path.pop();for(var i=0;i<segs.length;i++){var seg=segs[i];".."==seg?path.pop():"."!=seg&&path.push(seg)}return require(path.join("/"))}},require.register("compiler.js",function(module,exports,require){function isConstant(val){if(/^ *("([^"\\]*(\\.[^"\\]*)*)"|'([^'\\]*(\\.[^'\\]*)*)'|true|false|null|undefined) *$/i.test(val))return!0;if(!isNaN(Number(val)))return!0;var matches;return(matches=/^ *\[(.*)\
@h2non
h2non / inheritedMembers.js
Last active December 16, 2015 01:49
Simple Function to get inherited prototype Object members
// for ES5 compliant engines (tested in Chrome, FF and IE9+)
// Under WTFPL license ;)
function getObjectInheritedMembers(obj) {
var members = {};
if (['boolean', 'number', 'string', 'undefined'].indexOf(typeof obj) !== -1 || obj === null) { // support for primitives types
obj = Object(obj);
} else if (typeof obj === 'function') {
members[obj.name || (obj.toString().match(/function (\w*)/) || obj.toString().match(/\[object (\w*)\]/))[1] || 'Anonymous Function'] = Object.getOwnPropertyNames(obj);
obj = obj.prototype;
} else if (obj.toString() !== '[object Object]' && obj.prototype) { // fix Objects instances and IE
@h2non
h2non / proto-inheritance-reflect.js
Last active December 16, 2015 01:19
Implement a recursive reflection in JavaScript prototype chain inheritance
// for ES5 compliant engines (tested in Chrome, FF and IE9+)
// Under WTFPL license ;)
function getObjectInheritance(obj) {
var hierarchy = [];
if (['boolean', 'number', 'string', 'undefined'].indexOf(typeof obj) !== -1 || obj === null) { // support for primitives types
obj = Object(obj);
} else if (typeof obj === 'function') {
hierarchy.push(obj.name || (obj.toString().match(/function (\w*)/) || obj.toString().match(/\[object (\w*)\]/))[1] || 'Anonymous Function');
obj = obj.prototype;
} else if (obj.toString() !== '[object Object]' && obj.prototype) { // fix Objects instances and IE