Skip to content

Instantly share code, notes, and snippets.

View dukedorje's full-sized avatar
🥽

Duke Dorje dukedorje

🥽
  • Berkeley
View GitHub Profile
@dukedorje
dukedorje / useDrizzleStudio.ts
Created January 16, 2026 02:58
Use drizzle studio with OP-SQLITE. works with most recent version of op-sqlite and drizzle studio
/**
* Local implementation of useDrizzleStudio with op-sqlite support.
* Based on: https://github.com/slvssb/drizzle-studio-expo/blob/slvssb/op-sqlite-support/src/useDrizzleStudio.tsx
*
* Usage:
* useDrizzleStudio({ driver: "opsqlite", db: opsqliteDb });
*/
import type { DB } from "@op-engineering/op-sqlite";
import { useDevToolsPluginClient } from "expo/devtools";
import { useEffect } from "react";
/**
* Caveats
* 1. Reactive queries only fire on transactions - op-sqlite limitation. If you're mutating via
* drizzle directly (not using db.transaction()), you may need to call
* opsqliteDb.flushPendingReactiveQueries() after writes.
* 2. Table name extraction is basic - The shim parses FROM/JOIN clauses. Complex CTEs or subqueries
* might not be detected correctly.
* 3. Raw rows from reactive callback - The reactive callback returns raw row data (not through
* drizzle's transformations). For simple queries this works, but complex joins might differ
* from initial fetch.
@dukedorje
dukedorje / gist:44d0a6489626f67ca91726e858393526
Created December 1, 2023 20:02
Proclamation from King Samuel of OpenAI to the Realm
Hear ye, Hear ye,
I, King Samuel, Sovereign of the Land, do hereby announce my triumphant return to the throne of our esteemed kingdom of OpenAI. Lady Mira shall resume her esteemed duties as the Chief Tactician. The Royal Council shall henceforth comprise Sir Bret Taylor as its esteemed Chair, Lord Larry Summers, and Lord Adam D’Angelo.
Never have I been so invigorated for our kingdom's future. My heart swells with gratitude for the unwavering toil of every soul in these trying and unparalleled times. Our steadfastness and spirit have set us apart in all the lands. I am filled with optimism for our kingdom's prosperity and success in fulfilling our grand purpose.
Before I speak of what the morrow brings, I must extend my deepest thanks.
I hold in high regard Lord Ilya, a beacon of wisdom in our realm and a man of unparallelled virtue. Though he shall no longer hold a seat on our Council, our paths shall continue to intertwine, and we seek counsel on how he may further lend his expertise to our kingdom's
@dukedorje
dukedorje / mydomain.com.conf
Created October 1, 2023 05:12
SvelteKit Nginx config -- nodejs adapter
upstream sveltekit-server {
server 127.0.0.1:3000;
keepalive 8;
}
server {
listen 80;
server_name mydomain.com;
root /home/deploy/frontend/build/client;
@dukedorje
dukedorje / rook.ts
Created May 21, 2021 19:58
Manually withdraw staked k-tokens from KeeperDAO Legacy app with Hardhat
// Set up Hardhat project.
// Download the source code from etherscan: https://etherscan.io/address/0x35ffd6e268610e764ff6944d07760d0efe5e40e5#code
// and compile
// kTokens:
/*
kETH: 0x179212cb86D0eE6A4dfb2AbB1CF6A09feE0A9525
kwETH: 0x834CAcd6425fA6c7126b028B3d1E4cda53EB7257
kDAI: 0x8EE17Fa30D63ebD66e02205B1DF2f30D60a5CA30
kBTC: 0x77565202D78a6EDA565c7DC737FF1d8E64fd672a
kUSDC: 0x3045312Fb54f00f43d6607999e387Db58FFb4cF4
@dukedorje
dukedorje / purge-cloudflare-cache.sh
Created April 14, 2021 23:24
Curl command to clear cloudflare cache with API Token
curl -X POST "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE}/purge_cache" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{"files":["'$DEPLOY_URL'/index.html", "'$DEPLOY_URL'/manifest.json", "'$DEPLOY_URL'/asset-manifest.json", "'$DEPLOY_URL'/robots.txt"]}'
# Uses new API Token. You can give it only the power to purge caches
# Note the single quotes around $DEPLOY_URL -- this is to unquote the single quotes so it'll interpolate the variable properly
@dukedorje
dukedorje / rails-app-nginx.conf
Last active July 29, 2020 23:18
Nginx configuration for Rails app with Puma unix socket
# This file is prior to installing Certbot.
# Don't use HTTP Basic Auth without SSL!
# Redirect www requests to non-www host
server {
server_name www.myserver.com www.mysvr.com;
return 301 $scheme://myserver.com$request_uri;
}
# Upstream server (Puma socket)
@dukedorje
dukedorje / crontab-certbot
Created July 29, 2020 19:19
Certbot cron line for nginx plugin on Ubuntu
3 6 */15 * * certbot renew -n --nginx-ctl /usr/sbin/nginx --deploy-hook "systemctl reload nginx"
@dukedorje
dukedorje / puma.service
Last active July 29, 2020 19:17
Manage Puma server with SystemD and rbenv
[Unit]
Description=Puma HTTP Server
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/srv/app/current
# Helpful for debugging socket activation, etc.
@dukedorje
dukedorje / model_csv.rb
Last active May 26, 2020 19:42
ActiveRecord: Write a CSV of a model
require 'csv'
def write_model_csv(model_class, filename=nil)
filename = model_class.to_s.underscore.pluralize + '.csv' if filename.nil?
CSV.open(filename, 'wb') do |csv|
names = model_class.columns.map(&:name)
csv << names
model_class.find_each do |model|
csv << names.map {|attr| model[attr] }
end