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 / minesweeper.go
Created September 6, 2015 02:28
Quick and dirty console minesweeper game
package main
import (
"fmt"
"time"
)
import "math/rand"
func main() {
interactiveGame()
@macu
macu / UIViewController+Modal.swift
Created September 2, 2015 13:19
Useful modal UIViewController extensions.
import Foundation
import UIKit
extension UIViewController {
/// Whether the view is currently displayed in modal style.
var isModal: Bool {
return self.presentingViewController?.presentedViewController == self
|| self.navigationController?.presentingViewController?.presentedViewController == self.navigationController
|| self.tabBarController?.presentingViewController?.isKindOfClass(UITabBarController) == true
@macu
macu / adjust-insets-for-keyboard.swift
Last active September 9, 2015 00:24
WIP and has a bug
// ...
override func viewDidLoad()
{
super.viewDidLoad()
// Thanks http://stackoverflow.com/a/27665207
NSNotificationCenter.defaultCenter().addObserverForName(
UIKeyboardWillChangeFrameNotification,
object: nil,
@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)
@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 / 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 / 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 / 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 / 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 / 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},