This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isInside(pos, rect) { | |
return ( | |
pos[0] > rect[0] && pos[1] > rect[1] && pos[0] < rect[2] && pos[1] < rect[2] | |
); | |
} | |
const rect1 = new Uint16Array([10, 10, 100, 1000]); | |
const rect2 = new Uint16Array([0, 0, 10, 10]); | |
const pos1 = new Uint16Array([250, 50]); | |
const pos2 = new Uint16Array([20, 20]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function scrapeProduct (url) { | |
// the same code as you have ... | |
return {srcText, price, title}; | |
} | |
async function main() { | |
const results = await scrapeProduct("..."); | |
// here you can do something with results = {srcText, price, title}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"$id": "http://shone.com/anorak.json", | |
"title": "Anorak", | |
"description": "Portable Realtime Maritime Navigational Data Protocol", | |
"oneOf": [ | |
{ "$ref": "#subscribeMessage" }, | |
{ "$ref": "#unsubscribeMessage" }, | |
{ "$ref": "#getMessage" }, | |
{ "$ref": "#deltaMessage" }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// css is | |
// .day {color: black; background-color:white} | |
// .night {color: white; background-color:blue} | |
const DivChanging = ({ text }) => { | |
if (new Date().getHours() > 12) { | |
return <div class="night">{text}</div>; | |
} else { | |
return <div class="day">{text}</div>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import logo from "./logo.svg"; | |
import "./App.css"; | |
const Child = ({ onClick }) => <button onClick={onClick}>Click me</button>; | |
class Parent extends Component { | |
field = "hello"; | |
handleClick = e => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const util = require("util"); | |
const readFile = util.promisify(fs.readFile); | |
async function long() { | |
const content = await readFile("./dummy1000000.csv", "utf-8"); | |
content.split(/\n/); | |
} | |
const arr = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getGroupsById = (state, ids) => ids.map(id => state.groups[id]) | |
const getUsersWithGroupsById = (state, ids) => ids.map(id => ({...state.users[id], groups: getGroupsById(state.users[id].groups)})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 - instead of | |
const state = { | |
users: [ | |
{ id: 1, name: "Bat", groups: [{ name: "admin" }, { name: "regular" }] }, | |
{ id: 2, name: "Vince", groups: { name: "admin" } }, | |
{ id: 1, name: "Romain", groups: { name: "normal" } } | |
] | |
}; | |
// 2- Normalize and index by primary key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 - instead of | |
const mapDispatchToProps = dispatch => { | |
return { | |
addUser: payload => dispatch({type:'my-app/users/ADD',payload}) | |
} | |
} | |
const connect(null, mapDispatchToProps)(MyComponent) | |
// 2 - with action creators | |
import {addUser} from './redux/users' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 - instead of | |
const action = {type: 'my-app/users/ADD', {id: 1, name:'Bat'}} | |
/* we can */ | |
// 2 - we define an action creator in the users file | |
export const addUser = payload => ({type: 'my-app/users/ADD', payload}) | |
// we can get the action in another file when we need it | |
import {addUser} from '../redux/users' | |
const action = addUser({id: 1, name:'Bat'}) |