Skip to content

Instantly share code, notes, and snippets.

View tarcisiozf's full-sized avatar

Tarcísio Zotelli Ferraz tarcisiozf

View GitHub Profile
@tarcisiozf
tarcisiozf / add_to_zshrc.sh
Created August 26, 2024 13:51 — forked from karpathy/add_to_zshrc.sh
Git Commit Message AI
# -----------------------------------------------------------------------------
# AI-powered Git Commit Function
# Copy paste this gist into your ~/.bashrc or ~/.zshrc to gain the `gcm` command. It:
# 1) gets the current staged changed diff
# 2) sends them to an LLM to write the git commit message
# 3) allows you to easily accept, edit, regenerate, cancel
# But - just read and edit the code however you like
# the `llm` CLI util is awesome, can get it here: https://llm.datasette.io/en/stable/
gcm() {
#include <sys/mman.h>
#include <fcntl.h>
unsigned char* shared(const char* path) {
int fd = open(path, O_RDWR | O_CREAT, (mode_t) 0600);
posix_fallocate(fd, 0, 65536);
return (unsigned char*) mmap(0, 65536, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
}
// double 12345.67 -> int 1234567
struct Trie {
std::array<int, (size_t) 1.1e7> cnt, sum;
void update(int price, int qty) {
int cnt_delta = qty ? (cnt[price] ? 0 : +1) : (cnt[price] ? -1 : 0);
int sum_delta = qty - sum[price];
for (int node = 0, tmp = price, p10 = 1e7; p10; tmp %= p10, p10 /= 10) {
node = 10 * node + tmp / p10;
@tarcisiozf
tarcisiozf / Price-Time Matching Engine.c
Last active October 5, 2020 13:31 — forked from Jud/Price-Time Matching Engine.c
Price-Time Matching Engine
/*****************************************************************************
* QuantCup 1: Price-Time Matching Engine
*
* Submitted by: voyager
*
* Design Overview:
* In this implementation, the limit order book is represented using
* a flat linear array (pricePoints), indexed by the numeric price value.
* Each entry in this array corresponds to a specific price point and holds
* an instance of struct pricePoint. This data structure maintains a list