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 / merge_sort.py
Created October 1, 2021 12:23
The Merge sort algorithm simple and readable implementation in Python
from typing import List
def merge_sort(lst: List[int]) -> List[int]:
"""The Merge sort algorithm.
Wikipedia: https://en.wikipedia.org/wiki/Merge_sort
"""
if len(lst) <= 1:
return lst
@ohaval
ohaval / bubble_sort.py
Created October 1, 2021 12:20
The Bubble sort algorithm simple and readable implementation in Python
from typing import List
def bubble_sort(lst: List[int]) -> None:
"""The Bubble sort algorithm.
The sorted list is placed in place.
Wikipedia: https://en.wikipedia.org/wiki/Bubble_sort
"""
for i in range(len(lst) - 1, 0, -1):
@ohaval
ohaval / quick_sort.py
Created October 1, 2021 12:15
The Quicksort algorithm simple and readable implementation in Python
from typing import List, Tuple
def quick_sort(lst: List[int]) -> List[int]:
"""The Quicksort algorithm.
Wikipedia: https://en.wikipedia.org/wiki/Quicksort
"""
if len(lst) < 2:
return lst
@ohaval
ohaval / SaveImageFromClipboard.cpp
Last active April 22, 2023 09:03
Save an image from the clipboard to a file
/*
I wanted to play with the clipboard via Windows API so I wrote a small program that
checks if the clipboard contains an image, and if so saves the image as a .bmp file.
This program obtains the handle on the clipboard data, put together all of the
information and raw data a .bmp file holds, and writes it to the disk.
With small changes it's possible to make this code run in a loop and save an image
from the clipboard every X seconds.
@ohaval
ohaval / logoff_user.py
Created September 8, 2021 12:09
A small program that log off a user (possibly in another session) in Windows
"""A small program that log off a user (possibly in another session) in Windows
This is actually an implementation in Python of the `LogoffUser.cpp` program I have made.
I made that program in order to automate the manual operation of logging off my family
user in the workstation each time after they have used it :)
LogoffUser.cpp link: https://gist.github.com/ohaval/a922fc07f4585b81c119614e852d9dbd
Make sure that the `pywin32` packages is installed before using
/*
This program receives the accurate string of the username (as written by `net user`)
and log offs the session associated with that user, if any is active.
In order to log off another users on the system, Administrator permissions
are required. Thus, the program should be run as an Administrator.
Flow of the code is:
1) Enumerate active sessions
2) For each session, enumerate the username string associated with the session