Skip to content

Instantly share code, notes, and snippets.

View colematt's full-sized avatar
:shipit:
Secret Squirrel

Matthew Cole colematt

:shipit:
Secret Squirrel
View GitHub Profile
@colematt
colematt / Aloof.py
Last active November 1, 2022 20:26
[Use Wagner-Fischer algorithm to find aloof words] #algorithms #python3
#!/usr/bin/python3
# Aloof.py
# Created by Matthew Cole on 3/1/15.
"""
A word is ALOOF if and only if it has no words which differ from it by only one letter.
"""
def LDistance(str1, str2):
"""
@colematt
colematt / partition.py
Last active September 2, 2020 21:13
[Partition a set into a ordered set of disjoint subsets] #python
#!/usr/bin/python3
"""
File: partition.py
Author: Matthew Cole
Date: 6/7/16
"""
def partition(collection, partitions):
"""
@colematt
colematt / python-check.py
Last active November 1, 2022 20:24
[Check your python implementation from a running script] #python
#!/usr/bin/env python3
"""
File: python-check.py
Author: Matthew Cole
Date: 28 Nov 2016
"""
import sys, os
if __name__ == "__main__":
@colematt
colematt / input.txt
Last active September 10, 2020 15:55
[Using Context Managers for File I/O] #python #python3
Line 1
Line 2
Line 3
@colematt
colematt / runproc.py
Last active November 1, 2022 20:25
[Run a process as a subprocess of the python interpreter] #python3
import argparse
import subprocess
import sys
"""
Run a command and its arguments as a subprocess of the python interpreter.
"""
if __name__ == "__main__":
@colematt
colematt / Makefile
Last active February 9, 2022 17:50
[Storing pointers in Thread-Specific Storage across process boundaries] #tss #pthreads #linux
PWD := $(shell pwd)
CFLAGS := -g -Wall
LDFLAGS := -L=. -Wl,-rpath=.
all: tss-fork
tss-fork: tss-fork.c
$(CC) $(CFLAGS) tss-fork.c -o tss-fork -pthread
.PHONY: clean
@colematt
colematt / Polite shell aliases.md
Last active February 12, 2020 18:25
Lazy commands for the Bash shell.

Re-run the last command with root privilege.

alias please='sudo $(history -p !!)'

Re-run the last command saying yes to all interactive questions.

alias really='yes | $(history -p !!)'
@colematt
colematt / Makefile
Last active September 24, 2017 23:37
Using Preprocessor Directives for Troubleshooting
CFLAGS:= -g -Wall -std=c99
LDFLAGS:= -lc
all: main
main: main.c
$(CC) $(CFLAGS) $^ -o $@
.PHONY: clean
clean:
rm -fv main
@colematt
colematt / .Building-a-SPEC-CPU2017-Sandbox.md
Last active January 18, 2024 17:49
Building a SPEC CPU 2017 Sandbox

Motivation

You may want to build a sandbox if one or more of these sound familiar:

  • You want to build recognizable, representative binaries instead of toy programs for experimentation, but you also don't want the overhead of the actual SPEC CPU2017 benchmark suite, nor a script to manage the binaries' execution.
  • You want to modify the source code of the benchmarks without corrupting the SPEC CPU2017 source tree. Modifying the source code is allowed if you use the strict_rundir_verify=no option in your configuration file, or if you create a modified installation of the benchmark using the convert_to_development utility. But an easier option is to create sandboxes for each benchmark program you wish to investigate, and it doesn't corrupt the source tree if you're reusing it with other experiments.
  • You want to modify the options or inputs provided to the benchmarks to investigate how the benchmark binaries respond.

About SPEC CPU2017

@colematt
colematt / .Adding-Sections-to-Elf-Binaries.md
Last active March 1, 2024 20:04
[Add a section to an ELF binary] #llvm

Adding Sections to ELF Binaries

Suppose you need to add a section to an ELF binary to contain information gathered at compile time, but to be used at link time or run time. Here's how to add a section named .okdata and either populate it with data either after or before emitting the ELF binary.

Adding a Section After Emitting

In this case, you'll add file’s contents to an already existing binary. objcopy copies and translates object files, such that adding a new section is a matter of writing that new section’s contents into the ELF file.

(Optional) Create a simple program’s object file.