Skip to content

Instantly share code, notes, and snippets.

View thanakijwanavit's full-sized avatar

Nic Wanavit thanakijwanavit

View GitHub Profile
@thanakijwanavit
thanakijwanavit / lambdaLayer.sh
Last active March 7, 2024 23:11
create a lambda layer package using docker
#!/bin/bash
export PKG_DIR="python"
rm -rf ${PKG_DIR} &&\
rm package.zip &&\
mkdir -p ${PKG_DIR}
docker run --rm -v $(pwd):/foo -w /foo lambci/lambda:build-python3.8 \
pip install -r requirements.txt -t ${PKG_DIR}
@thanakijwanavit
thanakijwanavit / decodeDynamo.py
Created February 25, 2024 12:20
export and decode dynamodb
def decodeDynamo(path):
allItems = []
with gzip.open(path, 'rb') as f:
for line in f:
try:
line_str = line.decode('utf-8').strip()
item_data = json.loads(line_str)['Item']['data']['S']
allItems.append(json.loads(item_data))
except json.JSONDecodeError as e: # Change this to the specific exceptions you expect
print(f"Error parsing line: {e}")
@thanakijwanavit
thanakijwanavit / python38_sam_deploy.yaml
Created December 3, 2023 01:57
sam deployment for python3.8 using official image
name: deploy
on:
push:
branches:
- 'master'
jobs:
build:
name: build
@thanakijwanavit
thanakijwanavit / zoomableView.swift
Created July 18, 2023 01:39
swiftui zoomable view
import SwiftUI
import PDFKit
struct PhotoDetailView: UIViewRepresentable {
let image: UIImage
func makeUIView(context: Context) -> PDFView {
let view = PDFView()
view.document = PDFDocument()
guard let page = PDFPage(image: image) else { return view }
@thanakijwanavit
thanakijwanavit / swiftHashing.swift
Created June 7, 2023 05:01
swift hashing extension
import Foundation
import CryptoKit
extension String {
private func hash<H: HashFunction>(with closure: () -> H) -> String {
let inputData = Data(self.utf8)
let hash = H.hash(data: inputData)
let hashString = hash.compactMap { String(format: "%02hhx", $0) }.joined()
return hashString
@thanakijwanavit
thanakijwanavit / freezeRuntimeVersion.py
Created May 11, 2023 20:22
freeze runtime version configuration of all functions in database
import boto3
import itertools
# Initialize the boto3 client for AWS Lambda
lambda_client = boto3.client('lambda', region_name='ap-southeast-1')
# Get the list of all lambda functions
paginator = lambda_client.get_paginator('list_functions')
# response = lambda_client.list_functions(MaxItems=10000)
@thanakijwanavit
thanakijwanavit / 7z.sh
Created March 16, 2021 03:42
compress with 7z
7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on /tmp/archive.7z $dir
@thanakijwanavit
thanakijwanavit / setAwsEnvironmentInBoto3.py
Last active February 15, 2023 06:01
set aws environment in boto3 python
os.environ['AWS_PROFILE'] = 'tenxor'
os.environ['AWS_DEFAULT_PROFILE'] = 'tenxor'
@thanakijwanavit
thanakijwanavit / enumWithUnknownOrMissing.py
Created February 13, 2023 01:35
enum with unknown or missing value
from enum import Enum
class Foo(Enum):
A = 1
B = 2
C = 3
def __str__(self):
return self.name
@thanakijwanavit
thanakijwanavit / sudokuSolution.py
Created February 12, 2023 02:10
heuristic sudoku solution
def solve(grid):
empty_cell = find_empty_cell(grid)
if not empty_cell:
return grid
row, col = empty_cell
possible_numbers = get_possible_numbers(grid, row, col)
for num in possible_numbers:
grid[row][col] = num
solved_grid = solve(grid)