Skip to content

Instantly share code, notes, and snippets.

@qtangs
qtangs / sql_alchemy.py
Last active September 22, 2024 03:43
chainlit.data.SQLAlchemyDataLayer
# https://github.com/qtangs/chainlit/blob/b81f82c9eff86fc9fd6da6f8f9f09ec03d95d8e0/backend/chainlit/data/sql_alchemy_orm.py
import datetime
import json
import logging
import os
import ssl
import uuid
from typing import Any, Callable, Dict, List, Optional, Union, cast
@qtangs
qtangs / streaming_tts_using_google.ts
Created August 27, 2024 01:56
Google Cloud TTS Streaming
const textToSpeech = require('@google-cloud/text-to-speech');
const fs = require('fs');
async function streamTextToSpeech(texts: string[]) {
const client = new textToSpeech.TextToSpeechClient();
const ttsStream = client.streamingSynthesize();
// Write the response to a file, replace with your desired output stream
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$ref": "#/definitions/Flow",
"definitions": {
"Flow": {
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"type": "string"
@qtangs
qtangs / terraform_state_cloudformation_template.yml
Created November 21, 2020 13:12
CloudFormation Template for creating S3 bucket and DynamoDB table to hold Terraform state and locks
AWSTemplateFormatVersion: 2010-09-09
Description: >
Template for creating S3 bucket and DynamoDB table to hold Terraform state and locks
Validate: aws cloudformation validate-template --template-body file://terraform_state.yml
Deploy: aws cloudformation create-stack --region us-east-1 --stack-name Terraform-State-Resources --enable-termination-protection --template-body file://terraform_state.yml --parameters ParameterKey=TerraformStateBucketPrefix,ParameterValue=terraform-state ParameterKey=TerraformStateLockTableName,ParameterValue=terraform-state-locks
Parameters:
TerraformStateBucketPrefix:
Type: String
Default: terraform-state
Description: A prefix for S3 bucket name, account id will be added to ensure global uniqueness
@qtangs
qtangs / challenges.md
Created June 10, 2020 02:51
2020 Code Challenges

Problem #1 (Kubernetes)

We will be using kubernetes to manage our containers, and we need to know how basic kubernetes objects work, and how to provision them.

Challenge

Write the k8 config required to deploy a basic nginx webserver with this image nginxdemos/hello, using minikube to provision your cluster control plane.

Your resulting created objects should look similar to the likes of the below:

NAME                                     READY   STATUS    RESTARTS   AGE
pod/nginx-hello-world-84c67f76c4-4g5sd   1/1     Running   0          6s
@qtangs
qtangs / hello_world.sh
Last active March 15, 2020 09:17
Covid 19 Dashboard hello_world.sh
python -c '''
import dash; import dash_html_components as html; app = dash.Dash(); app.layout=html.H1("Yay! It works!"); app.run_server()
'''
@qtangs
qtangs / file_structure.txt
Last active March 12, 2020 16:52
Covid 19 Dashboard file_structure.txt
covid-19-dashboard
|_ dashboard
|_ assets
|_ data
|_ model.py
|_ view.py
|_ controller.py
|_ app.py
|_ .gitignore
|_ Procfile
@qtangs
qtangs / run_app.sh
Created March 12, 2020 15:26
Covid 19 Dashboard run_app.sh
python app.py
### Output:
Running on http://127.0.0.1:8050/
Debugger PIN: 853-611-907
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
Running on http://127.0.0.1:8050/
@qtangs
qtangs / setup.sh
Last active March 15, 2020 09:07
Covid 19 Dashboard setup.sh
cd covid-19-dashboard
python -m venv venv # or python3 -m venv venv
source venv/bin/activate
pip list # ensure that only pip and setuptools are listed
echo "dash==1.9.1" > requirements.txt
pip install -r requirements.txt
@qtangs
qtangs / app.py
Last active March 12, 2020 15:18
Covid 19 Dashboard app.py
import dash
import dash_core_components as dcc
import dash_html_components as html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),