Skip to content

Instantly share code, notes, and snippets.

@Rhomboid
Rhomboid / nouns.txt
Created August 20, 2016 11:29
WordNet nouns list
This file has been truncated, but you can view the full file.
'hood
's Gravenhage
.22
0
1
1 Chronicles
1 Esdras
1 Kings
1 Maccabees
1 Samuel
@Rhomboid
Rhomboid / bench.py
Created June 5, 2016 09:04
Uniqueness functions that preserve order in Python
import random
import itertools
import timeit
import re
def f1(seq):
''' continue '''
seen = set()
result = []
for item in seq:
@Rhomboid
Rhomboid / tokenize.c
Created April 2, 2016 17:02
string tokenization in C with dynamic memory
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
size_t tokenize(const char *s, const char *delim, char ***tokenarray)
{
size_t size = 0, capacity = 4, wordlen;
const char *begin = s, *end;
char **tokens = malloc(capacity * sizeof(char *));
@Rhomboid
Rhomboid / process_access_rights.txt
Created March 2, 2016 08:53
Summary of Win32 Process Access Rights
https://msdn.microsoft.com/en-us/library/windows/desktop/aa446632.aspx // Generic Access Rights
https://msdn.microsoft.com/en-us/library/windows/desktop/aa379607.aspx // Standard Access Rights
https://msdn.microsoft.com/en-us/library/windows/desktop/aa374896.aspx // Access Mask Format
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880.aspx // Process Security and Access Rights
Mask Format:
bits 0 - 15 [16 bits]: object-specific rights
bits 16 - 23 [ 8 bits]: standard access rights
bit 24: [ 1 bit]: right to access SACL (ACCESS_SYSTEM_SECURITY)
@Rhomboid
Rhomboid / mersenne_predict.py
Last active December 11, 2023 09:47
Predict output of Mersenne Twister after seeing 624 values
#!/usr/bin/env python
#
# Mersenne Twister predictor
#
# Feed this program the output of any 32-bit MT19937 Mersenne Twister and
# after seeing 624 values it will correctly predict the rest.
#
# The values may come from any point in the sequence -- the program does not
# need to see the first 624 values, just *any* 624 consecutive values. The
# seed used is also irrelevant, and it will work even if the generator was
@Rhomboid
Rhomboid / tokenize.c
Created October 13, 2015 17:35
Tokenizing a string based on a set of delimiters into a dynamic array in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
size_t tokenize(const char *s, const char *delim, char ***tokenarray)
{
size_t size = 0, capacity = 4, wordlen;
const char *begin = s, *end;
char **tokens = malloc(capacity * sizeof(char *));
@Rhomboid
Rhomboid / example.c
Created September 21, 2015 01:05
Units conversion example in C
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
struct conversion {
const char *from, *to;
double scale, offset;
} conversions[] = {
{ "Celsius", "Fahrenheit", 9./5, 32 },
{ "Fahrenheit", "Celsius", 5./9, -32 * 5./9 },
@Rhomboid
Rhomboid / example.c
Last active December 22, 2023 21:09
X-Macros for serialization of C structs
#include <stdio.h>
#include <stdint.h>
typedef enum {
enOne,
enTwo,
enThree,
invalidMax = 2147483647
} MyEnum;
@Rhomboid
Rhomboid / swaptest.cpp
Created March 14, 2015 18:51
The stupidity of using XOR to swap integers
#include <iostream>
#include <vector>
#include <random>
#include <iterator>
#include <algorithm>
#include <functional>
#include <chrono>
using test_type = unsigned;
@Rhomboid
Rhomboid / string_reverse_msdos.asm
Created March 9, 2015 03:22
MS-DOS string reverse program
.model small
; int 21h functions used:
DOS_PRINTSTR equ 09h ; output a $-terminated string in DS:DX
DOS_INPUT equ 0ah ; read buffered input into structure at DS:DX
DOS_EXIT equ 4ch ; terminate program with exit code in AL
.stack
.data
prompt_text db 'Enter a string: $'
output_text db 0ah, 0dh, 'Your string reversed: $'