Skip to content

Instantly share code, notes, and snippets.

View iolloyd's full-sized avatar
💭
Busy bee

Lloyd Moore iolloyd

💭
Busy bee
View GitHub Profile
@iolloyd
iolloyd / hanoi.ml
Created March 20, 2015 11:52
Towers of Hanoi in ocaml
let rec hanoi f t x = function
| n when n = 1 ->
(Printf.printf "Move from %i to %i\n" f t)
| n ->;
hanoi f x t (n - 1); hanoi f t x 1; hanoi x t f (n - 1);
in hanoi 1 2 3 5 (* number of rings *)
@iolloyd
iolloyd / file-cherry-pick.sh
Created March 24, 2015 09:47
Apply all the changes recorded in git to a particular file from one branch to another
# THEBRANCH is the branch that has the changes
# THEFILE is the file that you want to update in the current branch
git rev-list --reverse THEBRANCH -- THEFILE | git cherry-pick -n --stdin
@iolloyd
iolloyd / alba.txt
Created April 10, 2015 08:22
A poem for Alba
And then dawn breaks, seemingly at once
Puts paid to the touch of night time's hold
Birdsong bathes the dew-soaked lawn
Another day, life's own new-born
On the horizon, where, from the sea,
Up lifts the sun from depths unknown
His sheaths of yellow fire run rife
@iolloyd
iolloyd / bintree.py
Last active August 29, 2015 14:19
quick balanced binary tree in python
def insert(new_value, (l, v, r)):
new_node = ((None, None, None), new_value, (None, None, None))
if new_value < v:
if not l:
new_node = (new_node, v, r)
else:
new_node = (insert(new_value, l), v, r)
elif new_value > v:
if not r:
@iolloyd
iolloyd / bin-bal.ml
Created April 20, 2015 12:32
balancing method for a binary tree
let rec bal(l, v, r) =
let hl = height l and hr = height r in
match l, v, r with
| Node(ll, lv, lr, _), v, r when hl > hr+1 ->
let hll = height ll and hlr = height lr in
(match lr with
| Node(lrl, lrv, lrr, _) when hll < hlr ->
node(node(ll, lv, lrl), lrv, node(lrr, v, r))
| lr -> node(ll, lv, node(lr, v, r)))
| l, v, Node(rl, rv, rr, _) when hl+1 < hr ->
@iolloyd
iolloyd / merge-theirs.md
Last active August 29, 2015 14:19
merge a mature branch into your local branch

In the case that you have a branch you want to merge that is giving a lot of conflicts, it's quite often that you trust all the commits in the branch to be merged and you want some kind of way to add those during the merge by default.

Here is one way to do that painlessly.

  git checkout my-branch
  git merge branch-you-want-to-merge

At this point, there may be a bunch of conflicts. Run the following, rememberint the dot '.' when checking out.

 git checkout --theirs .
@iolloyd
iolloyd / really_git_fetch.sh
Created May 1, 2015 08:39
fetch and track all remote branches from upstream
git branch -r| xargs -n 1 git branch --track
@iolloyd
iolloyd / knob.php
Created May 15, 2015 11:53
Find the knobhead
<?php
$bits = ["Vn", " G", "ube", "agba"];
function getsome($x) {
return str_rot13($x);
}
function findTheKnob($x) {
return getSome($x);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>DBAPIError: (pyodbc.Error) ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)") // Werkzeug Debugger</title>
<link rel="stylesheet" href="?__debugger__=yes&cmd=resource&f=style.css" type="text/css">
<!-- We need to make sure this has a favicon so that the debugger does not by
accident trigger a request to /favicon.ico which might change the application
state. -->
<link rel="shortcut icon" href="?__debugger__=yes&cmd=resource&f=console.png">
@iolloyd
iolloyd / db_migrations_flow.md
Last active August 29, 2015 14:21
Lookbooks migrations workflow

DB migrations flow

This is a proposal for dealing with database migrations when using git (or similiar). The problem with migrations is ensuring that the current state of the database is in sync with the code-base. In practice, this means being able to guarantee that the state of the database correctly reflects the version of the code checked out.

The correct way to build the database schema is to run all db migrations from zero. But as the project grows, this takes longer and longer to execute and quickly becomes inpractical.

To avoid having to re-run all the migrations, it makes sense to have a base sql that avoids running earlier migrations that are relevant to the currently deployed code.

With that in mind, the following is proposed: