Skip to content

Instantly share code, notes, and snippets.

@HumanEquivalentUnit
HumanEquivalentUnit / notes.dyalog
Last active December 21, 2019 13:14
PowerShell Cmdlet in Dyalog APL proof of concept
⍝ This is in a workspace, default namespace
⍝ created by )Ed ○InvokeAplExpression
⍝ Then exported as a Microsoft .Net Assembly
⍝ With the Isolation Mode dropdown set to
⍝ 'Each assembly attempts to use local bridge and interpreter libraries'
⍝ pre-req: make a project folder e.g. "D:\m\" and copy file
⍝ System.Management.Automation.dll from the .Net GAC into it.
⍝ PS> Copy-Item -Path ([psobject].Assembly.Location) -Destination 'd:\m\' -Verbose
$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())
@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
@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) <[email protected]>
# 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 / 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 / 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 / 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
#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.
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()]
@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