Skip to content

Instantly share code, notes, and snippets.

@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]
@sychou
sychou / Contacts-Obsidian Sync.scpt
Created May 25, 2023 04:09
Mac Contacts and Obsidian Markdown File Sync
(*
Contacts-Obsidian Sync
May 24, 2023
This script syncs Contacts to Obsidian files. It is lightweight and not
intended to be a robust solution covering edge cases. This script assumes:
- There is a 1:1 correlation between a Person and an Obsidian file.
- The Obsidian file is in a certain format.
@sychou
sychou / Generate Page Tag List.js
Last active May 21, 2023 16:53
Obsidian Templater Script to Generate List of Pages and Their Tags
<%*
/**
To use this script:
1) Create an empty page in your Templater folder and copy this script into it
2) Go to page where you'd like to insert the list of Pages and their Tags
3) Use the Command Palette to "Open Insert Template Modal"
4) Select the page with this script
**/
tR += "# Page Tags (Auto Generated)\n\n"
@sychou
sychou / clean_contacts.scpt
Created April 29, 2023 12:09
AppleScript to clean up Contact labels when syncing with Google Contacts
tell application "Contacts"
-- set allContacts to every person
set allContacts to selection
repeat with aContact in allContacts
set allPhones to phones of aContact
repeat with aPhone in allPhones
if label of aPhone is "WORK" then
set label of aPhone to "work"
for i in *.txt
do
# ${i%%.*} uses Bash expansion to strip off the file extension
echo mv $i ${i%%.*}-suffix.txt
done
@sychou
sychou / guid.js
Last active December 18, 2015 03:22
Generate a simple guid
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
@sychou
sychou / nltk_play.py
Last active September 27, 2015 02:38
NLTK Book
import nltk
from nltk.book import *
from nltk.probability import FreqDist
console.log('NODE_PATH=' + process.env.NODE_PATH);
/* On the first time this file is loaded, check the database for proper
structure and version. If it doesn't exist, create it or update it.
*/
var connectionString = "pg://schou@localhost/heroku_db";
pg.connect(connectionString, function(err, client, done) {
console.log("simple query started");
client.query('SELECT * FROM test_table', function(err, result) {
console.log(result.rows[0].sender);
});
// client.on('error', function(err) {