Skip to content

Instantly share code, notes, and snippets.

View soutar's full-sized avatar
🤖
automating things

John Soutar soutar

🤖
automating things
  • London, UK
  • 11:31 (UTC +01:00)
View GitHub Profile
@soutar
soutar / add_spacer.sh
Last active August 29, 2015 14:06
Add x spacers to your Dock in Mac OS X (./add_spacer.sh x)
#!/bin/bash
function add_spacer {
[[ $1 =~ ^[0-9]+$ ]] && times=$1 || times=1
echo "Adding $times spacer(s)"
i=0;
while [[ $i -lt $times ]]; do
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
((i++))
@soutar
soutar / retina.less
Created October 14, 2014 14:47
Retina background image mixin for LESS
// Set the background image for retina devices
.background-image-retina(@url, @ext, @width, @height) {
@lowres: "@{url}.@{ext}";
@highres: "@{url}@2x.@{ext}";
background-image: url(@lowres);
background-size: @width @height;
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
@soutar
soutar / get_template_part_with.php
Last active August 29, 2015 14:07
get_template_part_with()
<?php
/**
* This function extends get_template_part to include the ability
* to pass variables to the template file
*
* @param $template_names array|string Either a single template name or an array of template names, ordered by priority
* @param $variables array The variables to make available to the template
*/
function get_template_part_with($template_names, $variables = array()) {
@soutar
soutar / update.sh
Last active August 29, 2015 14:10
Pull all repos in the current directory
#!/bin/bash
stash_name="wip"
echo "> Updating master on all git repositories in the current directory"
for dir in */
do
if [ -d ${dir}/.git ]; then
cd ${dir}
stashed=false
@soutar
soutar / nvm.sh
Created March 2, 2015 11:00
Swap between Node.js and io.js with NVM
curl https://raw.githubusercontent.com/creationix/nvm/v0.23.3/install.sh | bash
nvm install iojs-1.4.2
nvm install v0.12.0
nvm alias io iojs-1.4.2
nvm alias node v0.12.0
nvm use io
@soutar
soutar / api.js
Last active August 29, 2015 14:22
PHP vs JS stv apis
api
.get('episodes')
.orderBy(['matId'])
.where({'shortName': 'The Riverside Show'})
.go()
.then((episodes) => {
// episodes is an array of Episode instances, not just plain objects
});
// or even
@soutar
soutar / apicache.js
Last active August 29, 2015 14:22
API response caching with ObjectCache in Javascript
import ObjectCache from '../ObjectCache';
import ObjectStoreDriver from '../drivers/ObjectStoreDriver';
let cache = new ObjectCache(ObjectStoreDriver);
let requests = 0;
let cacheHits = 0;
function getData () {
let cached = cache.get('apidata');
@soutar
soutar / proxy.js
Last active November 14, 2022 20:14
Redirect HTTP traffic on Internet Sharing to a local Charles proxy
#!/usr/bin/env node
var options = require('minimist')(process.argv.slice(2), { default: {
cport: 8888
}});
var disable = options.disable || options.d;
var enable = options.enable || options.e;
var status = options.s || options.status;
var child = require('child_process');
@soutar
soutar / 1.js
Last active December 7, 2015 17:02
Advent of Code
const input = "(((())))()((((((((())()(()))(()((((()(()(((()((()((()(()()()()()))(((()(()((((((((((())(()()((())()(((())))()(()(()((()(()))(()()()()((()((()(((()()(((((((()()())()((((()()(((((()(())()(())((())()()))()(((((((())(()())(()(((())(()))((())))(()((()())))()())((((())))(()(((((()(())(((()()((()((()((((((((((())(()())))))()))())()()((((()()()()()()((((((())())(((()())()((()()(((()()()))(((((()))(((()(()()()(()(()(((())()))(()(((()((())()(()())())))((()()()(()()(((()))(((()((((()(((((()()(()())((()())())(()((((((()(()()))((((()))))())((())()()((()(()))))((((((((()))(()()(((())())(())()((()()()()((()((()((()()(((())))(()((())()((((((((()((()(()()(((())())())))(())())))()((((()))))))())))()()))()())((()())()((()()()))(()()(((()(())((((())())((((((((()()()()())))()()()((((()()))))))()((((()(((()))(()()())))((()()(((()))()()())())(((())((()()(())()()()(((())))))()())((()))()))((())()()())()())()()(()))())))())()))(())((()(())))(()(())(()))))(()(())())(()(())(()(()))))((()())()))()((((()()))))())))()()())(
@soutar
soutar / circuit.js
Created December 7, 2015 19:13
Advent of Code - Day 7
import fetch from 'node-fetch';
const OPERATIONS = {
'AND': (x, y) => x & y,
'OR': (x, y) => x | y,
'NOT': (value) => ~ value,
'LSHIFT': (x, y) => x << y,
'RSHIFT': (x, y) => x >> y
}