This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add the following block: | |
<Plugin network> | |
Server "127.0.0.1" | |
</Plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer