Skip to content

Instantly share code, notes, and snippets.

View megawac's full-sized avatar

Graeme Yeates megawac

  • Clearpath Robotics
  • Waterloo, Ontario
View GitHub Profile
@megawac
megawac / fun.md
Created January 16, 2018 21:03
JaVaScRiPt4FUN
@megawac
megawac / board-solver.js
Last active July 27, 2016 16:37
rough sudo code for emkay
function checkSquare(matrix, i, j) {
return columnValid(matrix, i) && rowValid(matrix, j)
}
function solvePuzzle(boardMatrix) {
(i, j) = selectFirstUnfilled(boardMatrix)
matrix = boardMatrix.clone()
matrix[i, j] = red
@megawac
megawac / hack-debounce.js
Created June 29, 2015 19:34
log if debounce isn't called
function hackyDebounce(func, wait, options) {
var called = false;
var debounced = _.debounce(function() {
called = true;
func.apply(this, arguments);
}, wait, options);
return function() {
debounced.apply(this, arguments);
if (!called) {
console.log("It wasn't called");
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.resource import Resource
import json, hmac
from hashlib import sha1
from blinker import signal
class WebhookServer(Resource):
@megawac
megawac / .travis.yml
Created May 5, 2015 19:48
NIM travis.yml file
language: C
compiler:
- gcc
before_install:
# Install nim
- git clone -b master git://github.com/Araq/Nim.git --depth 1
- cd Nim
- git clone -b master --depth 1 git://github.com/nim-lang/csources
- cd csources && sh build.sh
- cd ..
@megawac
megawac / ci.sh
Created February 7, 2015 18:20
marionette-travis script
#!/bin/bash
npm install -g grunt-cli
npm install
npm dedupe
if [[ -n "$UNDERSCORE" ]]
then
npm install underscore@"$UNDERSCORE"
fi
function sortedIndex(array, value, iterator, pivot) {
var low = 0,
high = array.length,
target = iterator(value);
while (low - pivot < high) {
var mid = (((low + high) >>> 1) + pivot) % array.length;
if (iterator(array[mid]) < target) low = mid + 1;
else high = mid;
}
return low;
<!DOCTYPE html>
<html>
<head>
<link href="//cdn.jsdelivr.net/qunit/1.14.0/qunit.css" rel="stylesheet" type="text/css" />
<script src="//cdn.jsdelivr.net/qunit/1.14.0/qunit.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="qunit"></div>
@megawac
megawac / Log-.md
Last active August 29, 2015 13:56 — forked from bgrins/Log-.md

Javascript log Function

Every time I start a new project, I want to pull in a log function that allows the same functionality as the console.log, including the full functionality of the Console API.

There are a lot of ways to do this, but many are lacking. A common problem with wrapper functions is that the line number that shows up next to the log is the line number of the log function itself, not where log was invoked. There are also times where the arguments get logged in a way that isn't quite the same as the native function.

This is an attempt to once and for all document the function that I pull in to new projects. There are two different options:

  • The full version: Inspired by the plugin in HTML5 Boilerplate. Use this if you are writing an application and want to create a window.log function. Additionally,
@megawac
megawac / gist:8355978
Last active January 2, 2016 20:19
IE textNode throws error

So far I've tested this in

IE 10 win8
IE 9 win7
IE 8 emulated by IE9 win7

Consider the following:

var x = document.createElement('div');