Skip to content

Instantly share code, notes, and snippets.

View commondatageek's full-sized avatar

Aaron Johnson commondatageek

View GitHub Profile
@commondatageek
commondatageek / ggplot_eps.R
Created July 1, 2014 17:48
Save a file in EPS format
### Hey, Alison, here's how you save a ggplot graph in EPS format.
# Load the ggplot library
library(ggplot2)
# Need some data. We'll just make it up for now
obs = data.frame(
user=factor(c("A", "B", "C", "D")),
count=c(1, 2, 3, 4),
money=c(0.12, 3.45, 6.78, 9.10))
@commondatageek
commondatageek / while_let.clj
Last active October 13, 2015 19:02
while-let: Keep looping while let bindings are truthy
(defmacro while-let
"While all bindings are truthy, execute body. Useful for draining
channels, buffers, anything that can be read, etc."
[bindings & body]
(let [pairs (partition 2 bindings)
test-exprs (map second pairs)
test-vals (map first pairs)]
`(loop ~bindings
(if (and ~@test-vals)
(do
;;; collection utilities
(defn multi-filter
"Perform multiple filter operations in one function call."
[fns coll]
(reduce (fn [remaining filter-fn]
(filter filter-fn remaining))
coll
fns))
;;; reflection utilities
@commondatageek
commondatageek / bokeh_hist_bad_stack.py
Created August 17, 2016 15:05
It appears that the Histogram chart in Bokeh will incorrectly stack bars when the range of the distribution is small.
import numpy as np
import bokeh.charts as ch
from bokeh.plotting import output_notebook, show
output_notebook()
p = ch.Histogram(data=np.random.uniform(low=0.55, high=0.65, size=1000))
show(p)
setxkbmap -option ctrl:nocaps
@commondatageek
commondatageek / fast_row_count.sql
Created May 7, 2017 01:26
Fast count rows in postgresql
-- from Erwin Brandstetter
-- http://stackoverflow.com/a/7945274/852196
SELECT reltuples::bigint AS estimate
FROM pg_class
WHERE oid = 'myschema.mytable'::regclass;
-- see running queries
select * from pg_stat_activity;
-- Find the process you want to kill, then type:
select pg_cancel_backend(<pid of the process>)
@commondatageek
commondatageek / boot-mode.sh
Created May 15, 2017 17:52
Ubuntu toggle between text and graphical boot modes
# From https://askubuntu.com/a/870226
# Tested on Ubuntu 17.04 on 2017-05-15
# To boot Ubuntu Desktop without X one time, add systemd.unit=multi-user.target to the linux command line in GRUB.
# To make this the default, use:
sudo systemctl set-default multi-user.target
# To return to default booting into X, use:
sudo systemctl set-default graphical.target