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 / counting_sort.py
Created May 7, 2024 19:06
An implementation of the counting-sort algorithm, including time complexity stats showing O(n)
"""A python example which shows the time complexity of the counting sort algorithm (O(n + k)).
The final output is a table showing the execution time of the counting sort algorithm for lists of different lengths.
Copied from my execution on my machine:
524288 (2**19) -> 0.25
1048576 (2**20) -> 0.49
2097152 (2**21) -> 0.92
4194304 (2**22) -> 1.75
8388608 (2**23) -> 3.47
@ohaval
ohaval / sort_five_elements_seven_comparisons.py
Created May 5, 2024 08:34
An implementation of the Ford-Johnson Algorithm for a 5 integer list in Python, which sorts in 7 comparisons only
"""As part of the 'Data Structures and Introduction to Algorithms' course, I was asked to solve the following problem:
Write a function that sorts five elements in seven comparisons in the worst case.
As I found this problem interesting, I decided to implement it in Python. For better understanding, I recommend
reading the answer from the link below, which explains the algorithm.
"""
import random
from typing import List
@ohaval
ohaval / gist:98b0face7f28d3555327a0873e8e4137
Created July 20, 2023 10:17
Pass dynamic secrets to an action based on an input
name: Secrets trial
on:
workflow_dispatch:
inputs:
secrets_list:
required: true
description: 'List of secrets to pass to action'
jobs:
tmp-secrets:
@ohaval
ohaval / print_workflow_logs.py
Created July 2, 2023 13:16
Print all workflows logs from a specific repository in GitHub Actions using PyGithub
import datetime
import os
import requests
from github import Github
REPO_NAME = 'some-repo'
REPO_OWNER = 'some-owner'
LAST_WF_DATE_TO_SHOW = datetime.datetime(2023, 7, 2, 9, 11)
@ohaval
ohaval / aws-vault-add.sh
Created June 12, 2023 14:19
AWS-Vault add example
# A configured profile can already exist or not. If not, aws-vault will create the profile in `~/.aws/config`.
> aws-vault add some-developer
Enter Access Key Id: ***
Enter Secret Access Key: ***
@ohaval
ohaval / get-session-token-usage-example.sh
Created June 12, 2023 13:51
get-sessiont-token usage example
> aws sts get-session-token
{
"Credentials": {
"AccessKeyId": "***",
"SecretAccessKey": "***",
"SessionToken": "***",
...
}
}
@ohaval
ohaval / aws-vault-exec-different-profiles.sh
Created June 12, 2023 13:49
AWS-Vault exec example with different profiles
> aws-vault exec dev -- aws lambda invoke --function-name some-function --payload '{}'
> aws-vault exec staging -- aws lambda list-functions
@ohaval
ohaval / config
Created June 12, 2023 13:42
Sample AWS config file with multiple environment
[default]
region = us-east-1
mfa_serial = arn:aws:iam::1000:mfa/some-developer
[profile some-developer]
Credential_process = aws-vault export --format=json some-developer
[profile dev]
role_arn = arn:aws:iam::2000:role/Admin
source_profile = some-developer
@ohaval
ohaval / aws-vault-list.sh
Created June 12, 2023 13:40
AWS-Vault list example
> aws-vault list
Profile Credentials Sessions
======= =========== ========
default - -
some-developer some-developer sts.GetSessionToken:8h29m31s
dev - -
staging - -
prod - -
@ohaval
ohaval / aws-vault-exec.sh
Created June 12, 2023 13:34
AWS-Vault exec example
> aws-vault exec some-developer -- env | grep AWS
AWS_ACCESS_KEY_ID=***
AWS_SECRET_ACCESS_KEY=***
AWS_SESSION_TOKEN=***