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 / pre-load.html
Last active May 2, 2022 02:56
pre-loading
<div id="loading-page" class="loading-page">
<div class="loader"></div>
</div>
<div class="content">
<h1>Page loaded!</h1>
</div>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Static Template</title>
</head>
<body></body>
<script>
function shuffle(array) {
var m = array.length, t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
@obrenoco
obrenoco / fibonacci.ts
Last active January 10, 2022 01:55
Fibonacci
// using phi - best performance
// see: https://akuli.github.io/math-tutorial/fib.html
function fibonacciGoldenRation(n: number) {
const phi = (1 + Math.sqrt(5))/2;
const asymptotic = Math.pow(phi, n) / Math.sqrt(5);
return Math.round(asymptotic);
}
// using for() loop
const fibonacciForLoop = (num: number) => {
{
"name": "learn-semver",
"dependencies": {
"update-patch": "~0.0.1",
"update-minor": "^0.1.0"
},
}
@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;
@obrenoco
obrenoco / html-tags-details-summary.html
Last active October 22, 2023 11:20
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 / 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 / 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) {