Skip to content

Instantly share code, notes, and snippets.

@dyoo
dyoo / keystate.rkt
Created October 15, 2012 14:44
record full keyboard state in a racket/gui window
#lang racket/base
(require racket/gui/base
racket/class
racket/pretty)
(struct keyboard-state (alt-down? shift-down? control-down? meta-down? caps-down?
keys-down)
#:inspector (make-inspector))
;; Try to record the state of the keymap by watching on-subwindow-char
@dyoo
dyoo / cantor_pairing.go
Last active October 27, 2021 19:20
Cantor pairing function
// http://en.wikipedia.org/wiki/Pairing_function
package main
import (
"fmt"
"math"
)
func InvertedCantorPairing(z int) (int, int) {
w := int(math.Floor((math.Sqrt(float64(8*z+1)) - 1) / 2))
@dyoo
dyoo / mergesort.rkt
Created November 12, 2012 00:24
mergesort using the same trick as SICP 2.64 to avoid intermediate random access vector
#lang racket
;; Implementation of a mergesort on lists, while avoiding intermediate
;; vector construction. Uses the same trick as that in SICP Exercise
;; 2.64 to keep track of the elements we haven't yet processed.
(provide mergesort)
(define (mergesort elts)
@dyoo
dyoo / letsencrypt-GAE.md
Created July 16, 2017 22:48
Set up HTTPS for Google App Engine using Let's Encrypt

Copied from https://www.jeffgodwyll.com/posts/2016/letsencrypt

Let’s Encrypt is a free, automated, and open certificate authority (CA), run for the public’s benefit. Let’s Encrypt is a service provided by the Internet Security Research Group (ISRG)

About Let's Encrypt

This post won't go into details as to what Let's Encrypt is about. We should probably read the FAQs if we want to learn more.

Until the Google App Engine Team fully automate the process of using Let's Encrypt on Google App Engine or even provide some sort of API to handle certs, we'll probably have to find ways of either automating the process just a little bit or stick to some other easier cert authority.

// The curse of a programmer; if you read articles with data,
// you continuously fight the temptation to write a program to
// play with that data. In this case, I failed.
package main
import (
"fmt"
"math"
)
@dyoo
dyoo / .emacs
Created September 22, 2013 04:16
My current .emacs on my Mac OS X laptop
;; These are the settings I'm using for Emacs on my Mac laptop.
;; Turn off the splash screen.
(setq inhibit-splash-screen t)
;; Set the Command key to work like meta.
;; http://superuser.com/questions/297259/set-emacs-meta-key-to-be-the-mac-key
(setq mac-option-key-is-meta nil
mac-command-key-is-meta t
@dyoo
dyoo / count_t_words_1.go
Last active December 22, 2015 02:59
More play with Go. A question from reading Barry Schwartz's "The Paradox of Choice": how many English words start with 't', and how many have 't' as the third letter?
package main
// A question from reading Barry Schwartz's "The Paradox of Choice".
//
// How many English words start with "t"?
//
// How many English words have "t" as the third letter?
import (
"bufio"
@dyoo
dyoo / count_t_words_2.go
Last active December 22, 2015 02:59
A second version of the program in https://gist.github.com/dyoo/6407562. Make simple things more complicated! :P
package main
// A question from reading Barry Schwartz's "The Paradox of Choice".
//
// How many English words start with "t"?
//
// How many English words have "t" as the third letter?
import (
"bufio"
@dyoo
dyoo / sort_func.go
Created August 11, 2013 20:28
More play with Go; sorting with a comparison function. It's interesting to note that we have to do type conversions that we wouldn't have to do if we were to go along the grain of the sort.Sort() function.
package main
import (
"fmt"
"sort"
)
type ComparableSlice struct {
elts []interface{}
cmp func(interface{}, interface{}) bool
@dyoo
dyoo / sort.go
Created July 25, 2013 19:59
A few notes on how to use Go's sort, and observation on how the language features interact.
// A little bit of play with Go's sorting routines, coupled with
// type system stuff.
// Let's say that we'd like to sort a list of numbers in reverse
// order. (and pretend that we know about sort.Sort(), but neglected
// to read about sort.Reverse(). Let's start this off:
package main
import (