Skip to content

Instantly share code, notes, and snippets.

@jdpaton
jdpaton / popstddev.go
Created May 12, 2015 06:26
[Go] Population Standard Deviation
package main
import (
"flag"
"fmt"
"math"
"strconv"
)
func main() {
@jdpaton
jdpaton / add-folder-as-submodule.sh
Created August 30, 2013 04:49
Adds a bunch of subdirectories that are git modules to the parent git repo/folder
for i in $(ls -d bundle/*); do;if [ -d "$i"/.git ]; then; git submodule add $(cd $i && git remote show origin | grep Fetch | awk '{print $3}') ./$i; fi; done
@jdpaton
jdpaton / curlit.sh
Created August 29, 2013 20:59
Shows the curl connection timings. Can't remember where I got this from.
#!/bin/bash
#
# curl wrapper returning timing information.
#
# curl format adapted from
# http://josephscott.org/archives/2011/10/timing-details-with-curl/
#
# Example usage:
# $ curlt http://www.apple.com
# $ time curlt http://www.apple.com -v
@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 $?)
@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 / 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;
± 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 / 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;
@jdpaton
jdpaton / corvette.sh
Created October 26, 2012 07:24
Encrypted file using image steganography
#!/bin/bash
# Author: [email protected]
# 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 / 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;