Skip to content

Instantly share code, notes, and snippets.

View mtovmassian's full-sized avatar

Martin Tovmassian mtovmassian

View GitHub Profile
@mtovmassian
mtovmassian / sign-vmware-vmmon-vmnet.sh
Created December 8, 2020 08:42
VMware drivers, such as vmmon and vmnet, are not able to be loaded if not signed before (this is likely to happen after update). This script helps to automaticly sign vmon and vmnet drivers.
#!/usr/bin/env bash
main() {
today_date=$(date +%Y%m%d)
key_filename="VMWARE${today_date}.priv"
cert_filename="VMWARE${today_date}.der"
openssl req -new -x509 -newkey rsa:2048 -keyout "${key_filename}" -outform DER -out "${cert_filename}" -nodes -days 36500 -subj "/CN=VMWARE/"
@mtovmassian
mtovmassian / clock.py
Created December 8, 2020 08:46
Continuous display of time
#!/usr/bin/python3
from datetime import datetime
from time import sleep
while True:
time_ = datetime.now().strftime("%H:%M:%S:%f")[:-3]
print(f"\r{time_}", end="")
sleep(0.1)
@mtovmassian
mtovmassian / ssh-tunnel.sh
Created December 8, 2020 09:29
Open a SSH tunnel
ssh -i <path/to/my/private/ssh/key> -L <remote_port>:127.0.0.1:<local_port> <user>@<hostname> -N -vv
@mtovmassian
mtovmassian / demlo_triangle.py
Created February 10, 2021 20:46
Demlo palindromic triangle
def calc_base_one_repunits(n):
# https://en.wikipedia.org/wiki/Repunit
return sum(
map(lambda x: pow(10, x), range(0, n))
)
for i in range(1, int(input("Triangle size: "))+1):
print(pow(calc_base_one_repunits(i), 2))
@mtovmassian
mtovmassian / palindrome_check.py
Created February 14, 2021 22:49
Mathematically check if a number is a palindrome
def extract_digits_left(num):
if num < 10:
return [num]
else:
return [*extract_digits_left(num // 10), num % 10]
def extract_digits_right(num):
if num < 10:
return [num]
@mtovmassian
mtovmassian / url_quote_unquote.py
Last active February 24, 2021 14:50
Url encoding/decoding
from urllib.parse import quote, unquote
# https://www.urlencoder.io/python/
url = "https//hello.world.api.com/v1/print?value=hello world"
quoted = quote("https//hello.world.api.com/v1/print?value=hello world")
unquoted = unquote(quoted)
print(quoted)
@mtovmassian
mtovmassian / python_anonymous_class.py
Last active September 3, 2021 14:11
Anonymous class in Python
# https://stackoverflow.com/questions/1123000/does-python-have-anonymous-classes
anonymous_class = type(
"",
(),
{
"attr1": None,
"get_attr1": lambda self: getattr(self, "attr1"),
"set_attr1": lambda self, value: setattr(self, "attr1", value)
}
@mtovmassian
mtovmassian / php-TestUtils.php
Last active October 17, 2022 09:54
Helpers for PHP unit testing
<?php
namespace Tests;
use PHPUnit\Framework\TestCase;
class TestUtils
{
public static function invokePrivateMethod(object $object, string $methodName): callable
{
@mtovmassian
mtovmassian / python_deprecation_helper.py
Last active October 17, 2022 09:54
Python deprecation decorator
def deprecated(arg):
if callable(arg):
return deprecated_auto_message(arg)
else:
return deprecated_user_message(arg)
def deprecated_auto_message(func):
def wrapper(*args, **kwargs):
message = "Function {} is deprecated.".format(func.__name__)
warn_deprecation(message, 3)
@mtovmassian
mtovmassian / python_cache.py
Last active October 17, 2022 09:55
Cache store with memoizing behavior and decorator
import logging
import pickle
from datetime import datetime
from sys import getsizeof
logger = logging.getLogger(__name__)
class CacheStore: