Skip to content

Instantly share code, notes, and snippets.

View melcor76's full-sized avatar

Michael Karén melcor76

View GitHub Profile
@melcor76
melcor76 / has-role.directive.ts
Created January 15, 2022 19:23
Structural directive - inpuyt
@Directive({ selector: '[hasRole]' })
export class HasRoleDirective {
constructor(
private templateRef: TemplateRef<any>
private viewContainer: ViewContainerRef) {}
@Input('hasRole')
roles: string[];
@Input('hasRoleElse')
@melcor76
melcor76 / breakout.js
Created January 10, 2022 17:43
Breakout brick direction hit
// Check if ball is inside from left side
ball.x + 2 * ball.radius > brick x
// Decrease by dx and check if position was on left side of brick x
ball.x + 2 * ball.radius - ball.dx <= brick.x;
// Similarly for right side
ball.x < brick.x + brick.width
ball.x - ball.dx >= brick.x + brick.width
@melcor76
melcor76 / app.tsx
Last active July 30, 2019 07:59
Reactangular - React function component
import React, { useState, useRef, useEffect } from 'react';
import '@reactangular/elements';
const App = () => {
const [counter, setCounter] = useState(0);
const buttonRef = useRef(null);
useEffect(() => {
const handleEvent = () => setCounter(counter + 1);
const btnAddToCart = buttonRef.current;