Skip to content

Instantly share code, notes, and snippets.

@adriansr
adriansr / compare-golden.py
Created February 4, 2019 17:29
Compare two -expected.json ES events
# Usage:
# compare-golden-events.py <old.json> <new.json>
import json
import sys
def missing(keys, dct):
r = []
for key in keys:
# Anonymize IPTABLES logs for documentation!
import os
import re
import sys
random_macs = set()
macs = {}
@adriansr
adriansr / remdog.py
Created December 10, 2018 11:36
Delete all Pull Request comments from HoundCI user
import json
import requests
REPO='user/repo'
PULL= # PULL_REQUEST_ID (1234)
USER_TO_DELETE='houndci-bot'
TOKEN=YOUR_GITHUB_API_TOKEN
headers = { 'Authorization': 'token ' + TOKEN }
@adriansr
adriansr / syscall_stress.go
Last active January 4, 2022 15:19
Call a syscall in a loop, optionally limiting the number of calls per second
package main
import (
"sync/atomic"
"fmt"
"os"
"strconv"
"syscall"
"time"
)
@adriansr
adriansr / svg2icns.sh
Created February 19, 2018 15:21
Convert SVG file to macOS icon (icns) format
#!/bin/sh -x
set -e
SIZES="
16,16x16
32,16x16@2x
32,32x32
64,32x32@2x
128,128x128
@adriansr
adriansr / pkgcleanup.sh
Created February 6, 2018 22:10
Uninstall macOS pkg removing all files
#!/bin/bash
die() {
echo "error: $@" >&2
exit 1
}
test "$#" -gt 0 || die "Usage: $0 <package identifier>"
test "$(uname -s)" = "Darwin" || die "Must be run under macOS"
test $(id -u) -eq 0 || die "Must be root"
@adriansr
adriansr / main.go
Created January 11, 2018 14:56
GetExtendedTcpTable golang
// +build windows
package main
import (
"encoding/binary"
"encoding/hex"
"fmt"
"syscall"
"time"
@adriansr
adriansr / wherefroms.go
Created December 21, 2017 00:35
Read kMDItemWhereFroms in Go
package main
/*
#include <stdlib.h>
#include <sys/xattr.h>
*/
import "C"
import (
"fmt"
@adriansr
adriansr / codegen.py
Last active August 1, 2017 09:51
REST resource code gen
import sys
# Writes the body of a REST resource
# input is a list of <type> <name> variables, one per line:
# i.e:
# String nwDstAddress
# int nwDstLength
# UUID[] inPorts
# [...]
# helloWorld => HELLO_WORLD
@adriansr
adriansr / RaceMain.scala
Last active February 2, 2017 16:55
Akka actor creation/deletion race-condition
package adriansr.test
import scala.util.control.NonFatal
import akka.actor.{Actor, ActorRef, ActorSystem, InvalidActorNameException, Props}
case class Test(name: String, retries: Int, delay: Long)
case class Create(iter: Long, cfg: Test)
case class Remove(iter: Long, actor: ActorRef, cfg: Test)