Skip to content

Instantly share code, notes, and snippets.

View 2color's full-sized avatar
🚢

Daniel Norman 2color

🚢
View GitHub Profile
@2color
2color / js-libp2p.ts
Created May 2, 2024 16:00
persistent libp2p peerid
import { IDBDatastore } from 'datastore-idb'
import {
createDelegatedRoutingV1HttpApiClient,
DelegatedRoutingV1HttpApiClient,
} from '@helia/delegated-routing-v1-http-api-client'
import { createLibp2p, Libp2p } from 'libp2p'
import { identify } from '@libp2p/identify'
import { peerIdFromString } from '@libp2p/peer-id'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
@2color
2color / test.yaml
Last active April 10, 2024 18:57
How to run integration tests with PostgreSQL and Prisma on GitHub Actions
# .github/workflows/test.yaml
name: test
on: push
jobs:
test:
runs-on: ubuntu-latest
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
@2color
2color / httpie-graphql.sh
Created April 16, 2020 13:35
How to send a GraphQL request with HTTPie
http POST https://graphqlapi.now.sh query="query { feed { id title } }"
@2color
2color / typescript.md
Last active January 9, 2023 15:37
Snippets and Learnings from Effective TypeScript

Learnings

Types as sets of values

keyof with union (|) and intersection (&)

There are no keys that TypeScript can guarantee belong to a value in the union type, so keyof for the union must be the empty set (never). Or, more formally:

@2color
2color / ipfs-commands.md
Created May 31, 2022 14:08
Useful IPFS commands

dig +noall +answer TXT \_dnslink.chat.thedisco.zone

@2color
2color / main.rs
Created January 4, 2022 14:37
Mean, median, and mode of a vector with Rust
use std::collections::HashMap;
fn main() {
let v: Vec<u32> = vec![10, 20, 20, 30, 38, 42, 48, 51, 62, 70];
println!("vector: {:?}", v);
println!("mean: {}", mean(&v));
// println!("median: {}", median(&mut v));
println!("median: {}", median_1(&v));
// println!("median: {}", median_2(v.clone()));
println!("mode: {}", mode(&v));
@2color
2color / main.md
Last active December 2, 2021 16:01

Comparing B-Tree and Hash indices

Operation B-Tree Hash
Lookup single record O(log(n)) O(1)
Lookup range O(log(n)) O(n) full table scan
Insertion O(log(n) O(1)
Deletion O(log(n) O(1)
SELECT `main`.`User`.`id`, `main`.`User`.`email`, `main`.`User`.`city`, `main`.`User`.`name`, `aggr_selection_0_Post`.`_aggr_count_posts` FROM `main`.`User` LEFT JOIN (SELECT `main`.`Post`.`authorId`, COUNT(*) AS `orderby_aggregator` FROM `main`.`Post` GROUP BY `main`.`Post`.`authorId`) AS `orderby_0_Post` ON (`main`.`User`.`id` = `orderby_0_Post`.`authorId`) LEFT JOIN (SELECT `main`.`Post`.`authorId`, COUNT(*) AS `_aggr_count_posts` FROM `main`.`Post` GROUP BY `main`.`Post`.`authorId`) AS `aggr_selection_0_Post` ON (`main`.`User`.`id` = `aggr_selection_0_Post`.`authorId`) WHERE 1=1 ORDER BY COALESCE(`orderby_0_Post`.`orderby_aggregator`, ?) DESC LIMIT ? OFFSET ?
@2color
2color / session.js
Created February 3, 2017 14:13
redux-observable sessionStorage epic example
import { Observable } from 'rxjs'
import 'rxjs/add/observable/of'
import 'rxjs/add/operator/map'
import 'rxjs/add/operator/merge'
import { createAction } from 'redux-actions'
export const SESSION_STORAGE_KEY = 'SESSION_STORAGE_KEY'
export const GET_SESSION_REQUESTED = 'payout/GET_SESSION_REQUESTED'
export const GET_SESSION_FOUND = 'payout/GET_SESSION_FOUND'