Skip to content

Instantly share code, notes, and snippets.

@mikeyhew
mikeyhew / exam-schedule.html
Last active August 29, 2015 14:16
AngularJS - University of Waterloo Exam Schedule
<!DOCTYPE html>
<html>
<head>
<!-- note: this gist breaks with the latest stable version (1.3.14) of Angular -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.min.js"></script>
<script>
function Ctrl ($scope, $http) {
@mikeyhew
mikeyhew / tagCreator.coffee
Created January 27, 2016 20:06
Simple DOM element creator with nice syntax for coffeescript. Not recommended for production applications.
range = (start, stop, step=1) ->
if arguments.length == 1
stop = start
start = 0
x = start
while start < stop
old = start
start += step
old
@mikeyhew
mikeyhew / xkcd-myhobby.html
Created February 12, 2016 03:20
A web page that displays all xkcd "My Hobby" comics in an iframe, with next/previous buttons to navigate between them.
<!DOCTYPE html>
<html>
<head>
<script>
COMIC_NUMS = ['37', '53', '60', '75', '79', '148', '168', '174', '236', '259', '287', '296', '326', '331', '389', '437', '451', '559', '590', '605', '687', '719', '733', '790', '845', '966', '1004', '1119', '1145', '1169', '1208', '1278', '1304', '1329', '1340', '1355', '1405', '1480', '1546', '1598'];
</script>
<style>
html, body, iframe {
height: 100%;
margin: 0;
@mikeyhew
mikeyhew / api_connection.rb
Created July 8, 2016 01:38
Custom ShopifyAPI connection class with 429-retrial and throttling
class ApiConnection < ShopifyAPI::Connection
cattr_accessor :logger
self.logger = Logger.new(STDOUT) # for now
class_attribute :leak_rate
self.leak_rate = 2 # 2 per second
class_attribute :call_limit_header
self.call_limit_header = 'X-Shopify-Shop-Api-Call-Limit'
@mikeyhew
mikeyhew / instructions.md
Last active January 26, 2017 00:51
Use f-strings with mypy before python/mypy#2622 is merged

uninstall the old version of mypy so that the mypy command won't point to the old one

pip3 uninstall mypy

use the version of typed_ast from this PR: python/typed_ast#22

pip3 install -e git+https://github.com/kirbyfan64/typed_ast@fstring#egg=typed_ast
@mikeyhew
mikeyhew / dst_vec.rs
Last active May 31, 2017 20:11
A Vec-like data structure for trait objects
// This gist has been moved into a [repository](https://github.com/mikeyhew/dst_vec)
@mikeyhew
mikeyhew / bst.rs
Last active May 5, 2017 04:55
A Binary Search Tree written in Rust
//! Playground link: https://play.rust-lang.org/?gist=21091ecff9c46677fcb0670fb5a7f413&version=stable&backtrace=0
use std::cmp::Ordering::*;
pub struct Node<K: Ord> {
key: K,
left: BST<K>,
right: BST<K>,
}
pub struct BST<K: Ord>(Option<Box<Node<K>>>);
@mikeyhew
mikeyhew / size_of_val.rs
Created June 2, 2017 00:10
Demonstrates that std::mem::size_of_val and std::mem::align_of_val do not need to take a `&`-reference (a `*const` raw pointer is all that is needed)
#![feature(raw)]
use std::mem;
use std::ptr;
use std::raw::TraitObject;
use std::slice;
trait Foo {}
impl<T: ?Sized> Foo for T {}
@mikeyhew
mikeyhew / thread_local_scratchpad.rs
Last active June 9, 2017 06:50
An example of storing a Vec in a thread-local "scratchpad" static variable, to keep from repeatedly allocating and deallocating eat
use std::cell::UnsafeCell;
#[repr(C)]
struct Channel;
extern {
fn foo(inputs: *mut *mut Channel);
}
fn call_foo(inputs: &mut [&mut [Channel]]) {
use std::fmt;
pub trait Unwrap {
type Target;
type ErrorMessage: fmt::Display;
/// takes Self and either unwraps it into Target,
/// or returns an error message to panic with
fn unwrap(self) -> Result<Self::Target, Self::ErrorMessage>;