Skip to content

Instantly share code, notes, and snippets.

@jld
jld / numclients.c
Created April 15, 2021 03:29
Print how many clients the X server has (including this one)
/* Link with -lXRes -lX11 */
#include <X11/Xlib.h>
#include <X11/extensions/XRes.h>
#include <stdio.h>
int main() {
Display *display = NULL;
XResClient *clients = NULL;
egrep -c '\.(cpp|cc|c) ' $(fgrep -l 'ProtocolUtils.h' **/.deps/*.o.pp) | cut -d: -f2 | awk '$1>=1{t+=$1-1}END{print t}'
@jld
jld / anonymized-location.wls
Created April 17, 2020 13:52
Visualization of how not to “anonymize” location data
jitter[] :=
RandomReal[{500, 2500}]*
RotationTransform[RandomReal[{0, 2*Pi}]][{1, 0}]
Table[With[{points = Table[jitter[], 20]},
With[{annuli = Annulus[#, {500, 2500}] & /@ points},
Show[Graphics[{Opacity[0.05], annuli}],
Graphics[{Yellow, Point /@ points, Circle[{0, 0}, 500],
Circle[{0, 0}, 2500]}],
RegionPlot[RegionIntersection @@ Region /@ annuli,
(define (m5 x y)
(cons (+ (* (car x) (car y)) (* 5 (cdr x) (cdr y)))
(+ (* (car x) (cdr y)) (* (cdr x) (car y)))))
(define (q5 x) (m5 x x))
(define (p5 x n)
(cond ((zero? n) '(1 . 0))
((even? n) (q5 (p5 x (/ n 2))))
(#t (m5 x (q5 (p5 x (/ (- n 1) 2)))))))
@jld
jld / snapcraft.yaml
Created December 7, 2018 17:33
Cut-down snapcraft.yaml for hand-repacking a Firefox Try build
name: firefox
version: 65.0a1-20181114194420
summary: Mozilla Firefox web browser
description: Firefox is a powerful, extensible web browser with support for modern web application technologies.
confinement: strict
grade: stable
apps:
firefox:
command: desktop-launch $SNAP/firefox
#!/usr/bin/env python
import os, sys, ctypes
CLONE_NEWNS = 0x00020000
CLONE_NEWUSER = 0x10000000
CLONE_NEWPID = 0x20000000
c = ctypes.CDLL("libc.so.6", use_errno=True)
def errwrap(f):
def wrapped(*args):
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <stdio.h>
#include <string.h>
#define LEN_B 15
#define LEN_C 16
int main() {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LARGENUM 0x80000001
int main()
{
char* buf = malloc(LARGENUM + 1);
memset(buf, 'X', LARGENUM);
extern "C" MOZ_EXPORT int
connect(int sockfd, const struct sockaddr* addr, socklen_t addrlen)
{
static auto sRealFunc =
(int (*)(int, const struct sockaddr*, socklen_t))
dlsym(RTLD_NEXT, "connect");
auto pid = getpid();
if (addr == nullptr) {
SANDBOX_LOG_ERROR("connect[%d]: %d to nullptr", pid, sockfd);
#!/bin/sh
exec qemu-system-x86_64 -enable-kvm \
-monitor stdio \
-hda vidyo.qcow2 \
-m 4096 -smp 4 \
-balloon virtio \
-vga qxl \
-usb \
-device usb-ehci,id=ehci \
-device usb-host,bus=ehci.0,vendorid=0x046d,productid=0x082d \