Skip to content

Instantly share code, notes, and snippets.

View trailofdad's full-sized avatar
👹

Christian Hapgood trailofdad

👹
  • REDspace
  • Halifax, NS
  • 20:57 (UTC -03:00)
View GitHub Profile
@trailofdad
trailofdad / prune.sh
Created September 26, 2018 16:46
Prune local branches that have been merged
git branch | grep -v master | xargs git branch -d
@trailofdad
trailofdad / fakenews.js
Created September 24, 2018 23:47
fake news function
export default convertFakeNews() {
document.body.innerHTML = document.body.innerHTML.replace(/fake news/gi, 'Propaganda');
}
@trailofdad
trailofdad / parameterize.js
Created May 24, 2018 17:30
Parameterize an object for a URL
function parameterize(obj) {
return Object.keys(obj).map(key => [key, obj[key]].map(encodeURIComponent).join('=')).join('&')
}
@trailofdad
trailofdad / Node.js File Looper
Created October 11, 2017 14:51 — forked from adamwdraper/Node.js File Looper
Loop through all files in a given directory with node.js
var fs = require('fs');
var walkPath = './';
var walk = function (dir, done) {
fs.readdir(dir, function (error, list) {
if (error) {
return done(error);
}
@trailofdad
trailofdad / .md
Last active September 27, 2017 15:08
Static File Server using Connect

Connect and ServeStatic with Node.js:

  • Install connect and serve-static with NPM $ npm install connect serve-static
  • Create server.js file with this content:
var connect = require('connect');
var serveStatic = require('serve-static');
connect().use(serveStatic(__dirname)).listen(8080, function(){
    console.log('Server running on 8080...');
function slugify($text) {
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
$text = preg_replace('~[^-\w]+~', '', $text);
$text = trim($text, '-');
$text = preg_replace('~-+~', '-', $text);
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
@trailofdad
trailofdad / LocalStorage.js
Last active June 5, 2018 18:10
LocalStorage Getter & Setter
this.storage = window.localStorage;
prefixKey(key: string): string {
return `SPS|${key}`;
}
getStorageItem(key) {
const prefixedKey = this.prefixKey(key);
return this.storage.getItem(prefixedKey);
}
Repeating an SVG background image in IE 10 & 11
Add preserveAspectRatio="none slice" to your <svg> source
http://www.kaspertidemann.com/how-to-repeat-a-background-svg-image-in-internet-explorer-10/
@trailofdad
trailofdad / fix-wordpress-permissions.sh
Created January 7, 2017 00:23 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory