Skip to content

Instantly share code, notes, and snippets.

@pedrovgp
pedrovgp / upsert_df.py
Last active June 14, 2024 13:19
Allow upserting a pandas dataframe to a postgres table (equivalent to df.to_sql(..., if_exists='update')
# Upsert function for pandas to_sql with postgres
# https://stackoverflow.com/questions/1109061/insert-on-duplicate-update-in-postgresql/8702291#8702291
# https://www.postgresql.org/docs/devel/sql-insert.html#SQL-ON-CONFLICT
import pandas as pd
import sqlalchemy
import uuid
import os
def upsert_df(df: pd.DataFrame, table_name: str, engine: sqlalchemy.engine.Engine):
@arnodeceuninck
arnodeceuninck / sheets-to-calendar.gs
Last active May 13, 2023 00:54
Import events from a Spreadsheet into Google Calendar. Written in Google Apps script, allows you to create a planning in Google Sheets, and then sync the dates written in the sheet to your calendar.
// ID of the calendar, can be found in sharing settings of the calendar
var calendarID = "winak.be_7somerandomcharacters@group.calendar.google.com"
// Input data from the sheet with name "Final Planning"
let planning = SpreadsheetApp.getActive().getSheetByName('Final Planning')
// Get cell values as strings in 2D array format
let eventsData = planning.getDataRange().getValues()
// Column name shortcuts, their index get determined in setRowIndices based on the column header
@Webreaper
Webreaper / docker-compose.yml
Last active June 22, 2024 15:53
Sample Docker-compose file which shows how to set up Sonarr, Radarr, Prowlarr, Lidarr, QBittorrent and a VPN container so that all all traffic from the containers is routed through the VPN. Also includes Plex and get_iplayer containers, which are not routed through the VPN.
# Docker compose to set up containers for all services you need:
# VPN
# Sonarr, Radarr, Lidarr, Qbittorrent
# Non-VPN
# Plex, get_iplayer
# Before running docker-compose, you should pre-create all of the following folders.
# Folders for Docker State:
# /volume1/dockerdata. - root where this docker-compose.yml should live
# /volume1/dockerdata/plex - Plex config and DB
# /volume1/dockerdata/sonarr - Sonarr config and DB
@alfredlucero
alfredlucero / emailLinkRedirectCypress.ts
Last active July 9, 2022 15:45
Cypress Tips/Tricks - Using cheerio to parse email body contents, make cy.request() to links, follow redirect back to web app
// In some page_object.ts
// For this scenario, we have a Cypress test that triggers a download email to be sent to the user's inbox after performing
// some UI steps on the page i.e. clicking a button on the page to export data to a CSV for us to download
// We need to follow the download link in the email back to the web app we own and control to continue the test
redirectToCSVDownloadPageFromEmail({
user,
pass,
searchString,
}: {
user: string;
@JonahKr
JonahKr / climate.yaml
Last active April 18, 2023 08:33
Automation Template for managing Homeassistant Climate entities through events (Rhasspy)
# Manging Rhasspy calls for the climate entity
# A climate entity controls temperature, humidity, or fans, such as A/C systems and humidifiers.
# --> https://developers.home-assistant.io/docs/core/entity/climate/
automation:
#Changing the Temperature
- alias: Rhasspy Set Temperature
description: Set new target temperature
trigger:
- event_data: {}
@terafin
terafin / UniFi USG DNS Redirect Setup.md
Last active April 19, 2024 21:40
UniFi USG DNS Redirect Setup
  1. Log into unifi controller web UI
  2. Go to Settings
  3. Select Routing & Firewall
  4. Select Firewall
  5. Select Groups
  6. Hit "Create new Group"
  7. Enter all your DNS servers here you want to be allowed on the local LAN (Eg, mine is 10.0.1.1 - gateway, 10.0.1.14 - pi-hole)
  8. Name this "Allowed DNS Servers"
  9. Hit OK
  10. SSH into the Gateway - NOT the CloudKey (username/password is whatever you set up)
@prasanthmj
prasanthmj / messages.html
Last active January 29, 2024 17:50
Parse and extract data from Gmail to Google Sheet. Read full article here: http://blog.gsmart.in/parse-and-extract-data-from-gmail-to-google-sheets/
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<title>Message Display Test</title>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>
<body style="padding:3em;">
<h1>Messages</h1>
<ul>
@sferich888
sferich888 / requests-saml.py
Last active January 13, 2023 06:59
Example SAML implementation using Python Requests
from requests.auth import AuthBase
class SAML(AuthBase):
from bs4 import BeautifulSoup
"""Implemeents SSO with RH auth.redhat.com"""
def __init__(self, username, password):
# setup any auth-related data here
self.username = username
self.password = password
function YNABAccounts(accessToken, budgetId) {
const accounts = _getBudgetAccounts(accessToken, budgetId);
if(accounts == null) {
return null;
}
const columns = ["Name", "Type", "Budget", "Closed", "Balance"];
const rows = accounts.map(function (acc) {
return [
@thomassuckow
thomassuckow / ExtractEmailBodyText.java
Created November 10, 2017 16:30
Nifi Extract Email Body Text Processor
package foo;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.nio.charset.StandardCharsets;
import org.apache.nifi.annotation.behavior.InputRequirement;
import org.apache.nifi.annotation.documentation.CapabilityDescription;