Skip to content

Instantly share code, notes, and snippets.

View ShreyanJain9's full-sized avatar

Shreyan Jain ShreyanJain9

View GitHub Profile
@ShreyanJain9
ShreyanJain9 / datarepos.md
Created September 6, 2024 04:30
ATProto data repositories

ATProto Data Repositories, Demystified

If you’re an ATProto developer (feel free to read this if you’re a normie too - I hope I’d be able to impart at least some of the magic to you too, though there’s a high chance most of this ends up flying over your head) you’ve probably heard the term “repo” come up at least once in discussions of the ATProto architecture. While most of the time you can ignore the details of how these data repositories work, since they are the beating heart of ATProto, you may want to learn more about them, and if you know with some detail their inner workings you may also find yourself able to use the protocol more effectively.

If you’ve touched even a bit of ATProto, you probably know that data is organized into typed ‘collections’ of ‘records’. These are actually conceptually not that different from what in an SQL or similar database you might refer to as ‘columns’ of ‘rows’ or ‘records’ - and that’s intentional. ATProto repos are, essentially, a database containing your personal

@ShreyanJain9
ShreyanJain9 / add_rotationkey.ts
Created July 18, 2024 22:38
very lazy and quick edit of hailey's pds migration script in a way i think should let you just add a rotation key. untested, use at your own risk
import AtpAgent from '@atproto/api'
import { Secp256k1Keypair } from '@atproto/crypto'
import * as ui8 from 'uint8arrays'
const OLD_PDS_URL = 'https://bsky.social'
const CURRENT_HANDLE = 'haileyok.com'
const CURRENT_PASSWORD = ''
const TOKEN = '' // Use `getEmail` first, and set this to the token that you receive.
const getEmail = async () => {
@ShreyanJain9
ShreyanJain9 / bloom_filter.ex
Last active March 28, 2024 20:48
A Bloom Filter in Elixir
defmodule BloomFilter do
@moduledoc """
A small Bloom Filter in Elixir
"""
@default_hash_fns [:sha256, :sha512, :blake2b]
defstruct bits: <<0::size(64)>>, hash_fns: @default_hash_fns
@ShreyanJain9
ShreyanJain9 / IRRemote.h
Last active November 14, 2023 21:21
Arduino RC Car Code
#ifndef ROBOT_CONTROL_H
#define ROBOT_CONTROL_H
#include <ArxContainer.h>
#include <IRremote.hpp>
/*!
* @brief Alias for uint8_t to enhance code readability.
*/
using uint8_t = u8;
@ShreyanJain9
ShreyanJain9 / hose.rb
Created October 14, 2023 20:52
BlueSky Firehose Stuff
require "faye/websocket"
require "cbor"
require "base32"
SubscribeReposEndpoint = "wss://bsky.network/xrpc/com.atproto.sync.subscribeRepos"
# Decode CBOR data into JSON as it appears
def decode_cbor_data(data)
CBOR::Unpacker.new(StringIO.new(data))
.each.to_a
@ShreyanJain9
ShreyanJain9 / nex.go
Created August 27, 2023 04:11
Nex Protocol Client in Go
package main
import (
"bufio"
"fmt"
"net"
"os"
)
const (
@ShreyanJain9
ShreyanJain9 / gemini.go
Created August 17, 2023 03:37
A few nice Go functions for making requests on the Gemini protocol (also exports a C function MakeGeminiRequest for use from my Ruby)
package main
import (
"C"
"bufio"
"crypto/tls"
"fmt"
"io/ioutil"
"net"
"net/url"
@ShreyanJain9
ShreyanJain9 / bip39.py
Last active August 13, 2023 01:00
BIP 39 encode to mnemonic and decode for any string of length 16, 20, 24, 28, or 32 chars
#!/usr/bin/env python3
import argparse
from mnemonic import Mnemonic
import sys
def encode(mnemonic_str):
m = Mnemonic("english")
words = m.to_mnemonic(mnemonic_str.encode("utf-8"))
return words
@ShreyanJain9
ShreyanJain9 / nostrpaths.md
Last active June 27, 2023 18:09
An assortment of thoughts on how a potential NIP for giving Nostr events URI-paths could work

Nostr Paths: Just Thoughts, Not a NIP Yet

Event Structure

An event would follow the following structure:

{
  "id": <event_id>,
  "pubkey": <event_creator_pubkey>,
  "created_at": <timestamp>,
  "kind": <event_kind>,
@ShreyanJain9
ShreyanJain9 / jsonobj.rb
Last active June 26, 2023 21:40
A ruby module that instantly turns json into an object
require 'json'
module JSONObject
def self.create(json)
data = JSON.parse(json)
klass = Class.new do
data.each do |key, value|
attr_accessor key.to_sym
define_method(:initialize) { |**args| args.each { |k, v| instance_variable_set("@#{k}", v) } }