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
/** | |
* Renders a template string based on positional and keyword arguments. | |
* Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals | |
* @example | |
* // returns 'YAY!' | |
* let t1Closure = template`${0}${1}${0}!`; | |
* t1Closure('Y', 'A'); | |
* @example | |
* // returns 'Hello World!' | |
* let t2Closure = template`${0} ${'foo'}!`; |
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
// This code snippet requires jQuery to be loaded onto the page. | |
/** | |
* Wraps jQuery's ajax implementation inside an ES6 Promise structure. | |
* Source: https://stackoverflow.com/questions/35135110/jquery-ajax-with-es6-promises | |
* @function ajax | |
* @param {object} options - The config to pass to the ajax call. | |
* @return {object} - A Promise object to complete an ajax call. | |
*/ | |
function ajax(options) { |
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
def saveToCSV(arrayDict): | |
filename = 'name.csv' #call your file something | |
with open(filename, 'w') as output_file: | |
fieldnames = [ 'key1', # fill this array with the names of your keys in your dict | |
'key2', | |
... | |
'keyn' | |
] | |
writer = csv.DictWriter(output_file, fieldnames=fieldnames) | |
writer.writeheader() |
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
/* | |
Basic web scraping example with node | |
Includes scape and SQL insert | |
Variant of guide found here: https://scotch.io/tutorials/scraping-the-web-with-node-js | |
Scrapes the title of Anchorman 2 and places it into SQL table | |
*/ | |
var express = require('express'); | |
var fs = require('fs'); | |
var request = require('request'); |
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
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ | |
var saveAs=saveAs||function(e){"use strict";if(typeof e==="undefined"||typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),o="download"in r,i=function(e){var t=new MouseEvent("click");e.dispatchEvent(t)},a=/constructor/i.test(e.HTMLElement),f=/CriOS\/[\d]+/.test(navigator.userAgent),u=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},d="application/octet-stream",s=1e3*40,c=function(e){var t=function(){if(typeof e==="string"){n().revokeObjectURL(e)}else{e.remove()}};setTimeout(t,s)},l=function(e,t,n){t=[].concat(t);var r=t.length;while(r--){var o=e["on"+t[r]];if(typeof o==="function"){try{o.call(e,n||e)}catch(i){u(i)}}}},p=function(e){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)){return new Blob([String.fromCharCode(65279 |
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
/* | |
Code snippet for vanilla cross-browser height and width gathering | |
*/ | |
function getPageSize() { | |
return { | |
height: Math.max(document.documentElement.clientHeight, window.innerHeight || 0), | |
width: Math.max(document.documentElement.clientWidth, window.innerWidth || 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 datetime import datetime | |
""" | |
@function updateLog | |
Adds a line to the .log file with a timestamp | |
@param {str} text: The line to add | |
@kwarg {int} [level]: The intendenation level of the line, default=0 | |
""" | |
def updateLog(text, **kwargs): | |
if 'level' in kwargs: |
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 sys | |
""" | |
@type dict | |
A dictionary containing data for the spinning line character output | |
@property {str} count: The amount of time, the spinner has spun | |
@property {List} chars: The list of characters to cycle through in order to simulate spinning | |
@constant | |
""" | |
spinner = {'count':0,'chars':['|','/','-','\\']} |
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 pickle | |
""" | |
@function save | |
Saves the saveData global variable into a pickle file | |
""" | |
def save(): | |
global saveData | |
with open('filename.pickle','wb') as f: | |
pickle.dump(saveData, f) |
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 geopy.geocoders import Nominatim | |
from geopy.exc import GeocoderServiceError, GeocoderTimedOut | |
""" | |
@function getZipCode | |
Finds the zip code given a Cincinnati, OH address | |
@param {str} addressStreet: The address to find the zip code of | |
@return {str}: The zip code or an empty string if no zip code is found. | |
""" | |
def getZipCode(addressStreet): |