version: '3.9'
services:
db:
image: postgres
restart: always
ports:
- 5430:5432
volumes:Use this IAM policy for the Serverless Framework with the AWS Provider for deploying Node.js apps as serverless functions on AWS Lambda.
Replace AWS_ID with your AWS Account ID (e.g. 123456789) which you can find under AWS IAM in the console.
This file contains hidden or 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
| /* | |
| Next.js/Edge function method for hasing passwords | |
| Using the Web API Crypto feature instead of | |
| Built-in Node.js Crypto | |
| */ | |
| export default async function pbkdf2(password, salt, iterations, keylen) { | |
| const enc = new TextEncoder(); | |
| const passwordBuffer = enc.encode(password); | |
| const saltBuffer = enc.encode(salt); |
This file contains hidden or 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
| export default async function isValidURL(url, disallowedDomains) { | |
| // Construct a regular expression pattern to match disallowed domains | |
| const disallowedPattern = `^https?:\\/\\/(?:${disallowedDomains.join('|')})\\b`; | |
| let disallowedRegex = new RegExp(disallowedPattern, 'i'); | |
| // Regular expression pattern to match a URL (excluding localhost) | |
| const urlPattern = /^(https?:\/\/)?((?!localhost)[\w.-]+)\.([a-z]{2,})(:\d{1,5})?(\/.*)?$/i; | |
| let urlRegex = new RegExp(urlPattern); | |
| // Test the URL against both URL pattern and disallowed domain pattern |
This file contains hidden or 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 version at https://knative.dev/docs/install/yaml-install/serving/install-serving-with-yaml/ | |
| export KNATIVE_VERSION="v1.10.1" # ensure ISTIO install matches this version too | |
| # Install knative serving | |
| # Ref: https://knative.dev/docs/install/yaml-install/serving/install-serving-with-yaml/#install-the-knative-serving-component | |
| kubectl apply -f https://github.com/knative/serving/releases/download/knative-$KNATIVE_VERSION/serving-crds.yaml | |
| kubectl apply -f https://github.com/knative/serving/releases/download/knative-$KNATIVE_VERSION/serving-core.yaml | |
| # install istio |
This file contains hidden or 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
| # Video https://youtube.com/shorts/MNUdPGIjMPw | |
| # Python 3.10 | |
| # pip install openai-whisper | |
| # pip install git+https://github.com/openai/whisper.git | |
| # install ffmpeg | |
| # brew install ffmpeg | |
| import subprocess | |
| import whisper | |
| model = whisper.load_model("base") |
I've been using cassandra a lot lately. It's very common to denote ID fields in cassanda as a time-based uuid field called timeuuid docs. In python, a timeuuuid is mearly uuid.uuid1 from the built-in uuid package.
Using the cassandra-driver, you might end up with a model like:
import uuid
from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model
This file contains hidden or 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 fractions import Fraction | |
| def number_str_to_float(amount_str:str) -> (any, bool): | |
| """ | |
| Take in an amount string to return float (if possible). | |
| Valid string returns: | |
| Float | |
| Boolean -> True |