Skip to content

Instantly share code, notes, and snippets.

View afkvido's full-sized avatar
:electron:
rush

gemsvidø afkvido

:electron:
rush
View GitHub Profile
@afkvido
afkvido / global.js
Created May 15, 2023 21:24
window.global polyfill
globalThis.global=globalThis;
@afkvido
afkvido / polyfill.js
Created March 1, 2023 23:17
Ensures that the webpage has all JavaScript standard library features, and loads them if it doesn't. (using core-js)
(async()=>{eval(await(await fetch("https://cdn.jsdelivr.net/npm/core-js-bundle/minified.min.js")).text())})();
@afkvido
afkvido / loadSwal.js
Last active February 28, 2023 21:13
Load SweetAlert2 Neutral into the current webpage.
(async()=>{if(window.Swal){return}eval(await(await fetch("https://cdn.jsdelivr.net/npm/sweetalert2-neutral@latest/dist/sweetalert2.all.min.js")).text())})();
@afkvido
afkvido / dirname.ts
Last active February 28, 2023 21:14
EMCAscript fill for CommonJS __dirname.
import path from "path";
import { fileURLToPath } from "url";
const dirname : string = path.resolve(fileURLToPath(import.meta.url), "../..");
export default dirname;
@afkvido
afkvido / tsconfig.json
Last active February 28, 2023 21:15
TypeScript config for quickstarting prototype.
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
"incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
"tsBuildInfoFile": "./dist/.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
@afkvido
afkvido / JavalinCORS.kt
Last active February 28, 2023 21:12
A simple method to allow all origins to access your Javalin server.
val app = Javalin.create().start(7070)
app.before { ctx ->
ctx.header("Access-Control-Allow-Origin", "*") // Allow CORS
}
app.get("/") {
ctx -> ctx.result("Hello World")
}
@afkvido
afkvido / StringMatch.kt
Last active February 28, 2023 21:16
Capture one RegEx match from a String in Kotlin.
/** Captures a String from a regex */
fun String.match (regex : String) : String {
return this.match(Regex(regex))
}
/** Captures a String from a regex */
fun String.match (regex : Regex) : String {
val x : String? = regex.find(this)?.value
return if (x !== null) x else ""
}
@afkvido
afkvido / Fetch.kt
Last active February 28, 2023 21:16
Read data from URL in Kotlin.
import java.net.URI
import java.net.URL
import java.util.*
/** Get text from an online resource */
fun fetch (url : URL) : String {
println("Fetching resource from $url")
return Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next()
}
@afkvido
afkvido / NoEcho.sh
Last active February 28, 2023 21:17
Remove functionality of echo and print for some reason.
echo () { }
print () { }