Skip to content

Instantly share code, notes, and snippets.

@ksurent
ksurent / silly.go2
Last active December 6, 2020 19:34
Silly Go–with–generics (FGG) program to demonstrate the syntax.
package main
import "fmt"
func Fold(type T, U)(acc T, f func(T, U) T, xs []U) T {
for _, x := range xs {
acc = f(acc, x)
}
return acc
@ksurent
ksurent / bf.rs
Last active May 7, 2023 16:41
Toy Brainfuck interpreter in Rust.
use std::fmt;
use std::io;
use thiserror::Error;
fn main() {
let mut bf = Bf::new(1000, true);
let mut input = String::new();
loop {
match io::stdin().read_line(&mut input) {
Ok(0) => return,
@ksurent
ksurent / cpan-typosquatting.rs
Last active July 19, 2023 19:23
A silly program that finds CPAN modules that could be deliberate typos. See https://threatpost.com/attackers-use-typo-squatting-to-steal-npm-credentials/127235/.
// Download index file: wget https://www.cpan.org/modules/02packages.details.txt.
use std::{
collections::HashSet,
fmt::Display,
fs::File,
io::{self, BufReader},
};
fn main() -> io::Result<()> {
@ksurent
ksurent / pdeathsig.py
Last active June 14, 2020 15:04
Simple test case for Linux's PR_SET_PDEATHSIG
#!/usr/bin/env python3
import os
import sys
import time
import prctl
import signal
def do_the_thing():
pid = os.fork()
@ksurent
ksurent / fuzz.go
Created November 24, 2019 19:43
A toy grammar–based fuzzer for bookingcom/carbonapi. Heavily inspired by The Fuzzing Book.
package main
import (
"flag"
"fmt"
"math"
"math/rand"
"os"
"runtime/debug"
"strings"
@ksurent
ksurent / nc.go
Created September 4, 2019 20:31
A simple netcat-like utility written as a coding exercise
package main
import (
"flag"
"fmt"
"io"
"log"
"net"
"os"
"time"
@ksurent
ksurent / wq.go
Last active August 21, 2018 10:24
A simple simulation to see how client-go's workqueue behaves in presence of stuck consumers
package main
import (
"log"
"math/rand"
"net/http"
"os"
"os/signal"
"time"
@ksurent
ksurent / ssadump.go
Last active December 16, 2023 17:30
Print Go's SSA form, much like ssadump but with concrete types
package main
import (
"flag"
"fmt"
"go/build"
"go/types"
"os"
"golang.org/x/tools/go/loader"
@ksurent
ksurent / strace.go
Last active February 2, 2020 22:36
A toy strace clone for my p2p study group
package main
// heavily inspired by https://blog.nelhage.com/2010/08/write-yourself-an-strace-in-70-lines-of-code/
import (
"errors"
"fmt"
"log"
"os"
"strconv"
use v5.14; [6/1836]
use warnings;
use IO::Socket;
use POSIX qw(:sys_wait_h);
my($ip, $host) = @ARGV;
my $sock = IO::Socket::INET->new(
PeerAddr => "$ip:80",