Skip to content

Instantly share code, notes, and snippets.

View rcoh's full-sized avatar

Russell Cohen rcoh

View GitHub Profile

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 / 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 / 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 / regexblog2.scala
Created August 18, 2014 20:37
regexblog2
object RegexParser extends RegexParsers {
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ {
char => Literal(char.head)
}
@rcoh
rcoh / regexblog2.scala
Created August 18, 2014 20:37
regexblog2
object RegexParser extends RegexParsers {
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ {
char => Literal(char.head)
}
@rcoh
rcoh / regexblog2.scala
Created August 18, 2014 20:37
regexblog2
object RegexParser extends RegexParsers {
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ {
char => Literal(char.head)
}
@rcoh
rcoh / blog1.scala
Created August 18, 2014 20:33
blog1.scala
abstract class RegexExpr
// ., a, b
case class Literal(c: Char) extends RegexExpr
// a|b
case class Or(expr1: RegexExpr, expr2: RegexExpr) extends RegexExpr
// ab -> Concat(a,b); abc -> Concat(a, Concat(b, c))
case class Concat(first: RegexExpr, second: RegexExpr) extends RegexExpr
@rcoh
rcoh / dangerouspattern.scala
Last active August 29, 2015 14:00
A dangerous pattern
try {
aDangerousFunction()
} catch {
case ex: Throwable => println(ex)
// Or even worse
case ex => println(ex)
}
@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 / scalaclosures.scala
Last active August 29, 2015 14:00
Scala Nested Closures
def inlineMeAgain[T](f: => T): T = {
f
}
def inlineme(f: => Int): Int = {
try {
inlineMeAgain {
return f
}
} catch {