Skip to content

Instantly share code, notes, and snippets.

class Pojazd:
def __init__(self, predkosc: int, kolor: str) -> None:
self.predkosc: int = predkosc
self.kolor: str = kolor
def jedz(self) -> None:
print("Pojazd jedzie.")
def zatrzymaj(self) -> None:
print("Pojazd zatrzymuje się.")
@jacoor
jacoor / test_example.py
Created July 4, 2023 14:49
model form test
def test_model_form_contact_fields():
form = ModelContactForm()
assert len(form.fields) == 4
assert "email" in form.fields
assert "first_name" in form.fields
assert "last_name" in form.fields
assert "message" in form.fields
def compare(a, b):
if a == b:
return True
else:
return False
@jacoor
jacoor / generate_zone_records_from_json.py
Created August 19, 2021 07:48
Generate zone records file (terraform) from AWS Route53 zone dump.
"""
Generate zone records file (terraform) from zone dump.
To get zone dump:
aws route53 list-resource-record-sets --hosted-zone-id ZONE ID > records.json
Example usage:
ZONE_FILE=records.json TERRAFORM_DIR=zone_name python generate_zone_records_from_json.py
Based on:
https://mrkaran.dev/posts/terraform-route53-import/
@jacoor
jacoor / context.ts
Created June 26, 2019 13:20
context for tests with aws lambda
import { Context } from "aws-lambda";
const context: Context = {
callbackWaitsForEmptyEventLoop: false,
functionName: "",
functionVersion: "string",
invokedFunctionArn: "string",
memoryLimitInMB: 1,
awsRequestId: "string",
logGroupName: "string",
@jacoor
jacoor / userdata.sh
Created April 30, 2019 11:34
AWS EC2 user data error handling
# error handling
# redirect logs so can be found in instance -> actions -> instance settings -> Get System log
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
# trap errors. Shutdown restarts machine in an hour and prevents further commands,
# so instances won't finish booting and won't report to ECS
function my_trap()
{
echo "Sorry, there was an error at line $1 $2" && shutdown -h +60
}
trap 'my_trap $${LINENO} $$? ' ERR
@jacoor
jacoor / header.py
Created September 17, 2018 16:20
skipping header in AWS glue
# use filter, Luke
# the idea is to use a filter function that will return True for the records to keep.
# Usage: just use before the last function at end of your ETL job script. Update frame and update next function frame with "filtered".
def filter_function(dynamicRecord):
if dynamicRecord.merchant_id == "merchant_id" and dynamicRecord.merchant_ref_number == "merchant_ref_number":
return False
else:
return True
filtered = Filter.apply(frame = dropnullfields3, f = filter_function, transformation_ctx = "filtered")
@jacoor
jacoor / aws-sdk.ts
Last active April 22, 2020 12:12
Manual mocks for aws-sdk.js using jest.
// inspired by: https://derikwhittaker.blog/2018/02/20/using-manual-mocks-to-test-the-aws-sdk-with-jest/
let AWS = {
// This here is to allow/prevent runtime errors if you are using
// AWS.config to do some runtime configuration of the library.
// If you do not need any runtime configuration you can omit this.
config: {
setPromisesDependency: (arg) => {},
update: (arg) => {},
},
@jacoor
jacoor / duplicate_jpgs_clean.py
Last active April 19, 2018 12:48
duplicate photos cleaner. Cleans JPG if RAW of the same name is present in the same dir. Uncomment remove line, 27, otherwise it just lists files.
# remove duplicate files: JPGs when RAW is present
from pathlib import Path
import os
class ProcessFiles(object):
"""
Walks over current dir and subdirectories searching for JPG and RAW (PEF) files.
Prints out a list of duplicates.
@jacoor
jacoor / github_release.sh
Created April 5, 2018 09:06
Create a github release
curl --data '{"tag_name": "'$TAG'","target_commitish": "'$PRODUCTION'","name": "'$TAG'","body": "","draft": false,"prerelease": false}' https://api.github.com/repos/:owner/:repository/releases?access_token=:your_access_token