Skip to content

Instantly share code, notes, and snippets.

View mheap's full-sized avatar
🦋
Follow me on Bluesky @mheap.dev

Michael Heap mheap

🦋
Follow me on Bluesky @mheap.dev
View GitHub Profile
kilo% ls ~/.zsh/completions
_hub
kilo% echo $fpath
/home/michael/.zsh/completion /usr/local/share/zsh/site-functions /usr/share/zsh/vendor-functions /usr/share/zsh/vendor-completions /usr/share/zsh/functions/Calendar /usr/share/zsh/functions/Chpwd /usr/share/zsh/functions/Completion /usr/share/zsh/functions/Completion/AIX /usr/share/zsh/functions/Completion/BSD /usr/share/zsh/functions/Completion/Base /usr/share/zsh/functions/Completion/Cygwin /usr/share/zsh/functions/Completion/Darwin /usr/share/zsh/functions/Completion/Debian /usr/share/zsh/functions/Completion/Linux /usr/share/zsh/functions/Completion/Mandriva /usr/share/zsh/functions/Completion/Redhat /usr/share/zsh/functions/Completion/Solaris /usr/share/zsh/functions/Completion/Unix /usr/share/zsh/functions/Completion/X /usr/share/zsh/functions/Completion/Zsh /usr/share/zsh/functions/Completion/openSUSE /usr/share/zsh/functions/Exceptions /usr/share/zsh/functions/MIME /usr/share/zsh/functions/Misc /usr/share/zsh/functions/Newuser /usr/share/zsh/functi
@mheap
mheap / gist:9f95d57492e7a85fda11
Created December 15, 2014 11:16
Mermaid/Graphviz

Graph

Mermaid

graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;
func oddNumberGenerator(n int) []int {
vals := make([]int, n);
origN := n;
// In PHP I'd do while count($arr) < $n, but as we initialise
// an array of size n that won't work in go
for i := 0; n > 0; i++ {
if (i % 2 == 1) {
# Install it
Add to composer:
"symfony/dependency-injection": "2.4.2",
"symfony/yaml": "2.4.2",
# Configure it
<?php
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('{"success":true}');
}).listen(9615);
@mheap
mheap / gist:4985392
Created February 19, 2013 12:22
Convert multidimensional array to 2D array with dot notation keys (via http://stackoverflow.com/a/10424516)
<?php
$ritit = new RecursiveIteratorIterator(new RecursiveArrayIterator($myArray));
$result = array();
foreach ($ritit as $leafValue) {
$keys = array();
foreach (range(0, $ritit->getDepth()) as $depth) {
$keys[] = $ritit->getSubIterator($depth)->key();
}
$result[ join('.', $keys) ] = $leafValue;
}
@mheap
mheap / pr.md
Created November 27, 2012 11:48 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@mheap
mheap / filter-branch.sh
Created September 9, 2012 19:50
Remove a file from a repo and delete all it's history
#!/bin/bash
set -o errexit
# Author: David Underhill
# Script to permanently delete files/folders from your git repository. To use
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2
if [ $# -eq 0 ]; then
exit 0
@mheap
mheap / README.md
Created May 20, 2012 20:52
JST Handlebars templates

I really struggled to get this working. I initially found https://gist.github.com/1990736 but it wasn't working for me, so I decided to throw it out, copy the original JST task and adapt it.

The jsthb helper has been lifted entirely from https://gist.github.com/1990736, the rest I've hacked at myself. This has been tested with both ajax loading and a release build.

@mheap
mheap / FileDupe.py
Created April 17, 2012 10:48
Find duplicate files in a given directory
#!/usr/bin/python
"""
Find duplicate files from a given root in the directory hierarchy of a given size
"""
import os
import glob
import sys
import hashlib
import optparse
import timeit