Skip to content

Instantly share code, notes, and snippets.

View cyrus01337's full-sized avatar

Cyrus cyrus01337

View GitHub Profile
# https://medium.com/@chantastic/p-525e68f17e56
p() {
if [[ -f bun.lockb ]]; then
command bun "$@"
elif [[ -f pnpm-lock.yaml ]]; then
command pnpm "$@"
elif [[ -f yarn.lock ]]; then
command yarn "$@"
elif [[ -f package-lock.json ]]; then
command npm "$@"
@cyrus01337
cyrus01337 / output.sh
Created September 1, 2023 03:00
Output for RVM failing to install on Ubuntu Budgie 23.04, with Fish 3.6.0 installed - pasted for external viewing
> source /etc/profile.d/rvm.sh
/etc/profile.d/rvm.sh (line 45): Missing end to balance this if statement
if [[ -n "${rvm_bin_path}" && ! ":${PATH}:" == *":${rvm_bin_path}:"* ]]
^^
from sourcing file /etc/profile.d/rvm.sh
source: Error while reading file '/etc/profile.d/rvm.sh'
> source /etc/profile.d/rvm.sh | bash
/etc/profile.d/rvm.sh (line 45): Missing end to balance this if statement
if [[ -n "${rvm_bin_path}" && ! ":${PATH}:" == *":${rvm_bin_path}:"* ]]
^^
@cyrus01337
cyrus01337 / FindPartsInRay.lua
Created July 12, 2023 10:08
Function to raycast and get back multiple instances the raycast skewers
type Parts = {BasePart}
local function findTopmostModelAncestor(instance: Instance): Instance?
local modelAncestorFound = instance:FindFirstAncestorOfClass("Model")
while modelAncestorFound do
local newModelAncestorFound = instance:FindFirstAncestorOfClass("Model")
if modelAncestorFound and newModelAncestorFound == nil then
@cyrus01337
cyrus01337 / Server.lua
Created July 7, 2023 12:50
PlayerAdded and PlayerRemoving connections without suspecting memory leaks.
local Players = game:GetService("Players")
local characterAddedConnections: { [Player]: RBXScriptConnection } = {}
local function onPlayerAdded(player: Player)
characterAddedConnections[player] = player.CharacterAdded:Connect(function(playerChar)
local Humanoid = playerChar:WaitForChild("Humanoid")
print(playerChar.Parent, Humanoid.Parent.Parent)
Humanoid.WalkSpeed = 0
@cyrus01337
cyrus01337 / 1 Embed.py
Created March 29, 2023 04:45
Example of custom Embed sub-class that avoids method calls by passing data as kwargs and hiding calls in the initialiser. This concept can also be thought of as providing sensible defaults to simplify developer input when creating embeds en masse.
# src/utils.py
from __future__ import annotations
from collections import namedtuple
import discord
Author = namedtuple("Author", ["name", "url", "icon_url"])
Footer = namedtuple("Footer", ["text", "icon_url"])
Field = namedtuple(
@cyrus01337
cyrus01337 / Button.jsx
Created February 20, 2023 22:08
Generic button component with default and additive styles. Doubles over as a link when `href` is passed to it.
import { forwardRef } from "react";
import Link from "next/link";
function Button(
{
children,
disabled,
download,
href,
@cyrus01337
cyrus01337 / out.log
Created February 18, 2023 08:08
Networking benchmark results - Golang 1.20.1 vs Bun 0.5.6
# Benchmarking Golang
2023/02/18 08:03:58 Server running at http://127.0.0.1:8000/
Bombarding http://127.0.0.1:8000/ with 10000 request(s) using 100 connection(s)
10000 / 10000 [=============================================] 100.00% 3300/s 3s
Done!
Statistics Avg Stdev Max
Reqs/sec 3569.13 1184.96 8204.28
Latency 28.68ms 17.66ms 135.88ms
HTTP codes:
1xx - 0, 2xx - 10000, 3xx - 0, 4xx - 0, 5xx - 0
@cyrus01337
cyrus01337 / Devices.jsx
Created January 5, 2023 11:36
Responsive component that conditionally renders based on resolution
import { useEffect, useState } from "react";
const MOBILE_WIDTH = 1024;
export const isDesktop = (limit = MOBILE_WIDTH) => window.innerWidth > limit;
export const isMobile = (limit = MOBILE_WIDTH) => window.innerWidth <= limit;2
const useResolutionChecker = ({ desktop, mobile }) => {
const [inMobileResolution, setInMobileResolution] = useState(isMobile());
@cyrus01337
cyrus01337 / expected.log
Last active November 9, 2022 16:24
Output logs when formatting a `.jsx` file with the Prettier VS Code extension and having Yarn
["INFO" - 16:03:58] Extension Name: esbenp.prettier-vscode.
["INFO" - 16:03:58] Extension Version: 9.9.0.
["DEBUG" - 16:03:58] Local prettier module path: '/home/cyrus/Desktop/projects/cyrus01337.co.uk/node_modules/prettier/index.js'
["DEBUG" - 16:03:58] Using prettier version 2.7.1
["DEBUG" - 16:03:58] Enabling Prettier globally
{
"languageSelector": [
{
"language": "javascript"
},
:root {
--default-emoji-size: 1.375rem;
--default-emoji-jumboable-size: 3rem;
--emoji-size: calc(var(--default-emoji-size) * 2);
--emoji-jumboable-size: calc(var(--default-emoji-jumboable-size) * 2);
}
/* Change emoji size */
[class*="messageContent"]:not([class*="repliedTextContent"]) .emoji {
height: var(--emoji-size) !important;