Skip to content

Instantly share code, notes, and snippets.

View TheDcoder's full-sized avatar

TheDcoder TheDcoder

View GitHub Profile
@TheDcoder
TheDcoder / background-image-url-copier.user.js
Last active April 12, 2020 15:08
Background Image URL Copier
// ==UserScript==
// @name Background Image URL Copier
// @namespace Violentmonkey Scripts
// @match *://*/*
// @noframes
// @grant GM_setClipboard
// @run-at document-start
// @version 1.3
// @author TheDcoder
// @description Started working on 4/5/2020, 11:54:15 PM
@TheDcoder
TheDcoder / sleep.js
Created February 5, 2020 11:14
sleep.js - synchronous sleep in JavaScript!
// Synchronous sleep
function sleep(ms) {
var start = performance.now();
while (performance.now() - start < ms);
}
// Calling the function will block all code in your script until the specified ms have passed
// It will also cause your CPU fans to run at full speed!
@TheDcoder
TheDcoder / absMin.js
Created September 16, 2019 08:02
Math.min in absolute terms
function absMin(...values) {
return values.find(value => {
value = Math.abs(value);
return values.every(x => Math.abs(x) >= value);
});
}
@TheDcoder
TheDcoder / UNLICENSE
Last active July 6, 2019 14:07
strseg - Get delimiter-separated segments from a string in a non-destructive method
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@TheDcoder
TheDcoder / InteractiveCoordinateSelect.au3
Last active February 5, 2019 12:25
AutoIt UDF for interactively selecting a coordinate/point on the screen
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; #FUNCTION# ====================================================================================================================
; Name ..........: InteractiveCoordinateSelect
; Description ...: Lets the user interactively select a point on the screen
; Syntax ........: InteractiveCoordinateSelect()
; Parameters ....: None
; Return values .: Success: An array with the X and Y positions of the selected point
; Failure: False (This happens when the overlay window is closed)
@TheDcoder
TheDcoder / monitor_focus.user.js
Last active March 3, 2020 05:38
DOM Focus Tracker Userscript
// ==UserScript==
// @name DOM Focus Tracker (Console)
// @version 0.2
// @description A quick and dirty focus tracker, logs the currently focused element to console
// @include *
// @run-at document-start
// ==/UserScript==
window.addEventListener("focusout", event => console.log(event.relatedTarget === null ? "The webpage has lost focus" : event.relatedTarget), true);
@TheDcoder
TheDcoder / Example.au3
Last active December 11, 2017 05:29
Generate custom/fake/pseudo events in OnEvent mode in AutoIt
; This snippet will show you a "hack" that you can use in GUI OnEvent mode in AutoIt
; With this hack you can create fake/pseudo events for a control in a OnEvent "handler"
; function which is registered with multiple controls.
; Usually you can get around this by using a unique function for every control
; but I like to use a single function that I use as a handler for a group of related
; controls. Looks neat and organized :)
; Let's get started!
@TheDcoder
TheDcoder / IsWindowNotResponding.au3
Last active December 6, 2017 14:02
IsWindowNotResponding
#include <WinAPISys.au3>
; #FUNCTION# ====================================================================================================================
; Name ..........: IsWindowNotResponding
; Description ...: Checks if a Window is not responding
; Syntax ........: IsWindowNotResponding($hWindow[, $iTimeout = 5000])
; Parameters ....: $hWindow - A window handle.
; $iTimeout - [optional] Shouldn't matter, Timeout in milliseconds. Default is 5000.
; Return values .: @error set by _WinAPI_SendMessageTimeout
; Author ........: Damon Harris (TheDcoder)
@TheDcoder
TheDcoder / LocalDateTime.bat
Created October 19, 2017 12:47
Locale-indepent way to get time and date in batch
@echo off
rem I do not claim authorship of this snippet, original source: https://serverfault.com/a/227375/414453
rem Get the time from WMI - at least that's a format we can work with
set X=
for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x
echo.%X%
rem dissect into parts
set DATE.YEAR=%X:~0,4%
@TheDcoder
TheDcoder / ConvertTime12To24.au3
Last active October 3, 2017 11:47
12 hour to 24 hour format in AutoIt
; #FUNCTION# ====================================================================================================================
; Name ..........: ConvertTime12To24
; Description ...: Converts 12 hour time to 24 hour time, made while keeping _DateDiff's format in mind :)
; Syntax ........: ConvertTime12To24($sTime, $sPeriod[, $sDelimiter = ':'])
; Parameters ....: $sTime - Timestamp. (Can be a single digit or a pattern like H:M:S)
; $sPeriod - AM or PM.
; $sDelimiter - [optional] Separator between units of time. Default is ':'.
; Return values .: $sTime in 24 hour format with 0 padding
; Author ........: Damon Harris (TheDcoder)
; Remarks .......: Ensures that the first 3 parts have 0 padding if the time unit is single digit (Example 09 instead of 9)