This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;;; Run this file with `racket test-big-bang.rkt` | |
;;; then type quickly "asdf" to trigger several successive to-draw events. | |
;;; Drawing the scene is fast, but rendering it on-screen is very slow? | |
(require 2htdp/image | |
2htdp/planetcute | |
2htdp/universe) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# From: http://nbviewer.ipython.org/url/norvig.com/ipython/xkcd1313.ipynb | |
import re | |
def verify(regex, winners, losers): | |
"Return true iff the regex matches all winners but no losers." | |
missed_winners = {W for W in winners if not re.search(regex, W)} | |
matched_losers = {L for L in losers if re.search(regex, L)} | |
if missed_winners: | |
print "Error: should match but did not:", ', '.join(missed_winners) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;; proc : procedure? ; procedure to apply | |
;; dict : dict? ; dictionary of keywords and values | |
;; A key can be either a keyword or a symbol that is turned into a keyword. | |
;; largs : list? ; positional arguments | |
;; Returns the result of the application of proc to the positional arguments and the keyword values. | |
(define (keyword-apply/dict proc dict largs) | |
(define alist | |
(sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/gui | |
(define my-frame% | |
(class frame% | |
(define/override (on-subwindow-event receiver event) | |
(when (send event button-down?) | |
(displayln (send receiver get-label))) | |
#f) | |
(super-new))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require racket/gui/base | |
racket/class | |
racket/format) | |
(define NUM-CELL-X 100) | |
(define NUM-CELL-Y 100) | |
(define CELL-SIZE 2) | |
(define XMAX (* NUM-CELL-X CELL-SIZE)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define ((foo #:a? [a? #t] #:b? [b? #t]) x) | |
(when b? | |
(displayln "b!")) | |
(if a? | |
(+ x 1) | |
(+ x 2))) | |
(define fooanb (foo #:b? #f)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require (planet shawnpresser/racket-unix-sockets) | |
"communicate.rkt") | |
(define-values (i o) | |
(unix-socket-connect socket-path)) | |
(communicate i o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require racket/class | |
racket/list | |
racket/format | |
;racket/gui ;for message-box | |
) | |
(define non-word-str "\"'`,;\r\n\t (){}[]") | |
(define non-word-chars (string->list non-word-str)) | |
(define non-word-re (regexp-quote non-word-str)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/gui | |
(require framework) ; for keymap:get-editor | |
(define keymap (keymap:get-editor)) | |
#| ; Or define them yourself: | |
(define keymap (new keymap%)) | |
(add-text-keymap-functions keymap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require racket/sandbox) | |
#| | |
Self-link: http://gist.github.com/Metaxal/5723825 | |
Original idea by Eliezer Yudkowski and Alex Mennen: | |
http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/4ru9 | |
http://lesswrong.com/lw/hmx/prisoners_dilemma_with_visible_source_code/ |
OlderNewer