Skip to content

Instantly share code, notes, and snippets.

@davidair
davidair / attachment_remover.py
Last active December 3, 2024 08:41
Tool that uses the Gmail API to remove attachments from emails. Requires a Google Cloud Project, Gmail API enabled, Desktop App Credentials and the following pip packages: google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client click
#
# The MIT License
#
# Copyright 2024 David Airapetyan
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
@davidair
davidair / analyze_news.py
Last active November 25, 2024 06:20
Analyze news article sentiment using ollama
#
# The MIT License
#
# Copyright 2024 David Airapetyan
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
@davidair
davidair / animate_cube.py
Created February 25, 2024 01:47
Blender Script to continuously animate cubes of different heights
import bpy
import random
def my_animator(scene):
print("Frame change", scene.frame_current)
if scene.frame_current == 100:
bpy.ops.object.delete()
bpy.ops.mesh.primitive_cube_add(scale = (1, 1, 1 + random.uniform(0, 2.0)))
cube = bpy.context.active_object
@davidair
davidair / remove_net_8.patch
Created May 3, 2023 15:52
Fixing a build issue with slngen when .NET 8.0 is missing (based off faf0c43d8b6911881d7b8cf9bed7949636d00357 commit)
diff --git a/src/Microsoft.VisualStudio.SlnGen.Tool/Microsoft.VisualStudio.SlnGen.Tool.csproj b/src/Microsoft.VisualStudio.SlnGen.Tool/Microsoft.VisualStudio.SlnGen.Tool.csproj
index cde9cbd..eeb9cee 100644
--- a/src/Microsoft.VisualStudio.SlnGen.Tool/Microsoft.VisualStudio.SlnGen.Tool.csproj
+++ b/src/Microsoft.VisualStudio.SlnGen.Tool/Microsoft.VisualStudio.SlnGen.Tool.csproj
@@ -62,14 +62,6 @@
ReferenceOutputAssembly="false"
SkipGetTargetFrameworkProperties="true"
TargetFramework="net7.0" />
- <ProjectReference Include="..\Microsoft.VisualStudio.SlnGen\Microsoft.VisualStudio.SlnGen.csproj"
- SetTargetFramework="TargetFramework=net8.0"
#!/bin/bash
# Inspired by https://raspberrypi.stackexchange.com/a/28047/127204
MY_PATH="`dirname \"$0\"`"
LOG_PATH="/home/log/network.log"
now=$(date +"%m-%d %r")
# Which Interface do you want to check
@davidair
davidair / InstallShrinkPdf.cmd
Created April 18, 2022 16:06
Batch file that adds the "ShrinkPDF" context menu
@echo off
echo Installing the Shrink PDF shell extension
::Detecting gswin
where /q gswin64c.exe
IF ERRORLEVEL 1 (
echo Cannot find gswin64c.exe. Make sure you've installed Ghostscript.
echo You can install it with "choco install ghostscript".
@davidair
davidair / dyncode_td.py
Created April 11, 2021 05:03
Selenium Downloader for TD Canada Trust statements (technique described in https://airtdave.medium.com/exploring-web-automation-with-dynamic-code-f727b84fb7c0)
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
if not ('main_window_handle' in vars() or 'main_window_handle' in globals()):
print('main_window_handle is not defined')
main_window_handle = driver.current_window_handle
driver.switch_to.window(main_window_handle)
frame = driver.find_element_by_css_selector('frame')
driver.switch_to.frame(frame)
@davidair
davidair / renamer.py
Created April 11, 2021 04:59
Filename renamer for TD Canada Trust statements to normalize timestamps
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
import os
import pathlib
import re
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
pattern_td = r'(.+)([A-Za-z]{3})_(\d\d)-([A-Za-z]{3})_(\d\d)\_(\d\d\d\d).pdf'
pattern_loc = r'(.+)([A-Za-z]{3})_(\d\d)(_|-)(\d\d\d\d).pdf'
@davidair
davidair / dyncode_wiki.py
Last active March 8, 2021 23:53
Selenium-based harness that dynamically evaluates code to allow exploring web automation without re-running the driver
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
search_input = driver.find_element_by_xpath("//input[@id='searchInput']")
search_input.clear()
search_input.send_keys('George Washington')
submit_button = driver.find_element_by_xpath("//button[@type='submit']")
submit_button.click()
@davidair
davidair / MainForm.cs
Last active August 12, 2022 06:39
Sample for self-registering desktop C# app that creates and reacts to toasts
/**
* Copyright 2020 Google LLC.
* SPDX-License-Identifier: MIT
*/
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Windows.Forms;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;