Skip to content

Instantly share code, notes, and snippets.

View dbrant's full-sized avatar
🍣
Kickin' it

Dmitry Brant dbrant

🍣
Kickin' it
View GitHub Profile
@dbrant
dbrant / validate_jsonschema.py
Last active January 4, 2024 17:52
Validate JSON from a URL against a Json Schema from another URL.
# Make sure to install 'jsonschema' as well as any validator packages,
# such as 'rfc3339-validator', that are used by the schema.
import json
import sys
import urllib.request
import urllib.error
import jsonschema
def main():
# Dmitry Brant, 2023
import requests
import urllib
def parseDescription(content):
description = ""
sStart = content.lower().find("{{short description|")
if sStart != -1:
sEnd = content.find("}}", sStart)
# Dmitry Brant, 2023
import requests
def cleanupForCsv(s):
return s.replace("\"", "”").replace("'", "’").replace("\r", " ").replace("\n", "")
apiBaseUrl = "https://www.wikidata.org/w/api.php?format=json&formatversion=2&"
continueStr = ""
userEditCounts = {}
@dbrant
dbrant / DeleteEmptySpam.gs
Last active May 2, 2022 00:25
Google Apps Script for deleting empty spam messages from Gmail
function deleteMessageIfEmpty() {
var threads = GmailApp.search('is:unread in:inbox')
for (const thread of threads) {
const messages = thread.getMessages()
if (messages.length != 1) { continue; }
const msg = messages[0];
const words = msg.getPlainBody().trim().split(" ");
@dbrant
dbrant / MacRetrospectTapeBackup.txt
Created April 20, 2022 13:50
Tape backup format for Mac Retrospect v??
(Dmitry Brant, Apr 2022)
Recently I came across a backup tape (an AIT-3 100GB tape) that was written with a format
I didn't recognize. The only thing I knew is that it came from a Mac workstation, which means
it was likely written using Retrospect, which was a popular backup tool at the time.
This is the result of my reverse-engineering effort to get the contents out of this archive.
------------------
This backup format is composed of a sequence of blocks which use FourCC-style formatting.
(All data is big-endian. Dates are formatted as seconds since Jan 1 1904.)
@dbrant
dbrant / playstorereport.py
Last active April 28, 2022 12:55
Download statistics from Google Play Store console using Google Cloud API.
import csv
from google.cloud import storage
# To install Google Cloud dependency:
# pip install --upgrade google-cloud-storage
# Private key to use for authenticating our service account:
key_file = 'playStoreAccessKey.json'
# Bucket name for our data (copy from Play Store Console):
@dbrant
dbrant / fix_quotes.sql
Created October 27, 2021 01:22
Fix incorrectly encoded quotes and apostrophes in SQL database
UPDATE wp_posts SET post_content = REPLACE(post_content, '“', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, '”', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, '’', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, '‘', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, '—', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, '–', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, '•', '-');
UPDATE wp_posts SET post_content = REPLACE(post_content, '…', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, '…', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'Â', ' ');
@dbrant
dbrant / uploadfiles.py
Created January 8, 2020 21:26
Upload a list of files to Google Drive
import os
import sys
import pickle
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
directoryIndexMap = {}
@dbrant
dbrant / sendemail.py
Created January 8, 2020 21:19
Send email via python
import smtplib
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("account@example.com", password)
msg = "To: destination@example.com\n"
msg += "From: source@example.com\n"
msg += "Subject: "
@dbrant
dbrant / symbology
Last active July 21, 2020 02:04
Useful symbols
ligature: ff fi fl ffi ffl
hyphen: ‐
non-breaking hyphen: ‑
minus sign: −
figure dash: ‒
en dash: –
em dash: —
horizontal bar: ―