Advertisement
EntropicBlackhole

Functions

Oct 20th, 2021 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GCD(x, y) {
  2.     Return y=0 ? Abs(x) : GCD(y,mod(x,y))
  3. }
  4. LCM(x, y) {
  5.     Return Floor(x*y/GCD(x,y))
  6. }
  7. IsPrime(n,k=2) {
  8.     d := k+(k<7 ? 1+(k>2) : SubStr("6-----4---2-4---2-4---6-----2",Mod(k,30),1))
  9.     Return n < 3 ? n>1 : Mod(n,k) ? (d*d <= n ? IsPrime(n,d) : 1) : 0
  10. }
  11. Fac(x) {
  12.     var := 1
  13.     Loop, %x%
  14.         var *= A_Index
  15.     return var
  16. }
  17. Per(x, y) {
  18.     Per :=(x/100)*y
  19.     return Per
  20. }
  21. TMet(x, y, d) {
  22.     return ZTrim(d/(x+y))
  23. }
  24. TRch(x, y, d) {
  25.     return ZTrim(d/(x>y ? x-y : y-x))
  26. }
  27. Dis(v0:=0, vf:=10, t:=10) {
  28.     return ((v0+vf)/2)*t
  29. }
  30. Area(shape, x) {
  31.     if (shape = 1)
  32.         return 3.1415926535*(x**2)
  33.     else
  34.         return ((x/(2*Tan((180/shape)*0.01745329252)))*(shape*x))/2
  35. }
  36. CheckItemSelected() {
  37.     global CheckItem
  38.     TotalSelectedItems := % LV_GetCount("S")
  39.     CheckItem := LV_GetNext()
  40.     if (TotalSelectedItems >= 1)
  41.         return true
  42.     else
  43.         return false
  44. }
  45. ZTrim(x) {
  46.     return (InStr(x, ".") > 0) ? RTrim(RTrim(x, 0), ".") : x
  47. }
  48. StrAmt(Haystack, Needle, casesense := false) {
  49.     StringCaseSense % casesense
  50.     StrReplace(Haystack, Needle, , Count)
  51.     return Count
  52. }
  53. Gst() {   ; GetSelectedText by Learning one
  54.     IsClipEmpty := (Clipboard = "") ? 1 : 0
  55.     if !IsClipEmpty  {
  56.         ClipboardBackup := ClipboardAll
  57.         While !(Clipboard = "")  {
  58.             Clipboard =
  59.             Sleep, 10
  60.         }
  61.     }
  62.     Send, ^c
  63.     ClipWait, 0.1
  64.     ToReturn := Clipboard, Clipboard := ClipboardBackup
  65.     if !IsClipEmpty
  66.         ClipWait, 0.5, 1
  67.     return ToReturn
  68. }
  69. Dice() {
  70.     Random, dice, 1, 6
  71.     return dice
  72. }
  73. Avg(numbers*) {
  74.     for index,number in numbers
  75.         sum += number
  76.     return sum/numbers.MaxIndex()
  77. }
  78. AvgArr(Array) {
  79.     Loop, % Array.MaxIndex()
  80.         sum += Array[A_Index]
  81.     return sum/Array.MaxIndex()
  82. }
  83. Rand(x:=-2147483648, y:=2147483647) {
  84.     Random, OutputVar, %x%, %y%
  85.     return OutputVar
  86. }
  87. RandArr(Array) {
  88.     Random, ArrRand, 1, % Array.MaxIndex()
  89.     return Array[ArrRand]
  90. }
  91. RandChance(Per) {
  92.     Random, OutputVar, 1, 100
  93.     if (OutputVar <= Per)
  94.         return true
  95.     else
  96.         return false
  97. }
  98. RandPassword(Amount := 8) {
  99.     Alphabet := ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
  100.     Numbers := [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
  101.     Symbols := ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")"]
  102.     Choose := ["Alphabet", "Numbers", "Symbols"]
  103.     Loop, %Amount%
  104.     {
  105.         Random, ArrRand, 1, % Choose.MaxIndex()
  106.         Thing := Choose[ArrRand]
  107.         Random, ArrRand, 1, % %Thing%.MaxIndex()
  108.         Send, % %Thing%[ArrRand]
  109.     }
  110. }
  111. Caesar(string, n, decode := false) {
  112.     Loop Parse, string
  113.     {
  114.         If (Asc(A_LoopField) >= 65 and Asc(A_LoopField) <= 90)
  115.             out .= Chr(Mod(Asc(A_LoopField)-(decode = true ? 97+n : 97-n),26)+65)
  116.         Else If (Asc(A_LoopField) >= 97 and Asc(A_LoopField) <= 122)
  117.             out .= Chr(Mod(Asc(A_LoopField)-(decode = true ? 97+n : 97-n),26)+97)
  118.         Else out .= A_LoopField
  119.     }
  120.     return out
  121. }
  122. LCSQ(a, b) {
  123.     while pos := RegExMatch(a "`n" b, "(.+)(?=.*\R.*\1)", m, pos?pos+StrLen(m):1)
  124.         res := StrLen(res) > StrLen(m1) ? res : m1
  125.     return res
  126. }
  127. LCST(a, b) {
  128.     Loop % StrLen(a)+2  {
  129.         i := A_Index-1
  130.         Loop % StrLen(b)+2
  131.             j := A_Index-1, len%i%_%j% := 0
  132.     }
  133.     Loop Parse, a
  134.      {
  135.         i := A_Index, i1 := i+1, x := A_LoopField
  136.         Loop Parse, b
  137.          {
  138.             j := A_Index, j1 := j+1, y := A_LoopField
  139.             len%i1%_%j1% := x=y ? len%i%_%j% + 1
  140.             : (u:=len%i1%_%j%) > (v:=len%i%_%j1%) ? u : v
  141.         }
  142.     }
  143.     x := StrLen(a)+1, y := StrLen(b)+1
  144.     While x*y  {
  145.         x1 := x-1, y1 := y-1
  146.         If (len%x%_%y% = len%x1%_%y%)
  147.             x := x1
  148.         Else If  (len%x%_%y% = len%x%_%y1%)
  149.             y := y1
  150.         Else
  151.             x := x1, y := y1, t := SubStr(a,x,1) t
  152.     }
  153.     Return t
  154. }
  155. ToolTipTimer(Text, Timeout := 2000, x := "", y := "", WhichToolTip := 1) {
  156.     if not x
  157.         MouseGetPos, X
  158.     if not y
  159.         MouseGetPos, , Y
  160.     ToolTip, %Text%, %X%, %Y%, %WhichToolTip%
  161.     SetTimer, RemoveToolTip, -%Timeout%
  162.     return
  163.    
  164.     RemoveToolTip:
  165.     ToolTip
  166.     return
  167. }
  168. ToolTipFont(Options := "", Name := "", hwnd := "") {
  169.     static hfont := 0
  170.     if (hwnd = "")
  171.         hfont := Options="Default" ? 0 : _TTG("Font", Options, Name), _TTHook()
  172.     else
  173.         DllCall("SendMessage", "ptr", hwnd, "uint", 0x30, "ptr", hfont, "ptr", 0)
  174. }
  175. ToolTipColor(Background := "", Text := "", hwnd := "") {
  176.     static bc := "", tc := ""
  177.     if (hwnd = "") {
  178.         if (Background != "")
  179.             bc := Background="Default" ? "" : _TTG("Color", Background)
  180.         if (Text != "")
  181.             tc := Text="Default" ? "" : _TTG("Color", Text)
  182.         _TTHook()
  183.     }
  184.     else {
  185.         VarSetCapacity(empty, 2, 0)
  186.         DllCall("UxTheme.dll\SetWindowTheme", "ptr", hwnd, "ptr", 0
  187.             , "ptr", (bc != "" && tc != "") ? &empty : 0)
  188.         if (bc != "")
  189.             DllCall("SendMessage", "ptr", hwnd, "uint", 1043, "ptr", bc, "ptr", 0)
  190.         if (tc != "")
  191.             DllCall("SendMessage", "ptr", hwnd, "uint", 1044, "ptr", tc, "ptr", 0)
  192.     }
  193. }
  194. _TTHook() {
  195.     static hook := 0
  196.     if !hook
  197.         hook := DllCall("SetWindowsHookExW", "int", 4
  198.             , "ptr", RegisterCallback("_TTWndProc"), "ptr", 0
  199.             , "uint", DllCall("GetCurrentThreadId"), "ptr")
  200. }
  201. _TTWndProc(nCode, _wp, _lp) {
  202.     Critical 999
  203.    ;lParam  := NumGet(_lp+0*A_PtrSize)
  204.    ;wParam  := NumGet(_lp+1*A_PtrSize)
  205.     uMsg    := NumGet(_lp+2*A_PtrSize, "uint")
  206.     hwnd    := NumGet(_lp+3*A_PtrSize)
  207.     if (nCode >= 0 && (uMsg = 1081 || uMsg = 1036)) {
  208.         _hack_ = ahk_id %hwnd%
  209.         WinGetClass wclass, %_hack_%
  210.         if (wclass = "tooltips_class32") {
  211.             ToolTipColor(,, hwnd)
  212.             ToolTipFont(,, hwnd)
  213.         }
  214.     }
  215.     return DllCall("CallNextHookEx", "ptr", 0, "int", nCode, "ptr", _wp, "ptr", _lp, "ptr")
  216. }
  217. _TTG(Cmd, Arg1, Arg2 := "") {
  218.     static htext := 0, hgui := 0
  219.     if !htext {
  220.         Gui _TTG: Add, Text, +hwndhtext
  221.         Gui _TTG: +hwndhgui +0x40000000
  222.     }
  223.     Gui _TTG: %Cmd%, %Arg1%, %Arg2%
  224.     if (Cmd = "Font") {
  225.         GuiControl _TTG: Font, %htext%
  226.         SendMessage 0x31, 0, 0,, ahk_id %htext%
  227.         return ErrorLevel
  228.     }
  229.     if (Cmd = "Color") {
  230.         hdc := DllCall("GetDC", "ptr", htext, "ptr")
  231.         SendMessage 0x138, hdc, htext,, ahk_id %hgui%
  232.         clr := DllCall("GetBkColor", "ptr", hdc, "uint")
  233.         DllCall("ReleaseDC", "ptr", htext, "ptr", hdc)
  234.         return clr
  235.     }
  236. }
  237. BraceExp(string, del:="`n") {
  238.     Loop, Parse, string
  239.         if (A_LoopField = "{")
  240.             break
  241.         else
  242.         substring .= A_LoopField
  243.     substr := SubStr(string, InStr(string, "{")+1, InStr(string, "}")-InStr(string, "{")-1)
  244.     Loop, Parse, substr, `,
  245.         toreturn .= substring . A_LoopField . del
  246.     return toreturn
  247. }
  248. CbAutoComplete() {
  249.     If ((GetKeyState("Delete", "P")) || (GetKeyState("Backspace", "P")))
  250.         Return
  251.     GuiControlGet, lHwnd, Hwnd, %A_GuiControl%
  252.     SendMessage, 0x0140, 0, 0,, ahk_id %lHwnd%
  253.     MakeShort(ErrorLevel, Start, End)
  254.     GuiControlGet, CurContent,, %lHwnd%
  255.     GuiControl, ChooseString, %A_GuiControl%, %CurContent%
  256.     If (ErrorLevel) {
  257.         ControlSetText,, %CurContent%, ahk_id %lHwnd%
  258.         PostMessage, 0x0142, 0, MakeLong(Start, End),, ahk_id %lHwnd%
  259.         Return
  260.     }
  261.     GuiControlGet, CurContent,, %lHwnd%
  262.     PostMessage, 0x0142, 0, MakeLong(Start, StrLen(CurContent)),, ahk_id %lHwnd%
  263. }
  264. MakeLong(LoWord, HiWord) {
  265.     Return, (HiWord << 16) | (LoWord & 0xffff)
  266. }
  267. MakeShort(Long, ByRef LoWord, ByRef HiWord) {
  268.     LoWord := Long & 0xffff, HiWord := Long >> 16
  269. }
  270. ChooseColor( Color=0x0, hWnd=0x0, Flags=0x2 ) {
  271.     VarSetCapacity(CC,36+64,0), NumPut(36,CC), NumPut(hWnd,CC,4), NumPut(Color,CC,12)
  272.     NumPut(&CC+36,CC,16), NumPut(Flags,CC,20), DllCall( "comdlg32\ChooseColorA", Str,CC )
  273.     Hex:="123456789ABCDEF0",   RGB:=&CC+11
  274.     Loop 3  
  275.         HexColorCode .=  SubStr(Hex, (*++RGB >> 4), 1) . SubStr(Hex, (*RGB & 15), 1)
  276.     Return HexColorCode  
  277. }
  278. HexDec(DX) {
  279.     DH := InStr(DX, "0x") > 0 ? "D" : "H"
  280.     SetFormat Integer, %DH%
  281.     Return DX + 0
  282. }
  283. UniversalVar(variable, value := "") {
  284.     if (value = "")
  285.         IniRead, univar, C:\Program Files\AutoHotkey\Custom.ini, UniversalVariables, %variable%
  286.     else
  287.         IniWrite, %value%, C:\Program Files\AutoHotkey\Custom.ini, UniversalVariables, %variable%
  288.     return univar
  289. }
  290. ConvertBase(InputBase, OutputBase, number) {
  291.     static u := A_IsUnicode ? "_wcstoui64" : "_strtoui64"
  292.     static v := A_IsUnicode ? "_i64tow"    : "_i64toa"
  293.     VarSetCapacity(s, 65, 0)
  294.     value := DllCall("msvcrt.dll\" u, "Str", number, "UInt", 0, "UInt", InputBase, "CDECL Int64")
  295.     DllCall("msvcrt.dll\" v, "Int64", value, "Str", s, "UInt", OutputBase, "CDECL")
  296.     return s
  297. }
  298. NumberToBinary(InputNumber) {
  299.     While, InputNumber
  300.         Result := (InputNumber & 1) . Result, InputNumber >>= 1
  301.     Return, Result
  302. }
  303. MorseBeep(passedString) {
  304.     StringLower, passedString, passedString
  305.     Loop, Parse, passedString
  306.         morse .= A_LoopField = " " ?  "     "
  307.         : A_LoopField = "a" ? ".- "
  308.         : A_LoopField = "b" ? "-... "
  309.         : A_LoopField = "c" ? "-.-. "
  310.         : A_LoopField = "d" ? "-.. "
  311.         : A_LoopField = "e" ? ". "
  312.         : A_LoopField = "f" ? "..-. "
  313.         : A_LoopField = "g" ? "--. "
  314.         : A_LoopField = "h" ? ".... "
  315.         : A_LoopField = "i" ? ".. "
  316.         : A_LoopField = "j" ? ".--- "
  317.         : A_LoopField = "k" ? "-.- "
  318.         : A_LoopField = "l" ? ".-.. "
  319.         : A_LoopField = "m" ? "-- "
  320.         : A_LoopField = "n" ? "-. "
  321.         : A_LoopField = "o" ? "--- "
  322.         : A_LoopField = "p" ? ".--. "
  323.         : A_LoopField = "q" ? "--.- "
  324.         : A_LoopField = "r" ? ".-. "
  325.         : A_LoopField = "s" ? "... "
  326.         : A_LoopField = "t" ? "- "
  327.         : A_LoopField = "u" ? "..- "
  328.         : A_LoopField = "v" ? "...- "
  329.         : A_LoopField = "w" ? ".-- "
  330.         : A_LoopField = "x" ? "-..- "
  331.         : A_LoopField = "y" ? "-.-- "
  332.         : A_LoopField = "z" ? "--.. "
  333.         : A_LoopField = "!" ? "---. "
  334.         : A_LoopField = "\" ? ".-..-. "
  335.         : A_LoopField = "$" ? "...-..- "
  336.         : A_LoopField = "'" ? ".----. "
  337.         : A_LoopField = "(" ? "-.--. "
  338.         : A_LoopField = ")" ? "-.--.- "
  339.         : A_LoopField = "+" ? ".-.-. "
  340.         : A_LoopField = "," ? "--..-- "
  341.         : A_LoopField = "-" ? "-....- "
  342.         : A_LoopField = "." ? ".-.-.- "
  343.         : A_LoopField = "/" ? "-..-. "
  344.         : A_LoopField = "0" ? "----- "
  345.         : A_LoopField = "1" ? ".---- "
  346.         : A_LoopField = "2" ? "..--- "
  347.         : A_LoopField = "3" ? "...-- "
  348.         : A_LoopField = "4" ? "....- "
  349.         : A_LoopField = "5" ? "..... "
  350.         : A_LoopField = "6" ? "-.... "
  351.         : A_LoopField = "7" ? "--... "
  352.         : A_LoopField = "8" ? "---.. "
  353.         : A_LoopField = "9" ? "----. "
  354.         : A_LoopField = ":" ? "---... "
  355.         : A_LoopField = ";" ? "-.-.-. "
  356.         : A_LoopField = "=" ? "-...- "
  357.         : A_LoopField = "?" ? "..--.. "
  358.         : A_LoopField = "@" ? ".--.-. "
  359.         : A_LoopField = "[" ? "-.--. "
  360.         : A_LoopField = "]" ? "-.--.- "
  361.         : A_LoopField = "_" ? "..--.- "
  362.         : "ERROR"
  363.     Loop, Parse, morse
  364.     {
  365.         morsebeep := 120
  366.         if (A_LoopField = ".")
  367.             SoundBeep, 10*morsebeep, morsebeep
  368.         If (A_LoopField = "-")
  369.             SoundBeep, 10*morsebeep, 3*morsebeep
  370.         If (A_LoopField = " ")
  371.             Sleep, morsebeep
  372.     }
  373.     return morse
  374. }
  375. Morse(string, to := "morse") {
  376.     MorseArrayM2T := {".-" : "A", "-..." : "B", "-.-." : "C", "-.." : "D", "." : "E"
  377.     , "..-." : "F", "--." : "G", "...." : "H", ".." : "I", ".---" : "J", "-.-" : "K"
  378.     , ".-.." : "L", "--" : "M", "-." : "N", "---" : "O", ".--." : "P", "--.-" : "Q"
  379.     , ".-." : "R", "..." : "S", "-" : "T", "..-" : "U", "...-" : "V", ".--" : "W"
  380.     , "-..-" : "X", "-.--" : "Y", "--.." : "Z", "-----" : 0, ".----" : 1, "..---" : 2
  381.     , "...--" : 3, "....-" : 4, "....." : 5, "-...." : 6, "--..." : 7, "---.." : 8, "----." : 9}
  382.     MorseArrayT2M := {"A" : ".-", "B" : "-...", "C" : "-.-.", "D" : "-..", "E" : "."
  383.     , "F" : "..-.", "G" : "--.", "H" : "....", "I" : "..", "J" : ".---", "K" : "-.-"
  384.     , "L" : ".-..", "M" : "--", "N" : "-.", "O" : "---", "P" : ".--.", "Q" : "--.-"
  385.     , "R" : ".-.", "S" : "...", "T" : "-", "U" : "..-", "V" : "...-", "W" : ".--"
  386.     , "X" : "-..-", "Y" : "-.--", "Z" : "--..", 0 : "-----", 1 : ".----", 2 : "..---"
  387.     , 3 : "...--", 4 : "....-", 5 : ".....", 6 : "-....", 7 : "--...", 8 : "---..", 9 : "----."}
  388.     if (to = "morse" || to = "m")
  389.         Loop, Parse, string, %A_Space%
  390.         {
  391.             Loop, Parse, A_LoopField
  392.                 text .= MorseArrayT2M[A_LoopField] . A_Space
  393.             text .= A_Space "/" A_Space
  394.         }
  395.     if (to = "text" || to = "t")
  396.     {
  397.         Loop, Parse, string, /
  398.         {
  399.             Loop, Parse, A_LoopField, %A_Space%
  400.                 text .= MorseArrayM2T[A_LoopField]
  401.             text .= A_Space
  402.         }
  403.     }
  404.     return RTrim(text, "/"" ")
  405. }
  406. SendInstant(text) {
  407.     clipbackup := clipboard
  408.     clipboard := text
  409.     Send, ^v
  410.     clipboard := clipbackup
  411. }
  412. MsgBox(Text := "Press Ok to Continue.", Options := 0, Title := "", Time := "", B1 := "", B2 := "", B3 := "", B4 := "") {
  413.     if (Title = "")
  414.         Title := A_ScriptName
  415.     if (B1 != "") || (B2 != "") || (B3 != "")
  416.         SetTimer, ChangeButtonNames, 10
  417.     MsgBox, % Options, % Title, % Text, % Time
  418.     return
  419.    
  420.     ChangeButtonNames:
  421.     IfWinNotExist, %Title%
  422.         return
  423.     SetTimer, ChangeButtonNames, off
  424.     WinActivate, % Title
  425.     ControlSetText, Button1, % (B1 = "") ? "Ok" : B1, % Title
  426.     try ControlSetText, Button2, % (B2 = "") ? "Cancel" : B2, % Title
  427.     try ControlSetText, Button3, % (B3 = "") ? "Close" : B3, % Title
  428.     try ControlSetText, Button4, % (B4 = "") ? "Help" : B4, % Title
  429.     return
  430. }
  431. IsEven(number) {
  432.     if (Mod(number, 2) = 0)
  433.         return true
  434.     else
  435.         return false
  436. }
  437. CueBanner(Hwnd, Text := "Search") {
  438.     SendMessage 0x1501, 0, &Text,, ahk_id %Hwnd%
  439. }
  440. UrlToVar(url) {
  441.     whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  442.     whr.Open("GET", url, true)
  443.     whr.Send()
  444.     whr.WaitForResponse()
  445.     return whr.ResponseText
  446. }
  447. SetWallpaper(BMPpath) {
  448.     SPI_SETDESKWALLPAPER := 20
  449.     SPIF_SENDWININICHANGE := 2  
  450.     Return DllCall("SystemParametersInfo", UINT, SPI_SETDESKWALLPAPER, UINT, uiParam, STR, BMPpath, UINT, SPIF_SENDWININICHANGE)
  451. }
  452. Alarm(24h, label) {
  453.     alarmhour := 24h*3600
  454.     realhour := A_Hour*3600
  455.     realminute := A_Min*60
  456.     alarm := alarmhour-(realhour+realminute)
  457.     Sleep, % alarm*1000
  458.     Gosub, %label%
  459. }
  460. TV_GetTextAll(TreeViewName := "SysTreeView321") {
  461.     Gui, TreeView, %TreeViewName%
  462.     ItemID := 0  ; Causes the loop's first iteration to start the search at the top of the tree.
  463.     Loop
  464.     {
  465.         ItemID := TV_GetNext(ItemID, "Full")  ; Replace "Full" with "Checked" to find all checkmarked items.
  466.         if not ItemID  ; No more items in tree.
  467.             break
  468.         if not TV_GetParent(ItemID)  ; Checks if the item is a parent, if so it stores the text in %ParentText% for later (only works with the top level however).
  469.             TV_GetText(ParentText, ItemID)
  470.         else  ; Checks if the item is a child, if so it stores the text in %ChildText% for later.
  471.         {
  472.             TV_GetText(Child, ItemID)
  473.             ChildText .= Child "|"
  474.             TempItemID := TV_GetNext(ItemID, "Full")
  475.             if not TV_GetParent(TempItemID)
  476.                 List .= ParentText "="ChildText "`n"
  477.         }
  478.     }
  479.     return RTrim(List, "`n" "|")
  480. }
  481. TV_AddFile(FileName) {
  482.     Loop, Read, %FileName%
  483.     {
  484.         StringSplit, Items, A_LoopReadLine, =
  485.         Parent := TV_Add(Items1, , "Expand")
  486.         Loop, Parse, Items2, |
  487.             TV_Add(A_LoopField, Parent)
  488.     }
  489.     return ErrorLevel
  490. }
  491. TV_MakeTree(List, Del := "`n") {
  492.     ID0 := 0
  493.     Loop, Parse, List, %Del%
  494.     {
  495.         if InStr(A_LoopField, "TV_Add")
  496.         {
  497.             StringSplit, TVAdd, A_LoopField, =
  498.             AssignLevel := StrReplace(TVAdd1, " :")
  499.             TV := SubStrInBtw(TVAdd2, "(", ")")
  500.             Loop, Parse, TV, CSV
  501.             {
  502.                 if (A_Index = 1)
  503.                     Name := A_LoopField
  504.                 if (A_Index = 2)
  505.                     Level := StrReplace(A_LoopField, " ")
  506.                 if (A_Index = 3)
  507.                     Options := A_LoopField
  508.             }
  509.             Options .= " Expand"
  510.             %AssignLevel% := TV_Add(Name, %Level%, Options)
  511.         }
  512.     }
  513. }
  514. TV_GetTree(ItemID := 0, Level := 0) { ; uses the default TreeView of the default Gui ;just me THANK YOU SO MUCH *hug*
  515.    Text := ""
  516.    If (ItemID = 0) {
  517.       ItemID := TV_GetNext()
  518.       Text := "ID0 := 0`r`n"
  519.    }
  520.    While (ItemID){
  521.       TV_GetText(ItemText, ItemID)
  522.       Text .= "ID" . (Level + 1) . " := TV_Add(""" . ItemText . """, ID" . Level . ")`r`n"
  523.       If ChildID := TV_GetChild(ItemID)
  524.          Text .= TV_GetTree(ChildID, Level + 1)
  525.       ItemID := TV_GetNext(ItemID)
  526.    }
  527.    Return (Level = 0 ? RTrim(Text, "`r`n") : Text)
  528. }
  529. IsInternetConnected() {
  530.     static sz := A_IsUnicode ? 408 : 204, addrToStr := "Ws2_32\WSAAddressToString" (A_IsUnicode ? "W" : "A")
  531.     VarSetCapacity(wsaData, 408)
  532.     if DllCall("Ws2_32\WSAStartup", "UShort", 0x0202, "Ptr", &wsaData)
  533.         return false
  534.     if DllCall("Ws2_32\GetAddrInfoW", "wstr", "dns.msftncsi.com", "wstr", "http", "ptr", 0, "ptr*", results)
  535.     {
  536.         DllCall("Ws2_32\WSACleanup")
  537.         return false
  538.     }
  539.     ai_family := NumGet(results+4, 0, "int")    ;address family (ipv4 or ipv6)
  540.     ai_addr := Numget(results+16, 2*A_PtrSize, "ptr")   ;binary ip address
  541.     ai_addrlen := Numget(results+16, 0, "ptr")   ;length of ip
  542.     DllCall(addrToStr, "ptr", ai_addr, "uint", ai_addrlen, "ptr", 0, "str", wsaData, "uint*", 204)
  543.     DllCall("Ws2_32\FreeAddrInfoW", "ptr", results)
  544.     DllCall("Ws2_32\WSACleanup")
  545.     http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  546.     if (ai_family = 2 && wsaData = "131.107.255.255:80")
  547.         http.Open("GET", "http://www.msftncsi.com/ncsi.txt")
  548.     else if (ai_family = 23 && wsaData = "[fd3e:4f5a:5b81::1]:80")
  549.         http.Open("GET", "http://ipv6.msftncsi.com/ncsi.txt")
  550.     else
  551.         return false
  552.     http.Send()
  553.     return (http.ResponseText = "Microsoft NCSI") ;ncsi.txt will contain exactly this text
  554. }
  555. GuiControls(Command := "", Value := "", ControlIDs*) {
  556.     for Index,Control in ControlIDs
  557.         GuiControl, %Command%, %Control%, %Value%
  558. }
  559. Join(Delimiter, Items*) {
  560.     for Index,Item in Items
  561.         Output .= Item . Delimiter
  562.     return RTrim(Output, Delimiter)
  563. }
  564. SubStrInBtw(String, StartingChar, EndingChar, OccurStartChar := 1, OccurEndChar := 1) {
  565.     StartingPos := InStr(String, StartingChar, , , OccurStartChar)+1
  566.     Length := InStr(String, EndingChar, , , OccurEndChar)-InStr(String, StartingChar, , , OccurStartChar)-1
  567.     return SubStr(String, StartingPos, Length)
  568. }
  569. Levenshtein(s, t) {
  570.     If s =
  571.         return StrLen(t)
  572.     If t =
  573.         return strLen(s)
  574.     If SubStr(s, 1, 1) = SubStr(t, 1, 1)
  575.         return levenshtein(SubStr(s, 2), SubStr(t, 2))
  576.     a := Levenshtein(SubStr(s, 2), SubStr(t, 2))
  577.     b := Levenshtein(s,            SubStr(t, 2))
  578.     c := Levenshtein(SubStr(s, 2), t           )
  579.     If (a > b)
  580.         a := b
  581.     if (a > c)
  582.         a := c
  583.     return a + 1
  584. }
  585. RandomBezier( X0, Y0, Xf, Yf, O="" ) {
  586.     Time := RegExMatch(O,"i)T(\d+)",M)&&(M1>0)? M1: 200
  587.     RO := InStr(O,"RO",0) , RD := InStr(O,"RD",0)
  588.     N:=!RegExMatch(O,"i)P(\d+)(-(\d+))?",M)||(M1<2)? 2: (M1>19)? 19: M1
  589.     If ((M:=(M3!="")? ((M3<2)? 2: ((M3>19)? 19: M3)): ((M1=="")? 5: ""))!="")
  590.         Random, N, %N%, %M%
  591.     OfT:=RegExMatch(O,"i)OT(-?\d+)",M)? M1: 100, OfB:=RegExMatch(O,"i)OB(-?\d+)",M)? M1: 100
  592.     OfL:=RegExMatch(O,"i)OL(-?\d+)",M)? M1: 100, OfR:=RegExMatch(O,"i)OR(-?\d+)",M)? M1: 100
  593.     MouseGetPos, XM, YM
  594.     If ( RO )
  595.         X0 += XM, Y0 += YM
  596.     If ( RD )
  597.         Xf += XM, Yf += YM
  598.     If ( X0 < Xf )
  599.         sX := X0-OfL, bX := Xf+OfR
  600.     Else
  601.         sX := Xf-OfL, bX := X0+OfR
  602.     If ( Y0 < Yf )
  603.         sY := Y0-OfT, bY := Yf+OfB
  604.     Else
  605.         sY := Yf-OfT, bY := Y0+OfB
  606.     Loop, % (--N)-1 {
  607.         Random, X%A_Index%, %sX%, %bX%
  608.         Random, Y%A_Index%, %sY%, %bY%
  609.     }
  610.     X%N% := Xf, Y%N% := Yf, E := ( I := A_TickCount ) + Time
  611.     While ( A_TickCount < E ) {
  612.         U := 1 - (T := (A_TickCount-I)/Time)
  613.         Loop, % N + 1 + (X := Y := 0) {
  614.             Loop, % Idx := A_Index - (F1 := F2 := F3 := 1)
  615.                 F2 *= A_Index, F1 *= A_Index
  616.             Loop, % D := N-Idx
  617.                 F3 *= A_Index, F1 *= A_Index+Idx
  618.             M:=(F1/(F2*F3))*((T+0.000001)**Idx)*((U-0.000001)**D), X+=M*X%Idx%, Y+=M*Y%Idx%
  619.         }
  620.         MouseMove, %X%, %Y%, 0
  621.         Sleep, 1
  622.     }
  623.     MouseMove, X%N%, Y%N%, 0
  624.     Return N+1
  625.     /*
  626.     # "Tx" (where x is a positive number)
  627.     > The time of the mouse movement, in miliseconds
  628.     > Defaults to 200 if not present
  629.     # "RO"
  630.     > Consider the origin coordinates (X0,Y0) as relative
  631.     > Defaults to "not relative" if not present
  632.     # "RD"
  633.     > Consider the destination coordinates (Xf,Yf) as relative
  634.     > Defaults to "not relative" if not present
  635.     # "Px" or "Py-z" (where x, y and z are positive numbers)
  636.     > "Px" uses exactly 'x' control points
  637.     > "Py-z" uses a random number of points (from 'y' to 'z', inclusive)
  638.     > Specifying 1 anywhere will be replaced by 2 instead
  639.     > Specifying a number greater than 19 anywhere will be replaced by 19
  640.     > Defaults to "P2-5"
  641.     # "OTx" (where x is a number) means Offset Top
  642.     # "OBx" (where x is a number) means Offset Bottom
  643.     # "OLx" (where x is a number) means Offset Left
  644.     # "ORx" (where x is a number) means Offset Right
  645.     > These offsets, specified in pixels, are actually boundaries that
  646.      apply to the [X0,Y0,Xf,Yf] rectangle, making it wider or narrower
  647.     > It is possible to use multiple offsets at the same time
  648.     > When not specified, an offset defaults to 100
  649.      - This means that, if none are specified, the random Bézier control
  650.     points will be generated within a box that is wider by 100 pixels
  651.     in all directions, and the trajectory will never go beyond that
  652.     */
  653. }
  654. HailStone(n) {
  655.     List := n
  656.     while (n > 1)
  657.         List .= "," n := (Mod(n, 2) ? (n*3)+1 : n//2)
  658.     return List
  659. }
  660. Collatz(n) {
  661.     while (n > 1)
  662.         {
  663.             count++
  664.             n := !(Mod(n, 2)) ? n//2 : (n*3)+1
  665.         }
  666.     return count+1
  667. }
  668. Similarity(String1, String2, returnwhat := 0){
  669.     StringSplit, A, String1
  670.     StringSplit, B, String2
  671.     LoopCount := (A0 > B0) ? A0 : B0
  672.     Loop, %LoopCount%
  673.     {
  674.         if (A%A_Index% = B%A_index%)
  675.         {
  676.             matches++
  677.             matchingchars .= A%A_Index%
  678.         }
  679.         else
  680.         {
  681.             unmatches++
  682.             StringSplit, out, unmatchingchars, |
  683.             out1 .= A%A_Index%
  684.             out2 .= B%A_Index%
  685.             unmatchingchars :=  out1 "|" out2
  686.         }
  687.     }
  688.     if not returnwhat
  689.         return (matches = "") ? 0 : Round(matches/LoopCount*100)
  690.     if (returnwhat = 1)
  691.         return (matches = "") ? 0 : matches
  692.     if (returnwhat = 2)
  693.         return unmatches
  694.     if (returnwhat = 3)
  695.         return matchingchars
  696.     if (returnwhat = 4)
  697.         return unmatchingchars
  698. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement