Skip to content

Instantly share code, notes, and snippets.

View thanakijwanavit's full-sized avatar
🎯
Focusing

Nic Wanavit thanakijwanavit

🎯
Focusing
View GitHub Profile
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
from sentry_sdk import add_breadcrumb, capture_exception
import sentry_sdk
sentry_sdk.init(
dsn="https://xxxxx.ingest.sentry.io/xxxxx",
integrations=[AwsLambdaIntegration()]
)
def sentryLog(message:str, data:(list,dict), category='main'):
@thanakijwanavit
thanakijwanavit / supermodel.py
Last active July 17, 2021 04:18
supermodel for pynamodb
schemaUrl = 'https://raw.githubusercontent.com/thanakijwanavit/villaMasterSchema/master/Product.json'
from nicHelper.pynamodb import SchemaAttribute, SuperModel
from typing import Any
class TestModel(SuperModel):
class Meta:
table_name="colab-test-sensitive-column"
region = 'ap-southeast-1'
dax_read_endpoints = ['longtermcluster.vuu7lr.clustercfg.dax.apse1.cache.amazonaws.com:8111']
dax_write_endpoints = ['longtermcluster.vuu7lr.clustercfg.dax.apse1.cache.amazonaws.com:8111']
data = SchemaAttribute(schemaUrl = schemaUrl, null=True)
@thanakijwanavit
thanakijwanavit / Order2.py
Created July 8, 2021 06:43
for query the order2 table
class OwnerIdIndex(GlobalSecondaryIndex):
class Meta:
index_name = 'ownerId'
read_capacity_units=1
write_capacity_units=1
projection = AllProjection()
ownerId=UnicodeAttribute(hash_key=True)
creationTime=NumberAttribute(range_key=True)
class BasketIdIndex(GlobalSecondaryIndex):
@thanakijwanavit
thanakijwanavit / sentryExample.py
Created July 7, 2021 10:41
sentry breadcrumbs example
#export
from nicHelper.exception import errorString
import sentry_sdk
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
from sentry_sdk import capture_message, capture_exception, add_breadcrumb, push_scope
sentry_sdk.init(
dsn="https://[email protected]/5852078",
integrations=[AwsLambdaIntegration()],
@thanakijwanavit
thanakijwanavit / newVillaLink.html
Last active July 2, 2021 14:24
link to new villa site alert html
import XCTest
@testable import planyoBooking
import Alamofire
class TestResourcesApi: XCTestCase {
func testApiCall(){
let exp = expectation(description: #function)
@thanakijwanavit
thanakijwanavit / asyncUrlCall.swift
Created June 13, 2021 07:02
swift async url call
do{
let url = URL(string: "htts://api.github.com/users/hadley/orgs")!
let (data, _) = try await URLSession.shared.data(from: url)
// decode json
let res = try JSONDecoder().decode([SampleJson].self, from: data)
// do stuff with result
// self.result = String(res.first!.id)
} catch {
print("error \(error)")
// send error to sentry sdk (optional)
@thanakijwanavit
thanakijwanavit / diskcache.py
Created May 27, 2021 05:25
disk cache for python
from diskcache import Cache
cache = Cache(directory='/tmp/')
@cache.memoize(tag='getApiKey',expire=900)
def somefunctionwithstringInput(input):
return 'hello'

With GitHub Actions, a workflow can publish artifacts, typically logs or binaries. As of early 2020, the life time of an artifact is hard-coded to 90 days (this may change in the future). After 90 days, an artifact is automatically deleted. But, in the meantime, artifacts for a repository may accumulate and generate mega-bytes or even giga-bytes of data files.

It is unclear if there is a size limit for the total accumulated size of artifacts for a public repository. But GitHub cannot reasonably let multi-giga-bytes of artifacts data accumulate without doing anything. So, if your workflows regularly produce large artifacts (such as "nightly build" procedures for instance), it is wise to cleanup and delete older artifacts without waiting for the 90 days limit.

Using the Web page for the "Actions" of a repository, it is possible to browse old workflow runs and manually delete artifacts. But the procedure is slow and tedious. It is fine to delete one selected artifact. It is not for a regular cleanup. We need

@thanakijwanavit
thanakijwanavit / deleteArtifacts.yml
Last active May 26, 2021 17:33
delete github artifacts
name: clean
on:
push:
branches:
- 'master'
jobs:
delete-artifacts:
runs-on: ubuntu-latest
steps: