Skip to content

Instantly share code, notes, and snippets.

View mmozeiko's full-sized avatar

Mārtiņš Možeiko mmozeiko

View GitHub Profile
@mmozeiko
mmozeiko / aes.py
Last active August 29, 2015 13:56
AES in Python
from __future__ import print_function
import sys
import struct
rcon = [ \
0x01000000, 0x02000000, 0x04000000, 0x08000000,
0x10000000, 0x20000000, 0x40000000, 0x80000000,
0x1b000000, 0x36000000,
]
@mmozeiko
mmozeiko / lz4.py
Created July 26, 2014 00:11
lz4 decompression in Python 2.x
# Warning: this implementation doesn't check if writes or reads will happen
# out of input/output buffer range, so that will generate IndexError exception
def LZ4_decompress(source, osize):
isize = len(source)
src = bytearray(source)
dst = bytearray(osize)
si = 0
#pragma once
template <class Fun>
class ScopeGuard
{
private:
Fun f;
bool active;
public:
#pragma once
#include <exception>
#include <stdexcept>
#include <utility>
template <class T>
class Expected
{
public:
@mmozeiko
mmozeiko / win32_crt_float.cpp
Last active October 12, 2024 20:47
Visual C/C++ CRT functionality
extern "C"
{
int _fltused;
#ifdef _M_IX86 // following functions are needed only for 32-bit architecture
__declspec(naked) void _ftol2()
{
__asm
{
@mmozeiko
mmozeiko / MemSpeed.cpp
Created December 21, 2014 19:48
Memory copy benchmark
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <xmmintrin.h> // SSE
#include <immintrin.h> // AVX
#ifdef _WIN32
#include <intrin.h> // for __movsb, __movsd, __movsq
@mmozeiko
mmozeiko / incbin.c
Last active October 13, 2024 00:16
Include binary file with gcc/clang
#include <stdio.h>
#define STR2(x) #x
#define STR(x) STR2(x)
#ifdef _WIN32
#define INCBIN_SECTION ".rdata, \"dr\""
#else
#define INCBIN_SECTION ".rodata"
#endif
@mmozeiko
mmozeiko / ctime.c
Last active October 13, 2024 00:27
ctime.c
/* ========================================================================
$File: tools/ctime/ctime.c $
$Date: 2016/05/08 04:16:55PM $
$Revision: 7 $
$Creator: Casey Muratori $
$Notice:
The author of this software MAKES NO WARRANTY as to the RELIABILITY,
SUITABILITY, or USABILITY of this software. USE IT AT YOUR OWN RISK.
@mmozeiko
mmozeiko / dxgl.c
Last active October 13, 2024 00:27
WGL_NV_DX_interop2 example
#define COBJMACROS
#define INITGUID
#include <intrin.h>
#include <windows.h>
#include <d3d11.h>
#include <gl/GL.h>
#include "glext.h" // https://www.opengl.org/registry/api/GL/glext.h
#include "wglext.h" // https://www.opengl.org/registry/api/GL/wglext.h