Skip to content

Instantly share code, notes, and snippets.

@Rhomboid
Rhomboid / ver1.c
Last active April 29, 2024 21:48
Obfuscated C code (Twelve days of Christmas)
#include <stdio.h>
main(t,_,a)
char *a;
{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86, 0, a+1 )+a)):1,t<_?main(t+1, _, a ):3,main ( -94, -27+t, a
)&&t == 2 ?_<13 ?main ( 2, _+1, "%s %d %d\n" ):9:16:t<0?t<-72?main(_,
t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+\
,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/\
+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){n\
@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 / 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 / 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 / index.html
Created January 6, 2015 08:08
Internet Archive MS DOS games index
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Internet Archive MS-DOS Games</title>
<style>li { list-style-type: none; margin-bottom: 1em }</style>
</head>
<body>
<ul>
<li><a href="https://archive.org/details/msdos_Nam_1965-1975_1991">'Nam 1965-1975 (1991)</a><br>
@Rhomboid
Rhomboid / memaccess.cpp
Created July 25, 2014 05:39
Memory access - sequential vs. random
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <chrono>
#include <random>
#include <limits>
int main()
{
@Rhomboid
Rhomboid / example.py
Created July 14, 2013 17:21
Very simple lexer/parser for chemical formula
import re
atomic_mass = {
"H": 1.0079, "He": 4.0026, "Li": 6.941, "Be": 9.0122,
"B": 10.811, "C": 12.011, "N": 14.007, "O": 15.999, "F": 18.998,
"Ne": 20.180, "Na": 22.990, "Mg": 24.305, "Al": 26.982,
"Si": 28.086, "P": 30.974, "S": 32.065, "Cl": 35.453,
"Ar": 39.948, "K": 39.098, "Ca": 40.078, "Sc": 44.956,
"Ti": 47.867, "V": 50.942, "Cr": 51.996, "Mn": 54.938,
"Fe": 55.845, "Co": 58.933, "Ni": 58.693, "Cu": 63.546,
@Rhomboid
Rhomboid / clipformats.py
Last active November 28, 2019 11:52
Enumerate clipboard formats with Python and Pywin32
import win32clipboard
formats = {val: name for name, val in vars(win32clipboard).items() if name.startswith('CF_')}
def format_name(fmt):
if fmt in formats:
return formats[fmt]
try:
return win32clipboard.GetClipboardFormatName(fmt)
except:
@Rhomboid
Rhomboid / 20121109.cpp
Created November 10, 2012 06:42
Removing punctuation from strings in C++98 and C++11
#include <string>
#include <iostream>
#include <cctype>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{