Skip to content

Instantly share code, notes, and snippets.


Abe Flansburg aflansburg

View GitHub Profile
aflansburg / README
Last active Sep 4, 2015 — forked from leandrosilva/README
Parsing Syslog files with Python and PyParsing
$ python sample.log
parsed: {'appname': '', 'timestamp': '2012-09-06 15:19:32', 'hostname': 'codezone.local', 'pid': '68898', 'priority': '132', 'message': 'bla bla bla warn'}
parsed: {'appname': '', 'timestamp': '2012-09-06 15:19:32', 'hostname': 'codezone.local', 'pid': '68902', 'priority': '131', 'message': 'bla bla bla error'}
parsed: {'appname': 'Dock', 'timestamp': '2012-09-06 15:19:32', 'hostname': 'codezone.local', 'pid': '154', 'priority': '11', 'message': 'CGSReleaseWindowList: called with 5 invalid window(s)'}
parsed: {'appname': 'WindowServer', 'timestamp': '2012-09-06 15:19:32', 'hostname': 'codezone.local', 'pid': '79', 'priority': '11', 'message': 'CGXSetWindowListAlpha: Invalid window 0'}
aflansburg / printDateRange.js
Last active Sep 7, 2017
Provided a number of days, pretty print a date range in MMDDYYYY format.
View printDateRange.js
// pretty print a date range MMDDYYYY
// argument is the number of days for the date range
function printDateRange(days){
let options = {timeZone: 'America/Chicago'} // set timeZone using IANA tz
let curr = new Date(), prev = new Date();
prev.setDate((prev.getDate() - days));
aflansburg / parsing.php
Created Sep 12, 2017
Just playing with HTML parsing
View parsing.php
$html = '
<!DOCTYPE html>
<p id="thisP">Some stuff here to parse! ABCDEFGHIJKLMNOPQRSTUVWXYZ</p>
aflansburg / tshirtobj.js
Last active Sep 27, 2017
Object Composition
View tshirtobj.js
const Item = function(name, cost){ = name;
this.isTopLevel = true;
this.baseCost = cost;
this.attributes = [];
this.totalCost = function(){
let total = this.baseCost;>{
total += x.cost;
aflansburg / imguri.js
Last active Oct 11, 2017
RC strip img uri from full url
View imguri.js
const regex = /^(.*product)\/cache.*(\/[a-z]\/[a-z]\/.*)/g;
let testUri = window.prompt('Input the full image url to be cleaned:');
let m;
let uriArr = [];
let cleanUri;
while ((m = regex.exec(testUri)) !== null) {
if (m.index === regex.lastIndex) {
aflansburg / imageupdate.js
Last active Oct 18, 2017
Update multiple images using CSV file and custom uri parser (specific application)
View imageupdate.js
// node v 8.5.0 (should work with earlier as long as regex available) & ES6
const axios = require('axios');
const fs = require('fs');
const parse = require('csv-parse');
const delimiter = ',';
const filename = 'update.csv';
const endpoint = '';
aflansburg /
Created Oct 20, 2017
Reads a CSV column, writes words and their counts to new CSV
import re, csv
import pandas as pd
from collections import Counter
from random import randint
csvfile = 'mycsvfile.csv'
# regex = r'\w+'
regex = r"\b[^\d\W]+\b" # this will get omit words containing numbers like 4WD or a part number 123ABCD
commonWords = ['a', 'with', 'the', 'and', 'set', 'foot', 'for', 'inch', 'on', 'models',
aflansburg /
Created Oct 24, 2017
Scrape an Amazon page for the bullet points
# This involves some manual work depending on the type and category of an item
import requests
from bs4 import BeautifulSoup as BS
# This function is for the list filter and is some information that unfortunately couldn't be exluded with Beautiful Soup
# (or I just couldn't figure it out)
aflansburg /
Created Nov 2, 2017
Scrape an Amazon product review IFrame (returned from the Product Advertising API for a particular ASIN)
from selenium import webdriver
# Python 3.6.3
# hold on to your butts
driver_path = '/usr/local/bin/chromedriver'
url = ''
browser = webdriver.Chrome(executable_path=driver_path)
aflansburg /
Created Nov 17, 2017
Validating image links in Python with urllib