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 doSearch = function (array, targetValue) { | |
let minIndex = 0; | |
let maxIndex = array.length - 1; | |
let guessIndex; | |
console.log(minIndex,maxIndex,guessIndex) | |
while(maxIndex >= minIndex){ | |
guessIndex = Math.floor((maxIndex+minIndex)/2) | |
console.log({minIndex, max, guessIndex}); |
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
let data = [ | |
{ | |
title: "menu 1", | |
children :[ | |
{ title: "menu 1.1"}, | |
{ | |
title: "menu 1.2", | |
children: [ | |
{title: "menu 1.2.1"}, | |
{title: "menu 1.2.2"}, |
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 cheerio = require('cheerio') | |
const cleaner = require('clean-html') | |
const axios = require('axios') | |
module.exports = async function getCleanDOM (url) { | |
// Wrap in a recusive retry func | |
async function retry() { | |
try { | |
// AJAX to get HTML | |
this.siteRequest = await axios.get(url) |
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
useEffect(() => { | |
// React.js recommends embedding self-executing async function w/ useEffect | |
(async function getit() { | |
// Fuzzy filter is also ready for filtering by 'name' field from payload of /comments | |
const result = await get("https://jsonplaceholder.typicode.com/todos"); | |
const jsonData = result.data; | |
defineInitialColumnSortStates(jsonData); | |
addButtonColumn(jsonData); | |
dispatch({ | |
type: "SET_DATA", |
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
// Inside component use | |
// const [{data}, dispatch] = useStateValue(); | |
// REDUCER | |
export default function (state, action) { | |
switch (action.type) { | |
case "SET_DATA": | |
return { | |
...state, |
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 LoadingSpinner = () => ( | |
<div className="loadingSpinner"> | |
<style jsx>{` | |
.loadingSpinner { | |
display: inline-block; | |
position: relative; | |
width: 300px; | |
height: 300px; | |
transform: translateZ(0); | |
} |
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
// From https://bit.ly/2XH31rw | |
import React, { createContext, useContext, useReducer } from "react"; | |
export const StateContext = createContext(); | |
export const StateProvider = ({ reducer, initialState, children }) => ( | |
<StateContext.Provider value={useReducer(reducer, initialState)}> | |
{children} | |
</StateContext.Provider> | |
); |
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' | |
const Index = () => ( | |
<div className="IndexPage"> | |
<label>{this.props.APIdata.key}</label> | |
<span>{this.props.APIdata.value}</span> | |
<style jsx>{` | |
.IndexPage { color: blue; } | |
`}</style> | |
</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
// "/en/sports_api/" + r + "/bets" | |
// "/en/sports_api/live/events?markets=none"; | |
// "/en/sports_api/live/event/" + t, | |
// "/en/sports_api/pre_match/competition/" + t + "/events" | |
// "/en/sports_api/pre_match/event/" + t, | |
// "/en/sports_api/pre_match/" + e.node + "/" + e.nodeid + "/events" : | |
// "/en/sports_api/pre_match/events" |
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
var express = require('express'); | |
var path = require('path'); | |
var favicon = require('static-favicon'); | |
var logger = require('morgan'); | |
var cookieParser = require('cookie-parser'); | |
var bodyParser = require('body-parser'); | |
var routes = require('./routes/index'); | |
var users = require('./routes/users'); |
NewerOlder