Skip to content

Instantly share code, notes, and snippets.

View jwoglom's full-sized avatar

James Woglom jwoglom

View GitHub Profile
import json
import socket # Just so we can properly handle hostname exceptions
import obspython as obs
import paho.mqtt.client as mqtt
import ssl
import pathlib
import time
import enum
import uuid
from multiprocessing import Lock
@jwoglom
jwoglom / lgtv-fullscreen-browser.js
Created February 12, 2023 03:13
LG WebOS TV Web Browser Fullscreen
#!/usr/bin/env node
var lgtv = require("lgtv2")({
url: 'ws://livingroomtv:3000'
});
lgtv.on('connect', function () {
console.log('connected');
lgtv.getSocket('ssap://com.webos.service.networkinput/getPointerInputSocket',
function(err, sock) {
if (!err) {
@jwoglom
jwoglom / twitter-likes-archiver.py
Created November 18, 2022 06:02
Download all tweets liked by a user from Twitter
# pip3 install tweepy
import tweepy
import json
import time
# Follow the instructions to create a new development project and API keys
# from https://developer.twitter.com/en/portal/petition/essential/basic-info
# and enter the key, secret, and bearer token.
apiv2 = tweepy.Client(
consumer_key='',
@jwoglom
jwoglom / nextcloud-postgres-cleanup-filecache.sql
Created November 12, 2022 18:40
Clean up unneeded items in Nextcloud filecache to save Postgres disk space
-- Connect to postgresql instance for nextcloud:
-- `psql -U nextcloud nextcloud`
-- Get tables with largest disk space
SELECT
table_name,
pg_size_pretty(table_size) AS table_size,
pg_size_pretty(indexes_size) AS indexes_size,
pg_size_pretty(total_size) AS total_size
FROM (
@jwoglom
jwoglom / avchd-mts-to-mp4.sh
Created June 3, 2022 03:04
Convert AVCHD folder containing BDMV MTS video files to MP4 with ffmpeg
#!/bin/bash -x
# Invoke with:
# ./avchd-mts-to-mp4.sh AVCHD/BDMV/STREAM/*.MTS
exifdateformat='%Y:%m:%d %T%z'
ffmpegdateformat='%FT%T'
filenamedateformat='%Y%m%d_%H%M%S'
getfileinfodateformat='%m/%d/%Y %T'
for srcfile in "$@"
do
exifcreatetime=$(exiftool -s -s -s -datetimeoriginal $srcfile)
@jwoglom
jwoglom / AndroidBugPOC.java
Last active December 10, 2021 18:48
AndroidBugPOC.java
import java.util.*;
import java.lang.*;
/**
Output:
with 75 random hashcode items, 1 / 1000000 (9.999999999999999E-5%) of sorts triggered an exception
java.lang.IllegalArgumentException: Comparison method violates its general contract!
with 93 random hashcode items, 1 / 1000000 (9.999999999999999E-5%) of sorts triggered an exception
java.lang.IllegalArgumentException: Comparison method violates its general contract!
with 193 random hashcode items, 1 / 1000000 (9.999999999999999E-5%) of sorts triggered an exception
@jwoglom
jwoglom / video-length.py
Created January 3, 2021 00:51
video-length.py: sums the duration of all video files passed as arguments using ffmpeg
#!/usr/bin/env python3
# video-length.py: sums the duration of all video files passed as arguments using ffmpeg
import subprocess
import sys
import datetime
files = sys.argv[1:]
CMD = "ffmpeg -i file:\"%s\" 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//"
@jwoglom
jwoglom / data.py
Created October 13, 2020 02:35
Download Perusall readings as PDF
title = "The title of the article"
urls="""
<image URLs scraped from the page>
"""
@jwoglom
jwoglom / provided.py
Created January 27, 2020 21:11
CS365 Python Intro Session
def numbers_sum_to_ten(num1, num2):
"""
Return True if num1 and num2 sum to 10.
Ex.: numbers_sum_to_ten(5, 5) => True
"""
pass
def word_count(search_word, sentences):
"""
Return the number of times a given word occurs in a group of sentences.
function single_replace {
python3 -c "import sys, re; print(re.sub(sys.argv[1], sys.argv[2], open(sys.argv[3]).read()))" "$@"
}
function multi_replace {
python3 -c "import sys, re; t=open(sys.argv[1]).read();
for i in range(2, len(sys.argv)-1, 2):
t=re.sub(sys.argv[i], sys.argv[i+1], t)
print(t, end='')" "$@"
}