Skip to content

Instantly share code, notes, and snippets.

#NoEnv
SetBatchLines, -1
Conversion := {"mph": 0.44704, "km/s": 0.277778}
MsgBox, Put the input on the clipboard then hit OK
Data := ParseInput(Clipboard)
Data.Cameras.Remove(1) ; This is a redundant camera for my purposes
Pens := [], Brushes := [], Fonts := []
GuiSize := 600
Gui, +hWndhWnd -Caption
hDC := DllCall("GetDC", "UPtr", hWnd, "UPtr")
hMemDC := DllCall("CreateCompatibleDC", "UPtr", hDC, "UPtr")
hBitmap := DllCall("CreateCompatibleBitmap", "UPtr", hDC, "Int", GuiSize, "Int", GuiSize, "UPtr")
hOriginalBitmap := DllCall("SelectObject", "UPtr", hMemDC, "UPtr", hBitmap)
OnExit, ExitSub
OnMessage(0xF, "WM_PAINT")
Gui, Color, Black
@G33kDude
G33kDude / GDI.ahk
Last active August 11, 2019 06:48
GDI wrapper for AutoHotkey
class GDI
{
__New(hWnd, CliWidth=0, CliHeight=0)
{
if !(CliWidth && CliHeight)
{
VarSetCapacity(Rect, 16, 0)
DllCall("GetClientRect", "Ptr", hWnd, "Ptr", &Rect)
CliWidth := NumGet(Rect, 8, "Int")
CliHeight := NumGet(Rect, 12, "Int")
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
This [strike]"tutorial"[/strike]/explanation requires the knowledge of how objects (aka arrays) work in AutoHotkey. If I got something wrong, please point it out.
[hr][/hr]
[center][b]What is a class?[/b][/center]
[quote="wiktionary"]class /klɑːs/
n. A group, collection, category or set sharing characteristics or attributes.[/quote]
In the case of AutHotkey, most commonly an object. In this post, we will be talking about the syntax of making custom object classes that have methods, and how it works.
^d::
Code := Clipboard ;"<div style='overflow:scroll; width: 100%; height: 100%; margin: none;'>" Clipboard "</div>"
Code := RegExReplace(Code, "s)\[list\](.*?)\[/list\]", "<ul>$1</ul>")
Code := RegExReplace(Code, "\[\*\](.*)", "<li>$1</li>")
Code := RegExReplace(Code, "\[quote(?:=""([^""]*)"")?\]", "<div class='author'>&nbsp;$1</div><div class='quote'>")
Code := RegExReplace(Code, "\[/quote\]", "</div>")
Code := RegExReplace(Code, "s)\[code[^\]]*\](.*?)\[/code\]", "<pre>$1</pre>")
Code := RegExReplace(Code, "\[c\](.*?)\[/c\]", "<code>$1</code>")
Code := RegExReplace(Code, "\[([^\]]*)\]", "<$1>")
Code := RegExReplace(Code, "\R", "<br/>")

#Description

It's 2015 and we've all moved on from IRC, right? Wrong! Freenode (the largest FOSS focused IRC network) has over 80,000 users, and gains around 5000 new users every year. /r/DailyProgrammer, as awesome as it is, happens to have its very own IRC channel on freenode (#reddit-dailyprogrammer), but it's missing one thing: Bots.

The goal of this channel is to create an interactive IRC bot capable of performing one or more basic bot-like things.

import random
ID_AIR = 0
ID_DIRT = 1
ID_SAND = 2
ID_LAVA = 3
ID_DIAMOND = 4
ID_HERO = 5
DEBUG = True
Macbeth := FileOpen("macbeth.txt", "r`r`n").Read() ; `r`n in the read options to normalize line endings to just "`n"
; Find which Act, scene, and dialog contains our phrase
; ---
; Replace multiple newlines with `r, which is not actually being used for anything.
; Makes it idea for a temporary separator. Then, split it based on `r (you can only
; split based on character, not based on string of characters)
Sections := StrSplit(RegExReplace(Macbeth, "\n{2,}", "`r"), "`r")
for each, Section in Sections
{
#NoEnv ; Don't try to pull variables from the environment (speeds things up)
SetBatchLines, -1 ; Don't pause between lines (also speeds things up)
Macbeth := Shakespeare.Writeth("Macbeth")
MsgBox, % Shakespeare.ReadethPassage(Macbeth.PassageThatContaineth("Eye of newt"))
class Shakespeare
{
static Phrases := StrSplit("Bated breath,Cold comfort,Devil incarnate,"
. "Elbow room,Faint hearted,Fancy-free,Flaming youth,Foregone conclusion,"