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.
View quic-cleanup.pl
# 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
View to_n
$(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
View dksslcheck.go
// Copyright (c) 2014 John Graham-Cumming
//
// Takes a CSV containing rows in the form
//
// ip,name
//
// Connects to 'ip' on port 443 using TLS presenting the SNI name 'name' and
// verifies the result.
package main
@jgrahamc
jgrahamc / 1000.pde
Created May 12, 2015 16:49
Draws a picture with 9,999 red squares and one green one
View 1000.pde
int b = 100;
int s = 640;
int w = b*(s/b);
int h = w;
void setup() {
background(0);
size(w, h);
int side = w/b - 1;
int x;
@jgrahamc
jgrahamc / 64k.c
Last active August 29, 2015 14:21
View 64k.c
#include "stdint.h"
#include "stdio.h"
void main(int argc, void *argv[]) {
uint64_t i;
for (i = 0; i < 2^32; i++) {
uint32_t x = (uint32_t)i;
uint32_t l = (-x-1) & 0xffff;
uint32_t r = ~x & 0xffff;
if (l != r) {
View vigenere.pl
use strict;
use warnings;
my @alpha = split('', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
my %frequencies = ( 'A' => 84, 'B' => 23, 'C' => 21, 'D' => 46, 'E' => 116,
'F' => 20, 'G' => 25, 'H' => 49, 'I' => 76, 'J' => 2,
'K' => 5, 'L' => 38, 'M' => 34, 'N' => 66, 'O' => 66,
'P' => 15, 'Q' => 2, 'R' => 64, 'S' => 73, 'T' => 81,
'U' => 19, 'V' => 11, 'W' => 21, 'X' => 2, 'Y' => 24,
View vertical.go
func doMightError() (err error) {
if err = doFirst(); err != nil {
return
}
if err = doSecond(); err != nil {
return
}
if err = doThird(); err != nil {
View switch.go
func doMightError() (err error) {
switch {
case !doFirst(&err):
case !doSecond(&err):
case !doThird(&err):
default:
moreStuff()
}
return
@jgrahamc
jgrahamc / gist:3039932
Created July 3, 2012 14:08
Counting ID generator
View gist:3039932
id := make(chan string)
count := make(chan int)
go func() {
h := sha1.New()
w := counter.New(h)
c := []byte(time.Now().String())
w.Write(c)
for {
select {
@jgrahamc
jgrahamc / gist:3058887
Created July 6, 2012 08:15
Alan Turing script
View gist:3058887
use strict;
use warnings;
use WWW::Mechanize;
use DB_File;
my %signed;
tie %signed, "DB_File", "signed", O_RDWR|O_CREAT,
0666, $DB_HASH or die "Failed to open signed\n";