Skip to content

Instantly share code, notes, and snippets.

View rcoh's full-sized avatar

Russell Cohen rcoh

View GitHub Profile
@rcoh
rcoh / converter.py
Created August 6, 2016 05:56
Strava JSON to GPX converter
### pip install gpxpy
import sys
import gpxpy
import gpxpy.gpx
import json
import datetime
def convert(f):
gpx = gpxpy.gpx.GPX()
@rcoh
rcoh / otp.py
Last active August 17, 2023 08:03
An implementation of Google Authenticator Compatible 2-factor Codes
"""
An implementation of TOTP as described in https://tools.ietf.org/html/rfc6238#section-4 aka Google Authenticator Style 2-factor Auth
"""
import base64
import datetime
import hashlib
import hmac
import sys
import struct
import time
@rcoh
rcoh / sshupdate.py
Created February 3, 2013 22:57
Automatically update your SSH config to allow ssh-ing into EC2 instances by their name. Works on Linux and Mac OS X.
import os
import subprocess
import boto.ec2
import itertools
AWS_KEY = os.getenv('AWS_ACCESS_KEY')
AWS_SECRET = os.getenv('AWS_SECRET_KEY')
# Tweak as necessary for your infrastructure
regions = ['us-east-1', 'us-west-1', 'eu-west-1']
@rcoh
rcoh / safelythrowable.scala
Last active June 15, 2020 21:32
Safely Catch Throwable
def safely[T](handler: PartialFunction[Throwable, T]): PartialFunction[Throwable, T] = {
case ex: ControlThrowable => throw ex
// case ex: OutOfMemoryError (Assorted other nasty exceptions you don't want to catch)
//If it's an exception they handle, pass it on
case ex: Throwable if handler.isDefinedAt(ex) => handler(ex)
// If they didn't handle it, rethrow. This line isn't necessary, just for clarity
case ex: Throwable => throw ex
}
@rcoh
rcoh / scala-patterns.scala
Last active September 13, 2018 12:59
Scala patterns for compiler construction
// Useful Scala Patterns for Compiler Design
// 1. Case Classes
// [For full details, see Programming in Scala 2ed, page 310]
// Case classes are syntactic sugar around normal Scala classes. They come prebaked with the following properties:
// * Factory constructor (don't need new) :
case class Foo(bar: String)

Assesment 1: (~4-6h)

Tic-Tac-Toe: The goal is to implement a basic tic-tac-toe game. We will build it in the terminal using Node. The game will support 2 players, X and O, that make alternating moves. You're free to google anything you want! Develop this like you would work on any other project but please work on it indepdently. This project is tough! It's meant to be hard and to stretch your skills.

  1. Use ES6 classes to create a board class. The class should be able to store a 3x3 grid of tic-tac-toe pieces.

  2. Add a method to the class to print the board to the terminal (console.log) The format is up to you, but it should be clear to the user which pieces are where. Here's a possibility:

X|-|O
@rcoh
rcoh / inkenablesimple.m
Created August 13, 2013 06:54
Ink Enable, nondynamic
INKBlob *blob = [INKBlob blobFromData:content];
blob.uti = @"public.png"
[myView INKEnableWithBlob:blob];
@rcoh
rcoh / returntoacaller.m
Last active December 20, 2015 03:29
Return to calle
if ([INK appShouldReturn]) {
// 3 choices (choose 1)
// Return with data unchanged
[Ink return];
// Return with updated data
[INK returnBlob:newBlob];
// Return with error: (You must indicate to the user what went wrong before calling this)
@rcoh
rcoh / registeractions.m
Last active December 20, 2015 03:29
Registering actions for Ink
// Get the UUID for your action from the developer portal
INKAction *store = [INKAction actionWithUUID:@"store-asdfasd-sdfads"];
[Ink registerAction:store withTarget:self selector:@selector(storeBlob:action:error:)];
@rcoh
rcoh / actions.json
Created July 23, 2013 17:12
New actions for actions.json
{
"actions": [ … ],
"leftActions": [
{...},
{...},
{
"id": 4,
"uuid": "abcdefg",
"name": "Return to Frame",
"call_to_action": "Return",