Skip to content

Instantly share code, notes, and snippets.

View brizandrew's full-sized avatar

Andrew Briz brizandrew

View GitHub Profile
@brizandrew
brizandrew / template.js
Created July 11, 2017 21:59
Renders a template string based on positional and keyword arguments.
/**
* 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'}!`;
@brizandrew
brizandrew / ajaxPromise.js
Created July 11, 2017 20:25
Wraps jQuery's ajax implementation inside an ES6 Promise structure.
// 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) {
@brizandrew
brizandrew / arrayDict2Csv.py
Created March 24, 2017 19:52
Saving An Array of Python Dictionaries to a CSV file
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()
@brizandrew
brizandrew / nodeScraping.js
Created December 6, 2016 21:12
Basic web scraping example with node
/*
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');
@brizandrew
brizandrew / saveFile.js
Last active October 25, 2016 21:35
A quick function to use eligrey's FileSaver. See gist for that git repo url.
/*! @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
/*
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)
}
}
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:
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':['|','/','-','\\']}
@brizandrew
brizandrew / save.py
Created August 5, 2016 19:46
Series of functions to handle save files
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)
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):