Skip to content

Instantly share code, notes, and snippets.

View citadelgrad's full-sized avatar
🤖
Identified IT Risk

Scott Nixon citadelgrad

🤖
Identified IT Risk
View GitHub Profile
@citadelgrad
citadelgrad / cf.sh
Last active February 7, 2024 18:02
Manage cloudformation stacks
#!/bin/bash
# Set default region (you can modify this)
AWS_REGION="us-east-1"
# Error handling function
error_exit() {
echo "Error: $1" >&2
exit 1
}
export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \
$(aws sts assume-role \
--role-arn arn:aws:iam::123456789012:role/MyAssumedRole \
--role-session-name MySessionName \
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \
--output text))

Getting started with Python Development

Setting up your Dev Environment

  • Highly recommend using VSCode for developing.
  • Learn and always use virtual environments: venv
  • Highly recommend only developing on a Mac or Linux. If you are on Windows you can use Docker + VSCode to give you a Linux shell. This will reduce your likely hood of having problems install dependencies.
  • I really love using ptpython and ptipython because it helps with autocomplete. https://github.com/prompt-toolkit/ptpython
  • Real Python is definitely one of the best resources from learning Python. This is their Intro Learning Path https://realpython.com/learning-paths/python3-introduction/
@citadelgrad
citadelgrad / search_for_keys.py
Last active May 3, 2021 22:05
Find all occurrences of a key in nested dictionaries and lists
# Source: https://stackoverflow.com/questions/9807634/find-all-occurrences-of-a-key-in-nested-dictionaries-and-lists
# Python dict.iteritems became just dict.items.
# Easily coherse the generator into a list with: `list(gen_dict_extract("KeytoFind", MyDict))`
def gen_dict_extract(key, var):
if hasattr(var, 'items'):
for k, v in var.items():
if k == key:
yield v
if isinstance(v, dict):

Backup:

pg_dump -p 5432 database_name > database_name_data.sql

Restore backup dump into local db

psql -U username -d database_name -f objects.sql

pg_restore --verbose --clean --no-acl --no-owner -h localhost -d [db_name] db_backup.dump

React Native Guide

React Native Debugger Reactotron

Open React Native Debugger first and set the RN publishing Port to 19001. Then enabled Debug Remote JS in the Expo app.

Offline Storage Debugging

React Native Debugger

Name Patterns for JS & React

I'm able to visually identify and understand React components. However, I do not know the names used to identify them.

Class Component:

class MyList extends React.Component {...}

Function component:

function App() {return (...)}

kill $(ps -e | grep hung_tasks | awk '{print $1}')

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm