Skip to content

Instantly share code, notes, and snippets.

View alastairmccormack's full-sized avatar

Alastair McCormack alastairmccormack

View GitHub Profile
@tyhawkins
tyhawkins / zoom-mute-status.scpt
Last active May 27, 2022 20:51
Get Zoom Mute/Unmute Status
property btnTitle : "Mute audio"
if application "zoom.us" is running then
tell application "System Events"
tell application process "zoom.us"
if exists (menu item btnTitle of menu 1 of menu bar item "Meeting" of menu bar 1) then
set returnValue to "Unmuted"
else
set returnValue to "Muted"
end if
@PM2Ring
PM2Ring / aes_ecb.py
Last active January 16, 2018 13:51
Call the AES_set_encrypt_key, AES_set_decrypt_key, and AES_ecb_encrypt functions from the OpenSSL library using ctypes
#!/usr/bin/env python3
''' AES ECB
Call the AES_set_encrypt_key, AES_set_decrypt_key, and
AES_ecb_encrypt functions from the OpenSSL library
Uses info from /usr/include/openssl/aes.h
Also see https://boringssl.googlesource.com/boringssl/+/2490/include/openssl/aes.h
@benkehoe
benkehoe / LambdaBase.py
Last active October 23, 2023 20:30
Code pattern for implementing class-based AWS Lambda handlers in Python
"""Base class for implementing Lambda handlers as classes.
Used across multiple Lambda functions (included in each zip file).
Add additional features here common to all your Lambdas, like logging."""
class LambdaBase(object):
@classmethod
def get_handler(cls, *args, **kwargs):
def handler(event, context):
return cls(*args, **kwargs).handle(event, context)
return handler
@niranjv
niranjv / change_lambda_logger_format.py
Last active February 7, 2024 11:03
Change Python logger format in AWS Lambda
# Python logger in AWS Lambda has a preset format. To change the format of the logging statement,
# remove the logging handler & add a new handler with the required format
import logging
import sys
def setup_logging():
logger = logging.getLogger()
for h in logger.handlers:
logger.removeHandler(h)
@pmauduit
pmauduit / collectd.conf
Last active May 21, 2019 13:13
[tomcat monitoring] JMX + collectd + logstash configuration
# add the following block:
<Plugin network>
Server "127.0.0.1"
</Plugin>
def debug_pickle(instance):
"""
:return: Which attribute from this object can't be pickled?
"""
attribute = None
for k, v in instance.__dict__.iteritems():
try:
cPickle.dumps(v)
except:
@sungitly
sungitly / todict.py
Last active November 15, 2023 21:04
convert python object recursively to dict
def todict(obj, classkey=None):
if isinstance(obj, dict):
data = {}
for (k, v) in obj.items():
data[k] = todict(v, classkey)
return data
elif hasattr(obj, "_ast"):
return todict(obj._ast())
elif hasattr(obj, "__iter__"):
return [todict(v, classkey) for v in obj]
@praseodym
praseodym / AESGCMUpdateAAD2.java
Last active May 13, 2024 10:20
JDK8 AES-GCM code example
import javax.crypto.*;
import javax.crypto.spec.GCMParameterSpec;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
import java.util.Arrays;
public class AESGCMUpdateAAD2 {
// AES-GCM parameters
public static final int AES_KEY_SIZE = 128; // in bits
@abhinav-upadhyay
abhinav-upadhyay / DateTimeDecoder.py
Last active July 4, 2023 13:12
A JSON decoder/encoder implementation for parsing dates as datetime objects in Python
#!/usr/bin/env python
# An example of decoding/encoding datetime values in JSON data in Python.
# Code adapted from: http://broadcast.oreilly.com/2009/05/pymotw-json.html
# Copyright (c) 2023, Abhinav Upadhyay
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@aparrish
aparrish / simplecometclient.py
Created January 24, 2012 21:57
simple python comet client
import email.utils # for rfc2822 formatted current timestamp
import requests
class CometClient(object):
def __init__(self, last_modified=None):
if last_modified is None:
self.last_modified = email.utils.formatdate()
else:
self.last_modified = last_modified