Skip to content

Instantly share code, notes, and snippets.

View obrenoco's full-sized avatar
🏗️
building things

Breno Romeiro obrenoco

🏗️
building things
View GitHub Profile
@obrenoco
obrenoco / aboutmee.gif
Last active July 6, 2020 18:52
About me
aboutmee.gif
@obrenoco
obrenoco / project.gif
Last active July 8, 2020 21:55
My projects
project.gif
@obrenoco
obrenoco / typing-utility-types.ts
Last active August 23, 2021 20:30
Rebuilding Utility Types
// Rebuilding Utility Types
// T = Type; K = Keys; U = Union;
// Nullable
type MyNullable<T> = T | null;
type MyNullableTest = MyNullable<🍓>; // MyNullableTest = 🍓 | null
// Non-Nullable (filter != null | undefined)
type MyNonNullable<T> = T extends null | undefined ? never : T;
type MyNonNullableTest = MyNullable<🍊 | 🥝 | null | undefined> // MyNonNullableTest = 🍊 | 🥝
@obrenoco
obrenoco / keyof.ts
Last active August 22, 2021 18:57
Keyof
// keyof
// creates a type based on provided obkect keys
type Lusophone = keyof {Brasil: 🇧🇷, Angola: 🇦🇴, "Cape Verde": 🇨🇻} // Lusophone = "Brasil" | "Angola" | "Cape Verde"
@obrenoco
obrenoco / freeze-seal.md
Last active August 22, 2021 19:13
Object.Freeze vs Object.Seal
Create Read Update
Object.freeze()
Object.seal()
@obrenoco
obrenoco / hof-callback.ts
Last active February 5, 2023 00:34
High Order + Callback functions
// Higher-Order Functions & Callback
// ¹. A higher order function takes a function as a parameter.
// ². A callback is a function (() => {...}) that is passed as an argument.
const higherOrderFunction¹= (callback²) => {
return callback();
}
@obrenoco
obrenoco / prototypes-classes.js
Last active August 31, 2021 02:33
Prototypes and Classes
// Functional Instantiation
// the weakness of this pattern is that whenever we create
// a new person, we have to re-create all the methods in memory,
// which is not cool..
function Person (name, energy) {
let person = {}
person.name = name
person.energy = energy
person.eat = function (amount) {
@obrenoco
obrenoco / import.js
Last active September 2, 2021 12:56
JS import
// Default importing
import Func from 'utils'
// Entire content importing
import * as Utils from 'utils'
// Selective importing
import {Func} from 'utils'
// Selective importing with alias
@obrenoco
obrenoco / html-tags-details-summary.html
Last active July 22, 2024 04:17
HTML + CSS | Native accordion + Open Animation
<!DOCTYPE html>
<html>
<head>
<style>
summary {
cursor: pointer;
list-style: none;
}
details[open] summary ~ * {
animation: toggle 0.1s ease-in-out;
@obrenoco
obrenoco / rebuild-usecallback-usememo.tsx
Last active January 28, 2022 17:19
Rebuild useCallback and useMemo hooks from React
type CallbackProps = (...args: any[]) => any;
const useCallback2 = <T extends CallbackProps>(
y: T,
dependencies: unknown[]
): T => {
const [myState, setMyState] = useState<T>(() => y);
useEffect(() => {
setMyState(() => y);
}, dependencies);
return myState;