Skip to content

Instantly share code, notes, and snippets.

View mads-hartmann's full-sized avatar

Mads Hartmann mads-hartmann

View GitHub Profile
@mads-hartmann
mads-hartmann / toggle-maximize-buffer.el
Created August 20, 2012 10:05
An Emacs function to temporarily make one buffer fullscreen. You can quickly restore the old window setup.
(defun toggle-maximize-buffer () "Maximize buffer"
(interactive)
(if (= 1 (length (window-list)))
(jump-to-register '_)
(progn
(set-register '_ (list (current-window-configuration)))
(delete-other-windows))))
;; Bind it to a key.
@mads-hartmann
mads-hartmann / SCC.scala
Created October 13, 2011 12:30
Strongly Connected Components algorithm implemented in Scala
/*
This is implemented following the instructions in "The Design and Analysis of
Computer Algorithms, AHO Hopcroft Ullman, 1974".
The implementation uses a DFS to find the strongly connected components (SCCs)
of a graph. During the DFS the vertices are placed on a stack in the order
they are visited. Whenever a root is found, all vertices of the corresponding
SSC are on the top of the stack and are popped.

Table of contents

@mads-hartmann
mads-hartmann / bundles.sh
Created December 7, 2010 16:04
This is how I manage my textmate bundles.
#
# This script will install the following Textmate bundles
#
# Languages
# - c https://github.com/textmate/c.tmbundle
# - coffeescript https://github.com/jashkenas/coffee-script-tmbundle
# - context free https://github.com/textmate/context-free.tmbundle
# - erlang https://github.com/textmate/erlang.tmbundle
# - haskell https://github.com/textmate/haskell.tmbundle.git
# - html https://github.com/textmate/html.tmbundle
object Peano {
sealed trait Nat
trait Zero extends Nat
object ZeroV extends Zero
case class Succ[A <: Nat](x: A) extends Nat
trait Sum[A <: Nat, B <: Nat] {
type Out <: Nat
}
@mads-hartmann
mads-hartmann / Coffeescript ctags
Created April 7, 2011 07:44
ctags definitions for Coffeescript. Very basic for now. "> ctags -e -R source_folder" and then M-. to jump to the definition of any function or variable (if you're using emacs)
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=.*->.*$/\1/f,function/
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/v,variable/
@mads-hartmann
mads-hartmann / anything-dirty.sh
Created March 20, 2018 19:58
🤖 Tiny script to check if I had any dirty repos or un-pushed branches before sending my MBP to repair.
#!/bin/bash
set -euo pipefail
function is-git-repository {
[[ -d "$1/.git" ]] || (cd "$1" && git rev-parse --git-dir > /dev/null 2>&1)
}
function echo-is-dirty {
cd "$1"
if [[ ! -z $(git status -s) ]]
@mads-hartmann
mads-hartmann / GADT.scala
Created January 23, 2018 15:50
GADT Example Translation from OCaml to Scala
// I tried to translate the GADT examples I have in my blog post[1] about GADTs
// from OCaml to Scala.
//
// A direct translation resulted in the code below, but I had to add two asInstanceOf
// so I don't consider this a successful translations.
//
// Any idea how to get rid of the asInstanceOf calls? Is it even possible?
//
// [1]: http://mads-hartmann.com/ocaml/2015/01/05/gadt-ocaml.html
@mads-hartmann
mads-hartmann / prototype-deploy.sh
Created August 20, 2017 10:10
A small script for deploying a Docker service to a docker-machine. Suitable to prototypes and small hobby projects.
#!/bin/bash
#
# usage: prototype-deploy <machine-name> <image-name> <container-name>
#
set -euo pipefail
#
# Functions
#
@mads-hartmann
mads-hartmann / mhj-explore-toggle-mod.el
Created March 17, 2017 09:11
A modification to mhj/show-project-explorer as requested by Benjamín Buccianti
(defun mhj/show-project-explorer ()
"Project dired buffer on the side of the frame.
Shows the projectile root folder using dired on the left side of
the frame and makes it a dedicated window for that buffer."
(let ((buffer (dired-noselect (projectile-project-root))))
(progn
(display-buffer-in-side-window buffer '((side . left) (window-width . 0.2)))
(set-window-dedicated-p (get-buffer-window buffer) t)
(select-window (get-buffer-window buffer)))))