Skip to content

Instantly share code, notes, and snippets.

@tylerburdsall
tylerburdsall / random_iterator.cpp
Last active April 14, 2021 10:39
RandomIterator - A C++ iterator-like class that can generate random, unique, and evenly-distributed numbers with O(1) memory space
/* RandomIterator - (c) Tyler Burdsall 2018
*
* A C++ class that can generate random, unique, and evenly-distributed
* numbers with O(1) memory space.
*/
#include <vector>
#include <random>
#include <iostream>
#include <stdexcept>
@tylerburdsall
tylerburdsall / asynchronous_example.py
Last active December 23, 2022 19:34
Example showing asynchronous HTTP request with Python 3.5.0 + asyncio
import requests
import asyncio
from concurrent.futures import ThreadPoolExecutor
from timeit import default_timer
START_TIME = default_timer()
def fetch(session, csv):
base_url = "https://people.sc.fsu.edu/~jburkardt/data/csv/"
with session.get(base_url + csv) as response:
@tylerburdsall
tylerburdsall / synchronous_example.py
Last active October 31, 2018 20:15
Example showing synchronous HTTP requests with Python 3.5.0
import requests
from timeit import default_timer
def fetch(session, csv):
base_url = "https://people.sc.fsu.edu/~jburkardt/data/csv/"
with session.get(base_url + csv) as response:
data = response.text
if response.status_code != 200:
print("FAILURE::{0}".format(url))
# Return .csv data for future consumption
from urllib.request import urlopen
from bs4 import BeautifulSoup
# add new modules
import textwrap
import texttable as tt
website = 'https://saltandstraw.com/flavors/'
page = urlopen(website)
soup = BeautifulSoup(page, 'html.parser')
results = soup.find('section', attrs={'class':'content-area clear portland'}).findAll('div', attrs={'class':'entry-title'})
from urllib.request import urlopen
from bs4 import BeautifulSoup
website = 'https://saltandstraw.com/flavors/'
page = urlopen(website)
soup = BeautifulSoup(page, 'html.parser')
results = soup.find('section', attrs={'class':'content-area clear portland'}).findAll('div', attrs={'class':'entry-title'})
flavors = []
for title in results:
from urllib.request import urlopen
from bs4 import BeautifulSoup
website = 'https://saltandstraw.com/flavors/'
page = urlopen(website)
soup = BeautifulSoup(page, 'html.parser')
results = soup.find('section', attrs={'class':'content-area clear portland'}).findAll('div', attrs={'class':'entry-title'})
flavors = []
for title in results:
from urllib.request import urlopen
from bs4 import BeautifulSoup
website = 'https://saltandstraw.com/flavors/'
page = urlopen(website)
soup = BeautifulSoup(page, 'html.parser')
results = soup.findAll('div', attrs={'class':'entry-title'})
for title in results:
from urllib.request import urlopen
from bs4 import BeautifulSoup
website = 'https://saltandstraw.com/flavors/'
page = urlopen(website)
soup = BeautifulSoup(page, 'html.parser')
results = soup.find('section', attrs={'class':'content-area clear portland'}.findAll('div', attrs={'class':'entry-title'})
flavors = [] # new code
from urllib.request import urlopen
from bs4 import BeautifulSoup
website = 'https://saltandstraw.com/flavors/'
page = urlopen(website)
soup = BeautifulSoup(page, 'html.parser')
results = soup.find('section', attrs={'class':'content-area clear portland'}).findAll('div', attrs={'class':'entry-title'})
flavors = []
@tylerburdsall
tylerburdsall / initial_test.py
Last active September 6, 2017 19:23
Initial search
from urllib.request import urlopen
from bs4 import BeautifulSoup
website = 'https://saltandstraw.com/flavors/'
page = urlopen(website)
soup = BeautifulSoup(page, 'html.parser')
results = soup.findAll('div', attrs={'class':'entry-title'})
for title in results: