Skip to content

Instantly share code, notes, and snippets.

@itsho
itsho / MontyHallProblemSimulation.cs
Created March 19, 2017 12:22
Simulating Monty Hall problem - running X times to get estimation by using Random
using System;
namespace MontyHallProblemSimulation
{
public class Program
{
private static Random _rnd = null;
private static char[] _arrDoors;
private const char DOOR_WITH_CAR = '*';
@itsho
itsho / StopWindowsTimeService.ps1
Created March 13, 2018 10:23
Stop windows time service - request Admin from end-user
# A self elevating PowerShell script
# https://blogs.msdn.microsoft.com/virtual_pc_guy/2010/09/23/a-self-elevating-powershell-script/
# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
@itsho
itsho / InnoScript_CompareVersionStrings.iss
Created May 22, 2018 08:24
Compare Versions as strings in InnoScript. fixed html tags from source article
// ----------------Compare versions - start ------------------
// source: http://www.arvydas.co.uk/2015/04/compare-version-strings-with-innosetup/
// Procedure to split a string into an array of integers
procedure Explode(var Dest: TArrayOfInteger; Text: String; Separator: String);
var
i, p: Integer;
begin
i := 0;
repeat
SetArrayLength(Dest, i+1);
@itsho
itsho / Force 100 DPI Scale.ps1
Created December 20, 2018 09:41
Force 100% DPI Scaling for all screens even if the default value is different
# =========================================================================================================
# if you like to reset your DPI Scaling to the DEFAULT, you can use the registry (Option five) from here:
# https://www.tenforums.com/tutorials/5990-change-dpi-scaling-level-displays-windows-10-a.html#option5
#
# But, since the default value is different on various monitors, if you like to force 100%,
# you need the following trick:
# for each monitor - set DPIValue to 0xFFFFFFFF (which is -1 in DWord)
#
# Last update: 18 December 2018
# Created by: Itsho
@itsho
itsho / RSA_SignAndVerify.cs
Last active June 4, 2023 17:26
RSA - create signature and verify
// ----------------------------------------------------
// Notice, this code is using BouncyCastle NuGet:
// https://www.nuget.org/packages/BouncyCastle/1.8.4/
// Created by: Itsho
// Creation Date: 20 December 2018
// ----------------------------------------------------
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
@itsho
itsho / TabletKeyboardAutoOpen.xaml
Last active January 2, 2019 10:24
Compile this WPF project with 4.6.2+ and run on Windows 10 1607+ (Anniversary Update)
<Window x:Class="TabletKeyboardAutoOpen.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TabletKeyboardAutoOpen"
mc:Ignorable="d"
FontSize="30"
Title="MainWindow"
WindowStartupLocation="CenterScreen"
@itsho
itsho / HwndHostEx.cs
Last active January 23, 2024 17:13
Hosting an app inside a WPF app (System.Windows.Interop)
using System;
using System.Runtime.InteropServices;
using System.Windows.Interop;
namespace HostingAppTest
{
// based on https://stackoverflow.com/q/30186930/426315
public class HwndHostEx : HwndHost
{
private readonly IntPtr _childHandle;
@itsho
itsho / RunThemidaMultiProcess.ps1
Created June 13, 2019 12:41
Run Themida on multiple files with multiple instances of Themida.exe
# Enable -Verbose option
[CmdletBinding()]
Param(
[string]$dllsFolder = "$PSScriptRoot",
[string]$txtWithFileList = "$PSScriptRoot\ListOfFilesToUseInThemida.txt",
[string]$themida32Path = "C:\Program Files\Themida\Themida.exe",
[string]$themidaProject = "D:\ThemidaProject.tmd",
[int]$totalProcesses = 8
)
@itsho
itsho / CreateMissingHashFile.ps1
Created March 4, 2020 08:26
Create missing SHA256-hash-file for NuGet
#requires -version 4.0
[cmdletbinding()]
Param([Parameter(Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[string]$Path )
Process {
Write-verbose "Creating hash for input file..."
$hash = (Get-FileHash -Path $Path -Algorithm "SHA256").Hash
@itsho
itsho / AddCertificateToCaBundle.ps1
Last active July 12, 2021 11:14
Add given certificate to ca-bundle.crt
# self elevate this script to run as admin
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit
}
$newCertContent = "# Certificate name for easy search
-----BEGIN CERTIFICATE-----
MIITHISISMYCERT_hereBeDragonshereBeDragons
-----END CERTIFICATE-----
"