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 / Snort-User-Defined-Language-in-Notepad.md
Created February 14, 2025 20:23
[Snort User Defined Language Schema] #snort #npp

Snort User Defined Language (UDL) in Notepad++ 1

I recently created a Snort “User Defined Language” in Notepad++ and wanted to share both the schema, what it looks like, and the steps necessary to create it.

To start, if not already done, you should download and install Notepad++ from here. It does not matter which package you choose so long as you remember where it is installed and/or where you placed the install folder.

Next, in order for the parser for Snort to work, we will need to install UDL2 from here. The download consists of two files (Notepad2++.exe and SciLexer2.dll) whi

Footnotes

  1. This writeup by Caleb Jaren, originally posted at http://www.tropismgroup.org/2012/08/02/snort-user-defined-language-udl-in-notepad/ on 02 August 2012.

@colematt
colematt / filesig.py
Created February 3, 2025 19:26
[Determine file type from magic numbers] #python3
#!/usr/bin/env python3
import sys
import os.path
def isELF(path):
with open(path, "rb") as fp:
return tuple(fp.read(4)) == (0x7F, 0x45, 0x4C, 0x46)
def isUniversalMachO(path):
@colematt
colematt / transforms.py
Created December 5, 2024 04:14
[Matrix Transformations Without Numpy] #python
#!/usr/bin/env python3
def transpose(matrix):
"Swap the rows and columns of a 2-D matrix."
return [list(row) for row in zip(*matrix, strict=True)]
def rotate(matrix):
"""
Rotate a matrix 90 degrees clockwise
@colematt
colematt / landscape-tabular.tex
Created June 27, 2024 02:56
[Lanscape, Full-page Tabular] #latex
% LaTeX tabular which is oriented in landscape and takes the entire page
\begin{landscape}
\begin{table}[h]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{|c|c|c|}
\hline
Header 1 & Header 2 & Header 3 \\ \hline
Item 1 & Item 2 & Item 3 \\ \hline
Item 4 & Item 5 & Item 6 \\ \hline
@colematt
colematt / run-app-in-dark-mode.md
Created June 20, 2024 02:41
[Run an app in dark or light mode without changing global GNOME settings] #linux #gnome

Pass the GTK_THEME environment variable to the app:

$ GTK_THEME=<theme> <path>

You can replace <theme> with any available theme:

$ ls /usr/share/themes
@colematt
colematt / next_pow_2.c
Created April 3, 2024 23:07
[Get the next power of 2 of an unsigned integer] #c
// Assuming 64-bit long
unsigned long np2(unsigned long x) {
--x;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x |= x >> 32;
++x;
@colematt
colematt / get_locale.c
Created February 26, 2024 19:03
[Get locale as a string] #c
#include <locale.h>
#include <stdio.h>
int main(int argc, char* argv[]){
setlocale(LC_ALL, "");
printf("LC_ALL: %s\n", setlocale(LC_ALL, NULL));
printf("LC_CTYPE: %s\n", setlocale(LC_CTYPE, NULL));
return 0;
@colematt
colematt / determine-if-a-package-is-installed.sh
Created February 21, 2024 17:26
[Determine if a package is installed] #apt #ubuntu
# Check to see if a package named ansible is installed
if [ "$(dpkg -l | awk '/ansible/ {print }'|wc -l)" -ge 1 ]; then
echo OK
else
echo FAIL
fi
@colematt
colematt / randstr.c
Created February 18, 2024 22:11
[Get a random word from wordnet] #c
// sudo apt update && apt install wordnet-dev
#include <stdio.h>
#include <stdlib.h>
char *pickword(char *file)
{
FILE *fp = fopen(file, "r");
if (!fp) perror(file), exit(1);
fseek(fp, 0, SEEK_END);
long end = ftell(fp);
@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