Skip to content

Instantly share code, notes, and snippets.

View ohaval's full-sized avatar
💭
Code can be a piece of art

Ohav ohaval

💭
Code can be a piece of art
View GitHub Profile
@ohaval
ohaval / aws_classic_keys.sh
Created June 12, 2023 13:32
Usage of classic AWS keys with the CLI
> cat ~/.aws/config
[default]
region=us-east-1
aws_access_key_id=***
aws_secret_access_key=***
> aws s3 ls
@ohaval
ohaval / aws_classic_keys.py
Created June 11, 2023 15:00
Use classic AWS keys with boto3
import boto3
session = boto3.Session(
region_name='us-east-1',
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
)
session.client('s3').list_buckets()
@ohaval
ohaval / dynamic-matrix-ghaction.yml
Created December 20, 2022 07:04
Example showing how to set a dynamic matrix sequence based on input
name: Dynamic Matrix
on:
push:
workflow_dispatch:
inputs:
someInput:
description: 'Some input'
required: true
type: choice
options: [ one, two, three ]
@ohaval
ohaval / multi_file_commit.py
Created December 12, 2022 06:30
An example shows how to push a single commit with multiple files to an existing branch using PyGithub
"""
Main Steps:
1. Create blob for each file
2. Create tree with the blobs on top of the specific branch
3. Commit the tree
4. Update the branch to point to the new commit
"""
import os
@ohaval
ohaval / apigatewayv2_integration_to_event_bridge.tf
Last active December 3, 2022 14:46
An example of Terraform code shows how to integrate AWS API Gateway V2 with Event Bridge
# 3 important steps:
#
# A) Create a role for the integration (allowing PutEvents)
# B) Create the integration resource (specify that role)
# C) Create a route targeting that integration
resource "aws_apigatewayv2_integration" "api-gw-v2-integration-to-event-bridge" {
api_id = aws_apigatewayv2_api.some-api-gw-v2.id
integration_type = "AWS_PROXY"
integration_subtype = "EventBridge-PutEvents"
@ohaval
ohaval / export_ecdsa_keys.py
Created November 1, 2021 17:34
Generate and export ECDSA public and private keys in Python.
"""This example shows how easy it is to generate and export ECDSA keys with python.
This program is similar to `ssh-keygen -t ecdsa` with no passphrase.
To export the private key with a passphrase, read paramiko.pkey.PKey._write_private_key method.
"""
import paramiko
from cryptography.hazmat.primitives.serialization import (
Encoding, PrivateFormat, PublicFormat, NoEncryption
)
@ohaval
ohaval / cycle_sort.py
Created October 1, 2021 12:32
The Cycle sort algorithm simple and readable implementation in Python
from typing import List
def cycle_sort(lst: List[int]) -> None:
"""The Cycle sort algorithm.
The sorted list is placed in place.
Wikipedia: https://en.wikipedia.org/wiki/Cycle_sort
"""
for i in range(len(lst) - 1):
@ohaval
ohaval / selection_sort.py
Created October 1, 2021 12:29
The Selection sort algorithm simple and readable implementation in Python
from typing import List
def selection_sort(lst: List[int]) -> None:
"""The Selection sort algorithm.
The sorted list is placed in place.
Wikipedia: https://en.wikipedia.org/wiki/Selection_sort
"""
for i in range(len(lst) - 1):
@ohaval
ohaval / insertion_sort.py
Created October 1, 2021 12:25
The Insertion sort algorithm simple and readable implementation in Python
from typing import List
def insertion_sort(lst: List[int]) -> None:
"""The Insertion sort algorithm.
The sorted list is placed in place.
Wikipedia: https://en.wikipedia.org/wiki/Insertion_sort
"""
for i in range(1, len(lst)):
@ohaval
ohaval / merge_sort.py
Created October 1, 2021 12:23
The Merge sort algorithm simple and readable implementation in Python
from typing import List
def merge_sort(lst: List[int]) -> List[int]:
"""The Merge sort algorithm.
Wikipedia: https://en.wikipedia.org/wiki/Merge_sort
"""
if len(lst) <= 1:
return lst