Skip to content

Instantly share code, notes, and snippets.

View chungquantin's full-sized avatar
:shipit:
Extreme learning

Tin Chung chungquantin

:shipit:
Extreme learning
View GitHub Profile
@jozanza
jozanza / borshDecoder.ts
Last active February 9, 2022 12:30
Borsh parsing is really pretty simple
// https://gist.github.com/diafygi/90a3e80ca1c2793220e5/
const B58_CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
// prettier-ignore
const toBase58: (buf: Uint8Array, map?: string) => string = (B: any, A: any = B58_CHARS) => {let d: any = [], s = '', i: any, j: any, c, n; for(i in B){j=0,c=B[i];s+=c||s.length^i?"":1;while(j in d||c){n=d[j];n=n?n*256+c:c;c=n/58|0;d[j]=n%58;j++}}while(j--)s+=A[d[j]];return s;}
export const toJSON = (data: any) => {
return JSON.stringify(
data,
(_key, value) => (typeof value === 'bigint' ? value.toString() : value),
2,
{
"defaultSeverity": "error",
"extends": ["tslint:latest", "tslint-config-prettier"],
"jsRules": {},
"rules": {
"no-console": false,
"member-access": false,
"object-literal-sort-keys": false,
"ordered-imports": false,
"interface-name": false,
@fundon
fundon / smol-hello.rs
Last active January 23, 2024 08:34
smol 16threads vs tokio 16threads
//! An HTTP server based on `hyper`.
//!
//! Run with:
//!
//! ```
//! cargo run --example hyper-server
//! ```
//!
//! Open in the browser any of these addresses:
//!
@allenday
allenday / gini-balance-erc20.sql
Created January 31, 2019 10:14
Calculate Gini coefficient for ERC-20 balances.
with
double_entry_book as (
-- debits
select to_address as address, CAST(value AS NUMERIC) as value, block_timestamp
from `bigquery-public-data.crypto_ethereum.token_transfers`
where from_address is not null and to_address is not null
and token_address = LOWER('0x408e41876cccdc0f92210600ef50372656052a38') --OMG
union all
-- credits
select from_address as address, -CAST(value AS NUMERIC) as value, block_timestamp
@genekogan
genekogan / scrapeImages.py
Created February 22, 2017 11:49
scraping full size images from Google Images
from bs4 import BeautifulSoup
import requests
import re
import urllib2
import os
import argparse
import sys
import json
# adapted from http://stackoverflow.com/questions/20716842/python-download-images-from-google-image-search
@Kartones
Kartones / postgres-cheatsheet.md
Last active February 13, 2026 13:15
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)