Skip to content

Instantly share code, notes, and snippets.

View gil00pita's full-sized avatar
💭
I may be slow to respond.

Gil Álvaro gil00pita

💭
I may be slow to respond.
View GitHub Profile
//Appending DOM is the most expensive operation, choose the right approach
// BAD
let container = document.querySelector('.container');
for (let i = 0; i < 1000; i++) {
let a = document.createElement('a');
a.text = `Row N° ${i}`;
container.appendChild(a);
}
@gil00pita
gil00pita / ES6.map.and.filter.js
Created January 25, 2019 19:55
Although this tutorial focuses on ES6, JavaScript array map and filter methods need to be mentioned since they are probably one of the most used ES5 features when building React application. Particularly on processing data. These two methods are muc
// For example, imagine a fetch from API result returns an array of JSON data:
const users = [
{ name: 'Nathan', age: 25 },
{ name: 'Jack', age: 30 },
{ name: 'Joe', age: 28 },
];
@gil00pita
gil00pita / ES6.destructuring.js
Created January 25, 2019 19:53
One of the most useful new syntax introduced in ES6, destructuring assignment is simply copying a part of object or array and put them into named variables. A quick example:
const developer = {
firstName: 'Nathan',
lastName: 'Sebhastian',
developer: true,
age: 25,
}
//destructure developer object
const { firstName, lastName } = developer;
console.log(firstName); // returns 'Nathan'
@gil00pita
gil00pita / ES6.class.inheritance.React.js
Last active January 25, 2019 19:50
A class can extends the definition of another class, and a new object initialized from that class will have all the methods of both classes. The class that extends another class is usually called child class or sub class, and the class that is being
//Now that we understand ES6 class and inheritance, we can understand the React class defined in src/app.js. This is a React component, but it's actually just a normal ES6 class which inherits the definition of React Component class, which is imported from the React package.
//Everytime we need variables. Consider the following example:
import React, { Component } from 'react';
class App extends Component {
// class content
render(){
const greeting = 'Welcome to React';
return (
<h1>{greeting}</h1>
@gil00pita
gil00pita / touchscreen.media.mixin.scss
Created January 18, 2019 12:49
CSS Media query to check if the defice has Touchscreen. The ‘pointer’ media feature is used to query about the presence and accuracy of a pointing device such as a mouse. If a device has multiple input mechanisms, it is recommended that the UA repor
@mixin isTouch {
@media (pointer:coarse) {
@content
}
}

Asynchronous Iteration

Iterating over a collection of data is an important part of programming. Prior to ES2015, JavaScript provided statements such as for, for...in, and while, and methods such as map(), filter(), and forEach() for this purpose. To enable programmers to process the elements in a collection one at a time, ES2015 introduced the iterator interface.

An object is iterable if it has a Symbol.iterator property. In ES2015, strings and collections objects such as Set, Map, and Array come with a Symbol.iteratorproperty and thus are iterable. The following code gives an example of how to access the elements of an iterable one at a time:

const arr = [10, 20, 30];
const iterator = arr[Symbol.iterator]();
 
@gil00pita
gil00pita / Install.Core.Apps.txt
Last active October 27, 2021 22:01
Automation Installer for Windows, Chocolatey.https://chocolatey.org/
##############################################################
# Description: Boxstarter Script
# Author: Gil Alvaro
# Last Updated: 2020-01-08
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
#
# You might need to set: Set-ExecutionPolicy RemoteSigned
#
@gil00pita
gil00pita / stylelint-fix.cmd
Last active November 1, 2018 11:34
stylelint fix files
stylelint "**/*.scss" --syntax scss --fix
@gil00pita
gil00pita / arrow-functions.js
Last active November 2, 2018 09:10
ES6 Refresher
// ARROW FUNCTIONS
function sayHello() {
console.log('Hello');
}
const sayHello = name => console.log(`Hello ${name}`);
const fruits = ['Apples', 'Oranges', 'Grapes'];
@gil00pita
gil00pita / cloudSettings
Last active February 23, 2021 22:20
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-02-23T22:20:27.781Z","extensionVersion":"v3.4.3"}