Skip to content

Instantly share code, notes, and snippets.

View rhinoman's full-sized avatar

James Adam rhinoman

View GitHub Profile
@rhinoman
rhinoman / adventday6.el
Last active December 7, 2017 13:11
Advent of Code 2017 day 6 solution
; Returns the index of the largest value
(defun maxv (xs)
(let* ((idx 1)
(mxidx 0)
(mxval (aref xs 0)))
(while (< idx (length xs))
(if (> (aref xs idx) mxval)
(progn
(setq mxval (aref xs idx))
(setq mxidx idx)))
@rhinoman
rhinoman / adventday5.el
Created December 5, 2017 15:53
Advent of Code 2017 Day 5 solution
(defun solution-p1 (in)
(let* ((idx 0)
(xs (copy-sequence in))
(num-steps 0)
(len (length xs)))
(while (and (> idx -1) (< idx len))
(let ((cur (aref xs idx)))
(aset xs idx (+ cur 1))
(setq idx (+ idx cur))
(setq num-steps (+ num-steps 1)))
@rhinoman
rhinoman / adventday2.el
Created December 3, 2017 05:54
Advent of Code 2017 Day 2 Solution
;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.
(setq raw-input '(409 194 207 470 178 454 235 333 511 103 474 293 525 372 408 428
4321 2786 6683 3921 265 262 6206 2207 5712 214 6750 2742 777 5297 3764 167
3536 2675 1298 1069 175 145 706 2614 4067 4377 146 134 1930 3850 213 4151
2169 1050 3705 2424 614 3253 222 3287 3340 2637 61 216 2894 247 3905 214
99 797 80 683 789 92 736 318 103 153 749 631 626 367 110 805
2922 1764 178 3420 3246 3456 73 2668 3518 1524 273 2237 228 1826 182 2312
2304 2058 286 2258 1607 2492 2479 164 171 663 62 144 1195 116 2172 1839
@rhinoman
rhinoman / Hateoas.scala
Last active February 3, 2022 21:11
Getting HAL style links for HATEOAS to map correctly to JSON in Scala. Assumes you're using json4s and Jackson. I'm using the below code with Scalatra -- my servlets have the 'JacksonJsonSupport' trait mixed in
//package object full o' utility functions for creating some HAL-style HATEOAS links
package object Hateoas{
//could add an additional field specifying MIME-type, for example
case class Link(href: String, method: String)
type HateoasLinks = Map[String, Link]
//case class for a response containing a Collection of items
case class ListResponse(_links: HateoasLinks, _embedded: Map[String, List[Any]])
object HateoasLinkFactory{
//could (should) add a function for generating a "custom" action link