Skip to content

Instantly share code, notes, and snippets.

View Veticus's full-sized avatar

Tim Veticus

  • Aarhus, Denmark
View GitHub Profile
@Veticus
Veticus / get_all_sizes.sql
Created April 17, 2021 18:47
Get size of all tables
SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;
SELECT table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
# This is to get a list of IP's, banned by fail2ban on a remote machine.
#
# It connects via SSH, so sqlite3 won't need to be exposed.
#
# Authentication is handled by the local machine, so in this case a keyfile is used.
#
# In addition the user has been granted NOPASSWD in the /etc/sudoers file. Below is an example
# username ALL=(ALL:ALL) NOPASSWD:ALL
# This allows the user to use sudo, without having to submit a password.
#
@Veticus
Veticus / mqtt_publish.py
Last active April 9, 2020 07:55
A quick and dirty way to publish a string to a mqtt broker.
# Get the paho-mqtt library using pip: "pip3 install paho-mqtt"
import paho.mqtt.publish as publish
def mqttpublish(topic="paho/test/multiple", payload="multiple 2"):
msgs = [(topic, payload, 0, False)]
publish.multiple(msgs, hostname="broker.hivemq.com")
mqttpublish("paho/test/multiple", "TEST01")
@Veticus
Veticus / is_vs_double_equals.py
Last active May 22, 2023 19:28
Dan Baders explanation of the difference between "is" and "==". A great explanation of a concept many teach badly.
# "is" vs "=="
a = [1, 2, 3]
b = a
a is b
# True
a == b
# True
#! /usr/bin/python
# Timing according to http://www.nu-ware.com/NuCode%20Help/index.html?morse_code_structure_and_timing_.htm
# Also, use python3 for this... and in general... please, for fuck's sake!
import numpy
import pyaudio
import math
@Veticus
Veticus / calendar.js
Last active May 22, 2023 19:29
Get 10 next events in a shared google calendar. (calendar id @line 51)(number of events on53)
const fs = require('fs');
const readline = require('readline');
const {google} = require('googleapis');
const SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'];
const TOKEN_PATH = 'token.json';
fs.readFile('credentials.json', (err, content) => {
if (err) return console.log('Error loading client secret file:', err);
authorize(JSON.parse(content), listEvents);
});
@Veticus
Veticus / eupgf.py
Last active May 22, 2023 19:31
Bad attempt at getting the european power grid supply frequency from swissgrid.ch. By the time someone reads this, the URL probably doesn't do the trick anymore.
import urllib.request
import urllib.parse
import ast
import codecs
url = "http://www.swissgrid.ch/mvc.do/applicationFrequencyTimeAjax?tooltipText=+Live+data+(updated+every+30+seconds%2c+capacity+data+delayed+by+20+minutes)&deviationText=Current+grid+time+deviation&frequencyText=Current+frequency&_charset_=UTF-8"
enc = codecs.encode(str.encode(url), "hex")
print(enc)
dec = str(codecs.decode(enc, "hex"))[2:-1]
@Veticus
Veticus / aboutdismac.sh
Last active November 29, 2022 03:29
Playing with "About Dis Mac" by mjk
#!/bin/bash
# This is almost a copy of "About Dis Mac" by mjk. I just made minor changes to make it work with the current beta 3 of OS X 10.14.1.
# Unfortunately i cannot find the original source of this wonderfull collection of functions. But it deserves to be preserved.
function write_header () {
local h="$@"
printf "%s\n" "####################"
printf "%s\n" "${h}"
printf "%s\n" "####################"