Skip to content

Instantly share code, notes, and snippets.

View panlw's full-sized avatar
🎯
Focusing

Neo Pan panlw

🎯
Focusing
View GitHub Profile
@panlw
panlw / ribbon_menu.html
Created February 25, 2014 02:04
CSS Ribbon Menu
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<title>CSS Ribbon</title>
<style>
* {
/* Basic CSS reset */
margin:0;
padding:0;
// @see http://krasimirtsonev.com/blog/article/Javascript-template-engine-in-just-20-line
var TemplateEngine = function(html, options) {
var re = /<%([^%>]+)?%>/g, reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g, code = 'var r=[];\n', cursor = 0;
var add = function(line, js) {
js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') :
(code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : '');
return add;
}
while(match = re.exec(html)) {
add(html.slice(cursor, match.index))(match[1], true);
@panlw
panlw / git.tip01.txt
Last active August 29, 2015 14:07
[Tip] Access git service by https://
# if access disabled by git://, you can retry https:// by git global config
# @see http://stackoverflow.com/questions/15669091/bower-install-using-only-https
git config --global url."https://".insteadOf git://
@panlw
panlw / hello.css
Last active August 29, 2015 14:09
AngularJS Bootstrap
/* enable absolute positioning */
.inner-addon {
position: relative;
}
/* style icon */
.inner-addon .glyphicon {
position: absolute;
padding: 10px;
/*pointer-events: none;*/

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

Resolve by module app-root-path

First, add bootstrap code like:

var appRootPath = require('app-root-path');
appRootPath.setPath(appRootPath.resolve('path/to/src/root'));
global.use = appRootPath.require;

And then use global function use like:

@panlw
panlw / introrx.md
Last active August 29, 2015 14:23 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@panlw
panlw / gist:4d2f86569f120b6d97f4
Last active September 18, 2015 05:00 — 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*
@panlw
panlw / bobp-python.md
Created November 22, 2015 05:54 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens