Skip to content

Instantly share code, notes, and snippets.

const useDnD = ({ onStart, onMove, onComplete }) => {
const [draging, setDraging] = useState(false)
const handleDragStart = useCallback(() => {
setDraging(true)
// [Record starting point]
onStart ?? onStart()
}, [setDraging, onStart])
const handleDragMove = useCallback(() => {
@joelbinn
joelbinn / cancellable-promise.spec.ts
Created October 8, 2019 07:03
A typescript implementation of a cancellable promise
import { CancellablePromise } from './cancellable-promise'
describe('CancellablePromise', () => {
describe('when cancelling', () => {
it( 'should reject with information of this', async () => {
const p: CancellablePromise<string> = new CancellablePromise(new Promise<string>(resolve => undefined))
p.cancel()
await expect(p).rejects.toEqual({wasCancelled: true})
@halfelf
halfelf / how_to_build_a_fast_limit_order_book.md
Created February 11, 2019 02:18
How to Build a Fast Limit Order Book

https://web.archive.org/web/20110219163448/http://howtohft.wordpress.com/2011/02/15/how-to-build-a-fast-limit-order-book/

The response to my first few posts has been much larger than I’d imagined and I’d like to thank everyone for the encouragement.

If you’re interested in building a trading system I recommend first reading my previous post on general ideas to keep in mind.

My first really technical post will be on how to build a limit order book, probably the single most important component of a trading system. Because the data structure chosen to represent the limit order book will be the primary source of market information for trading models, it is important to make it both absolutely correct and extremely fast.

To give some idea of the data volumes, the Nasdaq TotalView ITCH feed, which is every event in every instrument traded on the Nasdaq, can have data rates of 20+ gigabytes/day with spikes of 3 megabytes/second or more. The individual messages average about 20 bytes each so this means handling

@druska
druska / engine.c
Created September 17, 2018 15:18
Quant Cup 1's winning order book implementation
/*****************************************************************************
* 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
@sirreal
sirreal / README.md
Last active November 15, 2022 22:25
node-sass inline svgs via `svg()` function

Make it easy to include SVG strings inline via node-sass.

Escapes SVG (via encodeURIComponent + node-sass custom function).

Wraps <svg/> with appropriate url(data...) which I can never remember.

Call:

node-sass --source-map=true --functions=./node-sass-functions.js in.scss out.css
@paulirish
paulirish / what-forces-layout.md
Last active May 19, 2024 03:45
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@ghaiklor
ghaiklor / v8-compile-javascript-example.cc
Last active February 1, 2022 13:25
Simple example how V8 can compile JavaScript source and run it
// Create a new context.
Local<Context> context = Context::New(isolate);
// Enter the context for compiling and running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
// Compile the source code.
@imjasonh
imjasonh / markdown.css
Last active May 17, 2024 07:30
Render Markdown as unrendered Markdown (see http://jsbin.com/huwosomawo)
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}