Skip to content

Instantly share code, notes, and snippets.

@jesperorb
jesperorb / music_for_programming.md
Last active Apr 7, 2017
Music for Programming 💾 🔉
View music_for_programming.md
@jesperorb
jesperorb / react_errors.md
Last active Aug 31, 2017
Common Errors in React
View react_errors.md

Common Errors in React

Unterminated JSX Content

Don't focus on which element the cursor is pointing, just look for any element that hasn't been closed

Error

Unterminated JSX Content

Solution

@jesperorb
jesperorb / firebase_object_to_array.js
Created Jun 19, 2017
Firebase object to array: { key: '' , value: ''}
View firebase_object_to_array.js
let arr = Object.entries(obj).map(entry => Object.assign({value: entry[1]}, { key: entry[0] }));
@jesperorb
jesperorb / prototype.md
Last active May 10, 2018
Different prototype patterns
View prototype.md

Constructor Pattern

//Constructor pattern, a function that produces new
//objects. But still just a regular function
function Person(name, age){
    this.name = name;
    this.age = age;
}
View react_patterns.md
@jesperorb
jesperorb / git.md
Last active Nov 23, 2019
Git Stuff
View git.md

Git Commands

  • git clone /path/to/repository: Clone a repo
    • git clone https://github.com/jesperorb/json-server-heroku.git: basic clone
    • git clone https://github.com/jesperorb/json-server-heroku.git my-own-folder-name: with custom folder name (not the same as the repo name)
    • git clone git@github.com:jesperorb/json-server-heroku.git: only if you have manually set up SSH
  • git init: Initiate a new repo in current folder (without clone):
  • git add: Add files to staging area, must before commiting
    • git add .: adds all files
    • git add file-name another-file-name: adds one or more files
@jesperorb
jesperorb / binding_in_react.md
Last active Mar 1, 2021
Examples of how to bind functions in React
View binding_in_react.md

Binding In React


this and binding in JavaScript

To properly use react you need to get a good understanding about binding and the keyword this in regular JavaScript. When adding a function to an event i JavScript you don't call the

View alternateCasing.js
function alternateCasing(text){
let letters ''
for (const index in text) {
if(index % 2) {
letters += text[index].toLowerCase()
} else {
letters += text[index].toUpperCase()
}
}
@jesperorb
jesperorb / env_variables.md
Last active Sep 4, 2021
What the hell is env variables and how to add to path
View env_variables.md
@jesperorb
jesperorb / module_bundlers.md
Last active Nov 21, 2021
Kom igång med Module Bundlers (Parcel & Webpack)
View module_bundlers.md

Module Bundler (Parcel & Webpack)

Node & require

I Node.js finns ingen index.html som binder samman alla våra resurser (.js, .css etc.) men vi måste ändå ha ett sätt att kommunicera mellan filer på ett enkelt sätt. Detta löser node med att man exporterar och importerar explicit från varje fil, liknande som sass förutom att här måste vi även vara explicit med vad vi exporterar. Vi kan även välja att inte exportera allting i filen så vissa variabler kan vara "privata" till själva filen medan andra kan vara "publika" för resten av dina filer.

//index.js
const person = require('./person.js');
// const { name, age } = require('./person'); //destructure