Skip to content

Instantly share code, notes, and snippets.

View oberrich's full-sized avatar
🌴
Contemplating life, learning rust, starting to love programming again.

oberrich

🌴
Contemplating life, learning rust, starting to love programming again.
  • Self-Employed
  • 🇩🇪DE/🇦🇹AT
  • 20:08 (UTC +02:00)
View GitHub Profile
@oberrich
oberrich / static_cache.hpp
Created July 30, 2022 13:15
A simple statically allocated cache, auto-clears on overflow
template <typename ValT, std::size_t Capacity>
class StaticCache {
public:
ValT &operator[](std::uint32_t hash) {
for (std::size_t i = 0; i < num_entries; ++i) {
if (entries[i].hash == hash) return entries[i].value;
}
if (++num_entries > Capacity) num_entries = 1;
@oberrich
oberrich / hash_64bitwise.hpp
Last active February 2, 2022 18:08
FNV-1a hashing a wide-string with multiple of 4 length in chunks of 64-bits
constexpr auto hash_64bitwise(std::wstring_view str) noexcept
{
using SizeType = decltype(str)::size_type;
constexpr auto offset_basis = 0xcbf29ce484222325ull;
constexpr auto prime = 0x00000100000001B3ull;
auto value = offset_basis;
auto size = str.length();
if (size % 4)
return 0ull;
#!/bin/bash
source $HOME/.keychain/${HOSTNAME}-sh
cd ~/
if [ ! -d "phnt_maintain" ]; then
mkdir phnt_maintain
fi
@oberrich
oberrich / create_sheet.py
Last active October 9, 2021 01:48
Extract Bitcoin transactions with historical prices and fix up time zones in Python
import pandas as pd
import numpy as np
import datetime as dt
import csv, glob, os
from currency_converter import CurrencyConverter
pd.set_option('precision', 9)
filename_tpl = 'output/temp/'+str(int(dt.datetime.utcnow().timestamp()))+'_{}.csv'
#include <bit>
#include "stackext.hpp"
#ifdef RECLASS_PROXY_SINGLE_THREAD
# define RECLASS_PROXY_STORAGE_DUR
#else
# define RECLASS_PROXY_STORAGE_DUR thread_local
#endif
#define RECLASS_AUTO_INDIRECTION : public auto_indirection_tag
public class CRC {
private int degree;
private int poly;
public CRC(int poly) {
this.poly = poly;
this.degree = mostSignificantSetBit(poly) - 1;
}
public int getDegree() {
@oberrich
oberrich / main.py
Last active November 22, 2021 02:39
Manually decoding and viewing PNG file in Python
import os
import struct
import time
import zlib
import numpy as np
from math import floor
from sfml import sf
png_signature = b'\x89PNG\r\n\x1A\n'