This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Chat is a TCP server that connects couples so they can talk. | |
// Adapted from https://go.dev/talks/2012/chat.slide | |
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"net" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fibsrv is an HTTP server that calculate Fibonacci numbers. | |
package main | |
import ( | |
"fmt" | |
"log" | |
"math/big" | |
"net/http" | |
"strconv" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fetch prints the download time and size for each URL. Usage: | |
// | |
// go build fetchz.go | |
// ./fetchz urls.txt | |
package main | |
import ( | |
"bufio" | |
"fmt" | |
"io" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse, hashlib, sys | |
from pathlib import Path | |
def store(path, data, key): | |
data_path = Path(path) | |
hash_path = data_path.with_suffix('.hash') | |
hash_value = hashlib.blake2b(data, key=key).hexdigest() | |
with data_path.open(mode='x'), hash_path.open(mode='x'): | |
data_path.write_bytes(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import hashlib, sys | |
from hashlib import md5 | |
def hash_with_all_guaranteed_algoritms(msg: bytes): | |
"""hash functions guaranteed to be available for all platforms""" | |
for algo in sorted(hashlib.algorithms_guaranteed): | |
try: | |
h = hashlib.new(algo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
subnet=$1 | |
[ -z $subnet ] && echo "Usage: $0 <subnet>" && exit 1 | |
for host in $(seq 1 254); do | |
(ping -c1 -t1 $subnet.$host > /dev/null && arp $subnet.$host) & | |
done | |
sleep 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
start := time.Now() | |
go func() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pathresolver handles complex URL paths with wildcards. | |
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"path" | |
"strings" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Rball simulates a game of racquetball to find out whether | |
a slightly better player can win significant number of games. | |
*/ | |
package main | |
import ( | |
"flag" | |
"fmt" | |
"math/rand" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A common use case for Go is to take a stream of jobs of work and perform them | |
// automatically scaling up and down as work becomes available. | |
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"net/http" | |
"os" |
NewerOlder