Skip to content

Instantly share code, notes, and snippets.

@antoster
antoster / gist:b2475c981adb242f3d52
Created October 30, 2015 10:28 — forked from tonymtz/gist:d75101d9bdf764c890ef
Uninstall nodejs from OSX Yosemite
# First:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
#go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@antoster
antoster / protips.js
Last active August 29, 2015 14:25 — forked from nolanlawson/protips.js
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@antoster
antoster / nano-tpl.js
Created June 27, 2015 09:50
Nano-templating engine (tweet-sized), by @ThomasFuchs
function t(s, d) {
for (var p in d)
s = s.replace(new RegExp('{' + p + '}', 'g'), d[p]);
return s;
}
// Usage
var build = function(id, href) {
var options = {
id: id
@antoster
antoster / closest.js
Last active August 29, 2015 14:22
$.fn.closest in pure JS
// Inspired by http://clubmate.fi/jquerys-closest-function-and-pure-javascript-alternatives/
// Recursion implementation
function closestEl(el, fn) {
return el && (fn(el) ? el : closestEl(el.parentNode, fn));
}
// "By Class" helper (depends on closestEl)
function closestByClass(el, classValue, skipSelf) {
var targetEl = skipSelf ? el.parentNode : el;
@antoster
antoster / table-holy-grail.css
Last active August 29, 2015 14:08
Table holy grail layout // source http://jsbin.com/yegelexavi
html,
body {
height: 100%;
}
body {
background: #fffad5;
color: black;
}
.wrapper {
height: 100%;
@antoster
antoster / proto_inherit.js
Last active October 14, 2015 10:48
Proto inheritance - analogue of Object.create(): inherit without executing parent constructor
function inherit(obj) {
function F() {}
F.prototype = obj;
return new F();
}
// Usage
function A(){};
A.prototype.someMethod = function(){};
function B(){};
@antoster
antoster / inherit.js
Last active October 14, 2015 10:49
Classic inheritance (5)
var inherit = (function () {
var F = function () {};
return function (C, P) {
F.prototype = P.prototype;
C.prototype = new F();
C.uber = P.prototype;
C.prototype.constructor = C;
}
}());
@antoster
antoster / jsbin.bazos.css
Created June 12, 2014 12:57 — forked from anonymous/jsbin.bazos.css
Fixed-sized sidebar trick
.wrapper{
float: left;
width: 100%;
background: yellow;
}
.content{
margin-left: 200px;
}
.sidebar{
width: 200px;