Skip to content

Instantly share code, notes, and snippets.

View alecthegeek's full-sized avatar
🤖
Dem keyboards don't go click click on their own you know

Alec Clews alecthegeek

🤖
Dem keyboards don't go click click on their own you know
View GitHub Profile
@alecthegeek
alecthegeek / g
Created August 11, 2015 22:51
Google search from command line on a Mac
#!/usr/bin/env sh
# Google search from command line on a Mac
open "http://www.google.com/search?q=$(echo "$@" | sed -Ee 's/\s+/%20/g')"
@alecthegeek
alecthegeek / manageCloudStorageSync.sh
Created July 27, 2015 13:07
Pauses and Resumes data sync with cloud storage services
#!/usr/bin/env bash
# Pause the following Cloud Storage Services
services=('Google Drive' Copy Dropbox)
# Based on ideas and code on https://github.com/tjluoma/dropbox-pause-unpause
if [[ $0 =~ pause || $1 =~ pause ]] ; then
command=STOP
@alecthegeek
alecthegeek / deletesillycupsfiles
Created July 4, 2015 05:19
Remove spurious CUPS files created in /tmp
#!/usr/bin/env sh
# Remove spurious CUPS files created in /tmp
find /private/tmp -maxdepth 1 -type l -name 55\*|sudo xargs rm
@alecthegeek
alecthegeek / goinstallbinaries.sh
Created June 13, 2015 06:02
Using Vim and Vundle when developing Go code?
GOPATH=/tmp/$$.installgobin GOBIN=$(go env GOROOT)/bin vim -u ~/.vimrc -c ":GoInstallBinaries" -c ":q" /tmp/src/$$.go
@alecthegeek
alecthegeek / ackermann.go
Last active August 29, 2015 14:17
Simple Ackermann function
// Niave implementation of the Ackermann function
// https://en.wikipedia.org/wiki/Ackermann_function
package main
import "fmt"
func Ackermann(m, n uint) uint {
//fmt.Printf("Called Ackermann(%d,%d) ", m, n)
if m == 0 {
return n + 1
@alecthegeek
alecthegeek / wpa_supplicant.sh
Created January 13, 2015 06:54
Add a network to the wpa_supplicant.conf
#!/bin/dash
ssid=$1 ;shift
psk=$1; shift
# Is this network already defined?
network_id=$(wpa_cli list_networks | tail -n +3 | grep $ssid |cut -f 1)
if [ -z $network_id ] ; then
maxNetworkId=$(wpa_cli list_networks | tail -n +3 | tail -n 1 | cut -f 1)]
@alecthegeek
alecthegeek / setup_wifi.sh
Last active August 29, 2015 14:13
Setup up a wifi interface
#!/bin/sh
ssid=$1; shift
psk=$1; shift
network_id=$(wpa_cli list_networks | tail -n +3 | grep $ssid |cut -f 1)
if [ -z $network_id ] ; then
maxNetworkId=$(wpa_cli list_networks | tail -n +3 | tail -n 1| cut -f 1)]
if [ -z $maxNetworkId ] ; then
#! /usr/bin/env sh
# Set up some shit dependeing on primary mac address
if=en0 # Change this is you don't want to use primary
updateHost() {
# $1 = ip address
# $2 = hostname
# $3 = interface name
#!/bin/bash
# manage Tmux
if [ -n "$TMUX" ]; then # in tmux
if [ -n "$COLORTERM" ]; then # in rich VT
export TERM=xterm-256color-italic
fi
elif tmux list-sessions > /dev/null 2>&1 ; then
tmux attach # try to attach
@alecthegeek
alecthegeek / go-install-tools
Last active September 3, 2015 18:18
Set up a "standard" go project workspace with support for 3rdparty modules, version control repo and a template main package
# Install all the Go tools and godep tool
# Location of gobin is based on installation by OS X Homebrew
sudo -u admin GOPATH=/tmp GOBIN=/usr/local/opt/go/bin go get -u golang.org/x/tools/cmd/...
sudo -u admin GOPATH=/tmp GOBIN=/usr/local/opt/go/bin go get -u github.com/tools/godep