Skip to content

Instantly share code, notes, and snippets.

@dpwright
dpwright / .gitconfig
Created August 1, 2012 09:19
Git alias to get a git commit sha1 from an SVN revision number in git-svn
svn-ref = "!f() { git log --grep \\"git-svn-id.*@$1\\" --pretty=%H; }; f"
@dpwright
dpwright / git-rar.rb
Created September 25, 2012 00:42
Run a git command, and then rebase any branches which were built on top of the current one
#!/usr/bin/ruby
#GistID: 3779324
require 'escape'
exit if ARGV.empty?
current_branch = `git symbolic-ref -q HEAD`.sub(/^refs\/heads\//, "").strip
exit if current_branch.empty?
@dpwright
dpwright / gist:3786642
Created September 26, 2012 07:47
Demonstrating git's use of HEAD as default branch
$git init repo1
Initialized empty Git repository in /home/daniel/liamtest/repo1/.git/
$cd repo1
$git ci --allow-empty -m "Commit on master"
[master (root-commit) cf699b0] Commit on master
$git co --orphan another-branch
Switched to a new branch 'another-branch'
$git ci --allow-empty -m "Commit on another-branch"
[another-branch (root-commit) 06f7586] Commit on another-branch
$cd ..
@dpwright
dpwright / gist:4599677
Created January 22, 2013 23:13
Demonstrates how I'm passing the friend and dieter middlewares to Compojure's compojure.handler/site In my project.clj I have `:ring {:handler wedmgr.core/app}`
(def app
(-> (handler/site
(friend/authenticate app-routes
{:credential-fn users/authenticate
:workflows [(workflows/interactive-form)]}))
(dieter/asset-pipeline)))
@dpwright
dpwright / output
Last active October 7, 2018 15:30
Demonstrates filling in a u32vector from an FFI function returning a pointer in Chicken Scheme
(4 9 15)
@dpwright
dpwright / ctuple.h
Last active December 12, 2015 00:18
Statically-defined tuples in C
/* Basic tuple definitions */
#define ctuple1(a) union { struct { a hd; }; struct { a idx0; }; }
#define ctuple2(a, b) union { struct { a hd; ctuple1(b) tl; }; \
struct { a idx0; b idx1; }; }
#define ctuple3(a, b, c) union { struct { a hd; ctuple2(b, c) tl; }; \
struct { a idx0; b idx1; c idx2; }; }
#define ctuple4(a, b, c, d) union { struct { a hd; ctuple3(b, c, d) tl; }; \
@dpwright
dpwright / maybem.cpp
Created September 6, 2013 15:35
General Maybe monad in C++
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;
template<typename a> class Maybe
{
public:
static Maybe<a> Just(a value) { return Maybe(value); }
@dpwright
dpwright / README.md
Last active June 21, 2018 03:09
Monadic operations in C++

Monadic operations in C++

This began as a further attempt to implement the Maybe monad in C++, but quickly spiralled out of control and now includes an implementation of the List monad as well (using std::list!). This is really for my own amusement rather than to try and do anything useful with them. It also gave me an excuse to try out C++ 11 lambda functions for the first time.

My original implementation defined a macro called MBind which caused a number of problems -- thankfully [PJayB][pjayb] managed to find a way around that so

@dpwright
dpwright / watchdog.lhs
Last active September 30, 2016 18:25
Watchdog -- Dumb Haskell process monitor
Watchdog
========
Watchdog is a simple utility to spawn and monitor a process, respawning it if it
dies or is killed for whatever reason. This is useful if you have a daemon
process that may encounter an unexpected error, or even just as a quick 'n' easy
upgrade mechanic -- just pop the new executable over the old one and shut the
process down!
There are a million of these, but I needed something quick 'n' dirty to
@dpwright
dpwright / fixPath.ps1
Last active December 26, 2015 04:28
Overcoming Windows' bizarre ordering of %PATH% variables
# Windows constructs the %PATH% environment variable by appending the user
# PATH to the system PATH, which means you can't override system-level programs
# with your own, user-specific version.
# To fix this, save this script and set it to run on logon by following these
# instructions: http://technet.microsoft.com/en-us/library/cc770908.aspx
# (If step 1 is a mystery to you, go to Start->Run and type "gpedit.msc")
# Requires Windows 7
# If your path is longer than 1024 characters, this might not work :-(