Skip to content

Instantly share code, notes, and snippets.

View thanakijwanavit's full-sized avatar

Nic Wanavit thanakijwanavit

View GitHub Profile
@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)")
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thanakijwanavit
thanakijwanavit / sentryAddBreadcrumb.py
Last active August 15, 2022 04:12
add breadcrumb to sentry
import sentry_sdk
sentry_sdk.add_breadcrumb(
category='auth',
message='Authenticated user %s' % user.email,
level='info',
data={'data':'data'}
)
@thanakijwanavit
thanakijwanavit / pynamodb_override.py
Created August 7, 2022 03:18
pynamodbOverride override init for pynamodb example
#export
from nicHelper.pynamodb import SuperModel
from pynamodb.attributes import JSONAttribute, NumberAttribute, UnicodeAttribute
class PaymentRecordTable(SuperModel):
data = JSONAttribute(null=True)
timestamp = NumberAttribute(hash_key=True)
userId = UnicodeAttribute()
def __init__(self, hash_key=None, range_key=None, _user_instantiated=True, **kwargs):
@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 / enumCodableWithDefault.swift
Created March 18, 2022 22:04
swift enum extension for making it comply with codable and default type
extension Type: Codable {
public init(from decoder: Decoder) throws {
self = try Type(rawValue: decoder.singleValueContainer().decode(RawValue.self)) ?? .unknown
}
}
@thanakijwanavit
thanakijwanavit / View+isHidden.swift
Created January 18, 2022 08:17
view hidden extension swiftui
//
// View+Extension.swift
// squirrel2 (iOS)
//
// Created by nic wanavit on 11/3/21.
//
import SwiftUI
extension View {
@thanakijwanavit
thanakijwanavit / decodeCsv.swift
Created January 9, 2022 05:49
decoding pandas generated csv in swift
import CodableCSV
extension VillaMarket{
static func getOnlineCsv()async throws ->[Item]{
let url = URL(string: "https://url/item.csv")!
let (data, _) = try await URLSession.shared.data(from: url)
let decoder = CSVDecoder{
$0.bufferingStrategy = .sequential