Skip to content

Instantly share code, notes, and snippets.

View ReydVires's full-sized avatar
⚔️
Code-Knight

Arsyel ReydVires

⚔️
Code-Knight
  • Jakarta
View GitHub Profile
@Jelleebeen
Jelleebeen / ResolvingMatterCollisionsInPhaser3.ts
Last active February 4, 2024 14:24
Resolving collisions using Matter physics with Phaser 3 in constant O(1) time - Port to Typescript
/*
This code shows how to resolve collisions using Matter physics with Phaser 3 in constant O(1) time.
Going through all the collision pairs is still linear O(n) time depending on how many collisions happened this frame
but the code that handles the resolution of the collision is constant and will not change with the total number of CollisionCategories / collision-lookups.
The way the code works is by generating a number based on the each of the collision combinations, use that number as a key for storing a pointer to the respective collision handler function,
and then when a collision happens, calculate the number again of both bodies' collision categories and use that number to fetch the collision handler function. Simple.
// dreasgrech - https://github.com/dreasgrech/
// TS example - Jelleebeen - https://github.com/jelleebeen/
*/
@chadrehm
chadrehm / ScrollToTopArrow.js
Created November 6, 2020 16:38
ScrollToTopArrow
export const ScrollTopArrowComponent = () => {
// Track whether the scroll arrow is needed.
const [showScroll, setShowScroll] = useState(null);
// Check the scroll state, re-memoize when scroll state changes.
const checkScrollTop = useCallback(
() => {
const headerHeight = 400;
if (!showScroll && window.pageYOffset > headerHeight) {
setShowScroll(true);
@sandren
sandren / tailwind.md
Last active October 12, 2024 17:10
Tailwind CSS best practices

Tailwind CSS best practices

Utility classes

  1. When writing a string of multiple utility classes, always do so in an order with meaning. The "Concentric CSS" approach works well with utility classes (i.e,. 1. positioning/visibility 2. box model 3. borders 4. backgrounds 5. typography 6. other visual adjustments). Once you establish a familiar pattern of ordering, parsing through long strings of utility classes will become much, much faster so a little more effort up front goes a long way!

  2. Always use fewer utility classes when possible. For example, use mx-2 instead of ml-2 mr-2 and don't be afraid to use the simpler p-4 lg:pt-8 instead of the longer, more complicated pt-4 lg:pt-8 pr-4 pb-4 pl-4.

  3. Prefix all utility classes that will only apply at a certain breakpoint with that breakpoint's prefix. For example, use block lg:flex lg:flex-col lg:justify-center instead of block lg:flex flex-col justify-center to make it very clear that the flexbox utilities are only applicable at the

@nicloay
nicloay / button.lua
Last active March 23, 2019 20:49
Defold gui button which change scale on press event
local PRESSED_BUTTON_SCALE = vmath.vector3(1.15)
local NORMAL_BUTTON_SCALE = vmath.vector3(1)
local ANIMATION_TIME = 0.2
local Button = {}
Button.__index = Button
function Button.new(context, node_name, handler)
local self = setmetatable({}, Button)
assert(handler)
@hamaluik
hamaluik / AABB.hx
Created October 6, 2014 05:38
Continuous collision detection between two moving AABBs using Minkowski differences.
package ;
import openfl.display.Sprite;
/**
* ...
* @author Kenton Hamaluik
*/
class AABB
{
public var center:Vector = new Vector();