Skip to content

Instantly share code, notes, and snippets.

@hgiddens
hgiddens / Inject.scala
Last active November 24, 2015 01:18
Inject + PDTs
import scalaz.{Coproduct, Inject}
trait X { self ⇒
type O[Z]
def :+:(that: X): X { type O[Z] = Coproduct[that.O, self.O, Z] } =
new X { type O[Z] = Coproduct[that.O, self.O, Z] }
}
object X {
def apply[F[_]]: X { type O[Z] = F[Z] } =
new X { type O[Z] = F[Z] }
@hgiddens
hgiddens / gist:bda91ac3b4c598db50fa
Created May 2, 2015 09:09
Solarized Emacs stuff That Works On My Machine (TM)
;;; Solarized configuration is a total clusterfuck, but on the other hand
;;; I've somehow got the bastard playing nicely with NS frames, TTY frames,
;;; and both NS /and/ TTY clients of both.
;;;
;;; - solarized-broken-srgb is always false as we're using the new sRGB in master.
;;; - solarized-assume-solarized-terminal is also set to t. This is a new customisation
;;; variable I introduced that tells Solarized to use the window system RGB codes for
;;; terminal faces, assuming that they'll be mapped to the correct Solarized colours.
;;; This should be trivial to hack into solarized-color-definitions, when index is set change
;;; (cond window-system ...
@hgiddens
hgiddens / gist:2011d316ed661361f26f
Created September 23, 2014 02:48
Macrons and Perl
#!/usr/bin/env perl
# First up, this is the bible:
# https://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default
# Also good
# man perluniintro
# man perlunitut
# man perlunicode
# Tested via `PERL_UNICODE=S perl test.pl < macron.txt` where macron.txt just contained
trait A
trait B
trait E
trait S {
def publish(e: E): Unit
}
object Foo {
def p[F[+_]](f: F[E])(implicit F: Functor[F], s: S): F[Unit] = f.map(s.publish)
@hgiddens
hgiddens / gist:4152064
Created November 27, 2012 02:44
Why does this work?
"wtf" in {
trait Consumer { def consume(value: Root): Unit }
sealed trait Root
case class Alpha(s: String) extends Root
case class Beta(s: String) extends Root
val consumer = mock[Consumer]
consumer.consume(Alpha("ss"))
consumer.consume(Beta("ss"))
there was two(consumer).consume(any[Alpha]) // I would expect this to fail but it doesn't.
@hgiddens
hgiddens / gist:4133425
Created November 23, 2012 00:20
demangle
(defun demangle ()
(interactive)
(let* ((sym (thing-at-point 'symbol)))
(with-temp-buffer
(call-process "c++filt" nil t nil sym)
(backward-delete-char 1)
(message (buffer-string)))))
@hgiddens
hgiddens / gist:4109098
Created November 19, 2012 05:30
Easy to forget this syntax
class foo { foo(); int x; };
foo::foo() try : x(1) {
} catch (int e) {
--x;
}
@hgiddens
hgiddens / gist:3689404
Created September 10, 2012 07:22
Help!
// init guaranteed to be non-empty
// Basically this is trying to take a paginated response of Ts and turn it into a non-paginated list of all the Ts.
val init: M[List[T]] // guaranteed to be non-empty
val last: List[T] => T // does what it says on the tin
val continue: T => Option[S] // given a response T, returns the key necessary to retrieve the next page
val next: S => M[T] // given a key, retrieves the next page
...
combine: (List[T], M[T]) => M[List[T]]
@hgiddens
hgiddens / gist:2922567
Created June 13, 2012 07:39
Process HTMLish XMPP messages
(require 'cl)
(require 'xml)
(defun jabber-body-printer-with-xml (xml-data who mode)
"Prints XMPP message bodies, linkifying <a> elements.
See `jabber-chat-normal-body'. Requires Emacs 24.1 with LibXML2 support."
(if (eq mode :insert)
(let ((beginning (point)))
(jabber-chat-normal-body xml-data who mode)
(save-restriction
@hgiddens
hgiddens / gist:1260918
Created October 4, 2011 04:42
For the Emacs users in the house
;; Lets you insert a lambda using C-' l
;; Got the idea from Tim Bray, hence the name. Would be better as a minor mode or
;; something but I'm lazy and this works.
(defun braysian-insert (c)
"Inserts a special character."
(interactive "c")
(let* ((braysian-insertion-map '((?z . #x200b) ; zero width space
(?S . #x2018) ; left single quote
(?s . #x2019) ; right single quote
(?' . #x2019)