Skip to content

Instantly share code, notes, and snippets.

View mattconsto's full-sized avatar
👋

Matthew Consterdine mattconsto

👋
View GitHub Profile
SELECT TOP 10000
p.Id,
CONCAT('https://puzzling.stackexchange.com/questions/', p.Id) as URL,
p.Score, p.ViewCount, p.AnswerCount, p.FavoriteCount, p.Title, p.Tags,
p.Body, p.CreationDate,
COALESCE(NULLIF(p.OwnerUserId, ''), 0) as OwnerUserId, /* Deleted users */
COALESCE(NULLIF(pu.DisplayName, ''), 'Anonymous') as DisplayName,
COALESCE(NULLIF(pu.Reputation, ''), 0) as Reputation,
COALESCE(NULLIF(pb.Gold, ''), 0) as Gold,
COALESCE(NULLIF(pb.Silver, ''), 0) as Silver,
@mattconsto
mattconsto / ACMCitSeq.xsl
Created December 11, 2017 16:56
ACM References formatting, extended by me to support websites.
<?xml version="1.0" encoding="utf-8"?>
<!--
Stylesheet for Microsoft Word 2007 Bibliography formatting.
Author(s): Yves Dhondt (yves.dhondt@gmail.com) and Matt Consto (matt@consto.uk)
Copyright: Copyright (c) 2008 Yves Dhondt
Permission is hereby granted, free of charge, to any person obtaining a
from random import random
people = 1
limit = 500000
while True:
total = 0
for iteration in range(limit):
# Mutate
@mattconsto
mattconsto / StackSort.java
Created December 1, 2017 13:00
Sort a stack, using a stack, and only* a stack. It's not at all efficient.
import java.util.Stack;
public class StackSort {
/**
* Sort a stack, using a stack, and only* a stack. It's not at all efficient.
* @param asc The stack we want to sort into ascending order.
* @throws NullPointerException If any element in the stack is NULL.
*/
public static <T extends Comparable<? super T>> void sort(Stack<T> asc) {
Stack<T> desc = new Stack<>();
Date.prototype.format = function(string) {
// Helper function
var pad = function(width, string, padding) {
return (width <= (string + "").length) ? (string + "") : pad(width, (padding + "") + (string + ""), (padding + ""))
}
// Build data lazily, only evaluate when needed.
var date = this; // For scoping reasons.
var leap = ((date.getFullYear() % 4 == 0) && (date.getFullYear() % 100 != 0)) || (date.getFullYear() % 400 == 0);
var replacements = {
@mattconsto
mattconsto / detectrpi.sh
Created July 27, 2017 11:28
Detect a Raspberry Pi Model, RAM, CPU, and if it is a Compute Module or Zero.
#!/bin/bash
RPI_REV=$(sudo cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^ *//g' | sed 's/ *$//g')
if [ "$RPI_REV" = "Beta" ]; then RPI=true && RPI_RAM=256 && RPI_COMPUTE=false && RPI_ZERO=false && RPI_MODEL="Model 1B" && RPI_VERSION="0.0"
elif [ "$RPI_REV" = "0002" ]; then RPI=true && RPI_RAM=256 && RPI_COMPUTE=false && RPI_ZERO=false && RPI_MODEL="Model 1B" && RPI_VERSION="1.0"
elif [ "$RPI_REV" = "0003" ]; then RPI=true && RPI_RAM=256 && RPI_COMPUTE=false && RPI_ZERO=false && RPI_MODEL="Model 1B" && RPI_VERSION="1.0"
elif [ "$RPI_REV" = "0004" ]; then RPI=true && RPI_RAM=256 && RPI_COMPUTE=false && RPI_ZERO=false && RPI_MODEL="Model 1B" && RPI_VERSION="2.0"
elif [ "$RPI_REV" = "0005" ]; then RPI=true && RPI_RAM=256 && RPI_COMPUTE=false && RPI_ZERO=false && RPI_MODEL="Model 1B" && RPI_VERSION="2.0"
elif [ "$RPI_REV" = "0006" ]; then RPI=true && RPI_RAM=256 && RPI_COMPUTE=false && RPI_ZERO=false && RPI_MODEL="Model 1B" && RPI_VERSION="2.0"
@mattconsto
mattconsto / downloadie.js
Created July 8, 2017 23:10
IE HTML5 a[download] polyfill
// author: Carlos Machado and  Matthew Consterdine
// version: 0.2
// year: 2015 and 2017
const DownloadIE = {
name: "",
reference: "",
Listener: function() {
if(name == "") {name = reference;}
window.navigator.msSaveBlob(this.response, name);
@mattconsto
mattconsto / non-zero-days.md
Created May 29, 2017 11:55
Non-Zero Days, Three You’s, Forgiveness and Exercise

Non-Zero Days, Three You’s, Forgiveness and Exercise

Ouch. Sounds like you're having a tough time max. That sucks. I've been there, so I kinda know what you're talking about. I've been in the ever-circling vortex of self-doubt, frustration, and loathing. It's no bueno. I know. If you don't mind lemme tell you a couple things. You can read em if you want, read em again later if you feel like it. But honestly man, if I spend all this time typing this out to you and you don't let it be a little tinder for your fire, well, you're just letting us both down. And you don't HAVE to do that. You don't HAVE to do anything. But you get to choose.

(Who am I? My name’s Ryan and I live in Canada. Just moved to a new city for a dream job that I got because of the rules below. I owe a lot of my success to people much cooler, kinder, more loving and greater than me. When I get the chance to maybe let a little bit of help out, it’s a way of thanking them.)

Rule numero uno - There are no more zero days. What's a zero day?

This file has been truncated, but you can view the full file.
The First 1,000,000 Primes (from primes.utm.edu)
2 3 5 7 11 13 17 19
23 29 31 37 41 43 47 53
59 61 67 71 73 79 83 89
@mattconsto
mattconsto / FullScreenPlayMode.cs
Created April 23, 2017 11:14
Place inside your Editor folder to get a full screen game window. Adapted from: https://redd.it/2lymim
using UnityEditor;
using UnityEngine;
using System.Collections;
[InitializeOnLoad]
public class FullscreenPlayMode : MonoBehaviour {
//The size of the toolbar above the game view, excluding the OS border.
private static int tabHeight = 18;
private static int tabOffset = -1; // Try 4 on first launch, -1 on second