Skip to content

Instantly share code, notes, and snippets.

View jimjeffers's full-sized avatar

Jim Jeffers jimjeffers

View GitHub Profile
const handleCompletedUploaded: HandleFileUploadFn = useCallback(async preview => {
const normalizedPreviews = mergePreviewsToState([{ ...preview, status: FileUploadStatus.Available }], localPreviews)
setLocalPreviews(normalizedPreviews)
await savePreviews(normalizedPreviews)
}, [mergePreviewsToState, localPreviews, setLocalPreviews])
const [localPreviews, setLocalPreviews] = useState({} as INormalizedPreviews)
const handleCompletedUploaded: HandleFileUploadFn = async preview => {
const normalizedPreviews = mergePreviewsToState([{ ...preview, status: FileUploadStatus.Available }], localPreviews)
setLocalPreviews(normalizedPreviews)
}
// Track a completed download and use an effect to update the status
// of the associated upload via the latest component state.
const [finishedDownload, setFinishedDownload] = useState(null as string | null)
useEffect(() => {
if (!finishedDownload) { return }
const updatedPreview = localPreviews[finishedDownload]
if (localPreviews[finishedDownload].status !== FileUploadStatus.Available) {
const normalizedPreviews = mergePreviewsToState([{ ...updatedPreview, status: FileUploadStatus.Available }], localPreviews)
setLocalPreviews(normalizedPreviews)
const save = async () => {
@jimjeffers
jimjeffers / forecasts.xml
Created February 21, 2018 17:58
Proposed forecast schema.
<?xml version="1.0" encoding="UTF-8"?>
<data>
<time>9:12 AM</time>
<forecaster>M. Graves</forecaster>
<discussion>This week will be winter-like in Yuma as cold air remains settled over the region; High temperatures will stay in the low-mid 60s. Normal for this time of year is 75 degrees F. The main day of interest this week is Friday, on which breezy winds out of the northwest are forecast. Blowing dust may be possible on Friday and therefore the PM-10 (dust) forecast has been bumped up into the Moderate Air Quality (AQI) category to reflect this. PM-10 may increase again on Sunday with breezy northerly winds as well. Ozone is forecast to stay in the Good AQI category through this forecast period. We'll keep an eye out for any changes in the wind forecast later this week.<br/><br/>Check back tomorrow for the next Yuma air quality forecast.</discussion>
<forecasts>
<forecast>
<date>2/21/2018</date>
<day>WED</day>
<aqivalue>46</aqivalue>
<body>
<svg id="map" xmlns:xlink="http://www.w3.org/1999/xlink" width="671" height="367">
<g>
<g id="states">
<a id="s01" class="<?php the_field('al_legal'); ?>" href="http://dispensarypermits.com/united-states-marijuana-dispensary-laws/open-a-dispensary-in-alabama/">
<path d="M446.5848460941517,216.26501324764592L464.81286038377675,214.2603543573807L468.10323765853497,225.08860445900154L472.8937074082319,241.00178951997543L474.61008720683344,244.42048722827803L476.0625626818386,246.29743631830007L475.76722830026273,247.62689856030931L477.10805089685584,248.22910918121545L475.5070201786913,250.09623188502263L475.7873316078113,251.70362228164615L475.13993857965056,254.0096380222493L476.7334995824955,257.72478632149034L476.4216558002466,261.1981977477231L478.0945121552954,264.54108080067283L472.72709714484995,265.33683005517673L449.7452897425235,268.119261782702L449.57058192002177,269.8466738984158L452.3066137029198,272.0345007925466L452.1205917477962,274.1896880002505L453.08275860861545,275.148983180
@jimjeffers
jimjeffers / Lookup.js
Last active July 22, 2017 15:47
Naive object look up.
const get = (target, path) => path.split(".").reduce((value, key) => value ? value[key] : value, target)
const a = {
b: {
c: {
d: "result!"
}
}
}
@jimjeffers
jimjeffers / async_completion.js
Last active July 13, 2017 18:31
Generator + Promises === Shared Async Completion
/**
All of the intervals which call the pollDate() function
after different time intervals will resolve with similar
qualifying times thanks to managed state in the *fetchDate()
generator function.
*/
function* fetchDate() {
var isFetching = false
var date = 0
/**
Solution to an interview question posted by trello. I came across the link
not actually looking for a job but I love puzzles. So I went ahead and solved
it :)
Decrypts a value hashed by the following Pseudo code:
Int64 hash (String s) {
Int64 h = 7
private class QueryDataTask extends AsyncTask<Void, Void, DataReadResult> {
@Override
protected void onPreExecute() {
super.onPreExecute();
Log.d(TAG, "Executing query task");
}
protected DataReadResult doInBackground(Void... params) {
Calendar date = new GregorianCalendar();
date.set(Calendar.HOUR_OF_DAY, 0);
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:237:19: No member named 'move' in namespace 'std::__1'
/Users/jim/Documents/Xcode/ReadiumTestApp/readium-sdk/Platform/Apple/RDServices/Main/RDNavigationElement.mm:31:9: In file included from /Users/jim/Documents/Xcode/ReadiumTestApp/readium-sdk/Platform/Apple/RDServices/Main/RDNavigationElement.mm:31:
/Users/jim/Documents/Xcode/ReadiumTestApp/readium-sdk/Platform/Apple/include/ePub3/nav_element.h:24:10: In file included from /Users/jim/Documents/Xcode/ReadiumTestApp/readium-sdk/Platform/Apple/include/ePub3/nav_element.h:24:
/Users/jim/Documents/Xcode/ReadiumTestApp/readium-sdk/Platform/Apple/include/ePub3/epub3.h:25:10: In file included from /Users/jim/Documents/Xcode/ReadiumTestApp/readium-sdk/Platform/Apple/include/ePub3/epub3.h:25:
/Users/jim/Documents/Xcode/ReadiumTestApp/readium-sdk/Platform/Apple/include/ePub3/utilities/basic.h:31:10: In file included from /Users/jim/Documents/Xcode/ReadiumTestApp/r