Skip to content

Instantly share code, notes, and snippets.

View michaelrhodes's full-sized avatar

Michael Rhodes michaelrhodes

View GitHub Profile
@michaelrhodes
michaelrhodes / slugify
Created May 5, 2014 02:36
slugify the files of your working directory
#!/usr/bin/env bash
for file in $(pwd)/*
do
result=$(echo $(basename $file | tr 'A-Z' 'a-z') | tr ' ' '-')
mv "$file" $result
done
@michaelrhodes
michaelrhodes / gh-pages-toggle.bookmarklet
Last active September 6, 2020 00:43
A bookmarklet for toggling between github repositories and their github pages.
javascript:(function(){(function(){if(/github.io$/.test(location.host)){var%20paths=location.href.match(/^.+\/\/(.+)\.github\.io\/([^\/]+)?\/?.*$/).slice(1);location.href="https://github.com/"+paths[0]+"/"+(paths[1]||'')}else%20if(location.host=="github.com"){var%20paths=location.pathname.substr(1).split("/");location.href="http://"+paths[0]+".github.io/"+paths[1]}})()})();
@michaelrhodes
michaelrhodes / domify-server.js
Created September 24, 2014 07:49
Using domify on the server.
var sandboxed = require('sandboxed-module')
var domino = require('domino')
var domify = sandboxed.require('domify', {
globals: { document: domino.createDocument() }
})
var el = domify('<p>Hello, Dexter Morgan</p>')
el.classList.add('message')
console.log(el.outerHTML)
@michaelrhodes
michaelrhodes / psreadytext.sh
Last active August 29, 2015 14:08
Prepare copied text for pasting into Photoshop by transforming its newlines into end-of-text characters.
pbpaste | tr '\012' '\003' | pbcopy
@michaelrhodes
michaelrhodes / index.js
Last active August 29, 2015 14:13
Using JSONPatch to programatically update a package.json
var fs = require('fs')
var jsonpatch = require('fast-json-patch')
var pkg = require('./package.json')
var patch = require('./patch')(pkg)
var patches = jsonpatch.compare(pkg, patch)
// We don’t want to remove keys missing from our patch.
.filter(function (item) {
return item.op !== 'remove'
})
function remote (name) {
return 'greetings from the internet, ' + name
}
@michaelrhodes
michaelrhodes / announce.json
Created April 25, 2016 02:06
Ⓐ /announce
{ "repos": ["wzrd-require"] }
@michaelrhodes
michaelrhodes / oxford.js
Created May 19, 2016 00:48
Join an array with proper English
function oxford (arr, last) {
last = last || ', and '
return arr.reduce(function (a, b, i, arr) {
return (
!arr[i + 1] ? a + b :
!arr[i + 2] ? a + b + last :
a + b + ', '
)
}, '')
}
var safari = require('./regex')
// @return false or
// @return [string:version, boolean:is-mobile-safari]
module.exports = function (ua) {
var m = ua.match(safari)
return !m ? false : [m[1], !!m[2]]
}