This file contains hidden or 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 array = [1, 2, 3, 4, 5]; | |
| array.forEach((el, i) => { | |
| setTimeout(() => { | |
| console.log(el); | |
| }, 1000); | |
| }); |
This file contains hidden or 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 forEachWithCallback(callback) { | |
| const arrayCopy = this; | |
| let index = 0; | |
| const next = () => { | |
| index++; | |
| if (arrayCopy.length > 0) { | |
| callback(arrayCopy.shift(), index, next); | |
| } | |
| } | |
| next(); |
This file contains hidden or 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 array = [1, 2, 3, 4, 5]; | |
| array.forEachWithCallback((el, i, next) => { | |
| request({ | |
| method: 'GET', | |
| hostname: 'httpbin.org', | |
| path: '/get?myArg=' + el | |
| }).then((res) => { | |
| const responseBody = JSON.parse(res.body); | |
| console.log(responseBody.args.myArg); |
This file contains hidden or 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
| // request method implementation is in a GitHub Gist linked below | |
| const array = [1, 2, 3, 4, 5]; | |
| array.forEachWithCallback((el, i, next) => { | |
| request({ | |
| method: 'GET', | |
| hostname: 'httpbin.org', | |
| path: '/get?myArg=' + el | |
| }).then((res) => { | |
| const responseBody = JSON.parse(res.body); |
This file contains hidden or 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 googlesearch import search | |
| query = 'how old is samuel l jackson' | |
| ## Google Search query results as a Python List of URLs | |
| search_result_list = list(search(query, tld="co.in", num=10, stop=3, pause=1)) |
This file contains hidden or 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 requests | |
| from lxml import html | |
| from googlesearch import search | |
| from bs4 import BeautifulSoup | |
| query = 'how old is samuel l jackson' | |
| ## Google Search query results as a Python List of URLs | |
| search_result_list = list(search(query, tld="co.in", num=10, stop=3, pause=1)) |
This file contains hidden or 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 requests | |
| import string | |
| from lxml import html | |
| from googlesearch import search | |
| from bs4 import BeautifulSoup | |
| # to search | |
| # print(chatbot_query('how old is samuel l jackson')) | |
| def chatbot_query(query, index=0): |
This file contains hidden or 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 http.server | |
| import socketserver | |
| from google_search import chatbot_query | |
| PORT = 8080 | |
| DIRECTORY = 'public' |
This file contains hidden or 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
| class Handler(http.server.SimpleHTTPRequestHandler): | |
| def __init__(self, *args, **kwargs): | |
| super().__init__(*args, directory=DIRECTORY, **kwargs) | |
| def do_POST(self): | |
| self.send_response(200) | |
| content_length = int(self.headers['Content-Length']) | |
| post_body = self.rfile.read(content_length) | |
| self.end_headers() | |
| print('user query', post_body) |
This file contains hidden or 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 http.server | |
| import socketserver | |
| from google_search import chatbot_query | |
| PORT = 8080 | |
| DIRECTORY = 'public' | |
| class Handler(http.server.SimpleHTTPRequestHandler): | |
| def __init__(self, *args, **kwargs): | |
| super().__init__(*args, directory=DIRECTORY, **kwargs) |