Skip to content

Instantly share code, notes, and snippets.

@sychou
sychou / keccak_hex.py
Created July 23, 2024 16:12
Keccak encode hex value
# Example of how to keccak encode a hex value. Used for converting Snapshot proposal ID to Votium Initiate Deposit _proposal parameter.
#
# Given the Snapshot proposal ID:
# https://snapshot.org/#/cvx.eth/proposal/0xd2f6785ba7e199e3a0169c9bfd561ae6d7c81baa54de4291eef0c355251eb94c
# 0xd2f6785ba7e199e3a0169c9bfd561ae6d7c81baa54de4291eef0c355251eb94c
#
# Should match the following Votium initiation proposal ID:
# https://etherscan.io/tx/0xcb95fedbcbd8889a741e0a12a61536e0bcc46b13b59c997abda8f1e214ede253
# 0xab60d2a73796b1c01607b025b4fa6b83332b0adee021020a42ce56c88d9eebe2
@sychou
sychou / find_block_by_ts.py
Created July 23, 2024 16:06
Find Block Number by Timestamp
from datetime import datetime
from web3 import Web3
# Connect to a local Ethereum node
HTTP_PROVIDER='http://localhost:8545'
w3 = Web3(Web3.HTTPProvider(HTTP_PROVIDER))
def find_block_number_by_timestamp(target_timestamp, tolerance=60):
"""
@sychou
sychou / export_people.scpt
Last active May 27, 2024 22:10
Export Obsidian People to Contacts
--SCRIPT--
-- IMPORTANT SETTINGS
set peopleFolder to "/Users/sean/Vaults/Main/People/"
-- Create contacts from files
set fileNames to list folder (POSIX file peopleFolder) without invisibles
repeat with i from 1 to count of fileNames
set aFileName to item i of fileNames
set filePath to (peopleFolder & aFileName) as POSIX file
@sychou
sychou / Export Contacts to Obsidian Markdown.scpt
Created May 25, 2024 03:30
Export Contacts to Obsidian Markdown
-- Set the folder path for the Obsidian notes
set folderPath to "/Users/sean/Vaults/Test/People"
-- Function to convert special labels to human-readable form and title case them
on getReadableLabel(originalLabel)
if originalLabel is "_$!<Home>!$_" then
return "Home"
else if originalLabel is "_$!<Work>!$_" then
return "Work"
else if originalLabel is "_$!<Mobile>!$_" then
@sychou
sychou / main.js
Last active March 20, 2024 20:14
Task Processor Obsidian Plugin
/*
Task Processor Plugin for Obsidian
To use this plugin:
1. Create a directory named "task-proc" under your vault plugin directory
(e.g. .obsidian/plugins/task-proc)
2. Copy this file (main.js) and manifest.json to the "task-proc" directory
*/
@sychou
sychou / ask.py
Last active February 21, 2024 03:41
ChatGPT cli quickie
#!/usr/bin/env python
# Place this file in your path
# Mark it executable (chmod +x ask)
# You will need openai lib installed (pip install openai)
# You will also need to set the OPENAI_API_KEY environment variable
import os
import sys
from openai import OpenAI
@sychou
sychou / codegpt.py
Created February 20, 2024 18:47
Format Code with GPT
from openai import OpenAI
import os
import sys
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
raise ValueError("OPENAI_API_KEY environment variable not set")
exit()
@sychou
sychou / kagi_sum.js
Created October 23, 2023 17:58
Kagi Summarize Current URL
javascript:(function(){
var url = window.location.href;
var newUrl = "https://kagi.com/summarizer/?url=" + url;
window.open(newUrl, "_blank");
})();
@sychou
sychou / copy_noparam_url.js
Created October 22, 2023 16:02
Copy Noparam URL Bookmarklet
javascript:(function(){
var url = window.location.href;
var strippedUrl = url.split('?')[0];
if (navigator.clipboard) {
navigator.clipboard.writeText(strippedUrl).then(function() {
console.log('URL copied to clipboard successfully!');
}).catch(function(err) {
console.error('Could not copy URL: ', err);
});
} else {
@sychou
sychou / convert.py
Created October 11, 2023 11:19
Import Day One to Obsidian
import json
from datetime import datetime
from os import path
DATA_DIR = 'data'
VAULT_DIR = 'vault'
JOURNAL = 'World'
def parse_date(s: str):
datestr = s[0:10]