Skip to content

Instantly share code, notes, and snippets.

View lai32290's full-sized avatar

Lai Xuancheng lai32290

View GitHub Profile
@lai32290
lai32290 / reduce_example_3.js
Created October 6, 2020 00:16
Medium - Montando seu lanche com Reduce 3
const matriz = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ];
const valorInicial = [];
const vetor = matriz.reduce(function achatar(resultadoAnterior, lista) {
return [ ...resultadoAnterior, ...lista ];
}, valorInicial);
console.log(vetor);
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
@lai32290
lai32290 / reduce_example_with_init_value.js
Created October 6, 2020 00:14
Medium - Montando seu lanche com Reduce 2
const ingredientes = [ 'pao', 'tomate', 'queijo', 'ovo frito', 'ketchup', 'mostarda', 'pao' ];
const lanche = ingredientes.reduce(function juntarComPao(resultadoAnterior, ingrediente) {
return `${resultadoAnterior}, ${ingrediente}`;
}, 'prato');
console.log(`Aqui está o seu lanche: ${lanche}`);
// Aqui está o seu lanche: prato, pao, tomate, queijo, ovo frito, ketchup, mostarda, pao
@lai32290
lai32290 / reduce_example.js
Created October 6, 2020 00:13
Medium - Montando seu lanche com Reduce 1
const ingredientes = [ 'pao', 'tomate', 'queijo', 'ovo frito', 'ketchup', 'mostarda', 'pao' ];
const lanche = ingredientes.reduce(function juntarComPao(resultadoAnterior, ingrediente) {
return `${resultadoAnterior}, ${ingrediente}`;
});
console.log(`Aqui está o seu lanche: ${lanche}`);
// Aqui está o seu lanche: , pao, tomate, queijo, ovo frito, ketchup, mostarda, pao
// __tests__/accordion.rtl.js
import '@testing-library/jest-dom/extend-expect'
import React from 'react'
import {render, screen} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import Accordion from '../accordion'
test('can open accordion items to see the contents', () => {
const hats = {title: 'Favorite Hats', contents: 'Fedoras are classy'}
const footware = {
title: 'Favorite Footware',
test('setOpenIndex sets the open index state properly', () => {
const wrapper = mount(<Accordion items={[]} />)
- expect(wrapper.state('openIndex')).toEqual(0)
+ expect(wrapper.state('openIndexes')).toEqual([0])
wrapper.instance().setOpenIndex(1)
- expect(wrapper.state('openIndex')).toEqual(1)
+ expect(wrapper.state('openIndexes')).toEqual([1])
})
class Accordion extends React.Component {
- state = {openIndex: 0}
- setOpenIndex = openIndex => this.setState({openIndex})
+ state = {openIndexes: [0]}
+ setOpenIndex = openIndex => this.setState({openIndexes: [openIndex]})
render() {
- const {openIndex} = this.state
+ const {openIndexes} = this.state
return (
<div>
// __tests__/accordion.enzyme.js
import React from 'react'
// if you're wondering why not shallow,
// then please read <https://kcd.im/shallow>
import Enzyme, {mount} from 'enzyme'
import EnzymeAdapter from 'enzyme-adapter-react-16'
import Accordion from '../accordion'
// Setup enzyme's react adapter
Enzyme.configure({adapter: new EnzymeAdapter()})
test('setOpenIndex sets the open index state properly', () => {
// accordion.js
import React from 'react'
import AccordionContents from './accordion-contents'
class Accordion extends React.Component {
state = {openIndex: 0}
setOpenIndex = openIndex => this.setState({openIndex})
render() {
const {openIndex} = this.state
return (
<div>
@lai32290
lai32290 / Observer Class in C#
Created March 24, 2018 13:42
Observer Class
public class Observer<T>
{
public Observer() { }
public Observer(T initValue)
{
value = initValue;
}
private T value;
const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: true })
nightmare
.goto('http://blablablablabla/logon/logon.asp')
.wait(() => {
return document.querySelector('[name=username]') !== null;
})
.evaluate(() => {
document.querySelector('[name=username]').value = "visitante";