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
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"
(interactive)
(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"
(interactive)
(if (eq major-mode 'dired-mode)
(let ((filenames (dired-get-marked-files))
@justinhj
justinhj / clojure-heap.clj
Last active Sep 30, 2019
A binary queue and heap sort in Clojure
View clojure-heap.clj
;;; An implementation of a binary heap in Clojure
;;; This is an algorithm used for efficiently taking the
;;; largest value from a collection. Commonly used to implement
;;; a priority queue
;;; The heap itself is stored as a vector. For convenience with
;;; array indexing the first element is set to nil and not used
;;; I wrote this as a learning experience not to be used to land
;;; jet aircraft or manage a nuclear reactor.
;;; Should be reasonably efficient though.
@justinhj
justinhj / gist:eb2d354d06631076566f
Created May 12, 2014
Sending a notification from emacs
View gist:eb2d354d06631076566f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Terminal notifier
;; requires 'sudo gem install terminal-notifier'
;; stolen from erc-notifier
(defvar terminal-notifier-command (executable-find "terminal-notifier") "The path to terminal-notifier.")
; (terminal-notifier-notify "Emacs notification" "Something amusing happened")
(defun terminal-notifier-notify (title message)
@justinhj
justinhj / efind
Created Jun 29, 2014
A bash script to easily search files for a regular expression
View efind
#!/bin/bash
# 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
fi
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
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
justinhj / backupchangeslist.py
Last active Aug 29, 2015
backup your p$ change list files to a dated folder
View backupchangeslist.py
# Copies a changelist (any files open for edit or add) to a directory you specify
# (C)2011 Justin Heyes-Jones
# TODO
# 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
justinhj / help.md
Created Sep 22, 2015
Water jug help for A*
View help.md

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
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
// http://stackoverflow.com/questions/25236143/why-future-example-do-not-work
// http://stackoverflow.com/questions/2213340/what-is-daemon-thread-in-java
@justinhj
justinhj / translate.org
Created Nov 1, 2016
Translate tables of English words to Mandarin using python translate and org babel
View translate.org

-*- mode: org; org-confirm-babel-evaluate: nil; -*-

from translate import Translator
translator=Translator(to_lang="zh")
translated=translator.translate(translatetext)
You can’t perform that action at this time.