Skip to content

Instantly share code, notes, and snippets.

@tlack
tlack / express-js-dust-x-example.js
Created March 23, 2012 20:16
express-js and dust-x example app
/**
* Module dependencies.
*/
var express = require('express')
, dustx = require('dust-x')
/**
* Create the Express application.
*/
@tlack
tlack / vhosted-node.sh
Created March 26, 2012 21:47
Idea for auto-deployment system for vhosted node.js apps
for DIR in /home/*/node; do
PORT=[generate port based on crc32 of $DIR]
# somehow check if not running
NODE_ENV=dev NODE_PORT=$PORT node-dev $DIR/app.js
cat /etc/nginx/configs.avail/default-node.conf | \
sed -e s/DIR/$DIR/ | \
sed -e s/PORT/$PORT > /etc/nginx/configs.enabled/node-$DIR.conf
# somehow check if we actually created/changed a config here
if [ $changed -eq 1 ]; then
service nginx restart
@tlack
tlack / gist:2425247
Created April 20, 2012 01:47
example of node.js + handlebars
var h = require('handlebars');
var tmpl = h.compile("<p>{{name}}</p>");
var data = {name:"tlack"};
console.log(tmpl(data));
@tlack
tlack / jquery-ui-1.8.23-orig.js
Created September 18, 2012 20:30
possible bug in jquery ui's slider class and closestHandle? Cannot call method 'addClass' of undefined
_mouseCapture: function( event ) {
var o = this.options,
position,
normValue,
distance,
closestHandle,
self,
index,
allowed,
offset,
@tlack
tlack / gist:4576631
Last active December 11, 2015 08:58
Idea for CodePen plugins
Idea for CodePen plugins (by @tlack)
Step 1: Establish simple plugin architecture/API
```javascript
CP.Plugins.add({
context: CP.Html,
re: /fun ([a-z_][a-z0-9_]+)/,
callback: function(cpPluginContext, match) {
var str = "function "+match.$1+"() {\n// Comment\n\n}\n";
@tlack
tlack / tumblr-better-author-bios.md
Last active December 24, 2015 00:59
Javascript hack to improve Tumblr's lame byline options for group blogs

Tumblr's group blog features do not support per-author homepage links (such as Twitter) or bios. That sucks.

I've written here a Javascript function that kinda outputs something like what you may want. It maintains all the author data inside Javascript as well, for better or for worse. Eventually I'll make this pull from tags I guess.

Put this toward the top of your theme HTML, inside the script tag:

            var AUTHORS = {
                'caropopco': {
                    name: 'Carolina',
@tlack
tlack / custom-routes-with-react-page-example.md
Last active September 15, 2016 08:51
How to use custom routes with react-page and react-page-middleware

Note: This article was written December 24 2013, when react-page's version number is 0.2.0. This is all likely to change, so if the advice mentioned doesn't help, please reach out to the React community.

How to use custom URLs with the React-page router

Note: Technically, this functionality is provided by react-page-middleware. I'm going to refer to it generally as react-page, because I don't think they have enough of an independent identity (and usefulness outside of the whole react-page stack) to nitpick the naming.

react-page [https://github.com/facebook/react-page] is a cool new tool to link your ReactJS scripts in to your Node server config so that the entire site can be server rendered.

Unfortunately, it doesn't support custom routes - http://site.co/widget will always look for src/widget/index.js (or whatever your root elem is), even if you want http://site.co/widgets/new to go there instead.

@tlack
tlack / p01-matraka-explained.js
Created July 3, 2012 11:41
p01's Matraka javascript demo decoded
// Matraka's source code decoded and beautified
// by @tlack
//
// Matraka is a 1005 byte Javascript "demo" by p01. It includes an 'evolving animation'
// and great dirty synth music. View here:
//
// http://www.p01.org/releases/MATRAKA/matraka.png.html
//
// I fondly recall the demo scene of my youth, puzzling over the work of Future
// Creators and those guys. I was puzzled by this worked so I had to figure it
@tlack
tlack / gist:2387185
Created April 14, 2012 19:19
express.js / node.js get remote IP address
exports.req_ip = function(req) {
return ( req.headers["X-Forwarded-For"]
|| req.headers["x-forwarded-for"]
|| req.client.remoteAddress );
}

Keybase proof

I hereby claim:

  • I am tlack on github.
  • I am tlack (https://keybase.io/tlack) on keybase.
  • I have a public key ASAfzQXduVcmaqcGmj495IpYs0u8ynUslUtUcEneasSOPQo

To claim this, I am signing this object: