Skip to content

Instantly share code, notes, and snippets.

View brunormferreira's full-sized avatar
:octocat:
coding and learning

Bruno Ramires brunormferreira

:octocat:
coding and learning
View GitHub Profile
@neninja
neninja / emojicom.md
Last active October 7, 2021 12:56
emojicom
@customcommander
customcommander / spread-vs-assign.md
Last active December 18, 2023 11:13
On using assignment over spread to achieve performance

Spread vs assign

Abstract

In this article I compare the performance of the spread operator ... and the performance of the assignement operator = in the context of data transformation.

I show that using the spread operator isn't a trivial choice to make and I suggest that immutability and mutation don't have to be mutually exclusive. I also show how one-liner functions can be enriched with the comma operator ,.

What are we measuring?

@ericelliott
ericelliott / use-local-storage.js
Created March 30, 2020 23:34
A localStorage drop-in replacement for useState
import { useState } from 'react';
const configureLocalStorage = key => initialValue => {
const [state, setState] = useState(() => {
try {
const value = localStorage.getItem(key);
return value ? JSON.parse(value) : initialValue;
} catch (e) {
console.log(e);
return initialValue;
@ericelliott
ericelliott / use-promise.js
Created March 30, 2020 23:32
usePromise hook
import { useRef } from 'react';
const usePromise = () => {
const ref = [];
const container = useRef(ref);
ref[0] = new Promise((resolve, reject) => {
ref[1] = resolve;
ref[2] = reject;
});
@mpj
mpj / vanilla-hofs-with-reduce.js
Created February 3, 2020 14:16
code from episode
const isMoreThan5 = number => number > 5
const numbers = [ 2, 4, 8, 9 ]
const result = filter(isMoreThan5, numbers)
const addThree = number => number + 3
const result = map(addThree, numbers)
result
function map(transform, array) {
const initialArray = []
const mapReducer = (mappedArray, currentItem) =>
const numbers = [ 2, 4, 8, 9 ]
const addTwo = number => number + 1
const isMoreThan5 = number => number > 5
const result =
//numbers.filter(isMoreThan5)
filterArray(isMoreThan5, numbers)
//mapArray(addTwo, numbers
result
function filterArray(predicate, array) {
@guilhermebkel
guilhermebkel / 📊 Weekly development breakdown
Last active March 14, 2021 00:00
Weekly Development Stats
TypeScript 25 hrs 24 mins ████████████████▋░░░░ 79.7%
JavaScript 2 hrs 45 mins █▊░░░░░░░░░░░░░░░░░░░ 8.7%
Docker 1 hr 28 mins ▉░░░░░░░░░░░░░░░░░░░░ 4.6%
Markdown 36 mins ▍░░░░░░░░░░░░░░░░░░░░ 1.9%
Other 36 mins ▍░░░░░░░░░░░░░░░░░░░░ 1.9%
// time and time end
console.time("This");
let total = 0;
for (let j = 0; j < 10000; j++) {
total += j
}
console.log("Result", total);
console.timeEnd("This");
// Memory
[alias]
ci = commit
co = checkout
cm = checkout master
cb = checkout -b
st = status -sb
sf = show --name-only
lg = log --pretty=format:'%Cred%h%Creset %C(bold)%cr%Creset %Cgreen<%an>%Creset %s' --max-count=30
incoming = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' ..@{u})
outgoing = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' @{u}..)
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var domStyle = document.createElement("style");
domStyle.append(
'* { color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }\
* * { background-color: rgba(0,255,0,.2) !important; }\
* * * { background-color: rgba(0,0,255,.2) !important; }\
* * * * { background-color: rgba(255,0,255,.2) !important; }\
* * * * * { background-color: rgba(0,255,255,.2) !important; }\