Skip to content

Instantly share code, notes, and snippets.

View Veticus's full-sized avatar

Tim Veticus

  • Aarhus, Denmark
View GitHub Profile
@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" "####################"
@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 / 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);
});
#! /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 / 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
@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")
# 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 / 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;
@Veticus
Veticus / show_starting_digit_distribution_from_PFRAND.py
Last active September 10, 2023 13:31
distribution of numbers by first digit, from 1.6 milion randomly generated numbers
import numpy as np
import matplotlib.pyplot as plt
dist_nums = [834109, 193930, 83203, 83448, 83712, 83123, 83335, 83304, 83044]
rangenums = [i for i in range(1, 10)]
dist_vals = list(zip(rangenums, dist_nums))
labels, values = zip(*dist_vals)
indexes = np.arange(len(labels))
width = 1
@Veticus
Veticus / publicDNSServers.md
Created October 5, 2021 05:34
My current list of public DNS servers. Used for various purposes.
Service IPv4 IPv6
Google Public DNS 8.8.8.8 2001:4860:4860::8888
Google Public DNS 8.8.4.4 2001:4860:4860::8844
Cloudflare 1.1.1.1 2606:4700:4700::1111
Cloudflare 1.0.0.1 2606:4700:4700::1001
Quad9 9.9.9.9 2620:fe::9
Quad9 149.112.112.112 2620:fe::fe
OpenDNS 208.67.222.222 2620:119:35::35
OpenDNS 208.67.220.220 2620:119:53::53