This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// START include/flat_hash_map/flat_hash_map.hpp | |
// Copyright Malte Skarupke 2017. | |
// Distributed under the Boost Software License, Version 1.0. | |
// (See http://www.boost.org/LICENSE_1_0.txt) | |
#include <cstdint> | |
#include <cstddef> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Timer | |
{ | |
public: | |
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, | |
}) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// refers to this question of SO: | |
// https://stackoverflow.com/questions/17465061/how-to-parse-space-separated-floats-in-c-quickly/59013147 | |
#include <iomanip> | |
#include <iostream> | |
// for mmap: | |
#include <fcntl.h> | |
#include <sys/mman.h> | |
#include <sys/stat.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 http://crackprogramming.blogspot.sg/2012/10/implement-atof.html | |
// But it cannot convert floating point with high +/- exponent. | |
// The version below by Tian Bo fixes that problem and improves performance by 10% | |
// http://coliru.stacked-crooked.com/a/2e28f0d71f47ca5e | |
// Oliver Schonrock: I picked this code up from | |
// https://www.codeproject.com/Articles/1130262/Cplusplus-string-view-Conversion-to-Integral-Types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/* | |
* generates the code for sodium_compat.php | |
*/ | |
define('BASE', dirname(dirname(__FILE__)) . '/'); | |
$lib = '<?php |