Skip to content

Instantly share code, notes, and snippets.

Justin Heyes-Jones justinhj

Block or report user

Report or block justinhj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
justinhj / efind
Created Jun 29, 2014
A bash script to easily search files for a regular expression
View efind
# A simple script to recursively search files
if [ "$#" -ne 3 ]; then
echo "efind (easy find) usage: [path] [file pattern] [regex]"
echo 'efind ../c "*.c" "string"'
exit 1
find "$1" -name "$2" -type f -print0 | xargs -0 egrep -iHn "$3"
View gist:b1e43224a917f281dc93
// Determine if a value is the product of any two numbers in a vector
// Converts the array to a stream so it can be consumed lazily
// the helper function is recursive but subject to tail call optimization
def prod(in: Array[Int], v: Int): Boolean = {
def helper(in: Stream[Int], v: Int, found: Map[Int, Int]): Boolean = in match {
case x #:: xs => {
val r = v / x
if(r * x != v) helper(xs, v, found)
else if(found.contains(x)) true
justinhj / FileExt.scala
Last active Aug 29, 2015
Using unapply to match strings that are valid filenames with an extension
View FileExt.scala
object FileExt {
def unapply(s: String): Option[String] = {
val parts: Array[String] = s.split('.')
if(parts.length < 2) None
else Some(parts.last)
justinhj /
Last active Aug 29, 2015
backup your p$ change list files to a dated folder
# Copies a changelist (any files open for edit or add) to a directory you specify
# (C)2011 Justin Heyes-Jones
# Allow user to pass in PORT setting
# Or at least check that it is set before doing perforce interactions
# P4 set P4PORT=servername:port
import subprocess, sys, marshal, string, os, time, datetime
justinhj /
Created Sep 22, 2015
Water jug help for A*

State representation

In the 8Puzzle the state of each step in the solution is an array of tiles. In the water jug it can be an array of jug levels [0,0]

You can replace tiles with jugs TILE tiles[ BOARD_WIDTH*BOARD_HEIGHT ]; int jug_levels[ 2 ];

State transitions

justinhj / futureDemo.scala
Last active Oct 12, 2016
Demo of concurrency handling in for comprehension using Futures
View futureDemo.scala
// Demonstrating futures running concurrently and in sequence
import scala.concurrent.{ExecutionContext, Future}
import scala.language.postfixOps
// A simple execution context for us to use that will not shut down the JVM until the threads we start have all finished
// It does that by making the threads non-Daemon
justinhj / git-add-dired.el
Created Jul 7, 2013
Allows you to use dired to add multiple files to a git repository. This is useful since staging files in magit is sluggish and takes a long time when you have a lot of files.
View git-add-dired.el
(defun git-add-files(files)
"Run git add with the input file"
(shell-command (format "git add %s" files)))
(defun dired-git-add-marked-files()
"For each marked file in a dired buffer add it to the index"
(if (eq major-mode 'dired-mode)
(let ((filenames (dired-get-marked-files))
View adventofcode1.scala
object Xmas1 {
object Move {
def fromString(arg: String): Option[Move] = arg match {
case s if arg.startsWith("R") || arg.startsWith("L") =>
try {
val turn = if(arg.charAt(0) == 'R') Right else Left
View adventofcode1.2.scala
import scala.collection.{immutable, mutable}
object Xmas1 {
object Move {
def fromString(arg: String): Option[Move] = arg match {
case s if arg.startsWith("R") || arg.startsWith("L") =>
try {
View adventofcode2.1.scala
// Solution to
object Xmas2 {
case class Transition(name: Char, target: Digit)
case class Digit(value: Int, var transitions: Vector[Transition] = Vector[Transition]()) {
def addTransitions(newTransitions: Vector[Transition]) = {
transitions = transitions ++ newTransitions
You can’t perform that action at this time.