Skip to content

Instantly share code, notes, and snippets.

@freehuntx
freehuntx / pure-css-modal.html
Last active October 8, 2020 12:51
Pure CSS Modal (Single DIV)
<style>
.single-div-modal {
position: fixed;
box-sizing: border-box;
z-index: 1337;
top: 0;
right: 0;
bottom: 0;
left: 0;
window.WebSocket = class WebSocket extends window.WebSocket {
static event_listener = {}
static on(eventName, fn) {
WebSocket.event_listener[eventName] = WebSocket.event_listener[eventName] || []
WebSocket.event_listener[eventName].push(fn)
}
static on(eventName, fn) {
WebSocket.event_listener[eventName] = WebSocket.event_listener[eventName] || []
WebSocket.event_listener[eventName].push(fn)
(() => {
if (!window.speechSynthesis || !window.SpeechSynthesisUtterance) {
return alert('Nicht unterstützt!')
}
const say = text => {
if (!text) return
window.speechSynthesis.cancel()
const msg = new SpeechSynthesisUtterance(text)
@freehuntx
freehuntx / reactive-hash.ts
Last active February 27, 2023 01:42
reactive-react
import hash from 'hash-it';
import { useEffect, useState } from 'react';
const MIN_DELAY = 50;
const MAX_DELAY = 1000;
const STEP_DELAY = 50;
export function useReactive(target) {
const [val, setVal] = useState(target);
const [_toggle, setToggle] = useState(false);
@freehuntx
freehuntx / fn-hook-logger.js
Created November 1, 2023 18:24
Javascript function hook logger
function logHookFunction(obj, key, hookTime = 5000) {
if (typeof obj[key] !== "function") {
console.log("[-] Hook failed! Not a function!")
return
}
obj[`o${key}`] = obj[`o${key}`] || obj[key]
obj[key] = function(...args) {
console.log(`[HOOKR] ${key}(${args.join(',')})`)
return this[`o${key}`](...args)
}
@freehuntx
freehuntx / godot_promise.gd
Last active December 1, 2023 21:58
Godot Promise
class_name Promise extends RefCounted
# Constants
const State = {
PENDING = "pending",
FULFILLED = "fulfilled",
REJECTED = "rejected"
}
# Signals
@freehuntx
freehuntx / godot_eventemitter.gd
Last active December 22, 2023 16:04
Godot Eventemitter
class_name EventEmitter extends RefCounted
var _listeners := {} # Holds listener arrays
func emit(name: String, args:=[]):
if not name in _listeners: return # Skip if no listeners exist
_listeners[name] = _listeners[name].filter(func(e): return e.fn.get_object() != null) # Remove null instances
for e in _listeners[name]: # Iterate callbacks
e.fn.callv(args) # Call callback
_listeners[name] = _listeners[name].filter(func(e): return not e.once) # Remove "once" listeners
@freehuntx
freehuntx / godot_http.gd
Last active January 20, 2024 15:07
Godot HTTP
class_name Http extends RefCounted
class Response:
var code := -1
var headers := {}
var error := ""
var text := ""
var json = null
func _init(opts:={}):
for key in opts.keys():
@freehuntx
freehuntx / tracker_client.gd
Last active February 6, 2024 14:38
Godot Webtorrent
extends RefCounted
## Classes/Constants
enum State { NEW, CLOSED, CONNECTING, CONNECTED }
class Response:
var info_hash: String # The info_hash which the repsonse belongs to
var peer_id: String # The peer_id of the other peer (who've sent it)
var offer_id: String # The offer_id that this offer/answer belongs to
var sdp: String # The sdp (webrtc session description) of the other peer
@freehuntx
freehuntx / kcpp_random_chat.js
Last active September 18, 2024 06:16
KoboldCpp random chat
const fetchRandomChar = async () => {
const corsPrefix = 'https://corsproxy.io/?'
const count = await fetch(corsPrefix + encodeURI('https://api.chub.ai/search?search=&first=1&page=1&nsfw=true'))
.then(res => res.json())
.then(res => res.data.count)
const randId = Math.floor(Math.random() * count)
const project = await fetch(corsPrefix + encodeURI(`https://api.chub.ai/search?search=&first=1&page=${randId}&nsfw=true`))
.then(res => res.json())
.then(res => res.data.nodes[0])
const character = await fetch(corsPrefix + encodeURI(`https://api.chub.ai/api/v4/projects/${project.id}/repository/files/raw%252Ftavern_raw.json/raw?ref=main&response_type=json`))