Skip to content

Instantly share code, notes, and snippets.

Russell Cohen rcoh

View GitHub Profile
View javascript_assesment.md

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 May 23, 2019
An implementation of Google Authenticator Compatible 2-factor Codes
View otp.py
"""
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 Aug 6, 2016
Strava JSON to GPX converter
View converter.py
### pip install gpxpy
import sys
import gpxpy
import gpxpy.gpx
import json
import datetime
def convert(f):
gpx = gpxpy.gpx.GPX()
View regexblog2.scala
object RegexParser extends RegexParsers {
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ {
char => Literal(char.head)
}
View regexblog2.scala
object RegexParser extends RegexParsers {
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ {
char => Literal(char.head)
}
View regexblog2.scala
object RegexParser extends RegexParsers {
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ {
char => Literal(char.head)
}
View 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 Aug 29, 2015
A dangerous pattern
View dangerouspattern.scala
try {
aDangerousFunction()
} catch {
case ex: Throwable => println(ex)
// Or even worse
case ex => println(ex)
}
@rcoh
rcoh / safelythrowable.scala
Last active Jun 15, 2020
Safely Catch Throwable
View safelythrowable.scala
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 Aug 29, 2015
Scala Nested Closures
View scalaclosures.scala
def inlineMeAgain[T](f: => T): T = {
f
}
def inlineme(f: => Int): Int = {
try {
inlineMeAgain {
return f
}
} catch {
You can’t perform that action at this time.