Skip to content

Instantly share code, notes, and snippets.

Avatar
🔧

Abe Flansburg aflansburg

🔧
View GitHub Profile
@aflansburg
aflansburg / README
Last active Sep 4, 2015 — forked from leandrosilva/README
Parsing Syslog files with Python and PyParsing
View README
$ python xlogd.py sample.log
parsed: {'appname': 'test.app', 'timestamp': '2012-09-06 15:19:32', 'hostname': 'codezone.local', 'pid': '68898', 'priority': '132', 'message': 'bla bla bla warn'}
parsed: {'appname': 'test.app', '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
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
console.log(printDateRange(365));
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
aflansburg / parsing.php
Created Sep 12, 2017
Just playing with HTML parsing
View parsing.php
<?php
$html = '
<!DOCTYPE html>
<html>
<head>
<title><?=$title?></title>
</head>
<body>
<p id="thisP">Some stuff here to parse! ABCDEFGHIJKLMNOPQRSTUVWXYZ</p>
@aflansburg
aflansburg / tshirtobj.js
Last active Sep 27, 2017
Object Composition
View tshirtobj.js
const Item = function(name, cost){
this.name = name;
this.isTopLevel = true;
this.baseCost = cost;
this.attributes = [];
this.totalCost = function(){
let total = this.baseCost;
this.attributes.map(x=>{
total += x.cost;
})
@aflansburg
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
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 = 'https://api.ebay.com/ws/api.dll';
@aflansburg
aflansburg / wordcounts.py
Created Oct 20, 2017
Reads a CSV column, writes words and their counts to new CSV
View wordcounts.py
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
aflansburg / amzreader.py
Created Oct 24, 2017
Scrape an Amazon page for the bullet points
View amzreader.py
# This involves some manual work depending on the type and category of an item
# See below !! CATEGORY / ITEM SPECIFIC INFO !!
import requests
from bs4 import BeautifulSoup as BS
# !! CATEGORY / ITEM SPECIFIC INFO
# 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
aflansburg / amzreviewscrape.py
Created Nov 2, 2017
Scrape an Amazon product review IFrame (returned from the Product Advertising API for a particular ASIN)
View amzreviewscrape.py
from selenium import webdriver
# Python 3.6.3
# hold on to your butts
driver_path = '/usr/local/bin/chromedriver'
url = 'https://www.amazon.com/reviews/iframe?akid=AKIAIOWAH2MM2J3QSNPA&alinkCode=xm2&asin=B006R7AW6M&atag=AssociateTag%3Dsomeutility-20&exp=2017-11-02T21%3A59%3A44Z&v=2&sig=ljBbKJxQiq%252F90us8lfn1uDQ7VmXr%252BDknLvJ49jIsaHU%253D'
try:
browser = webdriver.Chrome(executable_path=driver_path)
@aflansburg
aflansburg / check_imagelinks.py
Created Nov 17, 2017
Validating image links in Python with urllib
View check_imagelinks.py