Skip to content

Instantly share code, notes, and snippets.

View achavez's full-sized avatar

Andrew Chavez achavez

View GitHub Profile
@achavez
achavez / gist:9767499
Created March 25, 2014 17:59
Post to Slack using javascript
var url = // Webhook URL
var text = // Text to post
$.ajax({
data: 'payload=' + JSON.stringify({
"text": text
}),
dataType: 'json',
processData: false,
type: 'POST',
url: url
@achavez
achavez / jou_scraper.py
Last active August 29, 2015 14:00
Scraper for schiefferschool.tcu.edu
from bs4 import BeautifulSoup
import requests, csv
# Settings
base_url = 'http://www.schiefferschool.tcu.edu/'
story_list_url = 'more_headlines.asp'
blacklist = ['931.htm', '1021.asp']
# Get a list of articles to scrape from the More Headlines page
news_page = requests.get(base_url + story_list_url)
@achavez
achavez / file_list.py
Last active August 29, 2015 14:07
Get all files in a directory with a specific file extension
import os
def list_files(source, extension):
matches = []
for root, dirnames, filenames in os.walk(source):
for filename in filenames:
if filename.endswith((extension)):
print filename
# Ex: Get all files in the directory docs with the extension PDF
@achavez
achavez / travis-elex-formatter.py
Last active August 29, 2015 14:08
Travis County precinct-by-precinct results parser
import csv, sys
# This is a quick and dirty solution to walk the file that Travis County distributes
# the day after the election and create a new .csv file that has one row per race
# per precinct with the winner and his/her/its vote percentage
#
# CLI usage: python travis-elex-formatter.py input_file.csv output_file.csv
last_field = None
winner_total_votes = 0
@achavez
achavez / window-downloader.sh
Created February 2, 2015 22:19
Download all Texas expenditures from comptroller
#!/bin/bash
###########################################
# Download full year files and unzip them #
###########################################
year_files=(
"2009"
"2010"
"2011"

Keybase proof

I hereby claim:

  • I am achavez on github.
  • I am achavez (https://keybase.io/achavez) on keybase.
  • I have a public key whose fingerprint is A204 9AB3 2FFD A454 14B0 3200 0329 8791 5060 3499

To claim this, I am signing this object:

@achavez
achavez / tocsv.sh
Created October 8, 2015 14:14
Convert a folder of Excel files to CSVs
#!/usr/bin/env bash
which xlsx2csv || pip install xlsx2csv
for file in *.xlsx
do
echo "Converting $file"
xlsx2csv --ignoreempty --date="%Y-%m-%d" "$file" "$file.csv"
done
@achavez
achavez / README.md
Last active October 15, 2015 16:34
Download fire maps from USDA Forest Services on an interval
  1. Install requests: pip install requests
  2. Set the INTERVAL
  3. Create the output directory mkdir maps
  4. python main.py
@achavez
achavez / README.md
Last active July 11, 2019 14:52
Development machine setup

Prerequisites

  1. Run all of the OS updates that are available
  2. Install Homebrew and tap the casks we'll need (brew tap homebrew/cask-fonts, brew tap homebrew/cask-versions)

Shell setup

  • install ZSH - brew install zsh
  • set ZSH as the default shell by 1) adding the output of which zsh to /etc/shells and 2) changing the default shell with chsh -s $(which zsh)
  • add autocompletion to ZSH brew install zsh-autosuggestions (be sure to follow the instructions output by brew to update your ~/.zshrc)
  • later, after installing Node install a cool command prompt like spaceship (more here) - npm install -g spaceship-prompt
@achavez
achavez / __init__.py
Last active May 3, 2016 17:26
Python class method call logger
import inspect
import datetime
class ClassToLog(object):
pass
def logging_decorator(fn, fn_name):
def logging_method(*args, **kwargs):