Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"math"
)
func main() {
limit := int64(math.Pow(10, 8))
ldiv4 := int64(limit / 4)
@dyoo
dyoo / circular-window.rkt
Created June 1, 2013 23:07
A circular array-based implementation of a rolling window.
#lang racket/base
;; A circular array to let us efficiently walk a window across a sequence.
(struct window (elts ;; (vectorof X) of length n
capacity ;; natural
start ;; natural
count ;; natural
)
#:mutable)
@dyoo
dyoo / bitmap-scale-with-flomap.rkt
Created May 28, 2013 22:44
bitmap image scaling with flomap operations
#lang racket
(require net/url
racket/gui/base
images/flomap)
(define ip (get-pure-port
(string->url "http://racket-lang.org/logo.png")))
(define bm (make-object bitmap% ip))
(define big-bm
@dyoo
dyoo / equal-with-id.rkt
Created May 15, 2013 20:24
example of equal?/recur that deals with cycles.
#lang racket/base
(require data/union-find)
(define (equal?/id x y)
(define ufs (make-hasheq))
(let loop ([x x]
[y y])
(cond [(and (identifier? x) (identifier? y))
(free-identifier=? x y)]
@dyoo
dyoo / unicode-name.rkt
Last active December 17, 2015 09:19
A function for getting the name of unicode code points
#lang racket/base
(provide unicode-name)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; We want to compute the table at compile-time, so that the result can be saved
;; by using raco make.
(require (for-syntax net/url
racket/base
@dyoo
dyoo / channel-example.rkt
Created May 3, 2013 20:20
An example of the synchronous channels in Racket
#lang racket
;; A translation of http://tour.golang.org/#63 in Racket
(define (sum elts c)
(channel-put c (for/sum ([e elts]) e)))
(define (main)
(define a (list 7 2 8 -9 4 0))
@dyoo
dyoo / simple-canvas-example.rkt
Last active December 16, 2015 23:21
A simple canvas example
#lang racket/gui
(define program-state 0)
(define f (new frame% [label "Example program"]))
(define c (new canvas%
[parent f]
[min-width 500]
[min-height 500]
[paint-callback
@dyoo
dyoo / gist:5484527
Created April 29, 2013 20:30
sketch
#lang racket/base
(define-namespace-anchor a)
(define (load-plug-in file)
(let ([ns (namespace-anchor->namespace a)])
(parameterize ([current-namespace ns])
(dynamic-require file 'print-colored))))
(define print-colored
@dyoo
dyoo / noisy-rackunit-example.rkt
Last active December 16, 2015 13:08
Make rackunit noisy.
#lang racket
(require rackunit)
(current-check-around (let ([original-check-around (current-check-around)])
(lambda (f)
(printf "Running test...\n")
(original-check-around f))))
(check-equal? (+ 1 1) 2)
(check-equal? (+ 1 1) 2)
Begin Dump
Begin Racket3m
<variable-code>: 8149 195576
<local-code>: 239 3824
<application-code>: 13043 966232
<unary-application-c: 19538 625216
<binary-application-: 10593 423720
<sequence-code>: 3258 123568
<branch-code>: 7772 310880
<procedure-code>: 15133 1089576