Skip to content

Instantly share code, notes, and snippets.

View cameronhotchkies's full-sized avatar

Cameron Hotchkies cameronhotchkies

View GitHub Profile
@cameronhotchkies
cameronhotchkies / SlickMapping.scala
Created June 3, 2015 16:39
Common Joda DateTime Mapping
import play.api.db.slick.Config.driver.simple._
import org.joda.time.DateTime
import java.sql.Timestamp
object SlickMapping {
implicit def jodaDateTimeMapping =
MappedColumnType.base[DateTime, Timestamp](
dt => new Timestamp(dt.getMillis),
ts => new DateTime(ts.getTime))
}
import org.joda.time.DateTime
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import play.api.Play.current
object SlickMapping {
protected val dbConfig = DatabaseConfigProvider.get[JdbcProfile](current)
import dbConfig._
import dbConfig.driver.api._
@cameronhotchkies
cameronhotchkies / gist:5620426
Created May 21, 2013 14:54
Why you shouldn't go back and forth on UTF-8 strings for binary data
// Run in a REPL
val bl : List[Byte] = List(-78,-5,-112,-31,127,-59,1,94,12,7,84,112,82,41,-95,50)
val ba = bl.toArray
val bs = new String(ba, "UTF-8")
bl.length
ba.length
bs.length
// Notice they aren't all equal
@cameronhotchkies
cameronhotchkies / Sha1Digest.scala
Last active December 21, 2015 02:09
An implementation of SHA-1 in pure Scala. More info at: http://www.semisafe.com/2013/08/sha-1-implementation-in-pure-scala/
package com.semisafe.cryptopals
/*
* Implementation of SHA-1 in pure Scala
*
* This was implemented as part of the Matasano Crypto Challenges
* http://www.matasano.com/articles/crypto-challenges/
*
* Having a native implementation of SHA-1 is required for the
* fourth set of challenges, building your own isn't, so feel
package com.semisafe.cryptopals
/*
* Implementation of MD4 in pure Scala
*
* derived from the RSA Data Security, Inc. MD4
* Message-Digest Algorithm (http://tools.ietf.org/html/rfc1320)
*
* This was implemented as part of the Matasano Crypto Challenges
* http://www.matasano.com/articles/crypto-challenges/

Keybase proof

I hereby claim:

  • I am cameronhotchkies on github.
  • I am chotchkies (https://keybase.io/chotchkies) on keybase.
  • I have a public key ASBwcIFwwOHKaDwzi20fYJ7PyirAdi_mBRv7dplUaEzbWAo

To claim this, I am signing this object:

@cameronhotchkies
cameronhotchkies / alphavantage_sample.py
Created August 5, 2019 00:05
Simple python script for alphavantage API
#!/usr/bin/env python3
import urllib.request
import urllib.parse
import json
api_key = 'demo'
ticker = 'MSFT'
@cameronhotchkies
cameronhotchkies / dynamicSidebar.js
Created April 17, 2020 04:07
Dynamic sidebar in Docusaurus
const fs = require('fs');
const autoIndexRegex = /^\d*\-.*\.md$/;
items = fs.readdirSync('docs/standards');
const detectedPages = items.filter(filename => {
return autoIndexRegex.test(filename)
});
Wed Jul 1 03:58:54 UTC 2020
@cameronhotchkies
cameronhotchkies / post_sink.py
Created January 19, 2021 07:21
Python script for logging POST requests to disk
from http.server import BaseHTTPRequestHandler
import socketserver
import time
PORT = 9000
class SinkHandler(BaseHTTPRequestHandler):
def do_POST(self):
incoming = self.rfile