Skip to content

Instantly share code, notes, and snippets.

View greghendershott's full-sized avatar

Greg Hendershott greghendershott

View GitHub Profile
@greghendershott
greghendershott / mssql-mysterx-example.rkt
Created February 6, 2011 22:30
Rough example of mysterx <--> ADO <--> Microsoft SQL Server
#lang racket
(require mysterx
racket/date)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; ado-sql-exec-query
;;
;; Note: This will return the rows in reverse order. If you care because you
@greghendershott
greghendershott / bug-example.rkt
Created August 3, 2012 22:52
Problem trying to do non-blocking I/O and reactor loop
#lang racket
;; 1. Run this:
;;
;; racket bug-example.rkt
;;
;; 2. Run ApacheBench:
;;
;; $ ab -n 1000 -c 20 http://localhost:8081/
;;
@greghendershott
greghendershott / problem.rkt
Created November 8, 2012 14:28
Using make-keyword-procedure in a macro
#lang racket
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Scenario 1: Plain function
;;
(define (def-proc ks)
;; Proc that takes a dict?
(define (f/dict d)
@greghendershott
greghendershott / bench.rkt
Created November 9, 2012 15:04
Why is a simple contract so much slower than a check?
#lang racket
(define (f/raw x)
#t)
(define (f/checked x)
(unless (exact-nonnegative-integer? x)
(error 'f/checked "blah blah"))
#t)
@greghendershott
greghendershott / termsheet.rkt
Created November 9, 2012 23:54
A "term sheet" is a light-weight, more casual version of a contract. :)
#lang racket
;; A term sheet is a light-weight, casual version of a contract. :)
;;
;; Seriously, `define/termsheet' takes the same form as
;; `define/contract', but uses the contract predicates as simple
;; checks. As a result, this runs much faster -- e.g. ~200x faster --
;; than a normal, chaperoned wrapped procedure.
;;
;; In other words it gives the declarative convenience of
@greghendershott
greghendershott / with-syntax.rkt
Created November 12, 2012 14:28
with-syntax* ?
#lang racket
;; This has a nested with-syntax
(define-syntax (good stx)
(syntax-case stx ()
[(_ x ...)
(with-syntax ([(y ...) #'(x ...)])
(with-syntax ([(z ...) (generate-temporaries #'(y ...))])
#'(let ([z x] ...)
#t)))]))
#lang racket
(require (for-syntax syntax/parse racket/syntax racket/list racket/match))
;; First, a syntax class to recognize function arguments:
(begin-for-syntax
(define-splicing-syntax-class argspec
#:description "argument"
#:attributes (id def kw)
(pattern id:id #:with kw #f #:with def #f)
#lang racket
(define (bytes->int32s b)
(for/list ([i (in-range 0 (bytes-length b) 2)])
(integer-bytes->integer (subbytes b i (+ i 2)) #t)))
(bytes->int32s #"\206\367\3447\372\245\247\374\341]\35\334\271\352\352\3527vg\270")
;; => '(-2170 14308 -23046 -857 24033 -9187 -5447 -5398 30263 -18329)
@greghendershott
greghendershott / aws.md
Created December 5, 2012 13:52
Hack of text-render.rkt to be markdown-render.rkt, plus an example of output. See comment at the bottom for more info.

Amazon Web Services

1 Introduction                                   
  1.1 Which services?                            
  1.2 Scope                                      
                                                 
2 Names                                          
                                                 
3 AWS Keys                                       

Amazon Web Services

1 Introduction                                   
  1.1 Which services?                            
  1.2 Scope                                      
                                                 
2 Names                                          
                                                 
3 AWS Keys