Skip to content

Instantly share code, notes, and snippets.

View wscnd's full-sized avatar

Wellingson Moraes wscnd

  • Brazil
View GitHub Profile
const getSearchParams = <T extends object>(): Partial<T> => {
// server side rendering
if (typeof window === "undefined") {
return {};
}
const params = new URLSearchParams(window.location.search);
return new Proxy(params, {
@wscnd
wscnd / houses.json
Created April 30, 2021 20:42 — forked from jherr/houses.json
Challenge #1
[
{ "name": "Atreides", "planets": "Calladan" },
{ "name": "Corrino", "planets": ["Kaitan", "Salusa Secundus"] },
{ "name": "Harkonnen", "planets": ["Giedi Prime", "Arrakis"] }
]
@wscnd
wscnd / ignorance.ts
Last active April 30, 2021 13:13
Persistence Ignorance
type Customer = string;
type CustomerId = string;
type GetCustomer = (customer: CustomerId) => Customer;
type Connection = string;
type getCustomerFromDataBase = (connection: Connection) => GetCustomer;
const connection = "DATABASE";
const gcfdb: getCustomerFromDataBase = (connection) => (customerId) => `
@wscnd
wscnd / types.js
Created February 15, 2021 14:57
types
const Last = (x) => ({
x,
concat: (o) => o,
});
// const Fn = f =>
// ({
// runFn: f,
// map: g => Fn(x => g(f(x))),
// concat: o =>
function* asynFunction () {
const data = yield fetch('url-here')
console.log(data)
}
function doAfterFetch (value){
returnAfterFetch.next(value)
}
const returnAfterFetch = asynFunction()
@wscnd
wscnd / generate-ssh-key.sh
Created December 15, 2020 16:49 — forked from grenade/01-generate-ed25519-ssh-key.sh
Correct file permissions for ssh keys and config.
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/github_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/mozilla_rsa
@wscnd
wscnd / 1.js
Created November 19, 2020 21:01 — forked from getify/1.js
tag function for formatting console.log(..) statements
function logger(strings,...values) {
var str = "";
for (let i = 0; i < strings.length; i++) {
if (i > 0) {
if (values[i-1] && typeof values[i-1] == "object") {
if (values[i-1] instanceof Error) {
if (values[i-1].stack) {
str += values[i-1].stack;
continue;
}
document.body.addEventListener('focusin', (event) => {
console.log(document.activeElement)
})
const loops = 100;
const numbers = [
[3, "Fizz"],
[5, "Buzz"],
];
for (i = 1; i <= loops; i++) {
r = numbers.filter((n) => !(i % n[0]));
console.log(r.length ? r.map((result) => result[1]).join(" ") : i);
}
@wscnd
wscnd / useSetState.js
Last active April 10, 2021 11:48
Managing state in forms
import React from "react";
const reducer = (previousState = {}, updatedState = {}) => {
return { ...previousState, ...updatedState };
};
const useSetState = (initialState = {}) => {
const [state, dispatch] = React.useReducer(reducer, initialState);
const setState = (updatedState) => dispatch(updatedState);