Skip to content

Instantly share code, notes, and snippets.

module Linear.VPTree
( fromList
, nearest
) where
import Linear
import Data.Word8
import Data.List (partition, sortBy)
import Data.Ord (comparing)
import Data.Function (on)
-- | A scan-conversion algorithm for drawing lines on integral coordinate
-- systems. Returns the list of coordinates that should be filled to draw
-- the line from point to point.
line :: (Integral a) => V2 a -> V2 a -> [V2 a]
line p p' = fmap near [0..end] where
end = case abs (p - p') of V2 dx dy -> max dx dy
near i = round <$> lerp (i % end)
(fmap fromIntegral p')
(fmap fromIntegral p)
import Monad
@doc """
Read and decode a file
Returns {:ok, result} or {:error, reason}
"""
def decode_file(fh) do
monad ErrorM do
contents <- File.read(fh)
# A bunny has three offspring each generation.
generation = -> (x) { [x,x,x] }
# How many bunnies will there be after two generations?
["bunny"].flat_map(&generation).flat_map(&generation).length # => 9
@reinh
reinh / README.md
Last active February 20, 2016 00:39

Syntax highlight SQL inside Ruby <<-SQL heredocs

Embeds SQL syntax highlighting inside Ruby heredocs labeled SQL. This will also work to embed other syntaxen, e.g., HTML.

Optional PGSQL enhanced syntax:

(requires https://github.com/exu/pgsql.vim)

 syntax include @SQL syntax/pgsql.vim
class people::reinh {
# Dev stuff
include tmux
include ctags
include vagrant
include iterm2::dev
include zsh
include java
include mysql
include redis
$home = "/Users/${::luser}"
$my = "${home}/my"
file { $my: ensure => directory }
repository {
"$my/keyword_search":
source => "reinh/keyword_search",
require => File[$my];
"$my/coffeequest":
@reinh
reinh / astar.coffee
Last active December 16, 2015 04:59
class Dijkstra extends PathFinder
heuristic: -> 0
class AStar extends PathFinder
heuristic: (start, finish) ->
_.max _.map [start.x - finish.x, start.y - finish.y], Math.abs
class DrunkAStar extends PathFinder
heuristic: Math.random
@reinh
reinh / gist:5304197
Last active December 15, 2015 18:29

While trade unions may have many of the benefits stated in the article, they also have some negative effects on markets. Many of these are covered (briefly) by Wikipedia in Opposition To Trade Unions, as are the responses to these arguments. I would like to present one further argument:

Unions Decrease The Option Value Of Employees

Having options is valuable. If you are considering buying a business valued at $110,000, which of these two options would you prefer?

  1. Six months from now you must pay $100,000 for the business.
  2. Six months from now you have the option of paying $100,000 for the business.
class @Engine
constructor: (@world, @context) ->
{height: height, width: width} = @world.dimensions
Backbone.on 'move', (args...) => @move args...
@player = @world.player
@display = new Display(rows: height, columns: width)
actors = [@player, new Random(10,10, @)]
@scheduler = new Scheduler(actors)