Skip to content

Instantly share code, notes, and snippets.

@mlapida
mlapida / tootstats.py
Created January 10, 2023 05:35
A small python script that will publish some basic local stats to Mastodon (or GoToSocial). Can be put on a cron to do so regularly.
import requests
import psutil
import time
# A small function to calculate updtime.
def seconds_elapsed():
return time.time() - psutil.boot_time()
requests.post(
@mlapida
mlapida / ParticleWebook.json
Created February 26, 2016 18:00
A webhook to be used with a Particle Photon
{
"event": "sendSleep",
"url": "https://[yourendpoint].execute-api.us-east-1.amazonaws.com/prod/ParticleSleepV1",
"requestType": "Post",
"headers": {
"x-api-key" : "[yourapikey]"
},
"json": {
"name": "{{SPARK_EVENT_NAME}}",
"data": "{{SPARK_EVENT_VALUE}}",
@mlapida
mlapida / SleepEndpoint-Lambda.py
Last active June 6, 2019 04:58
A Lambda Function for receiving data from an API Endpoint and sending it to a DynamoDB table.
from __future__ import print_function
import logging
import boto3
from datetime import *
from boto3.dynamodb.conditions import Key, Attr
# enable basic logging to CloudWatch Logs
logger = logging.getLogger()
logger.setLevel(logging.INFO)
@mlapida
mlapida / sleepsensor.cpp
Created February 26, 2016 17:17
A small Particle firmware for sending movement data to a web-hook.
// Make sure to include the spcial library for the internet button
#include "InternetButton/InternetButton.h"
// Create a Button named b. It will be your friend, and you two will spend lots of time together.
InternetButton b = InternetButton();
int ledOldPos = 0;
char ledPosTrust[5];
int moveCount = 0;
int loopCount =0;
@mlapida
mlapida / EC2-Tag-Assets-Lambda.py
Last active January 17, 2024 08:10
A lambda function that will copy EC2 tags to all related Volumes and Network Interfaces. A full writeup can be found on my site https://empty.coffee/tagging-and-snapshotting-with-lambda/ - Thank you to the community for keeping this updated!
from __future__ import print_function
import json
import boto3
import logging
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
@mlapida
mlapida / PlexToAlexa-Lambda.py
Last active December 7, 2017 08:00
This is my attempt to get Alexa to return Plex's On Deck and Recently Downloaded lists. It's not the prettiest, but Plex's API isn't the best at the moment. Step-by-step blog post may be found here: http://mlapida.com/thoughts/plex-alexa-interacting-with-your-media-server-through-voice
from __future__ import print_function
import urllib
import urllib2
import xml.etree.ElementTree
import logging
#enable basic logging to CloudWatch Logs
logger = logging.getLogger()
logger.setLevel(logging.INFO)
@mlapida
mlapida / FlowLogs-to-S3-Lambda.py
Last active April 15, 2021 05:39
A Lambda Function for streaming and translating flow logs on the fly. This example was used for HP ArcSight. A full writeup can be found on my site http://mlapida.com/thoughts/exporting-cloudwatch-logs-to-s3-lambda
import boto3
import logging
import json
import gzip
import urllib
import time
from StringIO import StringIO
logger = logging.getLogger()
logger.setLevel(logging.INFO)
@mlapida
mlapida / CloudWatchLogsKinesisFirehose-Lambda.py
Last active October 3, 2019 01:01
A short Lambda Function the can be sent CloudWatch Logs (in the case Flow Logs) and send them to Kinesis Firehose for storage in S3. A full writeup can be found on my site http://mlapida.com/thoughts/exporting-cloudwatch-logs-to-s3-lambda
import boto3
import logging
import json
import gzip
from StringIO import StringIO
logger = logging.getLogger()
logger.setLevel(logging.INFO)
client = boto3.client('firehose')
@mlapida
mlapida / EBS-Orphaned-Report-Lambda.py
Last active April 29, 2022 08:10
Generate a report of orphaned EBS volumes and send an SNS. A full writeup can be found on my site http://mlapida.com/thoughts/lambda-tracking-orphaned-ebs-volumes
import boto3
import logging
from datetime import *
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.WARNING)
#define the connection
ec2 = boto3.resource('ec2', region_name="us-west-2")
@mlapida
mlapida / EC2-Stopped-Tagged-Lambda.py
Last active January 30, 2023 15:09
Using a lambda function, stop all instances that are tagged appropriately.
import boto3
import logging
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.INFO)
#define the connection
ec2 = boto3.resource('ec2')