Skip to content

Instantly share code, notes, and snippets.

View fabriciofmsilva's full-sized avatar

Fabrício Silva fabriciofmsilva

View GitHub Profile
@fabriciofmsilva
fabriciofmsilva / aha-testing.md
Created July 30, 2019 16:41
JavaScript Testing
// __tests__/login.js
import React from 'react'
import {render, fireEvent} from '@testing-library/react'
import Login from '../login'
test('calls onSubmit with the username and password when submit is clicked', () => {
  const handleSubmit = jest.fn()
  const {getByLabelText, getByText} = render(<Login onSubmit={handleSubmit} />)
  const user = {username: 'michelle', password: 'smith'}
  fireEvent.change(getByLabelText(/username/i), {

prefers-color-scheme

Light mode

@media (prefers-color-scheme: light) {
    html {
        background: white;
        color: black;
    }
}
@fabriciofmsilva
fabriciofmsilva / object.js
Created July 26, 2019 20:50
JavaScript Objects
const NAME = Symbol();
const person = {
[NAME]: 'Flavio'
};
person[NAME]; //'Flavio'
const RUN = Symbol();
person[RUN] = () => 'Person is running';
console.log(person[RUN]()); //'Person is running'
@fabriciofmsilva
fabriciofmsilva / css-and-js.md
Last active July 26, 2019 20:35
Add CSS in JS
.btn {
	background-color: red;
	color: white;
	padding: 20px;
}
// Get the element
@fabriciofmsilva
fabriciofmsilva / performance.md
Last active July 26, 2019 19:28
Performance Testing JavaScript

Performance Testing JavaScript

Testing performance is surprisingly straightforward.

  1. Start a timer
  2. Run your tasks
  3. Stop the timer and note how much time has elapsed
  • The performance.now() method
  • The console.time() and console.timeEnd() methods
<comp
  role="alert|log|status|progressbar|marquee|timer|region"
  aria-live="POLITENESS_SETTING = [off]|polite|assertive"
  aria-controls="IDLIST"
  aria-atomic="BOOLEAN = true|false"
  aria-relevant="LIST_OF_CHANGES"
  aria-labelledby="IDLIST"
  aria-describedby="IDLIST"
 aria-label="LABEL"
// fetch("http://localhost:3000/people")
// .then(response => response.json())
// .then(people => {
// return people.map(person => {
// return fetch("http://localhost:3000/person" + person.id + "/address")
// .then(response => response.json())
// .then(address => {
// person.address = address;
// return person;
// });

asdf

asdf: Language version management

Installation

# core
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.2
@fabriciofmsilva
fabriciofmsilva / auth.js
Created June 10, 2019 19:30
Authentication
// https://github.com/santiq/nodejs-auth/tree/master/src/middlewares
import * as argon2 from 'argon2';
import * as jwt from 'jsonwebtoken';
class AuthService {
public async Login(email, password): Promise<any> {
const userRecord = await UserModel.findOne({ email });
if (!userRecord) {
throw new Error('User not found')
@fabriciofmsilva
fabriciofmsilva / good-practices.md
Last active June 7, 2019 21:08
Good Practices