Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View 8bitDesigner's full-sized avatar

Paul Sweeney 8bitDesigner

  • Cisco Meraki
  • Los Angeles
View GitHub Profile
@8bitDesigner
8bitDesigner / Makefile
Created April 2, 2012 17:05
Make productive
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 October 3, 2015 17:28
Data URI utility
#! /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 June 6, 2012 19:02
Getting Apache SSL working locally

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 October 2, 2012 23:59
Pretty Print git logs
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 December 17, 2012 21:59
Using underscore to make sense of `window.performance.timing`
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 December 10, 2015 00:19
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.
{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 December 10, 2015 21:29
Drop in replacement for `console` logging in a NodeJS application
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 December 11, 2015 05:18
Bare bones cluster/domain implementation.

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

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.

@8bitDesigner
8bitDesigner / 1.md
Last active December 15, 2015 23:19

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.