Skip to content

Instantly share code, notes, and snippets.

View ShreyanJain9's full-sized avatar

Shreyan Jain ShreyanJain9

View GitHub Profile
@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) } }
require 'json'
require 'net/http'
require 'date'
module ATProto
class Session
def initialize(username, password)
@atp_host = "https://bsky.social"
@atp_auth_token = ""
@did = ""
@username = username
#!/bin/ruby
#This program calls the Bing API and returns some search json_results.
require "net/https" #These are just some dependencies
require "uri"
require "cgi"
require "json"
#API Info
def search(term, safesearch, where)
accessKey = ENV["BING_API_KEY"]
uri = "https://api.bing.microsoft.com"