Skip to content

Instantly share code, notes, and snippets.

View vkopitsa's full-sized avatar

Volodymyr Kopytsia vkopitsa

  • Ukraine
  • 19:51 (UTC +03:00)
View GitHub Profile
@vkopitsa
vkopitsa / main.py
Created February 4, 2025 09:47
Sunrise Sunset Calculation
import math
def day_of_year(year, month, day):
"""
Calculate the day of year from month and day.
Accounts for leap years.
"""
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if month > 2 and ((year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)):
month_days[1] = 29

AitTag tracker

Steps to Run the Script on Startup

Move the Script to a Permanent Location: Save your script (e.g., airtag_tracker.py) in a directory like /home/pi/.

Make the Script Executable: Run the following command to make the script executable:

chmod +x /home/user/bl/blscan.py
@vkopitsa
vkopitsa / ollama_remote.py
Last active February 5, 2025 09:17
ollama remote
"""
Install:
pip install aiohttp
pip install --upgrade attrs
Run:
python3 ollama_remote.py
"""
import json
@vkopitsa
vkopitsa / go_code_inventory.py
Created January 29, 2024 13:34
go_code_inventory.py Battle
import os
import re
import sys
# Define the path to your Go project
project_path = '.'
# Regex patterns
struct_pattern = re.compile(r'type\s+(\w+)\s+struct')
field_pattern = re.compile(r'\s+(\w+)\s+(\w+)') # Match fields in a struct with their types
@vkopitsa
vkopitsa / php_code_inventory.py
Created November 9, 2023 15:57
python3 php_code_inventory.py
import os
import re
import csv
# Define the path to your PHP project
project_path = '.'
# Regex pattern to match class methods and comments
class_pattern = re.compile(r'class\s+(\w+)')
method_pattern = re.compile(r'function\s+(\w+)\(')
@vkopitsa
vkopitsa / file.js
Last active February 5, 2025 09:21
Binary String Parsing, Shifting, and Conversion Demonstration
var a = function(s) {
var r = parseInt(s.replace(".", ""), 2);
console.log(s, " ->", r);
return r;
};
var b = function(s) {
var r = (s >>> 0).toString(2);
console.log(s, " ->", r);
return r;
@vkopitsa
vkopitsa / traceback.py
Created July 29, 2020 07:46
Get exception description and stack trace as a string
# Format a stack trace and the exception information as a string
#
# Example:
#def a():
# b()
#
#
#def b():
# c()
#
/*
Serve is a very simple static file server in go
Usage:
-p="8100": port to serve on
-d=".": the directory of static files to host
-f="": the static file to host
Navigating to http://localhost:8100 will display the index.html or directory listing file or file content.
*/
package main
@vkopitsa
vkopitsa / Limit memory usage for a single Linux process
Last active December 24, 2019 14:11
Limit memory usage for a single Linux process
~$ sudo apt install cgroup-tools
~$ sudo cgcreate -a $USER:$USER -t $USER:$USER -g memory,cpu:myscript
~$ sudo cgset -r memory.limit_in_bytes=$((4*1024*1024*1024)) myscript
# prevent process from swapping
~$ sudo cgset -r memory.swappiness=0 myscript
~$ cgexec -g memory,cpu:myscript python app.py -d ....
@vkopitsa
vkopitsa / curl time
Last active September 26, 2018 10:09
curl -w " time_namelookup: %{time_namelookup}
time_connect: %{time_connect}
time_appconnect: %{time_appconnect}
time_pretransfer: %{time_pretransfer}
time_redirect: %{time_redirect}
time_starttransfer: %{time_starttransfer}
----------
time_total: %{time_total}\n" -o /dev/null -s https://google.com