Skip to content

Instantly share code, notes, and snippets.

@mlhaufe
mlhaufe / UnionIntersection.ts
Created April 30, 2023 16:40
TypeScript Union and Intersection types
View UnionIntersection.ts
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
type IntersectionToUnion<I> = (I extends any ? (x: I) => any : never) extends ((x: infer U) => any) ? U : never;
@mlhaufe
mlhaufe / ShellBrowse.vbs
Last active September 26, 2022 06:21
VBScript File Browser
View ShellBrowse.vbs
Option Explicit
' Flags for the options parameter
Const BIF_returnonlyfsdirs = &H0001
Const BIF_dontgobelowdomain = &H0002
Const BIF_statustext = &H0004
Const BIF_returnfsancestors = &H0008
Const BIF_editbox = &H0010
Const BIF_validate = &H0020
Const BIF_browseforcomputer = &H1000
@mlhaufe
mlhaufe / islanders.ts
Created May 5, 2022 01:42
12 islanders balancing problem
View islanders.ts
// Random Integer from m to n excluding e
const randInt = (m: number, n: number, e?: number): number => {
const result = Math.floor(Math.random() * m) + n;
return e == undefined ? result :
result == e ? randInt(m, n, e) :
result
}
class Person { constructor(public weight: number) {} }
@mlhaufe
mlhaufe / Functional.ts
Created April 16, 2022 03:37
Expression Problem
View Functional.ts
/** Number Expressions */
// data
type Exp =
{ tag: 'Lit', value: number } |
{ tag: 'Add', left: Exp, right: Exp }
// operations
function evaluate(exp: Exp): number {
switch (exp.tag) {
@mlhaufe
mlhaufe / downloadImage.vbs
Last active September 25, 2021 00:12
Downloading an image from a webpage in VBScript
View downloadImage.vbs
Dim document : Set document = WScript.GetObject("http://example.com")
While document.readyState <> "complete" : WScript.Sleep 200 : Wend
Dim xhr : Set xhr = CreateObject("MSXML2.XMLHTTP.3.0")
xhr.open "GET", document.getElementsByTagName("img")(0).src, False
xhr.send
Dim stream : Set stream = CreateObject("Adodb.Stream")
stream.Type = 1
stream.Open
stream.Write xhr.responseBody
stream.SaveToFile "C:\..\foo.jpg", 2
@mlhaufe
mlhaufe / parameters.vbs
Created June 19, 2011 12:52
VBScript class constructor parameters
View parameters.vbs
Class Person
Private m_Age
Private m_Name
Public Default Function Init(Name, Age)
m_Name = Name
m_Age = Age
Set Init = Me
End Function
@mlhaufe
mlhaufe / error.txt
Created May 24, 2021 13:57
Magnolia SPAv2 error
View error.txt
Context: <https://groups.google.com/a/magnolia-cms.com/g/user-list/c/MRpHYKkOMhA>
Type Exception Report
Message com.machinezoo.noexception.WrappedException: java.net.ConnectException: Connection refused (Connection refused)
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
@mlhaufe
mlhaufe / cyclicPerms.js
Last active May 12, 2021 14:07
Permutations
View cyclicPerms.js
// cyclicPerms(5)
// "1,2,3,4,5
// 2,3,4,5,1
// 3,4,5,1,2
// 4,5,1,2,3
// 5,1,2,3,4"
const cyclicPerms = (n) =>
Array.from({length: n},(_,i) => i + 1)
.map((_, i, xs) => [...xs, ...xs].slice(i, i+n))
.join('\n')
@mlhaufe
mlhaufe / htmlTitleList.vbs
Created January 6, 2012 00:48
Getting html details (VBScript)
View htmlTitleList.vbs
'Reference: <http://www.visualbasicscript.com/tm.aspx?high=&m=95638&mpage=1>
Option Explicit
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim files : Set files = fso.GetFolder("C:\test\").Files
Dim file
For Each file In files
If file.Type = "Firefox Document" Then '<-- update for your system
Dim doc : Set doc = CreateObject("htmlfile")
doc.write fso.OpenTextFile(file.Path).ReadAll()