Skip to content

Instantly share code, notes, and snippets.

@alexsavio
alexsavio / pubsub.py
Created April 19, 2021 07:13
GCP PubSub publisher
import time
from flask import Request
from google.cloud import pubsub_v1
from lib.logger import get_logger
logger = get_logger(__name__)
@alexsavio
alexsavio / switch_cloudwatch_rules.py
Created December 1, 2020 21:50
Switch on/off AWS CloudWatch Rules
import os
import logging
from typing import Dict, List
import boto3
from botocore.exceptions import ClientError
class CloudWatchRules:
@alexsavio
alexsavio / gnupg_scdaemon.md
Created February 11, 2020 15:19 — forked from artizirk/gnupg_scdaemon.md
OpenPGP SSH access with Yubikey and GnuPG

OpenPGP SSH access with Yubikey and GnuPG

Yubikey, Smart Cards, OpenSC and GnuPG are pain in the ass to get working. Those snippets here sould help alleviate pain.

Yubikey Config under Ubuntu

To reset and disable not used modes on Yubikey you need the ykman program

You can install it using those commands

@alexsavio
alexsavio / test_timed_cache.py
Last active July 15, 2024 21:23
Python TimedCache
from time import sleep
from timed_cache import Memoize
def test_memoize():
"""
Test if the cached function results expires in the expected time.
"""
@alexsavio
alexsavio / .gitconfig
Created November 13, 2019 21:02
.gitconfig
[alias]
co = checkout
br = branch
ci = commit
st = status
unstage = reset HEAD --
undo = reset --soft HEAD~1
last = log -1 HEAD
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%C
reset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --branches
@alexsavio
alexsavio / tmux.md
Created October 29, 2019 07:24 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@alexsavio
alexsavio / script.js
Last active August 12, 2019 17:10
Google Drive autofill template script
// create a menu
function onOpen() {
var menuEntries = [ {name: "Create invoice", functionName: "CreateInv"}];
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.addMenu("Invoice Generator", menuEntries);
}
function CreateInv() {
// specify doc template and get values from spread
@alexsavio
alexsavio / signing-vbox-kernel-modules.md
Last active August 5, 2019 14:21 — forked from reillysiemens/signing-vbox-kernel-modules.md
Signing VirtualBox Kernel Modules

Signing VirtualBox Kernel Modules

These are the steps I followed enable VirtualBox on my laptop without disabling UEFI Secure Boot. They're nearly identical to the process described on [Øyvind Stegard's blog][blog], save for a few key details. The images here are borrowed from the [Systemtap UEFI Secure Boot Wiki][systemtap].

  1. Install the VirtualBox package (this might be different for your platform).
    src='https://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo'
@alexsavio
alexsavio / conftest.py
Last active April 11, 2019 14:44
Demo of Ports and Adapters Architecture + Testing for cloud functions in Python
import os
class InMemoryUserRepository(UserRepository):
def __init__(self):
self._items = []
def add(self, user: User) -> User:
self._items.append(user)
def get(self, id: str) -> User:
@alexsavio
alexsavio / SNSTopic.py
Created July 8, 2017 11:15 — forked from stuartmyles/SNSTopic.py
A complete example of how to use Amazon Web Services Simple Notification Services from Python. This code uses the boto library https://github.com/boto/boto to create a topic, wait for a confirmation and then send a success message. Simply plug in your AWS access and secret keys, plus your email and mobile phone number.
# An example of how to use AWS SNS with Python's boto
# By Stuart Myles @smyles
# http://aws.amazon.com/sns/
# https://github.com/boto/boto
#
# Inspired by parts of the Ruby SWF SNS tutorial http://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-sns-tutorial-implementing-activities-poller.html
# And the Python SNS code in http://blog.coredumped.org/2010/04/amazon-announces-simple-notification.html and http://awsadvent.tumblr.com/post/37531769345/simple-notification-service-sns
import boto.sns as sns
import json