Skip to content

Instantly share code, notes, and snippets.

View gpoole's full-sized avatar

Greg Poole gpoole

  • Sydney, AU
View GitHub Profile
@gpoole
gpoole / xq
Last active August 29, 2015 14:05
Take an xpath and a file, run the xpath query and output nicely formatted result XML to the terminal or a file
#!/bin/bash
if [ -z "$2" ]; then
echo "Usage: `basename $0` XPATH FILE"
exit 1
fi
# For terminal output colourise it too, but for file output just tidy it up
if [ -t 1 ]; then
xmllint --xpath "$1" $2 | tidy -indent -xml -q | pygmentize -lxml
@gpoole
gpoole / gist:031a10957e3d910a7c01
Created September 27, 2014 09:09
Install CyanogenMod updates on an encrypted Nexus 5
#!/bin/bash
if [ -z "$1" ]; then
read -p "No file specified, would you like to download the latest version? (Y/n)" PROMPT
if [ "$PROMPT" == "n" ]; then
echo "Will not download update."
exit
fi
URL="http://download.cyanogenmod.org`curl -L http://download.cyanogenmod.org/\?type\=snapshot\&device\=hammerhead 2>/dev/null | perl -wlne 'print $1 if /<a href="(\/get\/jenkins\/\d+\/[^"]+\.zip)">/i' | head -n1`"
FILENAME=`basename $URL`
@gpoole
gpoole / gif
Created September 27, 2014 10:10
Easily create animated gifs from video files using ffmpeg, imagemagick and gifsicle
#!/bin/bash
# Creates animated gif images from video files by splicing a section out of the video file at the given framerate
# and dimensions using ffmpeg, gifscile and imagemagick.
# video gif start_time duration framerate [width height]
if [ -z "$4" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "Usage: `basename $0` in_file out_file start_time duration out_framerate [width height]"
echo
@gpoole
gpoole / restart-blued.sh
Created September 30, 2015 23:59
Restart blued (OSX)
# https://discussions.apple.com/message/12448781
defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState 0
defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState 1
killall blued
launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist
launchctl start com.apple.blued
import pushToDataLayer from 'fe-helper';
export default function track(Component) {
return (props) => {
const trackers = props.trackEvents.reduce((trackers, eventName) => {
trackers[eventName] = (...args) => {
pushToDataLayer({ event: event });
if (typeof props[eventName] !== 'undefined') {
return props[eventName](...args);
}
@gpoole
gpoole / up-and-atom.sh
Last active May 26, 2017 03:08
Opens Atom from the terminal on the current OSX space/desktop (kwm/khd powered)
#!/bin/bash
# Note where we are
SPACE_ID=`kwmc query space active id`
# Open atom and wait a moment
atom .
sleep 1
# Bring Atom and us back to where we were

Proxying Node apps with Charles

Setting up Charles to monitor outgoing Node app requests

// Enable the proxy for outgoing http requests made by this server (dev only)
if (process.env.APP_ENV === 'development' && process.env.http_proxy) {
  console.warn('http_proxy env variable is set, all outgoing requests will be proxied');
 globalTunnel.initialize();

Hashing in node

  • Farmhash is really fast
  • sha1 is the fastest hash in crypto

Benchmarks

sha1 (crypto) x 222,654 ops/sec ±2.06% (79 runs sampled)
md5 (crypto) x 196,396 ops/sec ±1.82% (78 runs sampled)
#!/usr/bin/env bash
# https://www.davidpashley.com/articles/writing-robust-shell-scripts/
set -ue
# Enable more complex glob patterns
shopt -s globstar
usage() {
echo "usage"
}
Get-ChildItem -Filter "*.mp4" | % { &ffmpeg -i $_ -c:v hap @([io.path]::ChangeExtension($_, "mov")) }