Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdint.h>
int rdrand(uint32_t *out) {
char rc;
unsigned int val;
__asm__ volatile(
"rdrand %0 ; setc %1"
: "=r" (val), "=qm" (rc)
@andrew-d
andrew-d / nix2-arm-build.sh
Last active February 10, 2021 11:53
Helpful script to build a copy of Nix 2.0 for ARM (arm-linux-gnueabihf)
#!/bin/bash
# USAGE: docker run -t -i --rm -v $PWD:/out ubuntu:16.04 /out/build.sh
set -eu
# Install
install_packages() {
apt-get update && apt-get upgrade -yy
@andrew-d
andrew-d / depsearch.rb
Created June 14, 2012 01:15
Quick hacky recursive gem-dependency search script for Ruby
#!/usr/bin/env ruby
require 'logger'
require 'optparse'
require 'rubygems'
require 'net/http'
require 'net/https'
require 'json'
@log = Logger.new(STDERR)
@andrew-d
andrew-d / httpd.py
Created December 12, 2012 19:35
Threaded or forking HTTP server in Python
#!/usr/bin/env python
import sys
from SocketServer import ThreadingMixIn, ForkingMixIn
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
class ForkingSimpleServer(ForkingMixIn, HTTPServer):
@andrew-d
andrew-d / resolve.sh
Created November 18, 2022 02:52
Extremely hacky set of scripts/instructions to fetch all user profiles from a Twitter archive
#!/bin/bash
set -euo pipefail
main() {
local url
url="$(jq -rc .response.data.url < "$1")"
if [[ -z "$url" ]]; then
echo "EMPTY: $1"
return
{
"datasource": {
"type": "prometheus",
"uid": "l-jz8T47k"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
@andrew-d
andrew-d / freeotp-redisplay.py
Created September 21, 2016 07:35
Read a FreeOTP tokens.xml file and display the entries as QR codes
#!/usr/bin/env python
from __future__ import print_function
import base64
import ctypes
import json
import subprocess
import sys
import xml.etree.ElementTree as ET
@andrew-d
andrew-d / set-power-uuid.sh
Created May 27, 2019 21:42
Bash script to set INT3400 Thermal zone power profile
#!/bin/bash
set -eu
die() {
echo "$1" >&2
exit 1
}
@andrew-d
andrew-d / main.c
Last active April 29, 2024 17:01
Example of how to get current binary's path using Apple's Code Signing Services
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <Security/Security.h>
// Compile with:
// gcc -o ourpath -framework CoreFoundation -framework Security main.c