Skip to content

Instantly share code, notes, and snippets.

View thanakijwanavit's full-sized avatar
🎯
Focusing

Nic Wanavit thanakijwanavit

🎯
Focusing
View GitHub Profile
@thanakijwanavit
thanakijwanavit / samLayerConfig.yaml
Created March 27, 2021 15:22
layer configuration for a sam app
############ layer ##############
OrderLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: inventory-layer
ContentUri: ./layer/package.zip
CompatibleRuntimes:
- python3.8
OrderLayerPermission:
@thanakijwanavit
thanakijwanavit / uploadwithcontenttype.ipynb
Last active March 26, 2021 10:16
uploadWithContentType
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thanakijwanavit
thanakijwanavit / compressDictToGzip.py
Created March 25, 2021 07:09
compress a dict into gzip
import gzip, json
inputDict = {'helloa':'world'}
gzip.compress(json.dumps(inputDict).encode())
from s3bz.s3bz import S3, ExtraArgs
bucket = 'pybz-test'
key = 'test.dict'
fields = {**ExtraArgs.jpeg}
S3.presignUpload(bucket, key, fields=fields)
@thanakijwanavit
thanakijwanavit / dfToGzipJson.py
Created March 25, 2021 00:28
save df to gzip json
onlineDf.to_json(path ,orient='split',compression='gzip')
@thanakijwanavit
thanakijwanavit / saveS3PublicRead.py
Last active March 25, 2021 06:12
save to s3 with public read and gzip
from s3bz.s3bz import S3, ExtraArgs
S3.saveFile(key=key,path=path,bucket=bucket,
ExtraArgs = {**ExtraArgs.jpeg, **ExtraArgs.publicRead })
@thanakijwanavit
thanakijwanavit / buildAllLayers.sh
Created March 23, 2021 16:25
build all layers in the repo
# list all folders
layerList=$(find -name 'layer')
curDir=$(pwd)
echo executing $layerList
echo curdir is $curDir
# loop though each path
for path in $layerList
do
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thanakijwanavit
thanakijwanavit / asyncAwait.py
Created March 21, 2021 15:30
async await example in python
import requests, time, random
import asyncio
from asgiref.sync import sync_to_async
from datetime import datetime
async def post(url, body):
t0 = datetime.now()
r = await sync_to_async(requests.post)(url,json=body)
return r.json()
async def main():
@thanakijwanavit
thanakijwanavit / requests.yaml
Created March 20, 2021 11:24
api gateway schemas
body: A JSON string of the request payload.
headers: '{String containing incoming request headers}'
httpMethod: Incoming request's method name
isBase64Encoded: A boolean flag to indicate if the applicable request payload is Base64-encoded
multiValueHeaders: '{List of strings containing incoming request headers}'
multiValueQueryStringParameters: '{List of query string parameters}'
path: Path parameter
pathParameters: '{path parameters}'
queryStringParameters: '{query string parameters }'
requestContext: '{Request context, including authorizer-returned key-value pairs}'