Skip to content

Instantly share code, notes, and snippets.

View jvacek's full-sized avatar

Jonas Vacek jvacek

View GitHub Profile
@jvacek
jvacek / bigquery_sql_paginate_generator.py
Created August 9, 2024 17:27
Python BigQuery client paginate SQL results via generator
from google.cloud import bigquery
def fetch_rows(batch_size: int):
"""Allows you to not store the entire BQ table as results in memory, and paginate over in batches instead through a generator"""
client = bigquery.Client(project='my.project)
job_config = bigquery.job.QueryJobConfig()
job_config.use_query_cache = True
query_string = "Select * from table"
@jvacek
jvacek / README.md
Created January 7, 2023 23:52
Homebridge Apple TV AirPlay Status Sensor

This setup will add a contact switch to show when your apple tv is playing music over airplay.

The config and script below will give you a contact switch which shows whether AirPlay Music is playing or not.

Follow the instructions for https://github.com/cristian5th/homebridge-appletv, and save your tokens separately from your script.

image

@jvacek
jvacek / README.md
Last active July 28, 2022 11:15
`aws-cli` easy 2FA authentication

This will help you set up two functions to manage your login status when using two-factor authentication with the aws-cli tool.

Of course, the auth tokens only live within the terminal session's environment, and are not persistent.

You will need to start a new terminal session after following the instructions.

Usage

When done, you can perform any aws tasks without authenticating, like below.

aws-login 123456
@jvacek
jvacek / Remove unused python imports on save in VSCode.md
Last active June 18, 2023 10:20
Remove unused python imports on save in VSCode

Auto-remove unused python imports in VSCode on save

I could not find a proper full configuration for this online, and I know I'll need this again in the future.

There are two ways to achieve this with some plugins; one via hitting the shell and doing an in-place replace, the other is by doing it with extensions configurable in vscode. Both should give you the same results.

Install VSCode extensions needed:

If running via bash:

@jvacek
jvacek / aws-mfa.sh
Last active September 7, 2021 14:16 — forked from mankins/aws-mfa.sh
aws mfa cli tool
#!/bin/bash
# From a user's MFA code, generate accesskey, secret, session token
#
# ENV inputs:
# AWS_CLI_INPUT = /path/to/token/config.json
# AWS_PROFILE = The Aws profile to use for aws commands
MFA_CODE=$1
if [ -z $MFA_CODE ]; then
@jvacek
jvacek / checkreboot.sh
Last active March 22, 2024 08:29
Check whether linux server needs reboot and return for how long has the reboot been necessary in PRTG's format
#!/bin/bash
#You can install and also update this script by running the follwoing command
# sudo curl https://gist.githubusercontent.com/jvacek/18aaf9858d8ab8016297bee5e71f59ef/raw/checkreboot.sh -L --create-dirs -o /var/prtg/scripts/checkreboot.sh; sudo chmod a+rx -R /var/prtg/
#Create a new sensor for your machine, select SSH script, and select checkreboot.sh from the script dropdown.
#The value returned is in seconds. 0 seconds means no file is present.
#The sensor will be set to warning when the file is present.
#If you want the sensor to go down when a reboot has been required for more than 24h, set the upper error limit of the valu channel on the sensor to 86400.