Skip to content

Instantly share code, notes, and snippets.

@Elemino
Elemino / BLOG.md
Created October 29, 2019 08:46 — forked from elierotenberg/BLOG.md
Idiomatic Data Fetching using React Hooks

Idiomatic Data Fetching using React Hooks

This post has been written in collaboration with @klervicn

Virtually all web apps and websites need to pull data from a server, usually through a JSON-returning API. When it comes to integrating data fetching in React component, the "impedence mismatch" between the React components, which are declarative and synchronous, and the HTTP requests, which are imperative and asynchronous, is often problematic.

Many apps use third-party libraries such as Redux or Apollo Client to abstract it away. This requires extra dependencies, and couple your app with a specific library to perform data fetching. In most cases, what we want is a direct way to integrate plain HTTP requests (e.g. using native fetch) for usage in React components.

Here we will discuss how we can use React Hooks to do this in an elegant, scalable manner.

@Elemino
Elemino / Remove git history
Last active October 21, 2019 09:24
Remove git history
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin [email protected]:<YOUR ACCOUNT>/<YOUR REPOS>.git
@Elemino
Elemino / js-terms.md
Created September 9, 2019 12:09 — forked from AllThingsSmitty/js-terms.md
10 terms to help you better understand JavaScript

10 JavaScript Terms You Should Know

From currying to closures there are quite a number of special words used in JavaScript. These will not only help you increase your vocabulary but also better understand JavaScript. Special terms are normally found in documentation and technical articles. But some of them like closures are pretty standard things to know about. Knowing what the word itself means can help you know the concept it's named for better.

  1. Arity
  2. Anonymous
  3. Closure
  4. Currying
  5. Hoisting
  6. Mutation
@Elemino
Elemino / gist:4a12409767b5fd3de8f5232d623d7f4d
Created April 21, 2019 01:05
my npm list before clean up
npm list -g
/home/user/.nvm/versions/node/v10.14.1/lib
├─┬ [email protected] -> /home/user/Desktop/Projects/create-react-native
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
@Elemino
Elemino / delete
Last active September 9, 2019 12:11
delete commit:
git push origin +^:master
// Class Inheritance Example
// NOT RECOMMENDED. Use object composition, instead.
// https://gist.github.com/ericelliott/b668ce0ad1ab540df915
// http://codepen.io/ericelliott/pen/pgdPOb?editors=001
class GuitarAmp {
constructor ({ cabinet = 'spruce', distortion = '1', volume = '0' } = {}) {
Object.assign(this, {
cabinet, distortion, volume
@Elemino
Elemino / ex1-prototype-style.js
Created November 9, 2018 07:41 — forked from getify/ex1-prototype-style.js
OLOO (objects linked to other objects) pattern explored (with comparison to the prototype style of the same code)
function Foo(who) {
this.me = who;
}
Foo.prototype.identify = function() {
return "I am " + this.me;
};
function Bar(who) {
Foo.call(this,"Bar:" + who);
How to revert to an earlier commit in git:
Two good ways to roll back to an earlier stable commit:
git revert --no-commit 0766c053..HEAD //The commit you want
git commit --am "Your comment"
git push
---
@Elemino
Elemino / Merge
Last active October 28, 2018 07:27
How to merge remote origin:
(Make sure to save or stash your local changes because the merge action will make you lose them)
git fetch origin
git reset --hard origin/master
git pull
//set context
var audioContext = new AudioContext()
var speakers = audioContext.destination
//call play function
play(0, 3, .5)
play(1, 10, .5)
play(2, 15, .5)
//play function
function play (delay, pitch, duration) {