Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Sweeney 8bitDesigner

  • Fullscreen, Inc.
  • Los Angeles
View GitHub Profile
View Makefile
productive:
tmux new-window -n refreshements 'cd adventurer; guard'; \
tmux split-window -t :2 'cd adventurer; supervisor server.js'; \
tmux select-window -t :1; \
tmux send-keys 'vi server.js' C-m;
@8bitDesigner
8bitDesigner / datauri.sh
Last active Oct 3, 2015
Data URI utility
View datauri.sh
#! /bin/bash
function usage {
echo "Usage: $0 /path/to/file"
[[ -n $1 ]] && echo $1
exit 1
}
# Only run if we have a single image file
[[ $# != 1 ]] && usage
@8bitDesigner
8bitDesigner / ssl.md
Created Jun 6, 2012
Getting Apache SSL working locally
View ssl.md

Lovingly skimmed from this guide

  1. Find your local host name, and hang onto it for later use
$ hostname
  1. Create a self-signed SSL cert:
openssl req -new -x509 -days 365 -sha1 -newkey rsa:1024 -nodes \
@8bitDesigner
8bitDesigner / output.txt
Created Oct 2, 2012
Pretty Print git logs
View output.txt
BM-PSweeney ~/Sites $ for i in js *mint; do in_folder $i git_message; done
js (20121001d_release) [no ticket] - Removing debug statement
beautymint (20121001b_release) Merge pull request #73 from beachmint/feature/1890/groupTracking
homemint (20121001c_release) Bumping platform to work around [BM-2297]
intimint (20121001d_release) Bumping platform to work around [BM-2297]
jewelmint (20121001c_release) Bumping platform to work around [BM-2297]
shoemint (20121001e_release) Bumping platform to work around [BM-2297]
stylemint (20121001d_release) Bumping platform to work around [BM-2297]
BM-PSweeney ~/Sites $ for i in stylemint homemint shoemint; do in_folder $i git_message; done
@8bitDesigner
8bitDesigner / timer.js
Created Dec 17, 2012
Using underscore to make sense of `window.performance.timing`
View timer.js
function pairs(value, key) {
return [value, key]
}
function nonZero(array) {
return array[0] !== 0
}
function relativeTime(item, index, list) {
var time = item[0]
@8bitDesigner
8bitDesigner / Route.coffee
Last active Dec 10, 2015
Express route to listen for hooks from GitHub on `POST /hook', and if a matching hook is found, then run `git pull` and crash the server. Handy if you want to be able to auto-update a running server whenever code is pushed to master - just run the server in Forever or Node-Supervisor and have that daemon restart the server on crash.
View Route.coffee
{exec} = require 'child_process'
target =
repo: 'platform'
branch: 'refs/heads/master'
update = ->
exec 'npm install && git pull', (err, stdout, stderr) ->
if err then console.error "Could not update application:", err
process.exit(0)
@8bitDesigner
8bitDesigner / index.js
Last active Dec 10, 2015
Drop in replacement for `console` logging in a NodeJS application
View index.js
var console = require(__dirname + '/logger')
// All three of these do the same thing
console.log(1, 2, 3) // Gets rewritten as console.log('info', 1, 2, 3)
console.log('info', 1, 2, 3) // Indentical as below
console.info(1, 2, 3)
// Works as well
console.warn('oh noes')
console.error('oh poop!')
@8bitDesigner
8bitDesigner / 1.md
Last active Dec 11, 2015
Bare bones cluster/domain implementation.
View 1.md

What does this do?

  • Spawns as many workers with your web server as you have CPUS
  • The domain around the worker will catch any errors the worker allows to escape, and escaped errors are punishable by death.
  • If a worker crashes, it's rebooted
  • If a worker exits cleanly (suicides), it's not replaced
  • Sending "SIGINT" to the master process will gracefully shutdown the child instances and then exit the master process
View 1_usage.md

Usage

node pruneCss.js styles.css output > strippedFile.css

Use Chrome's audit panel to get a list of unused CSS selectors on the current page, and, presuming your CSS file conforms to the style of "[selector] {all; rules; one: one-line;}" this script will print out the CSS file, omitting the unused selectors.

View 1.md

Sending a message with node-xmpp

Basically, you just need to create a client, and then send a formatted chunk of XML representing the message. The spec here has the details on what that XML should look like, and ltx is used to create that element.