Skip to content

Instantly share code, notes, and snippets.

View romelperez's full-sized avatar
:electron:
Creating epic shit!

Romel Perez romelperez

:electron:
Creating epic shit!
View GitHub Profile
# JAVASCRIPT
'.source.js, .source.ts, .source.tsx':
'Require':
'prefix': 'req'
'body': 'const ${1:module} = require(\'${1:module}\');'
'Module Exports':
'prefix': 'export'
'body': 'module.exports = $1;'
'Import':
'prefix': 'import'
import React, { useState, useEffect } from 'react';
import { render, act, cleanup } from '@testing-library/react';
import { EXITED, EXITING, ENTERED, ENTERING } from '../constants';
import { useAnimator } from '../useAnimator';
import { Component as Animator } from './Animator.component';
jest.useFakeTimers();
afterEach(cleanup);
@romelperez
romelperez / react-production-profiler.js
Last active April 7, 2021 23:11
Simple React profiler for mount phase for production environment.
import React, { useEffect, useState } from 'react';
import { render } from 'react-dom';
const ProductionProfiler = ({ children }) => {
const [mount, setMount] = useState(false);
useEffect(() => {
if (!mount) {
console.time('profile');
setMount(true);
}
@romelperez
romelperez / createRAFScheduler.ts
Last active February 26, 2022 04:54
Request Animation Frame Task Scheduler
import { isBrowser } from './browser';
type RAFSchedulerId = number | string;
type RAFSchedulerCallback = () => unknown;
// TODO: How to handle suspended schedules on suspended window?
const raf = (delay: number, callback: RAFSchedulerCallback): () => void => {
let scheduleId: number | undefined;
@romelperez
romelperez / createTOScheduler.ts
Created February 26, 2022 04:55
Timeout Task Scheduler
import { isBrowser } from './browser';
type TOSchedulerId = number | string;
type TOSchedulerCallback = () => unknown;
const timeoutTask = (delay: number, callback: TOSchedulerCallback): () => void => {
const scheduleId = setTimeout(() => callback(), delay);
return () => clearTimeout(scheduleId);
};
@romelperez
romelperez / arwesAnimationSystemExample.tsx
Created March 9, 2022 23:21
Arwes animation system example.
/** @jsxImportSource @emotion/react */
import { jsx } from '@emotion/react';
import { ReactElement, useState, useEffect } from 'react';
import { Animator, AnimatorGeneralProvider } from '@arwes/animator';
import { Animated } from '@arwes/animated';
const AnimatedItem = (props: { color: string }): ReactElement => {
return (
<Animated
function checkGameIndex (checkedIndexesCache, list, index) {
const offset = list[index];
const is0 = list[index] === 0;
const is0ToLeft = list[index - offset] === 0;
const is0ToRight = list[index + offset] === 0;
if (is0 || is0ToLeft || is0ToRight) {
return true;
}