Skip to content

Instantly share code, notes, and snippets.

func doMightError() (err error) {
switch {
case !doFirst(&err):
case !doSecond(&err):
case !doThird(&err):
default:
moreStuff()
}
return
func doMightError() (err error) {
if err = doFirst(); err != nil {
return
}
if err = doSecond(); err != nil {
return
}
if err = doThird(); err != nil {
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,
@jgrahamc
jgrahamc / 64k.c
Last active August 29, 2015 14:21
#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) {
@jgrahamc
jgrahamc / 1000.pde
Created May 12, 2015 16:49
Draws a picture with 9,999 red squares and one green one
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;
// 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
$(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
@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))
@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 / 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