Skip to content

Instantly share code, notes, and snippets.

View eldonwilliams's full-sized avatar
😁

Eldon Williams eldonwilliams

😁
View GitHub Profile
@eldonwilliams
eldonwilliams / EXPLAIN.md
Last active June 18, 2023 05:58
A cool little bit of code and how it works

What is going on here

Let's break down the thing we're trying to do...

The problem

We want to display text to the user. HTML lets us do this using p tags (short for paragraph). What if we need some text with a link inside it like

Hello, how are doing?

@eldonwilliams
eldonwilliams / useMediaQuery.ts
Created May 18, 2023 13:16
A react hook to make a media query
import { DependencyList, useEffect, useState } from "react";
/**
* Takes in the handler function, subscribes it to any functions you need, and then returns a cleanup function.
*/
export type eventSetup_fn = (handler: ()=>void) => (()=>void); // looks nasty cause react doesn't export Destructor type
/**
* Performs a media query and returns the result.
* Event setup allows you to subscribe to any events that the media query may depend on,
@eldonwilliams
eldonwilliams / UILineRenderer.cs
Created April 17, 2023 19:25
Renders a line using unity's canvas system. Takes any number of points. Scale should be Vector3.one and size should be (0,0) for best results. Credit to CGPala for the original version
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
/// <summary>
/// Renders a line using the UI canvas system.
/// </summary>
/// Thank you CGPala for the original UILineRender
/// https://gist.github.com/CGPala/d1ace7dddbfbe78cd2de2bb9e40f6393
[RequireComponent(typeof(CanvasRenderer))]
local Spr = require(game:GetService("ReplicatedStorage"):WaitForChild("Packages"):WaitForChild("Spr"))
export type TargetInstance = Frame
export type InitialPositionFunction = (target: TargetInstance) -> Vector2
export type NewSpringListElementParams = {
RenderInstance: GuiObject,
SpringDamping: number,
SpringFrequency: number,
CalculateInitalPosition: InitialPositionFunction,
TargetParent: Instance,
import { Divider, Paper, Stack, Typography } from "@mui/material";
import { motion } from "framer-motion";
import { useState } from "react";
import StyledTextField from "./StyledTextField";
const STFWrap = (props: Parameters<typeof StyledTextField>[0]) => {
const [focused, setFocused] = useState<boolean>(false);
const [inputValue, setInputValue] = useState<string>("");
return (
# GIST NOTE
"""
TimeProvider is a basic utility which will give a *reliable* signal X times a second.
It isn't considered to be 100% reliable and the signal connections are provided the deltatime as well as the tick number.
The timer also takes account of the time it takes to execute any connections
Possible efficency increases:
- Wrap each signal connection in a thread and wait for them all to resolve allowing multiple to run at once and keeping one for yielding (timeouts could be imposed)
- Fix the deltatime for the first two frames, currently it initalizes to 0 (which is normal I think) and the second frame is wonky, afterward I get expected behaviour
- Is it compatiable with different OS's?
local Players = game:GetService("Players")
local R15Blank = game:GetService("ReplicatedStorage"):WaitForChild("Assets"):WaitForChild("R15Blank")
local LoadCharacter = {}
-- Generally useful types
export type BrickColorID = number
export type AssetType = string
export type CharacterAsset = {
-- CONFIG
local RequestWaitTime: number = 5
local RequestURL: string = "https://eldon.zone/api/roblox/games/2316994223"
local MemoryStoreService = game:GetService("MemoryStoreService")
local Messaging = game:GetService("MessagingService")
local RunService = game:GetService("RunService")
local HttpService = game:GetService("HttpService")
local FavoritesProvider = MemoryStoreService:GetSortedMap("FAVORITES")
@eldonwilliams
eldonwilliams / useSocket.js
Created January 17, 2022 00:16
React.js hook wrapper around socket.io-client sockets. Also methods for making sure socket is safe to make calls on.
import { useEffect, useState } from "react";
import { io } from "socket.io-client";
/**
*
* @param {Object} options Options variable
* @param {string} [options.url=window.location] The location to attempt to connect a socket
* @param {Partial<import("socket.io-client").ManagerOptions & import("socket.io-client").SocketOptions>} [options.options={}] The options object to pass to io
* @returns {[import("socket.io-client").Socket, isSocketSafe, runSafely]}
*/
/*
CREATED BY: DEVVY/DEVTOPS
This is a react hook that allows you to create a state which will hold multiple values.
While this can be inefficient in some cases, it is useful when you don't need tons of states cluttering your code.
You can edit and use this as you'd like, but I'd appreciate if the creator tag was left in :)
P.S. : I tried to use minimal type checking, so that may give you some ~weird~ errors, or ones that don't make sense.
Feel free to edit this to add more specific checks.