Skip to content

Instantly share code, notes, and snippets.

View Sebastp's full-sized avatar
💪
Writing lots of code

Sebastian Sebastp

💪
Writing lots of code
View GitHub Profile
@Sebastp
Sebastp / test.js
Created October 2, 2021 11:16 — forked from mtoso/test.js
Unit Test Template
import test from 'tape';
// For each unit test you write,
// answer these questions:
test('What component aspect are you testing?', assert => {
const actual = 'What is the actual output?';
const expected = 'What is the expected output?';
assert.equal(actual, expected,
'What should the feature do?');
@Sebastp
Sebastp / Readme.md
Created December 19, 2019 15:06
README template

Logo of the project

Name of the project · Build Status npm PRs Welcome GitHub license

Additional information or tag line

A brief description of your project, what it is used for.

Installing / Getting started

A quick introduction of the minimal setup you need to get a hello world up &

@Sebastp
Sebastp / _rem.scss
Created December 11, 2019 20:47
Pixels to Rem in scss
$rem-baseline: 16px !default;
$rem-fallback: false !default;
$rem-px-only: false !default;
@function rem-separator($list, $separator: false) {
@if $separator == "comma" or $separator == "space" {
@return append($list, null, $separator);
}
@if function-exists("list-separator") == true {
@Sebastp
Sebastp / _normalize.scss
Created December 11, 2019 20:47
My usual normaize file + custom resets
/*! normalize.css v8.0.0 | MIT License | github.com/necolas/normalize.css */
/* Document
========================================================================== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
@Sebastp
Sebastp / gist:da47c32f33a8facaee8abf50ca6c23a0
Created December 8, 2019 19:24
Apollo auth link examples
1)-----------------------
// Setup the header for the request
const middlewareAuthLink = new ApolloLink((operation, forward) => {
const token = localStorage.getItem(JWT_TOKEN)
const authorizationHeader = token ? `Bearer ${token}` : null
operation.setContext({
headers: {
authorization: authorizationHeader,
},
@Sebastp
Sebastp / .gitignore
Created December 7, 2019 10:57
gitignore template
### Node ###
# Logs
logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Optional npm cache directory
.npm
@Sebastp
Sebastp / useMousePosition.ts
Created December 4, 2019 10:30
Mouse Position tracking react hook
import { useEffect, useState } from 'react'
//react hook for checking if clicked outside @param ref
// @param = funct runed if clicked outside @param ref
export const useOnClickOutside = (ref, handler) => {
useEffect(
() => {
const listener = event => {
// Do nothing if clicking ref's element or descendent elements
if (!ref.current || ref.current.contains(event.target)) {
@Sebastp
Sebastp / useOnClickOutside.ts
Created December 4, 2019 10:29
On Click Outside react hook
import { useEffect, useState } from 'react'
//react hook for checking if clicked outside @param ref
// @param = funct runed if clicked outside @param ref
export const useOnClickOutside = (ref, handler) => {
useEffect(
() => {
const listener = event => {
// Do nothing if clicking ref's element or descendent elements
if (!ref.current || ref.current.contains(event.target)) {
/**
* @param {string} email - string to check
* @return {boolean} if string = valid email
*/
const validateEmail = (email: string | number): boolean => {
if (typeof email != 'string') {
return false
}
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return re.test(email)