Skip to content

Instantly share code, notes, and snippets.

@jgrahamc
jgrahamc / quic-cleanup.pl
Created February 17, 2014 15:27
Script to take the files generated by wget -mkp --save-headers and remove headers that confuse quic_server and at the X-Original-Url header.
# quic-cleanup.pl
#
# When running the Google experimental quic_server it expects to find
# sites to serve in /tmp/quic-data. Under that there will be a
# directory per site.
#
# For example this was used to mirror the CloudFlare web site for
# QUIC testing.
#
# mkd
@jgrahamc
jgrahamc / rsa.pl
Created July 5, 2013 11:39
RSA with exponent of 65537 and 1
% perl rsa.pl rsa65537.key
Exponent 65537
Plaintext [2374623765656]
Ciphertext [54189570645149678794693940654778175623133064659696656007570945283886977179371080120152561977021117382440218161492193509392092366273501288958199326710633675404929026067821522578649296730459190572345487456189328545191187492476957378888329005173000564263384860107839239781974940823115540499210407765338815164272]
% perl rsa.pl rsa1.key
Exponent 1
Plaintext [2374623765656]
Ciphertext [2374623765656]
local ffi = require("ffi")
ffi.cdef[[
typedef long time_t;
typedef struct timeval {
time_t tv_sec;
time_t tv_usec;
} timeval;
local profiler = require 'lulip'
local p = profiler:new()
p:dont('some-module')
p:maxrows(25)
p:start()
-- execute code here
p:stop()
p:dump(output_file_name)
@jgrahamc
jgrahamc / counter.lua
Created April 3, 2013 12:55
Lua array insertion performance tests.
local t = {}
local c = 1
for i=1,5000000 do
t[c] = i
c = c + 1
end
@jgrahamc
jgrahamc / slide10.go
Last active December 15, 2015 12:48
The code associated with this talk: http://www.slideshare.net/jgrahamc/go-oncurrency
func worker(die chan bool) {
for {
select {
// ... do stuff cases
case <- die:
return
}
}
}
package main
import (
"fmt"
"runtime"
"time"
)
func waitAround(die chan bool) {
<- die
@jgrahamc
jgrahamc / gist:5137943
Created March 11, 2013 21:29
A system to save the location (line number) of every file edited with Emacs and let the user jump there with C-l
(setq last-location-file (concat my-emacs-d "/last-location"))
(defun load-last-location-file ()
(if (file-exists-p last-location-file)
(read (with-temp-buffer
(insert-file-contents last-location-file)
(buffer-string)))
(make-hash-table :test 'equal)))
(setq last-location-table (load-last-location-file))
package counter
import (
"io"
)
type Counter struct {
w io.Writer // Underlying writer to send data to
c int // Number of bytes written since last call to Count()
}
func redirect(to string, from *os.File) (err error) {
if out, err := os.Create(name); err == nil {
err = syscall.Dup2(int(out.Fd()), int(from.Fd()))
} else {
err = fmt.Errorf("Unable to create file %s", to)
}
return
}