Skip to content

Instantly share code, notes, and snippets.

View smithjessk's full-sized avatar

Jess Smith smithjessk

  • United States
View GitHub Profile
# Install OpenCV 2.4.9 for Ubuntu
# Derived from https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/2.4/opencv2_4_8.sh
# @author Jess Smith <smith.jessk@gmail.com>
# @license MIT
arch=$(uname -m)
if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
flag=1
else
import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.Context
import scala.reflect.ClassTag
import scala.reflect.runtime.universe.Flag._
// Add constructor arguments here.
class expand extends StaticAnnotation {
def macroTransform(annottees: Any*) = macro Expander.expand_impl
}
@smithjessk
smithjessk / ccManipulation.scala
Last active October 15, 2015 21:26
An interesting attempt at companion object manipulation. Note that this gets different results when interpreted and when compiled. companionOf is taken from http://stackoverflow.com/a/9174777
object CC {
def companionOf[T : Manifest] : Option[AnyRef] = try {
val classOfT = implicitly[Manifest[T]].erasure
val companionClassName = classOfT.getName + "$"
val companionClass = Class.forName(companionClassName)
val moduleField = companionClass.getField("MODULE$")
Some(moduleField.get(null))
} catch {
case e => None
}
import csv
def is_first_of_month(row):
date_string = row[0]
return row[0].split('-')[2] == '01'
def handle_row(row):
if is_first_of_month(row):
open_price, close_price = float(row[1]), float(row[4])
diff = close_price - open_price
#!/usr/bin/python3
import sys
lines = sys.stdin.readlines()
for line in lines:
chars = list(line)
output = ""
for char in chars:
output += char
@smithjessk
smithjessk / die.js
Created April 12, 2016 22:50
Remove those horrible, incipid flames logos from Politifact
$('img[alt="Pants on Fire!"]').remove();
@smithjessk
smithjessk / .spacemacs
Last active May 31, 2016 15:28
Spacemacs config
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@smithjessk
smithjessk / problem.scala
Last active August 1, 2016 18:35
Demonstrates a problem with by-name parameter extraction
// Inspired by http://stackoverflow.com/questions/29757584/handling-by-name-parameters-in-scala-macro
import scala.reflect.runtime.universe._
class X { def x(i: => Int, second: String, other: Int*) = i * 2 }
val typeSignature = typeOf[X].member(TermName("x")).typeSignature
val paramTypes = typeSignature match {
case MethodType(params, _) => params map { _.typeSignature }
}
@smithjessk
smithjessk / demo.go
Created September 28, 2016 21:51
Three separate ways of errors in a `http.Handler`
package main
import (
"encoding/json"
"net/http"
)
type request struct {
ID string
}
@smithjessk
smithjessk / timing_test.go
Last active October 4, 2016 14:40
Times error handling via panics vs. if statements
package bench
import (
"errors"
"os"
"testing"
)
func TestMain(m *testing.M) {
code := m.Run()