Skip to content

Instantly share code, notes, and snippets.

View Odepax's full-sized avatar
:shipit:
Edit this user's status

Odepax

:shipit:
Edit this user's status
View GitHub Profile
@Odepax
Odepax / firefox-image-pdf-2-png.js
Last active September 15, 2019 08:59
Page-basis PDF2PNG converter for Firefox.
// Note: the PDF must be image-based. Makes it not generic, but very usefull in some situations.
// Put this in the console:
// EXE: (function (pageId) { ... })("page3");
;(function(pageId = "page1") {
const canvas = document.getElementById(pageId)
const image = new Image()
image.src = canvas.toDataURL("image/png")
document.body.innerHTML = null
@Odepax
Odepax / diep-io-crosshair-cursor.js
Last active December 26, 2020 23:48
Diep.io crosshair cursor
// I use this to force the cursor to be a crosshair in diep.io as I think it's better for aiming than the arrow cursor.
// Just copy and paste this code snippet bellow in the browser console.
// The need for checking every 20s comes from the fact that the cursor is reset when hovering buttons (e.g. tank upgrade buttons).
// Cheking every 20s is quite smooth and does not decrease the game's performances.
// Alternatively, it's possible to opt for "move" instead of "crosshair" to get a fatter cross.
setInterval(function () {
if (document.getElementById("canvas").style.cursor != "crosshair")
document.getElementById("canvas").style.cursor = "crosshair"
}, 20000)
@Odepax
Odepax / build.gradle
Created March 3, 2018 21:24
Gradle + Kotlin + Spek + Jacoco (March 2018)
//
// [ INFO ]
//
// Date: 2018-03-03
// Works on: [ ? Linux ] [ Y Windows ] [ ? MacOSX ]
// Gradle: 4.6.0
// Kotlin: 1.2.30
// Spek: 1.1.5
// JUnit Platform: 1.0.0
// Jacoco: 0.8.0
@Odepax
Odepax / 1-PowerShell-Tips.md
Last active December 1, 2023 09:33
What I Understand about PowerShell Approved Verbs

PowerShell Tips

Write-Host vs Write-Output

Write-Host writes directly to the console; Write-Output writes to the pipeline, which often ends up to the console but not necessarily.

For example: Write-Host "The Cake is a lie" | Out-Null won't work as expected, Write-Output "The Cake is a lie" | Out-Null will.

False Friends

@Odepax
Odepax / FrontEndDesignTests.kt
Created July 7, 2018 15:26
Who said manual testing couldn't be automated?
package io.github.odepax.another.webapp
import org.junit.jupiter.api.Test
import java.util.Calendar
class FrontEndDesignTests {
private val months = 60 * 60 * 24 * 30
@Test
fun `displays correctly on all platforms`() {
@Odepax
Odepax / Read-SingleFileWebComponent.ps1
Last active September 15, 2019 09:05
Reading VueJs-like single-file components with Powershell, premise for other manipulations...
# https://www.business.com/articles/powershell-read-xml-files/
# https://stackoverflow.com/questions/11685265/casting-in-powershell-weird-syntax#answer-11685318
$k = (([Xml]("<R>" + (Get-Content -Path ".\sfc.html") + "</R>")).R)
Start-Something -With $k.style
Start-Something -With $k.template
Start-Something -With $k.script
@Odepax
Odepax / Promise.delay.js
Created September 21, 2019 10:32
Javascript Promise.delay
/** Returns a promise that resolves after 'timeout' ms. */
Promise.delay = function delay(/** @type {number} @description Unit: ms. */ timeout, value = undefined) {
return new Promise(resolve => setTimeout(() => resolve(value), timeout))
}
@Odepax
Odepax / Object.apply.js
Created September 21, 2019 10:35
Javascript Object.apply
Object.prototype.apply = function apply(/** @type {{ [prop: string]: any }|((it: any) => void)} */ init) {
if (typeof init == "function") {
init(this)
} else {
Object.assign(this, init)
}
return this
}
@Odepax
Odepax / Document.parseElements.js
Created September 21, 2019 10:37
Javascript DOM extensions
/** Converts given string into DOM tree, and extract elements marked with 'id' attributes. */
Document.prototype.parseElements = function parseElements(/** @type {string} */ htmlString) {
const div = this.createElement("div")
div.innerHTML = htmlString
const identifiedElements = {}
for (const element of div.querySelectorAll("[id]")) {
identifiedElements[element.getAttribute("id")] = element
@Odepax
Odepax / go-dark.js
Last active May 13, 2021 21:47
Quick & dirty dark theme
((invertImages, invertCode, applyBlackBackground) => {
document.body.style.filter = "invert()"
document.body.style.background = applyBlackBackground ? "black" : "white"
Array.from(document.querySelectorAll("pre")).map(pre => pre.style.filter = invertCode ? "invert()" : null)
Array.from(document.querySelectorAll("img")).map(img => img.style.filter = invertImages ? "invert()" : null)
})(/* Invert Image | Invert Code | Dark BG */ 1, 0, 1)