Skip to content

Instantly share code, notes, and snippets.

View mivanov's full-sized avatar

Mike Ivanov mivanov

View GitHub Profile
@mivanov
mivanov / scc-covid.sh
Created January 7, 2022 17:44
Santa Clara County COVID-19 cases
#!/bin/bash
# Prerequisites: curl, jq, termgraph
curl 'https://wabi-us-gov-virginia-api.analysis.usgovcloudapi.net/public/reports/querydata?synchronous=true' \
--data-raw '{"version":"1.0.0","queries":[{"Query":{"Commands":[{"SemanticQueryDataShapeCommand":{"Query":{"Version":2,"From":[{"Name":"c","Entity":"cases_date","Type":0}],"Select":[{"Column":{"Expression":{"SourceRef":{"Source":"c"}},"Property":"Date"},"Name":"cases_date.Date"},{"Aggregation":{"Expression":{"Column":{"Expression":{"SourceRef":{"Source":"c"}},"Property":"New_cases"}},"Function":0},"Name":"Sum(cases_date.New_cases)"},{"Aggregation":{"Expression":{"Column":{"Expression":{"SourceRef":{"Source":"c"}},"Property":"New_cases_7davg"}},"Function":0},"Name":"Sum(cases_date.New_cases_7davg)"}]},"Binding":{"Primary":{"Groupings":[{"Projections":[0,1,2]}]},"DataReduction":{"DataVolume":4,"Primary":{"Sample":{}}},"Version":1}}}]},"QueryId":""}],"cancelQueries":[],"modelId":344055}' \
--compressed | jq '.results[0].result.data.dsr.DS[0].PH[0].D
@mivanov
mivanov / pre-push
Created May 1, 2018 00:04
Git pre-push hook to prevent accidentally pushing to shared repo
#!/usr/bin/python
#
# Pre-push hook which aborts the push if it does not find current user's username in the remote path.
# To set up, copy into a folder of git hooks and mark as executable. To apply globally (starting with Git v2.9)
# use:
# git config --global core.hooksPath=/path/to/hooks
import sys
import getpass
@mivanov
mivanov / monitor.py
Created October 10, 2012 21:46
Quick site monitoring script
import pickle, os, sys, logging
from httplib import HTTPConnection, socket
from smtplib import SMTP
import pynotify
import time
pynotify.init("Monitoring")
def show_message(message):
n = pynotify.Notification("Status", message)
@mivanov
mivanov / Django shell.ipynb
Created September 6, 2012 17:19
IPython notebook that sets up a Django shell
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mivanov
mivanov / __init__.py
Created April 5, 2012 20:38 — forked from JasperVanDenBosch/fexpect.py
Fexpect module
from fexpect import expect, expecting, run, sudo
@mivanov
mivanov / gist:1138441
Created August 10, 2011 22:22
Convert latitude/longitude string in degrees to decimal
import re
def parse_lonlat(coord):
""" Pass in string in degrees like "( 24d37'55.25\"W, 73d42'10.75\"S)"
Returns decimal tuple (lon, lat)
"""
latlon_regex = r"\(\s*(\d+)d(\d+)'([\d.]+)\"([WE]),\s*(\d+)d(\d+)'([\d.]+)\"([NS])\s*\)"
m = re.match(latlon_regex, coord)
parts = m.groups()
lat = int(parts[0]) + float(parts[1]) / 60 + float(parts[2]) / 3600