Skip to content

Instantly share code, notes, and snippets.

@cxmeel
cxmeel / IIF.lua
Created August 30, 2018 23:00
Returns a given value based on whether the condition evaluates to true or false.
--[[
clockworksquirrel.iif
Returns a given value based on whether the condition evaluates to true or false.
Usage:
<variant> IIF(<boolean> expression, <variant> value_if_true, <variant> value_if_false)
--]]
return function(Condition, IfTrue, IfFalse)
if (not not Condition) then return IfTrue end
@cxmeel
cxmeel / const.lua
Created August 30, 2018 23:16
Emulates "Constants" by locking a given table to a metatable. Also adds functions to retrieve the table's keys, values, and entries.
--[[
clockworksquirrel.const
Emulates "Constants" by locking a given table to a metatable.
Also adds functions to retrieve the table's keys, values, and entries.
Usage: <table> const(<table> table)
--]]
local t = require(script.Parent.t)
@cxmeel
cxmeel / ExtendTree.lua
Created September 4, 2018 19:57
Extends game tree-traversal methods.
--[[
clockworksquirrel.extend-tree
Extends game tree-traversal methods.
Available methods -
Miscellaneous:
<boolean> HasProperty, <variant> Value :HasProperty(<Instance> Object, <string> Property)
Returns true if an Instance has the specified property, along with the value
of the property.
@cxmeel
cxmeel / README.md
Last active June 27, 2022 10:08
ES6 Extended DOM Traversal

ES6 HTMLElement Extensions

This is a small library for extending HTMLElement methods.

Element.descendant()

Returns the first descendant of the element which matches the given selector. This is identical to Element.querySelector().

Syntax

<HTMLElement> HTMLElement.descendant(<String> selector)

Element.ancestor()

@cxmeel
cxmeel / PseudoBody.jsx
Last active September 8, 2020 17:56
Fake body and navigation panels for React using Material UI. https://pseudo-body-component.stackblitz.io
import React, { useLayoutEffect, useState, useCallback } from 'react';
import clsx from 'clsx';
import { ThemeProvider, createMuiTheme } from '@material-ui/core/styles';
import { Paper, makeStyles } from '@material-ui/core';
const useStyles = makeStyles(theme => ({
pseudoBody: {
width: '100vw',
height: '100vh',
@cxmeel
cxmeel / roblox-units.js
Last active January 2, 2020 23:45
Convert between Roblox units.
class RobloxUnit {
constructor(value = new String) {
if (typeof(value) === 'number') value = `${value}s`;
if (typeof(value) !== 'string') throw new Error('Value must be a string with format [number][unit]; e.g. 20s');
console.info(`Got "${value}"`);
const __ov = value;
value = __ov.replace(/[A-Za-z"']+/gi, '');
let unit = __ov.replace(/[^A-Za-z"']+/gi, '');
@cxmeel
cxmeel / InstanceEncode.server.lua
Last active February 23, 2020 18:57
Serialises Roblox Instance properties into a JSON-formatted string. Run this via the `Command Bar` or `Model -> Run Script`.
-- clockworksquirrel.instance-encode
local dump = {}
local http = game:GetService("HttpService")
local response = http:RequestAsync({
Url = "https://raw.githubusercontent.com/ClockworkSquirrel/roblox-client-dump/master/API-Dump-Tree.json"
})
dump = http:JSONDecode(response.Body)
@cxmeel
cxmeel / README.md
Created April 2, 2020 22:50
Like a basic version of Handlebars/Mustache.

Setup

import StringTemplater from "path/to/StringTemplater.module.js";

const stringsToMap = {
  "year": new Date().getFullYear()
};

const stringTemplater = new StringTemplater(stringsToMap);
stringTemplater.apply();
local function timeToDegrees(hours, minutes, inRadians)
hours = type(hours) == "number" and hours or 0
minutes = type(minutes) == "number" and minutes or 0
local timeDegrees = {
hours = (hours / 12) * 360,
minutes = (minutes / 60) * 360
}
if (inRadians) then
@cxmeel
cxmeel / Polyfill.lua
Created April 30, 2020 05:17
Wrap any object to extend its methods and properties.
local Polyfill = {}; do
function Polyfill.new(base)
local Poly; Poly = setmetatable({}, {
__index = function(self, key)
if (Poly[key]) then
return Poly[key]
end
return base[key]
end