Skip to content

Instantly share code, notes, and snippets.

Avatar

Joshua Mervine jmervine

View GitHub Profile
@jmervine
jmervine / function.sh
Created Jan 31, 2014
Simple Ruby version switcher...
View function.sh
# add this to your .bashrc / .zshrc / etc
if test -e ~/scripts/renv.sh; then
function chrb {
CURRENT_VERSION="$1" source ~/scripts/renv.sh
}
fi
@jmervine
jmervine / gist:8788669
Created Feb 3, 2014
Strip specials in BASH
View gist:8788669
# replaces numbers, commas, periods, asterisks, slashes (forward and back), all brackets and parentheses
#
# note: I'd like to get this working with less '-e' calls but it wasn't for me on
#
# $ sed --version
# GNU sed version 4.2.1
sed -r -e 's/[0-2,\.\*\\\/]/_/g' -e 's/\[/_/g' -e 's/\]/_/g' -e 's/\{/_/g' -e 's/\}/_/g' -e 's/\(/_/g' -e 's/\)/_/g' -e 's/_{2,}/_/g' -e 's/_$//'
@jmervine
jmervine / .travis.yml
Last active Aug 29, 2015
request -> requets-lite
View .travis.yml
language: node_js
node_js:
- 0.8
- 0.10
@jmervine
jmervine / ssl.js
Created Feb 17, 2014
MaxCDN working SSL cert upload.
View ssl.js
#!/usr/bin/env node
/*********************************************************
* Example script for uploading ssl certs to maxcdn
* pull zone.
*
*
* Setup to run this script:
*
* $ npm install maxcdn http-debug
*
View gist:9127845
Server running on port 8000
-> /mervine_net
undefined:1
s%2Fheads%2Fmaster%22%2C%22after
f%22%3A%22refs%2Fheads%2Fmaster%22%2C%22after
^
View tab-helper.js
// http://cdn.zoker.me/tools/tab-helper.js
$("input:text").focus(function(){
$(this).select();$(this).mouseup(function(a){
a.preventDefault();
})
});
$(window).load(function() {
var hash;
var hash_suffix='_tab';
@jmervine
jmervine / 0node-maxcdn.md
Last active Aug 29, 2015
MaxCDN Node.js Blog Draft
View 0node-maxcdn.md

An Introduction to MaxCDN on Node.js

In addition to [MaxCDN]'s powerful [Oauth] API, they offer a number of simple modules for various languages. Here I'll be covering they're [Node.js] module.

In this post, I'll go over some basic examples of how to display reports and purge caches using the [MaxCDN Node module], which like all of [MaxCDN]'s modules, is open sourced at [github.com/MaxCDN/node-maxcdn].

If you're like me and prefer to read up on the technologies you'll be using in this post before diving in, here's what we'll be using:

  • [Node.js], "a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications"
  • [npm], "Node Packaged Modules"
View app.js
'use strict';
var express = require('express');
var MaxCDN = require('maxcdn');
// Initialize maxcdn from environment.
var maxcdn = new MaxCDN(process.env.ALIAS,
process.env.KEY,
process.env.SECRET);
// For this example, I'll restrict to a single zone,
@jmervine
jmervine / Gemfile
Created Feb 26, 2014
Simple Web Interface to Purge Caches via MaxCDN
View Gemfile
source "https://rubygems.org"
gem "sinatra"
gem "haml"
gem "maxcdn"
View 1test.js
var cluster = require('cluster');
var numCPUs = require('os').cpus().length;
var results = [];
var responded = 0;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}