Skip to content

Instantly share code, notes, and snippets.

View drbh's full-sized avatar
🕳️
a for AI

drbh drbh

🕳️
a for AI
  • drbh
  • state space
  • 15:02 (UTC -04:00)
View GitHub Profile
@drbh
drbh / demo.py
Created April 17, 2024 02:28
Deploy Inference Endpoint and use tools from OpenAI client
from openai import OpenAI
ENDPOINT_URL = "ENDPOINT_URL"
HF_TOKEN = "YOUR_TOKEN"
# Initialize the client, pointing it to one of the available models
client = OpenAI(
base_url=ENDPOINT_URL + "/v1/",
api_key=HF_TOKEN,
)
@drbh
drbh / email.ts
Created December 12, 2023 23:50
simple OTP email login
const SEND_IN_BLUE_KEY = "..."
const randomString = (length) => {
const bytes = new Uint8Array(length);
window.crypto.getRandomValues(bytes);
let result = '';
bytes.forEach((b) => {
// Convert each byte to a digit (0-9)
result += (b % 10).toString();
});
@drbh
drbh / sink-slack.script
Created July 19, 2023 01:08
smol apple script that sinks recent slack messages into a json file
tell application "Safari"
-- Open Slack and navigate to the desired channel
activate
-- Navigate to the desired channel (with Josh in the name)
tell window 1
set currentTab to tab 1
set URL of currentTab to "https://app.slack.com/client/SPACE/CHAN"
repeat until (do JavaScript "document.readyState" in currentTab) is "complete"
delay 0.2
curl -OL http://nginx.org/download/nginx-1.23.4.tar.gz
tar -xvzf nginx-1.23.4.tar.gz && rm nginx-1.23.4.tar.gz
# todo add openssl and prce
curl -OL https://osdn.net/projects/sfnet_pcre/downloads/pcre/8.45/pcre-8.45.tar.gz
tar -xvzf pcre-8.45.tar.gz && rm pcre-8.45.tar.gz
curl -OL https://github.com/openssl/openssl/releases/download/openssl-3.1.0/openssl-3.1.0.tar.gz
tar -xvzf openssl-3.1.0.tar.gz && rm openssl-3.1.0.tar.gz
@drbh
drbh / d1-from-do.ts
Created January 8, 2023 22:29
A hacky but working solution to call D1 from a Durable Object
// our DO class
export class SomeDurableObject {
// should upgrade to explicit type in prod
env: any;
constructor(_controller, env) {
this.env = env;
}
// manually make request to D1 binding
import { ApiPromise, Keyring, WsProvider } from "@polkadot/api";
async function main() {
const wsProvider = new WsProvider("wss://rpc.parallel.fi");
const api = await ApiPromise.create({ provider: wsProvider });
// no blockHash is specified, so we retrieve the latest
const signedBlock = await api.rpc.chain.getBlock();
@drbh
drbh / columbus-4-terra-node.sh
Created September 7, 2021 18:30
How to run a mainnet Terra node
# clone release branch
git clone git@github.com:terra-money/core.git --branch=v0.4.6
# move into dir
cd core
# build it
make install
# check that we have the right version... etc
@drbh
drbh / pointer-receivers-tick.go
Created April 29, 2021 02:56
Showing the importance of using pointer receivers
package main
import (
"fmt"
)
type Item struct {
TestChan chan int64
}
@drbh
drbh / percent_money_printed_fed.py
Last active March 10, 2021 21:00
A snippet to see how much money is added to USD M2 every year - data from the St. Louis Federal Reserve
import pandas as pd
# view original data here
# https://fred.stlouisfed.org/series/M2SL
url = "https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23e1e9f0&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=968&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=M2SL&scale=left&cosd=1959-01-01&coed=2021-01-01&line_color=%234572a7&link_values=false&line_style=solid&mark_type=none&mw=3&lw=2&ost=-99999&oet=99999&mma=0&fml=a&fq=Monthly&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2021-03-10&revision_date=2021-03-10&nd=1959-01-01"
df = pd.read_csv(url)
#### UNCOMMENT TO ACCOUNT FOR 1.9T
#new_total = df.tail(1)["M2SL"].values[0] + 1900.0
#df = df.append(pd.DataFrame([["2021-03-10", new_total]], columns = ["DATE", "M2SL"]))
@drbh
drbh / fetch-emsi-skills.py
Created February 22, 2021 16:30
fetch all emsi skills with pandas and requests in Python3
import pandas as pd
import requests
CLIENT_ID = "<CLIENT_ID>"
CLIENT_SECRET = "<CLIENT_SECRET>"
CLIENT_SCOPE = "emsi_open"
VERSION = "latest"
url = "https://auth.emsicloud.com/connect/token"
payload = f"client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}&grant_type=client_credentials&scope={CLIENT_SCOPE}"