Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"runtime"
"time"
)
func waitAround(die chan bool) {
<- die
@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
}
}
}
@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
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)
local ffi = require("ffi")
ffi.cdef[[
typedef long time_t;
typedef struct timeval {
time_t tv_sec;
time_t tv_usec;
} timeval;
@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]
@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 / loc_parser.go
Created March 27, 2014 13:43
DNS LOC textual record parser
// loc_parser: functions to parse the textual part of a LOC record
// stored in our DNS. The key function here is parseLOCString which
// should be passed a dns.LOC and a string containing the latitude,
// longitude etc.
//
// This is an implementation of RFC 1876. Read it for background as
// the format in a dns.LOC is slightly unusual.
//
// Copyright (c) 2014 CloudFlare, Inc.
@jgrahamc
jgrahamc / parallel
Last active November 19, 2019 22:38
all: | parallel ; @echo $(JOB_COUNT)
parallel: .parallel ; @$(eval JOB_COUNT := $(shell sort -n $< | tail -n 1))
.parallel: FORCE ; @$(MAKE) --no-print-directory par 2>/dev/null >$@ || true
FORCE:
to_n = $(words $2) $(if $(filter-out $1,$(words x $2)),$(call to_n,$1,x $2))
PAR_COUNT :=
par: $(addprefix par-,$(call to_n,32))
$(call to_n,4) = $(words ) $(if $(filter-out 4,$(words x )),$(call to_n,4,x )) # $1 == 4, $2 is blank
= 0 $(if $(filter-out 4,1),$(call to_n,4,x )) # $(filter-out 4,1) is 1
= 0 $(if 1,$(call to_n,4,x )) # So the $(call) will happen
= 0 $(call to_n,4,x )
= 0 $(words x ) $(if $(filter-out 4,$(words x x )),$(call to_n,4,x x ))
= 0 1 $(if $(filter-out 4,2)),$(call to_n,4,x x )) # $(filter-out 4,2) is 2
= 0 1 $(if 2,$(call to_n,4,x x)) # So the $(call) will happen
= 0 1 $(call to_n,4,x x)
= 0 1 $(words x x ) $(if $(filter-out 4,$(words x x x)),$(call to_n,4,x x x ))
= 0 1 2 $(if $(filter-out 4,3),$(call to_n,4,x x x )) # $(filter-out 4,3) is 3