Skip to content

Instantly share code, notes, and snippets.

View greghendershott's full-sized avatar

Greg Hendershott greghendershott

View GitHub Profile
#lang racket/base
(require openssl
racket/contract)
(provide ports->tls-ports/accept
ports->tls-ports/connect)
(define pem (build-path (collection-path "openssl") "test.pem"))
(define server-ctx (ssl-make-server-context 'tls12))
@greghendershott
greghendershott / trace.log-rkt
Last active October 25, 2018 22:48
Make racket/trace output go to a logger
#lang racket/base
(require racket/format
racket/list
racket/match
racket/trace)
(provide (all-defined-out)
(all-from-out racket/trace))

-*- mode:org ; mode:visual-line -*-

Hack && Tell 6 Boston

What is a “debugger”?

Specifically a “step debugger”?

A program that runs your program, letting you

  • Pause execution (“break”) at steps of its evaluation (“breakpoints”)
Say that /tmp/ex.rkt is
#lang racket
(define x 42)
x
Now:
$ racket
Welcome to Racket v6.10.
#lang racket/base
(require racket/match)
(define (combining xs pred?)
(let loop ([xs xs])
(match xs
[(list* (? pred? this) (? pred? next) more)
(loop (cons (string-append this next) more))]
[(cons this more)
(url
"http"
#f
"bttracker.debian.org"
6969
#t
(list (path/param "announce" '()))
'((info_hash . ";\u001D��x\u000E���S���zc�R�1�")
(peer_id . "-TR4940-i750j7wqz8tu")
(uploaded . "0")
@greghendershott
greghendershott / in-value.rkt
Created August 6, 2018 14:42
in-value exaple
#lang racket/base
(define (expensive-or-complicated v)
v) ;not really, but for example
(for*/list ([x (in-list '(1 2 3 4))]
[y (in-value (expensive-or-complicated x))]
#:unless (odd? y))
y)
;; '(2 4)
#lang racket/base
(module m racket/base
(provide (struct-out exn:fail)
(rename-out [exn-message exn:fail-message]
[exn-continuation-marks exn:fail-continuation-marks])))
(require 'm)
(define e (exn:fail "foo" (current-continuation-marks)))
@greghendershott
greghendershott / pkgs.md
Created November 11, 2015 20:05
Some interesting Racket packages

Sound and Vision

identikon

rsound

Testing and Coverage

rackunit-chk

@greghendershott
greghendershott / gist:5223970
Last active January 20, 2018 15:45
Using `with-handlers` to catch exceptions.
#lang racket
;; The way to catch exceptions is `with-handlers`.
;; See http://docs.racket-lang.org/reference/exns.html
;;
;; You specify the type of exception, and a function to handle it. The
;; exception object is passed to the function.
;;
;; For exmaple, we'll catch the "generic" `exn:fail?` with a function
;; that we define in-place using `lambda`: