Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
status=$1
status=${status:-off}
echo "Will toggle proxy: $status"
IFS=$'\n'; networks=($(networksetup -listallnetworkservices))
for (( i=1; i<${#networks[@]}; i++ )); do
net=${networks[i]}
@jimCresswell
jimCresswell / return-promise-for-an-object-of-values.js
Last active August 29, 2015 14:16
Resolving expectations against an object of promises
/**
* Return a promise for an object of test values
*/
var Q = require('q');
var promise1 = getPromiseForValue('someArg1');
var promise2 = getPromiseForValue('someArg2');
var promise3 = getPromiseForValue('someArg3');
return Q.all([
@jimCresswell
jimCresswell / StashJenkinsPRConfig
Created February 21, 2014 10:12
Jenkins config to report a pull request merge product job result back to the Stash UI
run this script to create a environment variable config file in the workspace containing the SHA of the feature branch merge parent.
# put the feature branch parent of the pull request merge sha into a file variable.
echo parentSha=`git rev-list HEAD^2 -n 1` > gitVariables
at the first build step read in the config file in an inject environment variables step
${WORKSPACE}/gitVariables
In the Stash notify step click Advanced... and set the commit SHA to
$parentSha
@jimCresswell
jimCresswell / StashPRRefspec
Created February 21, 2014 10:01
Git refspec for targetting Stash pull request merge products
+refs/pull-requests/*/merge:refs/remotes/origin/stashpr/*
@jimCresswell
jimCresswell / staticserver.js
Created October 27, 2013 17:09
static, local node server
// Static node server
// package.json fragment
// "devDependencies": {
// "http-server": "",
// "express": ""
// }
var express = require('express'),
http = require('http');
@jimCresswell
jimCresswell / jenkinsParsingForGithubPayload
Created October 18, 2013 09:00
Jenkins script in Groovy to parse a Github web hook payload for the commit that triggered the pull request that triggered the service hook ... and then set that as a build variable that can be used in further Jenkins scripts or parameterised jobs. See http://chloky.com/github-pull-req-webhook/ and https://gist.github.com/bjhess/2726012 for setti…
import hudson.model.*
def payloadString = build.buildVariableResolver.resolve("payload")
payloadObject = new groovy.json.JsonSlurper().parseText(payloadString)
targetCommit = payloadObject.pull_request.head.sha
build.addAction(new ParametersAction(new StringParameterValue('targetCommit', targetCommit)))
@jimCresswell
jimCresswell / jenkinsParsePayload.sh
Last active September 8, 2018 00:06
Node script for parsing a Github web hook payload in Jenkins and extracting the commit hash.
#!/usr/bin/env node
// Grab environment variables
var payloadString = process.env.payload;
// If no payload was received there is nothing to do. Not allowed to use "null".
if (payloadString === "nodata") { // This assume the default payload parameter value is "nodata". Not allowed to use "null".
return 0;
}
@jimCresswell
jimCresswell / forloop.sh
Last active December 23, 2015 12:29
Simple sh for loop script taking an optional number of loops argument
#!/usr/bin/env sh
# Parse input
if [ "$#" -gt "0" ]
then
NUMLOOPS=$1
else
NUMLOOPS=10
fi