Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
# ~*~ encoding: utf-8 ~*~
"""
make random drink for ben
"""
import random
from collections import Counter
MAX_PARTS = 10
@ellisvalentiner
ellisvalentiner / download-goes.jl
Created March 26, 2018 02:11
Download GOES-R imagery
url = "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/FD/GEOCOLOR/1808x1808.jpg"
while true
download(url, "images/$(now()).jpg")
sleep(54000)
end
@ellisvalentiner
ellisvalentiner / install-python-3.sh
Created February 17, 2018 15:58
Install script for Python 3 on Raspbian
#!/usr/local/bin/bash
# sudo apt-get -y update && sudo apt-get upgrade
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
tar xf Python-3.6.4.tar.xz
cd Python-3.6.4
./configure
make
sudo make altinstall
sudo rm -rf Python-3.6.4.tar.xz
using Distributions
using Requests
function main()
while true
result = speedtest()
out = """$(result["timestamp"]),$(result["serverinfo"]["city"]),$(result["serverinfo"]["ip"][1]),$(result["serverinfo"]["fqdn"]),$(result["serverinfo"]["site"]),$(result["upload"]),$(result["download"])\n""";
f = open("/home/pi/speedresults.csv", "a")
write(f, out)
close(f)
@ellisvalentiner
ellisvalentiner / install_julia.sh
Created November 6, 2017 02:05
Script to build Julia on Raspberry Pi
#!/usr/bin/env bash
# XXX - for making newly created files/directories less restrictive
umask 0022
# colors
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
RESET="\033[0m"
@ellisvalentiner
ellisvalentiner / Installer Log 22-Oct-2017.log
Created October 22, 2017 18:07
High Sierra install fail
Oct 22 16:59:33 localhost opendirectoryd[183]: opendirectoryd (build 483.100) launched - installer mode
Oct 22 16:59:33 localhost opendirectoryd[183]: [default] Failed to open file <private> [2: No such file or directory]
Oct 22 16:59:34 localhost opendirectoryd[183]: [default] Initialize trigger support
Oct 22 16:59:34 localhost opendirectoryd[183]: [default] Failed to open file <private> [2: No such file or directory]
Oct 22 16:59:34 localhost opendirectoryd[183]: [default] Failed to open file <private> [2: No such file or directory]
Oct 22 16:59:34 localhost opendirectoryd[183]: [default] created endpoint for mach service 'com.apple.private.opendirectoryd.rpc'
Oct 22 16:59:34 localhost opendirectoryd[183]: [session] Registered RPC over XPC 'reset_cache' for service 'com.apple.private.opendirectoryd.rpc'
Oct 22 16:59:34 localhost opendirectoryd[183]: [session] Registered RPC over XPC 'reset_statistics' for service 'com.apple.private.opendirectoryd.rpc'
Oct 22 16:59:34 localhost opendirectoryd[183]: [session
@ellisvalentiner
ellisvalentiner / bulk-insert.py
Last active January 10, 2023 19:03
Recipe for (fast) bulk insert from python Pandas DataFrame to Postgres database
#!/usr/bin/env/python
import psycopg2
import os
from io import StringIO
import pandas as pd
# Get a database connection
dsn = os.environ.get('DB_DSN') # Use ENV vars: keep it secret, keep it safe
conn = psycopg2.connect(dsn)
library(purrr)
library(dplyr)
library(tidyr)
deps <- readLines("~/Desktop/deps.txt")
df <- deps %>%
map(strsplit, split=": ") %>%
flatten %>% map_if(~length(.x) == 1L, ~c(.x, NA)) %>%
do.call(rbind.data.frame, .)
colnames(df) <- c("pkg", "dep")
@ellisvalentiner
ellisvalentiner / read_dir.R
Created February 6, 2017 20:09
Read all CSV files in a directory and return as a tibble. (Who knows how this might fail)
library(tidyverse)
all_df <- list.files("./data", full.names = TRUE) %>%
map_df(., read_csv)
#!/usr/bin/env bash
# Notes:
# - tsort requires as input a stream of pairs (a, b) where package a depends
# on package b. If package a has k > 1 dependencies, we should have k lines
# associated to it; if package a has no dependencies, then we should have a
# single line (a, a). The pairs are just space delimited, no parentheses.
# the little awk program below formats the data that way for tsort.
# - tsort outputs the order from bottom to top; that's why we need to reverse
# it with tail -r.