Skip to content

Instantly share code, notes, and snippets.

View drFabio's full-sized avatar

Fabio Oliveira Costa drFabio

View GitHub Profile
@drFabio
drFabio / addToObject.codemod.js
Last active February 9, 2022 12:11
Adds props to objects using jsCodeShift
export default (fileInfo, api, options) => {
const { path: rawPath, value, declarator = "theme" } = options;
if (!rawPath || !value) {
console.error("Pass paths AND value to change the code ");
process.exit(1);
}
const paths = rawPath.split(".");
const j = api.jscodeshift;
const root = j(fileInfo.source);
const possibleRoots = root.find(j.VariableDeclarator, {
{
"FunctionalComponent": {
"prefix": "reafc",
"body": [
"import React, {FC} from 'react'",
"",
"export interface ${1:${TM_DIRECTORY/^.+\\/(.*)$/$1/}}Props {",
"}",
"",
"export const ${1:${TM_DIRECTORY/^.+\\/(.*)$/$1/}}:FC<${1:${TM_DIRECTORY/^.+\\/(.*)$/$1/}}Props> = () => {",
_onInterval () {
const now = Date.now()
this.setState((oldState) => {
let { score, level, lastLeft, obstacleIndex } = oldState
const { right, up, down } = this._controls
this._resetControls()
let obstacleSpeed = INITIAL_OBSTACLE_STEP + INITIAL_OBSTACLE_STEP * (0.2) * level
if (right) {
obstacleSpeed *= 1 * 6 * Math.min(right, 2)
}
_checkColision(playerLeft, playerTop, obstacleData, newLeft) {
let isWithingHeight = false
const wrapperHeight = this._wrapper.offsetHeight
const obstacleHeight = wrapperHeight / 2
if (obstacleData.onTop) {
if (playerTop <= obstacleHeight) {
isWithingHeight = true
}
} else {
if ((playerTop + PLAYER_HEIGHT) >= wrapperHeight - obstacleHeight) {
_listenToKey(ev) {
if (ev.code === 'Enter') {
if (!this.state.running) {
this._startGame()
}
}
if (this.state.running) {
if (ev.code === 'Space' || ev.code === 'ArrowUp') {
this._controls.up++
}
import React, { Component } from 'react';
import styled, {keyframes} from 'styled-components'
const gentlyRock = keyframes`
0% {transform:rotate(4deg);}
50% {transform:rotate(-4deg);}
100% {transform:rotate(4deg);}
`
const dead = keyframes`
0% {transform:rotate(0);}
import React, { Component } from 'react';
import styled from 'styled-components'
const BackGround = styled.div`
background-color: blue;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
text-align: center;
`
import React, { Component } from 'react';
export class BgMusic extends Component {
render() {
if (this.props.mute) {
return null
}
if (this.props.gameOver) {
return (
<audio
@drFabio
drFabio / render.js
Last active December 27, 2017 12:27
Render de um jogo em react
render() {
return (
<div id="wrapper" ref={(c) => this._wrapper = c}>
<BgMusic
gameOver={this.state.gameOver}
running={this.state.running}
mute={this.state.mute}
/>
<Brackground
function sendMessage () {
idleButton()
var feedBack = document.getElementById('feedBack')
var question = document.getElementById("question").value.trim()
if (!question || question.length === 0){
setError('Insira uma pergunta')
return
}
if (question === lastQuestion) {
setError('Você já perguntou isso....')