Skip to content

Instantly share code, notes, and snippets.

@HumanEquivalentUnit
HumanEquivalentUnit / ps-sudoku-rust.rs
Created August 3, 2021 17:28
A port of a PowerShell Sudoku brute-force to Rust, staying as close as possible to the original (without knowing Rust very well)
// a naive Rust port of a PowerShell brute-force Sudoku solver
// trying to keep everything as close to the same implementation as possible.
fn main() {
let mut board : [[i8; 9]; 9] = [
[0,0,0, 0,3,0, 0,0,0],
[0,0,1, 0,7,6, 9,4,0],
[0,8,0, 9,0,0, 0,0,0],
[0,4,0, 0,0,1, 0,0,0],
@HumanEquivalentUnit
HumanEquivalentUnit / main.rs
Created April 30, 2021 01:51
Rust massive inline vectors with 3 minute compile time
use std::env;
fn main() {
// vector of prime "hashes", sorted so they can be binary searched
let lookup_primes : Vec<i64> = vec![11794860,11846142,12512808,15655440,16956360,18137400,18346020,21651280,22123600,25956240,29902200,31549560,40300260,42095196,42597520,44697576,45014200,46852656,49206300,51447780,52811220,65410224,71180340,71722280,80102484,80854620,86665840,87931500,93458568,99722800,100683660,103230666,103799850,105129432,108746484,109035300,111985020,113384502,119599788,124081320,125368650,129507400,130227900,136800600,137434220,140220850,150346392,151367370,155189100,156605460,156632322,164712900,172051110,174106200,180333560,181234350,182071890,188839860,191423100,194597480,196068180,197110452,198917950,204831408,209420750,211333276,211967376,214322280,217467684,220101420,220101420,220644468,228171720,234393720,238368300,239007760,245070980,246202440,246705690,248471300,253137720,257298888,257397140,264279246,264964968,265756260,268660700,272580924,280854420,282643740,291984660,29201
using namespace System.Collections.Generic
using namespace System.Management.Automation
using namespace System.Security.AccessControl
using namespace Microsoft.Win32
function Get-InstalledSoftware {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
#source of the main script : "https://gist.github.com/indented-automation/32efb05a5fb67ef9eed02bbb8fe90691"
#source of the Regex filtering : "https://github.com/gangstanthony/PowerShell/blob/master/Get-InstalledApps.ps1"
filter Get-InstalledSoftware {
<#
.SYNOPSIS
Get all installed from the Uninstall keys in the registry.
.DESCRIPTION
Read a list of installed software from each Uninstall key.
@HumanEquivalentUnit
HumanEquivalentUnit / tioCode.dyalog
Created August 25, 2020 04:28
decode a TIO.run link in Dyalog APL / .Net
tioCode←{
⍝ decodes a TIO.run link such as
⍝ tioCode 'https://tio.run/##SyzI0U2pTMzJT////1Hf1EdtExSMFYwf9W551LvZkgsioq4OZSg86lzwqHcFkor//wE'
⍝ load dfns workspace to use base64 decoder
_←{(⍎⍵ ⎕NS ⍬).⎕CY ⍵}'dfns'
⎕USING←'System' 'System.Net,System.dll'
hash←('^https://tio\.run/##'⎕R'')⍵ ⍝ remove web address parts of the link
@HumanEquivalentUnit
HumanEquivalentUnit / decode-aplcart-tsv-csharp.ps1
Created August 24, 2020 23:56
Decode APLCart TSV and show in Out-Gridview (C# decoder)
# Imports the table.tsv file from APLCart
# Decodes the TIO.run links
# Shows in Out-Gridview
$tablePath = "c:\sc\aplcart\table.tsv"
$csharp = @'
using System;
using System.IO;
using System.Net;
@HumanEquivalentUnit
HumanEquivalentUnit / decode-aplcart-tsv.ps1
Last active August 26, 2020 03:20
Import APLCart table.tsv and decode the tio.run links to check the code
# TIO Link verify helper for APLCart.
# Open this file in PowerShell ISE on Windows (or other Unicode-aware console, e.g. VS Code + PowerShell extension, new Windows Terminal; not basic PowerShell window)
# Update $tablePath to point to the table.
# Update the string of codes to find.
# Run.
$tablePath = "c:\sc\aplcart\table.tsv"
$codesToFind = @'
0∘×N
@HumanEquivalentUnit
HumanEquivalentUnit / Invoke-WithImpersonation.ps1
Created August 12, 2020 05:05 — forked from jborean93/Invoke-WithImpersonation.ps1
Invoke a scriptblock in powershell with impersonation
# Copyright: (c) 2020, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Add-Type -Namespace PInvoke -Name NativeMethods -MemberDefinition @'
[DllImport("Kernel32.dll")]
public static extern bool CloseHandle(
IntPtr hObject);
[DllImport("Advapi32.dll", SetLastError = true)]
public static extern bool ImpersonateLoggedOnUser(
@HumanEquivalentUnit
HumanEquivalentUnit / phaseI.dyalog
Created August 1, 2020 15:19
Dyalog APL Competition 2020 - Phase I solutions
((0>⊣)⌽((⊂↑),(⊂↓))) ⍝ 1. Let's Split
(⊢⊂⍨(128∘>∨191∘<)) ⍝ 2. Characters
{26⊥⎕A⍳⍵} ⍝ 3. Columns
{(0=400|⍵)∨(≠⌿0=4 100∘.|⍵)} ⍝ 4. Take a Leap
{⎕IO←0 ⋄ ⌽⍣(>/⍵)⊢(⌊/⍵)+⍳1+(⌈/-⌊/)⍵} ⍝ 5. Stepping
{⍵[⍒⍺=⍵]} ⍝ 6. Move To Front
{⍺=2⊥bits∧⍺⊤⍨2⍴⍨≢bits←2⊥⍣¯1⊢⍵} ⍝ 7. Bits
{(∨/(1 ¯1⍴⍨≢)⍷⍨(×2-/⊢))10⊥⍣¯1⊢⍵} ⍝ 8. Zigzag
{peak←(⊢⍳⌈/),⍵ ⋄ notDesc←(⍳∘≢≡⍋) ⋄ (notDesc peak↑⍵) ∧ (notDesc ⌽peak↓⍵)} ⍝ 9. Rise and fall
⍝ 10. Stacking It Up - not done
$keys = @{
'1'='' ; '2'='[abc]'; '3'='[def]' ;
'4'='[ghi]' ; '5'='[jkl]'; '6'='[mno]' ;
'7'='[pqrs]'; '8'='[tuv]'; '9'='[wxyz]';
}
$nums = '76937'
$pattern = foreach ($char in $nums.GetEnumerator())