Skip to content

Instantly share code, notes, and snippets.

@aruku7230
aruku7230 / create_file_filled_with_random_characters.md
Last active September 4, 2023 07:45
Create file filled with random characters

Get Random String

using System;
using System.Text;
					
public class Program
{
	public static void Main()
	{
 Console.WriteLine(GetRandomString(0));
@aruku7230
aruku7230 / algo_judge_two_expressions_are_equivalent.md
Last active April 5, 2023 10:22
Algorithm to judge whether two expressions are equivalent

Given two arithmetic expressions e1 and e2 that have same four operands, judge if they are equivalent. Two expression are equivalent if they can be arranged to be the same expression according to mathematical properties. Return true if they are equivalent, otherwise false.

Examples

Example 1:

  • Input: e1 is "6 * (2 + 5 - 3)", e2 is "(5 - 3 + 2) * 6".
  • Output: true
@aruku7230
aruku7230 / use_regex.vba
Created February 21, 2023 06:27
Use Regular Expression by VBA
Option Explicit
Public Function RegExpTest(text As String, pattern As String, Optional match_case As Boolean = True) As Boolean
Dim regex As Object
On Error GoTo ErrHandl
Set regex = CreateObject("VBScript.RegExp")
regex.pattern = pattern
regex.Global = True
@aruku7230
aruku7230 / run_sql_against_excel.ps1
Created February 20, 2023 06:36
Run SQL against Excel
$ErrorActionPreference = 'Stop'
# Create sheet if not exists
Function CreateSheetIfNotExist($Wb, $SheetName)
{
foreach($Ws In $Wb.Worksheets) {
If ($SheetName -ieq $Ws.Name) {
return $Ws
}
}
@aruku7230
aruku7230 / manage_chocolatey_packages.ps1
Last active February 20, 2023 06:37
Manage Pacakges on Windows
#Requires -RunAsAdministrator
# Pin packages.
$packages = @(
'emacs'
'firefox'
'vscode'
'vscode.install'
'microsoft-windows-terminal'
)
@aruku7230
aruku7230 / common_commands_windows.md
Created February 17, 2023 04:23
Commonly used commands on Windows

Start a WinMerge window to compare two files and return immediatelly.

Start-Process winmergeu.exe -WindowStyle Hidden "/s /t text ""left_file.txt"" ""right_file.txt"""
@aruku7230
aruku7230 / export_excel_to_csv.ps1
Created February 15, 2023 05:43
Use Powershell to Export Excel to CSV
# Export Excel sheet to CSV file
# $File: file path
# $SheetNames: An array, sheet names to export.
Function Export-ExcelToCsv ($File, $SheetNames) {
$Excel = New-Object -ComObject Excel.Application
# SaveAs will overwrite existing file
$Excel.Application.DisplayAlerts = $False
$wb = $Excel.Workbooks.Open($File)
@aruku7230
aruku7230 / install_latest_protonmail_bridge.sh
Created February 14, 2023 12:24
Install latest protonmail bridge on Ubuntu
# Import public key as the first time
pubkey_url=$(
curl -s \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/ProtonMail/proton-bridge/releases/latest \
| grep "browser_download_url" | grep -E "pubkey.gpg\"$" \
| awk -F "\"" '{print $4}'
)
pubkey_file=$(basename "$pubkey_url")
@aruku7230
aruku7230 / powershell_encoding.md
Created February 8, 2023 06:03
Poweshell character encoding

Set default encoding of Out-File. See about_Character_Encoding.

# On Windows Powershell
# Out-File and the redirection operators > and >> create UTF-16LE.
# Set defautl encoding of Out-File (or > redirection) to UTF-8 (with BOM).
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
@aruku7230
aruku7230 / verify_apk.md
Last active January 24, 2023 10:37
Verify the the apk

Use apksigner

apksigner verify --print-certs --verbose <name>.apk

Check checksums

Check checksums: sha256sum --check <name>.asc, change sha256sum to corresponding tool is checksums algorithm is not SHA256.