Skip to content

Instantly share code, notes, and snippets.

View jdahlin's full-sized avatar

Johan Dahlin jdahlin

View GitHub Profile
@jdahlin
jdahlin / lambda_handler.py
Created September 15, 2023 08:32
Lambda@Edge function to that can call Lambda Function URLs with AWS_IAM
# Based on https://medium.com/@dario_26152/restrict-access-to-lambda-functionurl-to-cloudfront-using-aws-iam-988583834705
import base64
from typing import TYPE_CHECKING
from boto3 import Session
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
if TYPE_CHECKING:
from typing import TypedDict
@jdahlin
jdahlin / cross-copy-aws-dynamodb-table
Last active August 2, 2023 10:47
Script to use batch-write-item to copy a dynamodb table from one account to another
#!/bin/bash
# Requires: aws cli and jq
set -eux
: ${OLD_TABLE:old_table}
: ${OLD_PROFILE:prod}
: ${NEW_TABLE=new_table}
: ${NEW_PROFILE:dev}
: ${REGION:eu-west-1}
//
// ViewController.swift
// storyboardtest2
//
// Created by Johan Dahlin on 2022-07-08.
//
import Cocoa
// https://developer.apple.com/documentation/appkit/nsviewcontroller
@jdahlin
jdahlin / generate-mypy-blacklist.md
Last active May 25, 2022 12:01
Use this script to generate a mypy.ini where you can enable strict mode based on errors from a current run.

Use this script to generate a mypy.ini where you can enable strict mode based on errors from a current run.

Needs a few improvments:

  • output pyproject.toml
  • update source files by adding # type: ignore[xxx] instead of ignore_errors
def fibonacci(n: int) -> int:
# The n:th Fibonacci number F(n) with the value of n provided by the user.
# https://en.wikipedia.org/wiki/Fibonacci_number
# https://en.wikipedia.org/wiki/Fibonacci_number#Sequence_properties
match n:
case n if not isinstance(n, int):
raise TypeError(f"n must be an int, not {type(n).__name__}")
case n if 1 >= n >= 0:
# F(0) = 0, F(1) = 1
return n
def part2(data):
def candidates(n):
return 1 + (n * (n + 1) // 2)
lines = [int(v) for v in data.split("\n")]
nums = list(sorted(lines)) + [max(lines) + 3]
a = 0
i = 0
total = 1
while i < len(nums):
b = nums[i]
import boto3
from typing import Optional, Generator
import enum
class TaskDefinitionStatus(enum.Enum):
ACTIVE = 'ACTIVE'
@jdahlin
jdahlin / .block
Created November 3, 2017 15:49 — forked from mbostock/.block
Bar Chart
license: gpl-3.0
impore re
import sys
IDENTIFIER = "IDENTIFIER"
INTEGER = "INTEGER"
STRING = "STRING"
COMMENT = "COMMENT"
DOT = "DOT"
COLON = "COLON"
SEMICOLON = "SEMICOLON"