Skip to content

Instantly share code, notes, and snippets.

View aflansburg's full-sized avatar
🔧

Abe Flansburg aflansburg

🔧
View GitHub Profile
@aflansburg
aflansburg / README
Last active September 4, 2015 15:41 — forked from leandrosilva/README
Parsing Syslog files with Python and PyParsing
$ 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 September 7, 2017 04:01
Provided a number of days, pretty print a date range in MMDDYYYY format.
// 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 September 12, 2017 20:22
Just playing with HTML parsing
<?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 September 27, 2017 03:57
Object Composition
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 October 11, 2017 15:44
RC strip img uri from full url
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 October 18, 2017 03:55
Update multiple images using CSV file and custom uri parser (specific application)
// 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 October 20, 2017 21:45
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
aflansburg / amzreader.py
Created October 24, 2017 17:44
Scrape an Amazon page for the bullet points
# 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 / gsheet-edit-stamp.js
Created October 31, 2017 16:27
Timestamp and user stamp last update on a google sheet
function timestampIt(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0]; // this will assign the first sheet
var cell = sheet.getRange('A1');
var d = new Date();
d.setHours(d.getHours() +1);
var user = Session.getActiveUser().getUserLoginId();
user = String(user);
user = user.replace('@gmail.com', '');
cell.setValue('Last updated: ' + d.toLocaleString() + ' by ' + user);
@aflansburg
aflansburg / amzreviewscrape.py
Created November 2, 2017 02:42
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 = '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)