Skip to content

Instantly share code, notes, and snippets.

@jdpaton
jdpaton / gist:1185359
Created September 1, 2011 03:24
NPM & HTTPS & Local caching Proxy
npm ERR! registry error parsing json
npm ERR! SyntaxError: Unexpected token ILLEGAL
npm ERR! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
npm ERR! <html><head>
npm ERR! <title>Proxy error: 400 Couldn't parse URL.</title>
npm ERR! </head><body>
npm ERR! <h1>400 Couldn't parse URL</h1>
npm ERR! <p>The following error occurred while trying to access <strong>https://registry.npmjs.org/request</strong>:<br><br>
npm ERR! <strong>400 Couldn't parse URL</strong></p>
npm ERR! <hr>Generated Wed, 31 Aug 2011 20:22:34 PDT by Polipo on <em>Manitoba:8123</em>.
@jdpaton
jdpaton / gist:2210886
Created March 27, 2012 00:09
Generate a random lowercase string with at least one number
python -c "import random; x = [random.choice('23456789') for x in range(1)] + [ random.choice('abcdefghjkmnpqrstwxyz') for x in range(3)]; random.shuffle(x); print ''.join(x)"
@jdpaton
jdpaton / humans.txt
Created September 29, 2012 07:58 — forked from ryanflorence/static_server.js
Node.JS + Foundation CSS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
/* Foundation was made by ZURB, an interaction design and design strategy firm in Campbell, CA */
/* zurb.com */
/* humanstxt.org */
/* SITE */
Standards: HTML5, CSS3
Components: jQuery, Orbit, Reveal
Software: Coda, Textmate, Git
@jdpaton
jdpaton / fork.c
Created October 25, 2012 18:40
Fork x number of child processes which have a set lifetime
#include <stdio.h>
#include <stdlib.h>
static int expiry = 30;
int main(int argc, char *argv[]){
int k = *argv[1];
int i=0;
@jdpaton
jdpaton / corvette.sh
Created October 26, 2012 07:24
Encrypted file using image steganography
#!/bin/bash
# Author: jamie.paton@googlmail.com
# COMMANDS
# create: Args: <path to image file> <path to plain file>
# Encrypts a file using the GPG utility, then zips it up and embeds
# it into the image file
@jdpaton
jdpaton / n4watcher.js
Created November 27, 2012 08:31
Nexus 4 watcher ... email alerts version
var email = require('emailjs');
var cheerio = require('cheerio');
var request = require('request');
var url8GB = 'https://play.google.com/store/devices/details?id=nexus_4_8gb';
var url16GB = 'https://play.google.com/store/devices/details?id=nexus_4_16gb';
var defaultState = 'UNKNOWN';
var trackingState8GB = defaultState;
var trackingState16GB = defaultState;
± for i in {1..10}; do ./wrk http://localhost:8000 -c 100 | grep Requests | awk '{print $2}';done | awk '{s+=$1} END {print s}'
5329.22
@jdpaton
jdpaton / app.js
Created May 22, 2013 06:56
Simply return any custom HTTP code by supplying the url param ?code=302
var url = require('url');
var http = require('http');
var querystring = require('querystring');
// Example usage: curl -I http://localhost:1337/?code=500
http.createServer(function (req, res) {
var purl = url.parse(req.url).query;
var qs = querystring.parse(purl);
var status_code = qs.code || 200;
@jdpaton
jdpaton / git-split-subfolder.sh
Created August 27, 2013 20:49
This script splits a subfolder of an existing git repo into its own separate repo. It will preserve all tags by default, and any branches specified with '-b'. Usage example: ./git-split-subfolder.sh -p git://repo.com/foo -services -s mysubfolder -b "branch1 branch2 branch3" The new repo 'mysubfolder' will be in the $CWD.
#!/bin/bash
set -e
usage() {
cat << EOF
usage: $0 [options]
This script splits an existing folder inside of a git repo into its own
separate git repo, optionally preserving all existing tags and branches from the
parent repo.
@jdpaton
jdpaton / git-clone-or-update.sh
Last active December 21, 2015 23:38
Clones or updates and checks out the appropriate branch while checking for existence of either.
#!/bin/bash
TARGET_DIR=${1:-"./new-repo"}
BRANCH=${2:-"master"}
REPO=${3:-"git://repo/name.git"}
if [ -e "${TARGET_DIR}" ]
then
pushd $TARGET_DIR
git fetch
exists=$(git show-branch $BRANCH > /dev/null 2>&1; echo $?)