Skip to content

Instantly share code, notes, and snippets.

@grey-code
grey-code / gist:7042282
Last active December 25, 2015 21:28
AutoHotkey: Download()
/*
Derived from Wicked - can't locate his thread but found this in the ff thread:
http://www.autohotkey.com/board/topic/97642-urldownloadtofile/#entry614852
*/
Download(url, dest) {
static r
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
if (!r || whr.Option(1) != url)
@grey-code
grey-code / gist:DynaRun
Last active December 21, 2015 09:39
AutoHotkey: DynaRun()
DynaRun(script, name:="", args*) { ;// http://goo.gl/ECC6Qw
if (name == "")
name := "AHK_" . A_TickCount
;// Create named pipe(s), first one is a dummy
for each, pipe in ["__PIPE_GA_", "__PIPE_"]
%pipe% := DllCall(
(Join Q C
"CreateNamedPipe", ;// http://goo.gl/3aJQg7
"Str", "\\.\pipe\" . name, ;// lpName
"UInt", 2, ;// dwOpenMode = PIPE_ACCESS_OUTBOUND
@grey-code
grey-code / gist:5615665
Created May 20, 2013 21:18
AutoHotkey: VAR_get()
; http://www.autohotkey.com/board/topic/20925-listvars/#entry156570
VAR_get() {
global
static hEdit, pSFW, pSW, bkpSFW, bkpSW
local dhw, AStr, Ptr, hmod, text, v, i := 0, vars := []
if !hEdit {
dhw := A_DetectHiddenWindows
DetectHiddenWindows, On
ControlGet, hEdit, Hwnd,, Edit1, % "ahk_id " A_ScriptHwnd
@grey-code
grey-code / gist:5570456
Created May 13, 2013 18:45
AutoHotkey: RemoveDuplicate()
RemoveDuplicate(str, delim:="`n", cs:=false) {
_ := cs ? ComObjCreate("Scripting.Dictionary") : []
Loop, Parse, str, % delim
alf := A_LoopField
, out .= cs ? (_.Exists(alf) ? "" : (alf . delim, _.Add(alf, 1)))
: (_[alf] ? "" : (alf . delim, _[alf] := 1))
return RTrim(out, delim)
}
@grey-code
grey-code / gist:5565115
Created May 12, 2013 22:13
AutoHotkey: Obj2Str()
Obj2Str(obj) {
str := "" , array := true
for k in obj {
if (k == A_Index)
continue
array := false
break
}
for a, b in obj
str .= (array ? "" : "'" a "': ") . (IsObject(b) ? Obj2Str(b) : "'" b "'") . ", "
@grey-code
grey-code / gist:5563674
Created May 12, 2013 14:00
AutoHotkey: JSON_parse()
/*
derived from Getfree's parseJson function
http://www.autohotkey.com/board/topic/93300-what-format-to-store-settings-in/#entry588268
credits to Getfree
*/
JSON_parse(jsonStr) {
SC := ComObjCreate("ScriptControl")
SC.Language := "JScript"
ComObjError(false)
jsCode =
@grey-code
grey-code / gist:5323228
Created April 5, 2013 22:34
AutoHotkey: Titan/polyethene's Anchor()
/*
Function: Anchor
Defines how controls should be automatically positioned relative to the new dimensions of a window when resized.
Parameters:
cl - a control HWND, associated variable name or ClassNN to operate on
a - (optional) one or more of the anchors: 'x', 'y', 'w' (width) and 'h' (height),
optionally followed by a relative factor, e.g. "x h0.5"
r - (optional) true to redraw controls, recommended for GroupBox and Button types
@grey-code
grey-code / gist:5322888
Last active December 15, 2015 20:59
AutoHotkey: range()
range(stop, start:=0, step:=1) {
r := []
Loop
v := start+step*(A_Index-1)
, r[v] := v
until (stop<0 ? v<=stop-step : v>=stop-step)
return r
}
@grey-code
grey-code / gist:5304819
Created April 3, 2013 20:16
AutoHotkey: WM_SETCURSOR()
; Prevent "sizing arrow" cursor when hovering over window border
WM_SETCURSOR(wParam, lParam) { ; WM_SETCURSOR := 0x0020
; standard arrow cursor
static HARROW := DllCall("LoadCursor", "Ptr", 0, "Ptr", 32512, "UPtr")
HTCODE := lParam & 0xFFFF
if (HTCODE > 9) && (HTCODE < 19) { ; cursor is on a border
DllCall("SetCursor", "Ptr", HARROW) ; show arrow cursor
return true ; prevent further processing
}
@grey-code
grey-code / gist:5286786
Created April 1, 2013 18:41
AutoHotkey: StrDiff()
/*
By Toralf:
Forum thread: http://www.autohotkey.com/forum/topic59407.html
Basic idea for SIFT3 code by Siderite Zackwehdex
http://siderite.blogspot.com/2007/04/super-fast-and-accurate-string-distance.html
Took idea to normalize it to longest string from Brad Wood
http://www.bradwood.com/string_compare/