Skip to content

Instantly share code, notes, and snippets.

@arthurgousset
arthurgousset / _lessons-on-operating-in-a-downturn.md
Last active June 27, 2024 06:09
💡 Lessons on operating in a downturn
@talegift
talegift / calculateUniswapTWAP.js
Created November 17, 2020 16:59 — forked from l3wi/calculateUniswapTWAP.js
Off-chain Uniswap V2 TWAP calculator in Javascript
import { ethers } from 'ethers'
// To use this you need to read the Uniswap v2 contract for a pair/
// PRICE pulled from priceXCumulativeLast
// TIMESTAMPS pulled from _blockTimestampLast in getReserves()
// Mock Data
// In a real scenario you would fetch and store price & timestamp at an interval
// to mirror the contract calculating the TWAP on chain
const price0 = '529527205677379158060966860839'
@ih2502mk
ih2502mk / list.md
Last active July 24, 2024 22:24
Quantopian Lectures Saved

I am testing Postgres insertion performance. I have a table with one column with number as its data type. There is an index on it as well. I filled the database up using this query:

insert into aNumber (id) values (564),(43536),(34560) ...

I inserted 4 million rows very quickly 10,000 at a time with the query above. After the database reached 6 million rows performance drastically declined to 1 Million rows every 15 min. Is there any trick to increase insertion performance? I need optimal insertion performance on this project. Using Windows 7 Pro on a machine with 5 GB RAM.

@sebastianwebber
sebastianwebber / benchmarks.sh
Last active March 17, 2023 14:33
Run benchmarks on postgres with pgbench
#!/bin/bash -ex
export PGBIN=/usr/pgsql-9.3/bin
export PGUSER=postgres
export PGDATABASE=bench
export DATADIR=/dados/pgbench
export CLUSTER_LOG=/tmp/benchmark.log
export TOTAL_CPUS=$(grep 'cpu cores' /proc/cpuinfo | uniq | awk '{print $NF}')
@ahopkins
ahopkins / # Sanic websocket feeds v2.md
Last active February 5, 2022 14:46
Sanic based websocket pubsub feed

Sanic Websockets Feeds v2

This is an outdated version

See latest

(function (d, w, c) {
(w[c] = w[c] || []).push(function() {
try {
w.yaCounter42337284 = new Ya.Metrika({
id:42337284,
clickmap:true,
trackLinks:true,
accurateTrackBounce:true
});
@valyala
valyala / README.md
Last active June 3, 2024 17:00
Optimizing postgresql table for more than 100K inserts per second

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@Humoud
Humoud / regex-arabic.md
Last active April 1, 2024 03:48
Detecting arabic characters with regex.

Detect all Arabic Characters:

/[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufbc1]|[\ufbd3-\ufd3f]|[\ufd50-\ufd8f]|[\ufd92-\ufdc7]|[\ufe70-\ufefc]|[\uFDF0-\uFDFD]/

Summary:

  Arabic (0600—06FF, 225 characters)

  Arabic Supplement (0750—077F, 48 characters)

Markov Chains

A while back I wrote a blog post explaining Markov chains and demonstrating different ways of finding their steady-state distribution in R. Now, I want to play with Markov chains as a graph. I’m going to pull examples from around the internet and answer the same questions in Cypher as the authors do with matrices. This gives me the opportunity to explore more advanced Cypher queries while working with a topic I enjoy very much (stochastic processes and Markov chains). So this is officially just for funsies.

I found three Markov chains online that I’m going to showcase, and they involve the following topics: