View react-list.js
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
const list = (text)=>(
text.map( (val) =>(
<ListItem>{val}</ListItem>
))
View react-this.js
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
class App extends React.Component {
constructor(){
super()
this.awesome = "love"
}
View javascript-this.js
function boo(){
console.log(this.name)
}
// bind simply passes "this" (object) to the function's argument
function cool(){
this.name = "tommy"
// passing current context of "this" to function
boo.bind(this)()
}
View docker-heredoc.sh
# heredoc is used as a file or input
# << EOF ("<<" is for appending, "EOF" is a delimeter to start string liter)
docker build -t htop - << EOF
FROM alpine
RUN apk --no-cache add htop
# Call EOF delimeter to end string literal
EOF
View redux-state.js
// state equals its reducer local state
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
console.log("state is:" ,state)
return state - 1;
default:
return state;
View go-slices.go
package main
import (
"fmt"
"log"
)
type user struct {
name string
username string
View es7-async-await.js
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
View redux.js
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
View js-reduce.js
const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10
// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
// expected output: 15