Skip to content

Instantly share code, notes, and snippets.

View eklitzke's full-sized avatar

Evan Klitzke eklitzke

View GitHub Profile
source /etc/bash_completion.d/git
# User specific aliases and functions
PATH=$HOME/.cabal/bin:$HOME/local/bin:$PATH
case $TERM in
xterm*|rxvt*|gnome*|eterm* )
PS1='\[\033[01;35m\][\[\033[01;32m\]\u@\h \[\033[01;34m\]\W$(__git_ps1 " (%s)")\[\033[00m\]\[\033[01;35m\]]\$\[\033[0m\] '
;;
-- An Addr is really 14 bits, but this should be close enough
type Addr = Word16
-- The status register
type StatusR = On | Off deriving (Show, Eq)
type Imm = LTZ
| LEZ
| EQZ
| GEZ
class Strategy s where
store :: s -> Ports -> IO ()
fetch :: s -> IO [Ports]
isDone :: Ports -> Bool
updatePorts :: Ports -> IO Ports
next :: s -> s
run :: Strategy s => s -> IO [Ports]
run world = let loop = do w' = next world
if isDone w'
class Strategy s where
storeOutput :: s -> Ports -> IO ()
nextInput :: s -> IO Ports
isDone :: s -> Bool
failed :: s -> Bool
run :: Strategy s => s -> IO [Ports]
run world = let loop = do w' = next world
if isDone w'
then fetch w'
type Ctx = Map String Double
fetch :: Ctx -> String -> Double
fetch = fromJust . lookup
data Orbit = Orbit IORef Position Velocity
class AltStrategy s where
impulse :: s -> Ctx -> Orbit -> IO (Ctx, Double, Double)
type Point = (Double, Double)
type Vector = Point
distance :: Point -> Point -> Double
distance (x1, y1), (x2, y2) = sqrt ((x2-x1)**2 + (y2-y1)**2)
-- Compute the normalized tangent vector from two points
normalizedVector :: Point -> Point -> Vector
normalizedVector (x1, y1) (x2, y1) = (xv / l, yv / l)
where
-- The fields are position, speed. Speed is positive for clockwise rotation,
-- negative for counter-clockwise rotation
data Course = Course Point Double
-- time is the time to do the hohmann transfer, use the hohTime function, The first course it your course, the second course is the target;s
computeJump :: Double -> Course -> Course -> Maybe (Vector, Vector)
computeJump time (Course (xs, ys) vs) targ@(Course (xt, yt) vt)
(require 'yelp)
(defun find-after (target xs)
(defun find-c (p ys)
(if p
(cons (car ys) nil)
(if (string-equal target (car ys))
(cons target (find-c t (cdr ys)))
(cons (car ys) (find-c nil (cdr ys))))))
(find-c nil xs))
(defun my-span (p lst)
"Break the input list into two components -- the front part of
the list whose elements satisfy the predicate p, and the rest of
the list (at least the car of this list does not satisfy p)."
(let (span-front span-back)
(while (and lst (funcall p (car lst)))
(setq span-front (cons (car lst) span-front))
(setq span-back (cdr lst))
(setq lst (cdr lst))
(setq span-front (nreverse span-front)))
@eklitzke
eklitzke / gist:149728
Created July 18, 2009 23:15
this is the code in gnome-system-monitor that draws the curves
cr = gdk_cairo_create (g->disp->window);
cairo_set_line_width (cr, 1);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
cairo_rectangle (cr, g->rmargin + g->indent + FRAME_WIDTH + 1, FRAME_WIDTH - 1,
g->draw_width - g->rmargin - g->indent - 1, g->real_draw_height + FRAME_WIDTH - 1);
cairo_clip(cr);
for (j = 0; j < g->n; ++j) {