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 sys | |
from pathlib import Path | |
from django.core import management | |
from django.core.management.base import BaseCommand | |
import boto3 | |
from botocore.config import Config | |
from botocore.exceptions import ClientError |
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
{ | |
"raw_command": "from django.db import connection;c = connection.cursor();table = 'TABLENAME';sql = f'TRUNCATE TABLE {table} CASCADE';c.execute(sql)" | |
} |
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
class ArrayFieldCheckboxSelectMultiple(CheckboxSelectMultiple): | |
"""A CheckboxSelectMultiple widget for use with ArrayField which fixes the Multiple items not selected issue""" | |
def format_value(self, value): | |
"""Return selected values as a list.""" | |
if value is None and self.allow_multiple_selected: | |
return [] | |
elif self.allow_multiple_selected: | |
value = [v for v in value.split(",")] |
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 create_drop_tables_raw_command(tables: list[str]) -> str: | |
"""Get list of tables using the 'manage sqlflush' command. This will create the DROP TABLE command for resetting the database""" | |
django_migrations_table = "django_migrations" | |
if django_migrations_table not in tables: | |
print(f"-- '{django_migrations_table}' not given, adding to tables!") | |
tables.append(django_migrations_table) | |
statements = ["from django.db import connection"] | |
statements.append("cursor = connection.cursor()") |
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
""" | |
Get/Set lambda environment variables | |
""" | |
import os | |
import pprint | |
from pathlib import Path | |
from typing import Tuple, List | |
from enum import Enum | |
import boto3 |
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
from time import sleep | |
from subprocess import check_output, CalledProcessError | |
controller_identifier = 'microKEY2' | |
configured = False | |
while True: | |
aconnect_list_command = ('aconnect', '-o') | |
output_bytes = check_output(aconnect_list_command) | |
output_str = output_bytes.decode('utf8') | |
controller_attached = False |
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
#! /bin/sh | |
# rasbian | |
# add the following line to /etc/rc.local above the "exit 0" line to start on boot | |
# /home/pi/autostartsynth.sh & | |
killall fluidsynth | |
# set sound | |
export DESIRED_SOUNDFONT=/usr/share/sounds/sf2/FluidR3_GM.sf2 | |
# start fluidsynth with desired sound |
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 boto3 | |
S3_CLIENT = boto3.client("s3") | |
def iterate_s3_csv(bucket: str, key: str) -> Generator: | |
with BytesIO() as bytesin: | |
S3_CLIENT.download_fileobj(bucket, key, bytesin) | |
bytesin.seek(0) | |
stringin = StringIO(bytesin.read().decode("utf8")) |
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
""" | |
Get/Set lambda environment variables | |
""" | |
import os | |
import pprint | |
from pathlib import Path | |
from typing import Tuple, List | |
from enum import Enum | |
import boto3 |
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
# the `update-function-configuration` overwrites the existing set envars. | |
# In order to *ADD* variables we need to read the existing envars and add to that. | |
# This command uses `jq` to read and transform the json result to an envar then update the lambda configuration | |
# create the updated envar set | |
export YOUR_FUNCTION_NAME={populate this} | |
export UPDATED_ENVIRONMNET_VARIABLES=$(aws lambda get-function-configuration --function-name ${YOUR_FUNCTION_NAME} | \ | |
jq --compact-output ".Environment + {\"Variables\": (.Environment.Variables + {\"NEW_ENVAR_NAME\": \"NEW_ENVAR_VALUE\"})}") | |
# check |
NewerOlder