Skip to content

Instantly share code, notes, and snippets.

View xv's full-sized avatar
🇷🇺

Jad xv

🇷🇺
View GitHub Profile
@xv
xv / GuessTheNumber.py
Created March 27, 2018 18:34
The good ol' guess the secret number game done in Python.
import random
rand = random.randint(1000, 9999)
attempts = 0
# print rand
def check_proximity(num, guess):
"""
:param str num: The generated random integer casted as a string.
@xv
xv / Commit.fs
Last active June 29, 2021 02:09
F# snippet to fetch and return the hash identifier of last commit in the specified repository using regex pattern matching.
open System.IO
open System.Net
open System.Text.RegularExpressions
open System
/// <summary>
/// Fetches the Id (SHA1 hash) of the most recent GitHub Git commit in the
/// specified repository.
/// </summary>
///
@xv
xv / GetRelativeTime.py
Created April 10, 2019 14:30
Returns the relative time (also known as 'time ago') based on the given datetime object input.
from datetime import datetime
from math import floor
def get_relative_time(dateTime):
current_time = datetime.utcnow()
time_diff = current_time - dateTime
intervals = (
(time_diff.days / 36500, "century", "centuries"),
(time_diff.days / 3650, "decade", "decades"),
@xv
xv / del_file_content.bat
Created May 18, 2019 18:56
Iterates through files of a matching extension and deletes their content while keeping the files themselves.
@echo off
rem change .txt to whatever extension you want
type nul > content
for %%f in (*.txt) do copy /y content %%f
del content
@xv
xv / cpp-cli-form-set-up.md
Created September 8, 2019 03:17
A really short guide on how to set up a UI form in C++/CLI.

If you are playing with C++/CLI you are probably already familiar with the C# or VB.NET way of doing WinForms, so there's nothing to be afraid of in CLI -- it is just a bit of pain in the ass at first.

Setting up the project

Assuming that you have C++/CLI installed, fire up Visual Studio and create an empty CLR project. Once the project is created, we need to let Visual Studio know what type of project (WinForms in this case) this is, as well as set an entry point for the application.

Open the project's Properties dialog (Alt+Enter) and select All Platforms from the Platform combo box. After that, you need to:

Define the project type

  1. Navigate to Configuration Properties &gt;&gt; Linker &gt;&gt; System in the tree-view control on the left side.
@xv
xv / InvertWindowBorder.cs
Created March 4, 2020 09:14
Flashes a screen-inverted rectangle around a window like in Microsoft Spy++.
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
[DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("gdi32.dll")]
static extern int SaveDC(IntPtr hWnd);
@xv
xv / ColorFromHTML.cs
Created May 13, 2020 10:43
A much faster alternative to Microsoft's ColorTranslator.FromHtml() function.
/// <summary>
/// Translates an HTML-format color value to a GDI+
/// <see cref="System.Drawing.Color"/> structure.
/// </summary>
///
/// <param name="htmlVal">
/// A 3 or 6 digit hexadecimal value to translate. Do not include the
/// leading "#" sign.
/// </param>
///
@xv
xv / toggle_disk_space_warning.bat
Last active October 17, 2020 11:56
Tiny script to enbale/disable the "Low Disk Space" warning.
@echo off
rem Run this script as administrator
rem You may need to restart your computer to take effect
set hKey=HKLM
for /f "tokens=2 delims==." %%a in ('wmic os get version /value') do (
if %%a neq 10 set hKey=HKCU
)
@xv
xv / UndocumentedAcrylic.cs
Created November 5, 2020 20:05
Undocumented API for Windows 10 Acrylic style.
internal enum WindowCompositionAttribute
{
WCA_UNDEFINED = 0,
WCA_NCRENDERING_ENABLED = 1,
WCA_NCRENDERING_POLICY = 2,
WCA_TRANSITIONS_FORCEDISABLED = 3,
WCA_ALLOW_NCPAINT = 4,
WCA_CAPTION_BUTTON_BOUNDS = 5,
WCA_NONCLIENT_RTL_LAYOUT = 6,
WCA_FORCE_ICONIC_REPRESENTATION = 7,
@xv
xv / ShellFileIcon.cs
Created November 6, 2020 10:52
Simple method to retrieve the 16x16 shell file icon using SHFILEINFO structure.
internal const uint FILE_ATTRIBUTE_NORMAL = 0x80;
[Flags]
internal enum SHGetFileInfoFlags
{
SHGFI_LARGEICON = 0x0,
SHGFI_SMALLICON = 0x1,
SHGFI_OPENICON = 0x2,
SHGFI_SHELLICONSIZE = 0x4,
SHGFI_PIDL = 0x8,