Skip to content

Instantly share code, notes, and snippets.

@wzwqoo
wzwqoo / ratelimiter.pyx
Created April 2, 2025 12:14 — forked from beatzxbt/ratelimiter.pyx
basic rate limiter
from libc.stdint cimport uint32_t
from mm_toolbox.time.time cimport time_s
from .engine cimport OrderAction
cdef class RateLimitCounter:
cdef:
uint32_t tokens_per_sec
uint32_t tokens_remaining
@wzwqoo
wzwqoo / dydxFlashLoanTemplate.sol
Created December 28, 2023 19:35 — forked from cryptoscopia/dydxFlashLoanTemplate.sol
A single-file simplest possible template for a contract that obtains a flash loan from dydx, does things, and pays it back.
// SPDX-License-Identifier: AGPL-3.0-or-later
// The ABI encoder is necessary, but older Solidity versions should work
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
// These definitions are taken from across multiple dydx contracts, and are
// limited to just the bare minimum necessary to make flash loans work.
library Types {
enum AssetDenomination { Wei, Par }
@wzwqoo
wzwqoo / ObserverPattern.cpp
Created April 29, 2022 14:48 — forked from silahian/ObserverPattern.cpp
Observer pattern created by silahian - https://repl.it/HpbL/15
#include <string>
#include <vector>
#include <thread>
#include <iostream>
#include <unistd.h>
using namespace std;
class IObserver
{
public:
@wzwqoo
wzwqoo / busy-waiting-example.cpp
Created April 29, 2022 14:48 — forked from silahian/busy-waiting-example.cpp
busy-waiting-example created by silahian - https://repl.it/Hry2/1
#include <string>
#include <vector>
#include <thread>
#include <iostream>
#include <unistd.h>
using namespace std;
mutex mtxData;
class Consumer
{
@wzwqoo
wzwqoo / MemoryAllocationHFT.cpp
Created April 29, 2022 14:48 — forked from silahian/MemoryAllocationHFT.cpp
Pre allocated vs dynamic arrays performance for low latency / high frequency trading systems
// Example program
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
// ***********************************
// This is for measuring CPU clocks
#if defined(__i386__)
static __inline__ unsigned long long rdtsc(void)