Promise.all
stops execution if any of the Promises have an uncaught error.
async function wait(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
My general strategy for testing is to separate out pure from non-pure functions.
All programs need a main function which should have the context needed to run the program as it's expected to run. This code can be tested using integration tests, but can't be unit tested. It is ideal to keep this function small, using external configuration if possible.
Pure functions don't need any tricks to test correctly. Just give them data, and they'll do their thing. This code should be where the business logic resides.
Non-pure functions are necessary for performing IO tasks or for doing something which varies (getting the current day of the week for instance). These functions can sometimes be tested with integration tests, other times not. The idea is to keep the code inside these functions extremely small so that it can be easily verified with a quick glance. These functions shouldn't contain branching logic, loops, or anything of the sort.
It is ideal to perform all of the needed IO with non-pure functio
# jq is a dependency and ChromeDriver needs to be running | |
# Create a headless Chrome session and save the sessionId to variable SID | |
SID=$(curl -X POST -d '{"desiredCapabilities":{"browserName":"chrome","chromeOptions":{"args":["--headless"]}}}' http://localhost:9515/session | jq -r '.sessionId') | |
echo "Session ID: $SID" | |
# Point session to a webpage | |
curl -X POST -d '{"url":"http://localhost:8080"}' "http://localhost:9515/session/$SID/url" | |
# Fetch an element using the xpath selector and save the elementId to ELEM | |
ELEM=$(curl -X POST -d '{"using": "xpath", "value": "//a[contains(.,'"'"'CSV format (.csv)'"'"')]"}' "http://localhost:9515/session/$SID/elements" | jq -r '.value[0].ELEMENT') | |
# Get the href attribute |
package main | |
// Dockerfiles build faster when Docker caches the result of your RUN commands. But, the | |
// resulting image can only be small if the the RUN commands are combined into only one | |
// RUN command. This script converts Dockerfiles with multiple RUN commands in a row in | |
// a single RUN command separated by "&& \". | |
// Use: Run the command while in the current directory to convert the Dockerfile there, | |
// or give it an optional folder path. |
package main | |
import ( | |
"fmt" | |
) | |
func checkPrime(i int, c chan int) { | |
prime := true | |
for j := 3; j < i/2; j += 2 { | |
if i%j == 0 { |
import exifread | |
import os | |
import pandas as pd | |
def convert_metatag_to_decimal(metatag_coordinate, direction_reference=None): | |
""" | |
Converts funky exif number format to float number | |
:param metatag_coordinate: Metatag coordinate (ie "[28, 120289/10000, 0]") | |
:param direction_reference: "N", "S", "E", or "W" |
from arcpy import CreateFeatureclass_management, os, da, ListFields, Describe | |
def project_better(in_dataset, out_dataset, spatial_reference): | |
# Script borrowed from http://joshwerts.com/blog/2015/09/10/arcpy-dot-project-in-memory-featureclass/ | |
# Can project a dataset and create the output in an 'in_memory' workspace | |
path, name = os.path.split(out_dataset) | |
CreateFeatureclass_management( | |
path, |
import location | |
import time | |
import datetime | |
location.start_updates() | |
loc = location.get_location() | |
last_loc = '{0},{1}\n'.format(loc['latitude'], loc['longitude']) | |
print(last_loc) | |
for seconds in range(1800): | |
loc = location.get_location() |
# | |
# CSV file must be in the format: Latitude,Longitude,datetime | |
# The third field is date time info from: datetime.datetime.utcnow() | |
# | |
from arcpy import Project_management, CreateFeatureclass_management, AddField_management, SpatialReference, da, Array,\ | |
Point, Polyline, GetParameterAsText, mapping, Describe, ListFields, MakeTableView_management, GetCount_management | |
import os | |
from datetime import datetime | |
from math import floor |