Skip to content

Instantly share code, notes, and snippets.

View matheusinacio7's full-sized avatar
🤖
surfing the AI hype wave

Matheus "Set" Inacio matheusinacio7

🤖
surfing the AI hype wave
View GitHub Profile
@matheusinacio7
matheusinacio7 / oracle.sh
Last active July 21, 2022 15:50
Oracle: always choose the best option when you're uncertain
# This program decides the best option
# when you're uncertain,
# with 100% accuracy
# Requires python3 to be installed and I've only tested it with zsh, but maybe works with bash as well
# drop this in your .zshrc file and run it like:
# oracle thai japanese sandwich
# to decide what to eat
# Takes an arbitrary number of arguments (depends on the maximum for your shell), will pick between them
@matheusinacio7
matheusinacio7 / illustration.svg
Created February 17, 2022 07:59
Jest mocking lost pointer
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matheusinacio7
matheusinacio7 / combineFilters.js
Last active August 16, 2021 17:59
combine filters
const combineFilters = ([head, ...tail]) => (data) => (head ? (head(data) && combineFilters(tail)(data)) : true);
@matheusinacio7
matheusinacio7 / tictactoe-06-01.jsx
Created February 11, 2021 09:07
React Tic-Tac-Toe Challenge#06-01
let status;
if (winner) {
status = "Winner: " + winner;
} else if(history.length === 10){ <<<
status = 'Draw!'; <<<
} else {
status = "Next player: " + (this.state.xIsNext ? "X" : "O");
}
@matheusinacio7
matheusinacio7 / tictactoe-05-04.jsx
Created February 11, 2021 08:58
React Tic-Tac-Toe Challenge#05-04
function Square(props) {
return (
<button
className="square"
onClick={props.onClick}
style={props.isWinning ? {boxShadow: 'inset 0px 0px 3px #4c768f, 0px 0px 3px #4c768f'} : {}} <<<
>
{props.value}
</button>
);
@matheusinacio7
matheusinacio7 / tictactoe-05-03.jsx
Created February 11, 2021 08:56
React Tic-Tac-Toe Challenge#05-03
class Board extends React.Component {
renderSquare(i) {
const winningArr = this.props.winningSquares.filter((sq) => sq === i); <<<
return (
<Square
value={this.props.squares[i]}
onClick={() => this.props.onClick(i)}
isWinning={winningArr.length ? true : false} <<<
/>
@matheusinacio7
matheusinacio7 / tictactoe-05-02.jsx
Created February 11, 2021 08:48
React Tic-Tac-Toe Challenge#05-02
let status;
let winningSquares = [];
if (winner) {
status = "Winner: " + winner.player;
winningSquares = winner.line;
} else {
status = "Next player: " + (this.state.xIsNext ? "X" : "O");
}
@matheusinacio7
matheusinacio7 / tictactoe-05-01.jsx
Created February 11, 2021 08:43
React Tic-Tac-Toe Challenge#05-01
function calculateWinner(squares) {
(...)
for (let i = 0; i < lines.length; i++) {
const [a, b, c] = lines[i];
if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
return { <<<
player: squares[a], <<<
line: [a, b, c], <<<
}; <<<
}
@matheusinacio7
matheusinacio7 / tictactoe-04-05.jsx
Created February 11, 2021 08:21
React Tic-Tac-Toe Challenge #04-05
if(!this.state.historyAscending) {
moves.sort((a, b) => b.key - a.key);
}
let status;
if (winner) {
(...)
@matheusinacio7
matheusinacio7 / tictactoe-04-04.jsx
Created February 11, 2021 08:05
React Tic-Tac-Toe Challenge#04-04
handleToggleOrder(historyAscending) {
this.setState({historyAscending});
}
jumpTo(step) {
(...)