Skip to content

Instantly share code, notes, and snippets.

@jasonrdsouza
jasonrdsouza / sqliteSchemaDiagram.sql
Created March 23, 2024 15:30
SQLite Schema Diagram Generator
-- Generates a diagram of table schema relationships in
-- GraphViz DOT format (https://graphviz.org/doc/info/lang.html)
-- via a SQLite query
-- To run:
-- > sqlite3 path/to/database.db -init sqlite-schema-diagram.sql "" > schema.dot
-- > dot -Tsvg schema.dot > schema.svg
-- Fork of: https://gitlab.com/Screwtapello/sqlite-schema-diagram/
@jasonrdsouza
jasonrdsouza / pocket_exporter.py
Last active January 31, 2024 19:13
Export archived article data from Pocket
'''This script can be used to export data from Pocket (getpocket.com)
Uses include migrating to a different "read it later" service, saving
specific articles to another service, backing up your reading history,
and more.
Currently it can be used to export links and metadata for archived
articles with a given tag, which are more recent than a given timestamp.
An example use case is to export all articles you have tagged as
"to-export", which are newer than 10 days old. The timestamp functionality
@jasonrdsouza
jasonrdsouza / key_detect.py
Created February 24, 2012 15:54
Python function to get keypresses from the terminal
def getchar():
#Returns a single character from standard input
import tty, termios, sys
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
@jasonrdsouza
jasonrdsouza / gmail.py
Created January 25, 2012 04:52
Python script to access a gmail account and download particular emails
import email, getpass, imaplib, os
detach_dir = '.' # directory where to save attachments (default: current)
user = raw_input("Enter your GMail username:")
pwd = getpass.getpass("Enter your password: ")
# connecting to the gmail imap server
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login(user,pwd)
m.select("cs2043") # here you a can choose a mail box like INBOX instead
@jasonrdsouza
jasonrdsouza / combineS3Files.py
Last active June 3, 2023 17:22
Python script to efficiently concatenate S3 files
'''
This script performs efficient concatenation of files stored in S3. Given a
folder, output location, and optional suffix, all files with the given suffix
will be concatenated into one file stored in the output location.
Concatenation is performed within S3 when possible, falling back to local
operations when necessary.
Run `python combineS3Files.py -h` for more info.
'''
@jasonrdsouza
jasonrdsouza / huffman.py
Last active July 13, 2022 00:33
Simple Huffman coding implementation
from queue import PriorityQueue
from collections import Counter
from dataclasses import dataclass, field
from typing import Any
@dataclass(order=True)
class Node:
count: int
value: Any=field(compare=False)
@jasonrdsouza
jasonrdsouza / declarative_migrator.py
Created May 3, 2022 21:35
Proof of Concept declarative schema migration script for SQLite
# coding: utf-8
"""Simple declarative schema migration for SQLite.
See <https://david.rothlis.net/declarative-schema-migration-for-sqlite>.
Author: William Manley <will@stb-tester.com>.
Copyright © 2019-2022 Stb-tester.com Ltd.
License: MIT.
"""
@jasonrdsouza
jasonrdsouza / expenses_appscript.js
Last active March 3, 2021 14:23
Google AppsScript script to automate splitting expenses and sending a monthly email requesting payment
/*
* Script to automate sending the monthly debt emails.
*/
var EMAIL_RECEPIENT = "example@gmail.com"
var COLUMNS = {
"date": 0,
"paid": 1,
"total": 2,
@jasonrdsouza
jasonrdsouza / compressFolder.go
Created February 27, 2021 16:29
Demonstration of how to compress a folder and all of its contents in Go
// Original source: https://github.com/mimoo/eureka/blob/master/folders.go
package main
import (
"archive/tar"
"bytes"
"compress/gzip"
"fmt"
"io"
"os"
@jasonrdsouza
jasonrdsouza / smart_connect.go
Last active February 27, 2021 16:23
Simple HTTP server to intelligently route and multiplex requests over a collection of backing network connections
// Small exploration into the ease of implementing an interface (and server) to abstract
// away the complexities of dealing with cumbersome and non-standardized network
// protocols.
//
// The resulting server exposes a simple HTTP API to clients, routing and forwarding
// their requests behind the scenes to a collection of raw network streams. The goal
// is to hide the underlying communication protocol and network multiplexing from
// clients, instead exposing a simple request/response API spoken in the lingua franca
// of the web.
//