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 / fix-numeric-limits-llvm-10.0.md
Last active February 14, 2024 18:35
[Fix ‘numeric_limits’ is not a member of ‘std’ error in LLVM 10.0] #llvm

Fix ‘numeric_limits’ is not a member of ‘std’ error in LLVM 10.0

This problem has been verified in both of the LLVM 10.0.0 and 10.0.1 releases' monorepos. The problem and fix is shown for 10.0.1, but the patch can be applied to a 10.0.0 monorepo.

Problem

[3273/3351] Building CXX object utils/.../benchmark.dir/benchmark_register.cc.o
FAILED: utils/benchmark/src/CMakeFiles/benchmark.dir/benchmark_register.cc.o 
/usr/bin/c++ -DHAVE_POSIX_REGEX -DHAVE_STD_REGEX -DHAVE_STEADY_CLOCK -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Dbenchmark_EXPORTS -I/home/matthew/llvm-project-10.0.1/build/utils/benchmark/src -I/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src -I/usr/include/libxml2 -I/home/matthew/llvm-project-10.0.1/build/include -I/home/matthew/llvm-project-10.0.1/llvm/include -I/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/include -I/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/../include -fPIC -fvisibility-inlines-hidden 
@colematt
colematt / print_ctrl_chars.c
Last active February 23, 2024 18:42
[Print Control Characters] #c
#include <locale.h>
#include <stdio.h>
#include <wchar.h>
/* REFERENCES
* Control Block: http://unicode.org/charts/PDF/U0000.pdf
* Control Pictures: http://unicode.org/charts/PDF/U2400.pdf
*/
int main(int argc, char* argv[]) {
@colematt
colematt / connecting-remote-ssh.md
Created January 18, 2024 03:22
[Connecting to Remote by SSH] #ssh #linux #windows #macos
@colematt
colematt / Makefile
Last active December 9, 2023 18:56
[CUnit Test Scaffolding] #c #cunit #testing
CFLAGS=-g -Wall -std=c99
LDFLAGS=
LDLIBS=-lcunit
RMFLAGS=-f
all: basic
.PHONY: clean
clean:
$(RM) $(RMFLAGS) basic
@colematt
colematt / twiddle.c
Created November 20, 2023 17:47
[Generate the next number with a given number of set bits] #c
#include <stdint.h> // uint64_t
#include <stdio.h> // printf
uint64_t twiddle(uint64_t x) {
uint64_t smallest, ripple, new_smallest, ones;
if (x == 0)
return 0;
smallest = (x & -x);
ripple = x + smallest;
@colematt
colematt / llvm-docset.md
Last active December 6, 2023 02:02 — forked from broadwaylamb/llvm-docset.md
How to generate an LLVM docset for Dash

How to generate an LLVM docset for Dash

Prerequisites

brew install swiftdocorg/formulae/docsetutil
sudo ln -s /usr/local/bin/docsetutil /Library/Developer/CommandLineTools/usr/bin/docsetutil
brew install doxygen graphviz
@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
Last active December 4, 2025 20:12
Array Recipes

Array Recipes

Get elements from a multi-dimensional array

import functools
import operator
import typing
def arrget(arr:typing.Sequence,pos:tuple[int,...]) -> typing.Any:
 """
@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