Skip to content

Instantly share code, notes, and snippets.

@sebmaynard
sebmaynard / quick-boot-repair.sh
Created September 17, 2012 11:18
Boot-repair script
#!/bin/bash
sudo add-apt-repository -y ppa:yannubuntu/boot-repair && sudo apt-get update
sudo apt-get install -y boot-repair && boot-repair
@sebmaynard
sebmaynard / camisc_unique.erl
Created May 15, 2013 09:03
Generate a somewhat unique 64 bit number.
-module(camisc_unique).
-export([semi_unique/0, get_timestamp/0, test/0]).
%% ===================================================================
%% API
%% ===================================================================
%% Generate a somewhat unique 64 bit number.
%%
@sebmaynard
sebmaynard / module_starter_hack.erl
Created June 6, 2013 13:54
A hack to try and startup an erlang application and its dependencies. Should only really be used for lazy development/fiddling as reltool/relx/rebar will handle all this for you.
-module(module_starter_hack).
-export([try_force_start_application/1]).
try_force_start_application(App) ->
start_application_process_result(App, try_start_application(App)).
%%%%%%%%%%%%%%%
%% Helpers
@sebmaynard
sebmaynard / ca_cowboy_middleware.erl
Created June 10, 2013 08:42
A Cowboy middleware to set some CORS headers for every request, and to handle OPTIONS requests without needing to implement them in every handler.
-module(ca_cowboy_middleware).
-behaviour(cowboy_middleware).
-export([execute/2]).
execute(Req, Env) ->
{ok, ReqWithCorsHeaders} = set_cors_headers(Req),
{Method, ReqMethod} = cowboy_req:method(ReqWithCorsHeaders),
@sebmaynard
sebmaynard / restore_dotfiles.sh
Created June 12, 2013 10:38
A bash script to restore dotfiles to ~/ from somewhere else (probably files under a git repository). Allows you to keep *some* of your dotfiles in git without needing everything, and a fast way to restore them on a new box.
#!/bin/bash
function link_files_to_folder() {
if [[ ! -d $1 || ! -d $2 ]] ; then
echo "Usage: link_files_to_folder <source_dir> <target_dir> [prefix]"
exit
fi
SOURCE_DIR=$1
TARGET_DIR=$2
@sebmaynard
sebmaynard / owncloud-upgrade.sh
Created June 12, 2013 15:52
Upgrade an owncloud instance. Check the notes at the top for assumptions
#!/bin/bash
# Upgrade an owncloud instance. Makes the following assumptions:
# 1. you're running this as the same user who owns (and can write to) $OWNCLOUD_FOLDER
# 2. $TMP_FOLDER is writeable by this user
# These should be absolute paths
OWNCLOUD_FOLDER=/var/public_html_ssl/cloud
TMP_FOLDER=/tmp/owncloud-upgrade
@sebmaynard
sebmaynard / emacsclient_gui.sh
Created June 14, 2013 08:43
Start emacsclient with some progress of what's going on (useful for desktop launchers)
#!/bin/bash
## for emacsclient:
## -c is gui window
## -n is no-wait - don't wait for the window to close
## sed buffers by default
## -u is unbuffered
## zenity expects text progress to start with #
emacsclient -c -n 2>&1 | sed -u -e 's/^/# /g' | zenity --title="Starting EmacsClient" --width=600 --progress --pulsate --auto-close
@sebmaynard
sebmaynard / crontab
Last active December 19, 2015 02:38
Generate an images-only feed for the Dilbert comic.
# update dilbert rss every morning at 2am
0 2 * * * /home/user/bin/update_dilbert.sh
@sebmaynard
sebmaynard / .tmux.conf
Last active December 29, 2015 15:19
Enable ctrl-<arrow> keys for moving between tmux and emacs panes (requires emacs, tmux and zsh). This allows you to use ctrl-<arrow> to switch panes in an emacs split, and then move to the nearest tmux pane once you get to the edge of the emacs window. Particularly useful if you have tmux split with emacs in one pane, and zsh in another
set-window-option -g xterm-keys on
@sebmaynard
sebmaynard / erlfind.sh
Last active August 29, 2015 14:01
A fast, simple find/grep wrapper targetted at Erlang projects
#!/bin/bash
# speed things up quite a lot!
export LC_ALL=C
# uses -P (perl regular expressions) for speed
find ./ -type f ! \
-path "*/deps/*" ! \
-path "*/caerldeps/*" ! \
-path "*/_rel/*" ! \