Skip to content

Instantly share code, notes, and snippets.

View alanbernstein's full-sized avatar

Alan Bernstein alanbernstein

View GitHub Profile
@alanbernstein
alanbernstein / benford.py
Created January 24, 2021 20:19
charts for benford blog post
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np
tableau20 = [(31, 119, 180), (174, 199, 232), (255, 127, 14), (255, 187, 120),
(44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150),
(148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148),
(227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199),
(188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)]
@alanbernstein
alanbernstein / jqurl
Created January 14, 2021 21:51
curl+jq have a baby
#!/bin/bash
# make an http request via curl
# try to decode it as json with jq
# if it works, pretty print the json
# if it doesn't, ugly print the response
F1="$HOME/tmp.curl"
F2="$HOME/tmp.jq"
curl -s $1 > $F1
@alanbernstein
alanbernstein / psch
Created February 4, 2020 19:10
Pilosa SCHema printer
#!/bin/bash
# psch # show full schema (indented json)
# psch -i # show indexnames
# psch -f # show indexnames and fieldnames
# psch indexname # show schema for specified index (table)
# psch -t # show full schema (table)
DATADIR="$HOME/.pilosa"
SCHEMA=$(curl -s localhost:10101/schema)
indexnames=$(echo "$SCHEMA" | jq -r .indexes[].name)
package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"github.com/olekukonko/tablewriter"
@alanbernstein
alanbernstein / config.md
Created September 7, 2018 17:25 — forked from 0xDE57/config.md
Firefox about:config privacy settings

ABOUT

about:config settings to harden the Firefox browser. Privacy and performance enhancements.
To change these settings type 'about:config' in the url bar. Then search the setting you would like to change and modify the value. Some settings may break certain websites from functioning and rendering normally. Some settings may also make firefox unstable.

I am not liable for any damages/loss of data.

Not all these changes are necessary and will be dependent upon your usage and hardware. Do some research on settings if you don't understand what they do. These settings are best combined with your standard privacy extensions (HTTPS Everywhere, NoScript/Request Policy, uBlock origin, agent spoofing, Privacy Badger etc), and all plugins set to "Ask To Activate".

@alanbernstein
alanbernstein / main.go
Last active August 1, 2018 15:57
pilosa menu bar example
package main
import (
"fmt"
"io/ioutil"
"time"
"github.com/getlantern/systray"
"github.com/skratchdot/open-golang/open"
"github.com/sqweek/dialog"
"""
simple tool for performing perspective correction
useful for "flattening" internet photos of things that i want to print or cut
"""
import os
import cv2
import numpy as np
def correct_image(fin, fout, pin, pout, dim=None, show=True):
function [t1 t2] = estimatePerspectiveTransform(x,y,X,Y)
% given two planar quadrilaterals, compute a perspective transformation
% that maps the first onto the second
%
% useful, for example, for inverting the perspective transformation that an
% image undergoes when photographed. this function is based on a simplified
% model of the perspective transformation that maps quadrilaterals on an
% arbitrary, unspecified plane in world-space, to the plane in image-space.
% simplified, relative to a full estimate of camera position, orientation,
% view angle, etc etc. it simply determines a transformation that maps one
@alanbernstein
alanbernstein / wunder_history.py
Created July 15, 2017 04:35
collect and cache historical wunderground data as json files
import os
import json
import requests
import time
from datetime import datetime as dt
from datetime import timedelta
CACHE_BASE = os.getenv('CACHE') # output directory
import re
import os
import requests
from time import sleep
from amazon.api import AmazonAPI
from canistreamit import search, streaming
# from bs4 import BeautifulSoup
# python-amazon-simple-product-api==2.1.0