Git Handbook for power users

I’ve documented a collection of useful Git commands that I use in my work. Feel free to contribute your suggestions by creating a PR on github. Change the commit message of last commit Use this when you want to edit the message of your most recent commit without creating a new one. git commit --amend Squash commit branch B to branch A This merges changes from branch-B into branch-A as a single commit, which helps keep the commit history clean. ...

June 5, 2025

Rust: Programming language for safety and speed

Introduction Rust is a non-garbage collected, compiled systems programming language with strong typing. It began as a personal project by a Mozilla research employee in 2006, and later, Mozilla started sponsoring the project in 2009. Eventually, Mozilla adopted Rust for Firefox and rewrote the core in Rust in 2017. Rust is an advanced language with numerous features that developers appreciate. Positioned as a compelling alternative to C/C++, Rust offers robust capabilities for system-level programming. ...

February 7, 2024

Python Dependency Management: pip and poetry

Install package using pip python3 -m pip install iotcore Show package details using pip python3 -m pip show iotcore Uninstall package using pip python3 -m pip uninstall iotcore List installed packages using pip python3 -m pip list Upgrade a package using pip python3 -m pip install --upgrade iotcore # or python3 -m pip install -U iotcore New python project using poetry poetry new poeetry_demo Install new package using poetry poetry add arrow Show installed packages using poetry ...

November 27, 2023

Learn Swedish - Grammar

Mjuka och Hårda vokaler (Soft & Hard Vowels) A O U Å Eg: Gammal (old) Gott (Tasty) Kul (Fun) Gå (walk) E I Y Ä Ö Eg: Ge (Give) Kypare (Waiter) Gilla (Like) Kärlek (Love) Get (Goat) Köpa (Buy) PERSONLIGA PRONOMEN Subjekt Objekt-Form Singular Jag (I) - ഞാൻ Mig (Me) - എന്നെ Du (You - singular, informal) - നീ Dig (You - singular, informal) - നിനക്ക് Han (He) - അവന്‍ Honom (Him) - അവനെ Hon (Her) - അവള്‍ Henne (Her) - അവളെ Hen Hen Den (It) - അത് Den Det (It) - അത് Det Man (ഒരുവന്‍) En Plural Vi (We)- ഞങ്ങള്‍ Oss (Us) - ഞങ്ങളെ Ni (You plural) - നിങ്ങൾ Er (You - plural or formal singular) De (They) - അവര്‍ Dem (Them) - അവരെ Notes: ...

November 20, 2023

Refresh C Programming

Convert void data-type (byte array) to uint8_t type static uint8_t notify_func(const void *data) { uint8_t value = ((uint8_t *)data)[7]; return value; } Structure data-type as function arguments static uint8_t notify_func(struct bt_gatt_subscribe_params *params) { printk("value_handle : %d", params->value_handle) } Declare enums as types typedef enum { STRING, NUMBERS, COMPLEX, DATATYPE_COUNT, INVALID_SENSOR } sensor_datatype_t; String initialisation to char pointer const char *p_mac_addr = "0C:8C:DC:41:E1:EF"; static void print_mac_addr(void) { printk("p_mac_addr : %s\n", p_mac_addr) } String as function return values char* get_sensor_mac_addr(void){ return p_mac_addr; } Parse unsigned int from byte array pointer ...

November 11, 2023

Zephyr RTOS: Taking Your Embedded Projects to the Next Level

what is Zephyr? Zephyr RTOS is a game-changing technology developed by experts with decades of collective experience in the embedded world. Originally created as Rocket by Wind River Systems in 2015 and later rebranded as Zephyr, this open-source project has gained immense popularity since its inception. As an open-source project, anyone can access the source code and understand its internal workings. Over the years, Zephyr has garnered a lot of attention from major tech giants like Google, Meta, Intel, and many more, resulting in significant investments in the project. The depth of contributions by multiple companies can be seen in the commits. Zephyr is not just an RTOS; it’s an ecosystem of a fully-fledged open-source project with strong foundations. ...

March 24, 2023

How to implement command design pattern in python?

import abc class CalcCmdAbs(metaclass=abc.ABCMeta): def __init__(self, *args, **kwargs): self._args = args self._kwargs = kwargs @property @abc.abstractmethod def name(self): raise NotImplemented() def execute(self): raise NotImplemented() from .interface import CalcCmdAbs OPERATORS = list() def register_operator(cls): OPERATORS.append(cls) return cls @register_operator class AddCmd(CalcCmdAbs): name = "add" def __init__(self, a, b): super().__init__(a, b) self.a = a self.b = b def execute(self): return self.a + self.b @register_operator class SubtractCmd(CalcCmdAbs): name = "subtract" def __init__(self, a, b): super().__init__(a, b) self.a = a self.b = b def execute(self): return self.a - self.b class NoneCmd(CalcCmdAbs): name = "None Command" def execute(self): print("Invalid Command") from .commands import OPERATORS, NoneCmd def get_commands() -> dict: return dict([cmd.name, cmd] for cmd in OPERATORS) def parse_commands(commands: dict, operation: str, *args): command = commands.setdefault(operation, NoneCmd) return command(*args) import unittest from .utils import get_commands, parse_commands class TestCase(unittest.TestCase): def setUp(self) -> None: self.commands = get_commands() def test_addition(self): command = parse_commands(self.commands, "add", 1, 1) self.assertEqual(command.execute(), 2, "Addition fail") def test_subtraction(self): command = parse_commands(self.commands, "subtract", 1, 1) self.assertEqual(command.execute(), 0, "Subtraction fail")

December 8, 2021

How to generate a zip file from given file list (Django)?

import os import shutil from io import BytesIO from zipfile import ZipFile from django.core.files.storage import FileSystemStorage from django.http import HttpResponse from django.conf import settings local_storage = FileSystemStorage() class ZipResponseMixin: def response(self, request, files: list, folder_name: str) -> HttpResponse: """Zip Response Generate a zip file from given file list and return Http response (Force download) :param request: request Object :param files: list of file like objects saved in models :param folder_name: desired folder name :return: """ folder_abs_path = f"{settings.MEDIA_ROOT}/temp-dl/{str(request.user.first_name)}/{folder_name}" if os.path.exists(folder_abs_path): shutil.rmtree(folder_abs_path) os.makedirs(folder_abs_path) file_names = list() for file in files: self._temp_save(file, file_names, folder_abs_path) buffer = BytesIO() zf = ZipFile(buffer, "w") for name in file_names: file_abs_path = folder_abs_path + "/" + name zf.write(file_abs_path, name) zf.close() response = HttpResponse(buffer.getvalue(), content_type="application/zip") response["Content-Disposition"] = f"attachment; filename={folder_name}.zip" return response def _temp_save(self, file, file_names, folder_abs_path): if file is not None: file_name = os.path.basename(file.name) file_abs_path = folder_abs_path + "/" + file_name local_storage.save(file_abs_path, file) file_names.append(file_name)

November 14, 2021