Skip to content

Instantly share code, notes, and snippets.

View eevmanu's full-sized avatar
🎯
focused

Manuel eevmanu

🎯
focused
View GitHub Profile
@eevmanu
eevmanu / get-date.alternatives.py
Last active March 5, 2024 15:04
Get Epoch Timestamp (Timezone-Aware) at Start of Specific Date
# some alternatives to get date or datetime
# in order to get epoch seconds of the beginning of the choosen date
# --------------------------------------------------------------------------------
# alternative 1
# --------------------------------------------------------------------------------
from datetime import datetime
from zoneinfo import ZoneInfo
datetime.now(tz=ZoneInfo('localtime'))
# requires an extra std package `zoneinfo`
@eevmanu
eevmanu / get_city_and_country.py
Created February 9, 2024 16:21
get city and country via vanilla python using ifconfig.co
import urllib.request
import json
def get_public_ip(url):
try:
req = urllib.request.Request(
url,
headers={'User-Agent': 'curl/7.74.0'}
)
with urllib.request.urlopen(req) as response:
@eevmanu
eevmanu / pre-commit
Created June 21, 2023 16:38
block git commit if any item from a list of strings (patterns) is contained in (match) any tracked files (or markdown files)
#!/bin/bash
# Replace with the actual directory path to search in
search_dir=$(git rev-parse --show-toplevel 2>/dev/null || git rev-parse --git-dir 2>/dev/null | sed 's/\.git$//')
# Replace with your list of strings
search_strings=("< pattern 1 >" "< pattern 2 >" "< pattern 3 >")
# Create a pattern by joining the search strings with a pipe (|) as the separator
pattern=$(printf "%s\\|" "${search_strings[@]}")
@eevmanu
eevmanu / bash_benchmarking.sh
Last active June 15, 2023 23:11
bash benchamrking in nanoseconds
start=$(date +%s%N)
# any command
end=$(date +%s%N)
elapsed_nanosec=$((end - start))
formatted_elapsed_nanosec=$(printf "%'d" "$elapsed_nanosec" | sed 's/,/_/g')
echo "Elapsed time: $formatted_elapsed_nanosec nanoseconds"
@eevmanu
eevmanu / input
Created March 21, 2023 22:19
get commits count from github repo using graphql API
{
test1: repository(owner: "robfig", name: "cron") {
...RepoFragment
}
}
fragment RepoFragment on Repository {
name
defaultBranchRef {
@eevmanu
eevmanu / script.py
Created February 17, 2023 16:07
results of tracking memory usage for alternatives to flatten a list of list in python (https://stackoverflow.com/a/59913424/3889948)
# --------------------------------------------------------------------------------
# option 1: using numpy.array(< list >, dtype=object).flat)
# --------------------------------------------------------------------------------
import tracemalloc
import functools
import operator
import itertools
import numpy
{
"backmatter": "",
"bulletListMarker": "-",
"codeBlockStyle": "fenced",
"contextMenus": true,
"disallowedChars": "[]#^",
"downloadImages": false,
"downloadMode": "downloadsApi",
"emDelimiter": "_",
"fence": "```",
@eevmanu
eevmanu / dockerfile
Created January 10, 2023 21:31
random example of multi-stage build of a fastapi app
# --------------------------------------------------------------------------------
# temp stage
FROM python:3.10.9-slim-bullseye as builder
WORKDIR /code
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
@eevmanu
eevmanu / settings.json
Created January 4, 2023 02:38
VS Code folder settings example / template for a python project
{
// --------------------------------------------------------------------------------
// personal code editor config
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"files.exclude": {
@eevmanu
eevmanu / explanation.md
Created September 6, 2022 15:34
differences between `odd`, `likelihood`, `probablity`, `chance` I found over internet
  • odd
    • in statistics
      • 0 to ∞
  • likelihood
    • in statistics
      • attach to hypotheses
      • before
      • 0 to 1
  • probablity
  • in statistics