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 / get-llvm10.md
Last active November 15, 2023 19:26
[Get LLVM-10 prebuilt binaries and libraries] #llvm
export PROJ_ROOT=$(pwd)
mkdir -p llvm && cd llvm

# Using Ubuntu 18.04 Prebuild Toolchain from https://releases.llvm.org/download.html
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz \
     https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz.sig \
     https://releases.llvm.org/10.0.0/hans-gpg-key.asc
gpg --import hans-gpg-key.asc
gpg --verify clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz.sig clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
@colematt
colematt / array-recipes.md
Created November 4, 2023 01:54
Array Recipes

Get elements from a multi-dimensional array

import functools
import operator
def arrget(array,tup):
	'''
	Given a tuple containing the dimensional indices, retrieve that element from a multi-dimensional array
	'''
	return functools.reduce(lambda arr, idx: operator.getitem(arr,idx), tup, array)
@colematt
colematt / allocating-multidimensional-arrays.md
Last active October 15, 2023 20:07
Allocating Multi-dimensional Arrays in C

Allocating Multi-dimensional Arrays in C

This gist was inspired by the Geeks for Geeks' writeup How to dynamically allocate a 2D array in C? by Abhay Rathi. It has been formatted to remove interstitial ads, provide a fixed URL for links, and to modify the problem statement to match that which is commonly used in Hackerrank/Grind75/LeetCode/ACM problems where the input must be read from standard input.

Problem

We want to read input from standard input, where the nature of the input is as follows:

  • On line 1, $R$: the number of rows, and $C$: the number of columns in a 2D array, space-separated and newline-terminated.
  • On lines 2 through $R+1$, the row's columns, space-separated and newline-terminated.
@colematt
colematt / where-does-compiler-find-headers.md
Created October 3, 2023 01:57
Where Does the C/C++ Compiler Find Header Files?

Where does the C/C++ Compiler Find Header Files?

Ask the Preprocessor

GNU

# GNU C++ preprocessor
`gcc -print-prog-name=cc1plus` -v
# GNU C preprocessor
@colematt
colematt / adding-programs-system-calls-xv6.md
Last active October 3, 2023 20:23
Adding Programs and System Calls to XV6

Adding Programs and System Calls to XV6

Adding Userspace programs

To add a userspace program that can be executed in xv6 shell, make the following additions/edits:

program.c

  1. Include the headers needed to gain access to system call wrapper prototypes: types.h, user.h.
  2. If you need access to struct stat, include its header: stat.h
@colematt
colematt / fix-apt-key-deprecation-warnings.md
Last active August 23, 2023 21:41
[Fix apt-key deprecation warnings] #ubuntu

When updating using apt-update, you get the following warnings:

$ sudo apt update
[sudo] password for matthew: 
...
Hit:10 https://packagecloud.io/slacktechnologies/slack/debian jessie InRelease                   
Fetched 9,870 B in 1s (7,957 B/s)
Reading package lists... Done
Building dependency tree... Done
@colematt
colematt / beamer-bib.tex
Created August 8, 2023 21:07
[Creating Beamer Bibliographies] #latex #beamer
\documentclass{beamer}
\begin{document}
\begin{frame}
\begin{thebibliography}{9}
\setbeamertemplate{bibliography item}[online]
\bibitem{A} ItemA
\setbeamertemplate{bibliography item}[book]
\bibitem{B} ItemB
@colematt
colematt / timeout_context.py
Created May 2, 2023 15:34
[Timeout a Long Running Function] #python3
import signal
import time
class timeout:
def __init__(self, seconds=1, error_message='Timeout'):
self.seconds = seconds
self.error_message = error_message
def handle_timeout(self, signum, frame):
raise TimeoutError(self.error_message)
def __enter__(self):
@colematt
colematt / get-date-and-time-of-history.md
Last active March 21, 2023 22:42
[Get Date and Time of a History Event] #bash #linux

Get Date and Time of a History Event

By default, history will only give an event designator and command line entry. Unless the event reference is absolute, the events are relative to the current position in the history list.

history
 1995  ls S*.pdf
 1996  ls -lh S*.pdf
 1997  xdg-open System_01Jun2018_30Jun2018_0133*.pdf
 1998  ssh matthew@localhost
@colematt
colematt / keybase.md
Created November 14, 2022 16:43
keybase.md

Keybase proof

I hereby claim:

  • I am colematt on github.
  • I am colematthew (https://keybase.io/colematthew) on keybase.
  • I have a public key ASArTG7xdS6WqkVEnPIuqXqZ_8Ur79INXvBpEfq4lykRPQo

To claim this, I am signing this object: