Skip to content

Instantly share code, notes, and snippets.

View macu's full-sized avatar

Matt Cudmore macu

  • Halifax, NS
View GitHub Profile
@macu
macu / star–and-moon.txt
Last active September 1, 2022 01:49
Star and Moon ASCII Text Art
★°..    . ☾°☆ .*●¸.   ★ °:. .•○°★ . * .     .
 ° .●.    °☾°☆ ¸.●.  ★  ★°☾☆¸.¸ ★ :. .•○°★ . * .
 .  ¸.  ° ¸.*●¸.    °☾° ¸.●¸.  ★ °:. .•° . * :. . ¸.
●¸   ★  ★☾°★.    . °☆ .●¸.   ★ °. •○°★ .
       * . ☾° ¸.*●¸    °☾°☆ .*¸.   ★ 
★°..    . ☾°☆ .*●¸.   ★ °:. .•○°★ . * .    . ° .
●.    °☾°☆ ¸.●.  ★  ★°☾☆¸.¸ ★ :. .•○°★ . * . .
 .  ¸.  ° ¸.*●¸.  °☾° ¸.●¸.  ★ °:. .•°
@macu
macu / if-var-scope-demo.go
Created January 12, 2015 16:40
I hadn't realized you could access variables declared in if statements beyond the first block following the expression. This enables lots of code cleanup :)
package main
import "fmt"
func fab() (int, error) {
return 0, nil
}
func main() {
if i, err := fab(); err != nil {
@macu
macu / timeout.swift
Last active February 22, 2022 08:03
Timeout utility in Swift, with the ability to cancel a deferred callback.
import Foundation
/// Timeout wrapps a callback deferral that may be cancelled.
///
/// Usage:
/// Timeout(1.0) { println("1 second has passed.") }
///
class Timeout: NSObject
{
private var timer: NSTimer?
@macu
macu / psort.go
Created February 25, 2015 11:46
Sort method to find best order
package main
import "fmt"
type element struct {
count int
}
var samples = [][]int{
{1, 2, 3, 4, 5, 6, 7, 8, 9},
@macu
macu / Separators.c
Last active August 29, 2015 14:17
Various block comments for delineating sections of code
/* =========================================================================== */
// 75 ='s followed by title/subject of section.
/* ================================================== */
// 50 ='s followed by title/subject of section.
/*
|--------------------------------------------------------------------------
| Title
|--------------------------------------------------------------------------
@macu
macu / footnotes.js
Created May 2, 2015 16:28
Convert <sup>*ID</sup> into action blocks that reveal their corresponding <p>*ID: text</p> on hover.
$(function() {
var footnotes = {};
// Gather footnotes.
var footnotePattern = /^\*(\w+):/;
$("p, .footnote").not(".footnote p, p .footnote").each(function() {
var match = footnotePattern.exec($(this).text());
if (match && match.length) {
footnotes[match[1]] = $(this);
}
});
@macu
macu / SuffixArray.go
Last active August 29, 2015 14:22
Build and search a suffix array in Go. Implemented after reading https://blog.nelhage.com/2015/02/regular-expression-search-with-suffix-arrays/
package main
import (
"bytes"
"fmt"
"sort"
)
func main() {
@macu
macu / deprecated.java
Last active August 29, 2015 14:25
How to mark deprecated in Java. http://stackoverflow.com/a/9031854
/**
* You shouldn't call this method anymore.
*
* Don't forget to add a clarifying javadoc field for the programmer:
*
* @deprecated Use {@link #new()} instead.
*/
@Deprecated
public void old() {
// ...
@macu
macu / snowden-ietf93.md
Last active August 29, 2015 14:27 — forked from mnot/snowden-ietf93.md
Transcript of Edward Snowden's comments at IETF93.
@macu
macu / LinkedSortedIntStack.js
Last active August 29, 2015 14:27
A JavaScript prototypal class that implements both a sorted list and a stack using linked lists
// Usage:
// var a = new LinkedSortedIntStack(1, 2, 5);
// a.push(4, 3);
// a.getStackAsArray();
// a.getSortedListAsArray();
var LinkedSortedIntStack = function() {
this.nodeCount = 0;
// Push all arguments (varargs-style)