Skip to content

Instantly share code, notes, and snippets.

View hashtable.c
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char* ht_key_t;
typedef int ht_value_t;
// key => value plus pointer to next item for hash collisions
typedef struct HashTableItem HashTableItem;
View ShelfClock-OS-V1.ino
#include <Adafruit_NeoPixel.h>
#include <DS3231_Simple.h>
// Which pin on the Arduino is connected to the NeoPixels?
const int LEDCLOCK_PIN = 6;
const int LEDDOWNLIGHT_PIN = 5;
// How many NeoPixels are attached to the Arduino?
const int LEDCLOCK_COUNT = 207;
const int LEDDOWNLIGHT_COUNT = 12;
oschonrock / txt_file_parsing.cpp
Last active Jan 8, 2020
High performance txt file parsing
View txt_file_parsing.cpp
// START include/flat_hash_map/flat_hash_map.hpp
// Copyright Malte Skarupke 2017.
// Distributed under the Boost Software License, Version 1.0.
// (See
#include <cstdint>
#include <cstddef>
oschonrock / timer.h
Created Dec 4, 2019
C++ Basic profiling timer class
View timer.h
class Timer
Timer(std::string label_) : start{std::chrono::high_resolution_clock::now()}, label{label_} {};
~Timer() { print(); }
void print() {
finish = std::chrono::high_resolution_clock::now();
auto elapsed_ms = std::chrono::duration_cast<std::chrono::duration<double>>(finish - start).count() * 1000;
oschonrock / profile_tests.cpp
Last active Dec 4, 2019
SequencedMap a C++ container like std::map which retains insertion order
View profile_tests.cpp
int main() {
using Key = std::string;
using Value = int;
SequencedMap<Key, Value> smap;
// arbitrary ad-hoc temporary structure for the data (for demo purposes only)
for (auto p: std::vector<std::pair<Key, Value>>{
{"Mary", 10}, {"Alex", 20}, {"Johnny", 40}, {"Roman", 40}, {"Johnny", 50},
}) {
oschonrock / fparse.cpp
Last active Jan 5, 2021
High speed parsing of floats in CSV format - C++
View fparse.cpp
// refers to this question of SO:
#include <iomanip>
#include <iostream>
// for mmap:
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
oschonrock / crack_atof.cpp
Created Nov 23, 2019
crack_atof() a blisteringly fast alternative to the teriibly slow C++ std::stod
View crack_atof.cpp
// the C++ STL is a mess for parsing numbers from strings, FAST. from_chars looked good but is not implemented in clang/gcc
// crack_atof is a very very fast alternative
// Original crack_atof version is at
// But it cannot convert floating point with high +/- exponent.
// The version below by Tian Bo fixes that problem and improves performance by 10%
// Oliver Schonrock: I picked this code up from
View Hipb.php
* intention of this class is not to do anything too fancy
* it basically just runs one query, but it does so with ease and in a scalable and safe way
* ie it won't block, you don't have to worry about setting up a new connection
* it will reuse the connection and the prepared statement if you make multiple calls
* been tested and refined in high volume production for 1 year.
* to use it just customise the __contrsuct below with your DB details and call:
oschonrock / leach.php
Last active Dec 7, 2017
leach() = "legacy each": php72 compat for deprecated each(). Use to refactor tired third party libs, when not performance critical.
View leach.php
* leach() = "legacy each"
* replacement for deprecated each() for php7.2
* use this if refactoring would be too painful and performance is not relevant
function leach(&$arr)
oschonrock / generate_sodium_compat.php
Last active Dec 7, 2017
pecl-libsodium to php72-sodium compat lib
View generate_sodium_compat.php
#!/usr/bin/env php
* generates the code for sodium_compat.php
define('BASE', dirname(dirname(__FILE__)) . '/');
$lib = '<?php