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 / 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 / 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)
@thanakijwanavit
thanakijwanavit / warmLambdaSam.yaml
Created February 8, 2023 04:41
keep lambda function warm in sam template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
WarmFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src
Handler: index.handler
Runtime: python3.8
Events:
@thanakijwanavit
thanakijwanavit / lambdaWithDocker.yaml
Created February 7, 2023 13:21
aws sam lambda with docker image
Resources:
HelloWorldAPI:
Type: AWS::Serverless::Api
Properties:
Name: Hello World API
StageName: Prod
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
PackageType: Image
<a href="#" style="
text-decoration: none;
font-family: helvetica;
font-weight: bold;
color: #ddd;
background-color: black;
height: 30px;
display: inline-block;
padding: 1px 12px 0 0;
border-radius: 5px;
@thanakijwanavit
thanakijwanavit / mountEfs.sh
Last active December 11, 2022 05:48
mount efs on amazon ec2 *this needs to be in the same vpc as the efs instance
sudo yum -y install amazon-efs-utils
sudo mount -t efs -o tls,accesspoint=<efs accesspoint> <efs id>:/ efs
@thanakijwanavit
thanakijwanavit / appstorageCodable.swift
Created November 14, 2022 03:51
extension for makinkg codable array conform to appstorage
extension Array: RawRepresentable where Element: Codable {
public init?(rawValue: String) {
guard let data = rawValue.data(using: .utf8),
let result = try? JSONDecoder().decode([Element].self, from: data)
else {
return nil
}
self = result
}
@thanakijwanavit
thanakijwanavit / dynamicAppstorage.swift
Created November 14, 2022 03:50
dynamic appstorage
struct ProductDetail: View {
@AppStorage private var isLocal: Bool
private var product: GumroadProduct
init(product: GumroadProduct) {
self.product = product
self._isLocal = AppStorage(wrappedValue: false, "LOCAL_LIBRARY_PRESENCE_PRODUCTID_\(product.id)")
}