Skip to content

Instantly share code, notes, and snippets.

;; A space invaders game in Racket
;; Copyright (c) 2020 Alex Harsányi (AlexHarsanyi@gmail.com)
;; Permission is hereby granted, free of charge, to any person obtaining a
;; copy of this software and associated documentation files (the "Software"),
;; to deal in the Software without restriction, including without limitation
;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;; and/or sell copies of the Software, and to permit persons to whom the
;; Software is furnished to do so, subject to the following conditions:
@alex-hhh
alex-hhh / tetris-4.rkt
Last active November 22, 2023 17:15
Tetris Game, Final Version
;; A tetris game -- partial implementation, part 4
;; Copyright (c) 2020 Alex Harsányi (AlexHarsanyi@gmail.com)
;; Permission is hereby granted, free of charge, to any person obtaining a
;; copy of this software and associated documentation files (the "Software"),
;; to deal in the Software without restriction, including without limitation
;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;; and/or sell copies of the Software, and to permit persons to whom the
;; Software is furnished to do so, subject to the following conditions:
@alex-hhh
alex-hhh / tetris-5.rkt
Created March 28, 2020 02:33
Full program for the "A Game of Tetris" blog posts.
;; A tetris game -- partial implementation, part 5
;; Copyright (c) 2020 Alex Harsányi (AlexHarsanyi@gmail.com)
;; Permission is hereby granted, free of charge, to any person obtaining a
;; copy of this software and associated documentation files (the "Software"),
;; to deal in the Software without restriction, including without limitation
;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;; and/or sell copies of the Software, and to permit persons to whom the
;; Software is furnished to do so, subject to the following conditions:
#lang racket/base
(require quickscript racket/string)
(define prefix-rx #px"^\\s*;+\\s*")
(define fill-column 78)
(define (determine-prefix line)
(define m (regexp-match prefix-rx line))
(if m (car m) ""))
"""Update weather data for sessions in an ActivityLog2 database using data
from the Meteostat service. The script will find sessions that have
latitude/longitude coordinates but no weather data, and will attempt to fetch
weather info from the Meteostat service and store it attached to the each
session. Sessions that already have weather data will not be updated.
For ActivityLog2, see https://github.com/alex-hhh/ActivityLog2
For Meteostat, see https://meteostat.net/en/
To use it, you will need to install Python 3, then install the meteostat
@alex-hhh
alex-hhh / wolf-goat-cabbage.rkt
Created October 9, 2022 06:54
The Wolf the Goat and the Cabbage puzzle in miniKanren and Racket
#lang racket
;; Using [miniKanren](http://www.minikanren.org), a DSL for logic
;; programming, to solve the Wolf, Goat, and Cabbage problem.
;; THE PUZZLE: https://en.wikipedia.org/wiki/Wolf,_goat_and_cabbage_problem
;;
;; Once upon a time a farmer went to a market and purchased a wolf, a goat,
;; and a cabbage. On his way home, the farmer came to the bank of a river and
;; rented a boat. But crossing the river by boat, the farmer could carry only
#lang racket/gui
(require embedded-gui)
(define chess-piece-snip-class
(make-object
(class snip-class%
(super-new)
(send this set-classname "chess-piece-snip"))))
(send (get-the-snip-class-list) add chess-piece-snip-class)
@alex-hhh
alex-hhh / current-value-fancy.rkt
Created March 20, 2018 06:13
Interactive overlays with the Racket Plot Package
#lang racket
(require racket/gui mrlib/snip-canvas plot pict racket/draw)
(define (pie-slice w h angle)
(define nangle (let ((npi (floor (/ angle (* 2 pi)))))
(- angle (* 2 pi npi))))
(define (draw dc dx dy) (send dc draw-arc dx dy w h (- (/ nangle 2)) (/ nangle 2)))
(dc draw w h))
(define item-font (send the-font-list find-or-create-font 12 'default 'normal 'normal))
#lang racket
(require math/array)
;; https://en.wikipedia.org/wiki/Conway's_Game_of_Life
;; These are the game rules for a single CELL which can be 1 (alive) or 0
;; dead. NEIGHBOR-COUNT is the number of live neighbors the cell has.
(define (game-rules cell neighbor-count)
(cond
;; Any live cell with fewer than two live neighbours dies, as if by
;; underpopulation.
@alex-hhh
alex-hhh / colormap.rkt
Last active March 21, 2022 06:51
plot color maps
#lang racket
(require racket/draw
racket/promise
plot
plot/utils
pict)
;; These color maps correspond to the Matplotlib 3.0.3 qualitative color maps
;; with the same names. See
;; https://matplotlib.org/examples/color/colormaps_reference.html