Skip to content

Instantly share code, notes, and snippets.

View benfasoli's full-sized avatar

Ben Fasoli benfasoli

View GitHub Profile
@benfasoli
benfasoli / serial_onoff.ino
Last active April 11, 2016 16:37
Use arduino digital pins to interface with the outside world.
// Arduino digital pin serial control
// Ben Fasoli
//
// Takes input strings over a standard serial connection and sets
// digital pins high/low.
//
// Input:
// Set pin# to 0,1 (LOW, HIGH)
// [pin#].[0,1]\n
// 2.1\n
@benfasoli
benfasoli / air_1.ino
Last active May 2, 2016 17:45
Arduino based handheld spatial meteorological and CO2 analysis platform.
// Air sensor 1
// Ben Fasoli
//
// Arduino based platform to measure temperature, relative humidity,
// pressure, CO2, and PM.
// Libraries
#include <dht.h>
#include <Adafruit_BMP085.h>
#include <Adafruit_GPS.h>
@benfasoli
benfasoli / valve_timing.py
Last active July 13, 2016 14:41
Raspberry Pi based timed valve controller.
#!/usr/bin/python
# Ben Fasoli
import datetime
import RPi.GPIO as GPIO
from time import sleep
std_pins = [11, 13, 15, 29]
qc_pins = [11, 13, 15, 31, 33]
all_pins = [11, 13, 15, 29, 31, 33]
t = datetime.datetime.utcnow()
@benfasoli
benfasoli / stay_online.py
Last active May 22, 2017 15:18
Force change linux network interface status if unable to make an outgoing connection
#!/usr/bin/python
# Ben Fasoli
# Maintain an internet connection by monitoring outgoing requests to google's
# dns server (8.8.8.8)
import os
from time import sleep
def ping(host = '8.8.8.8'):
print('Attempting outgoing connection')
@benfasoli
benfasoli / api.py
Last active October 26, 2017 20:49
Sync local database with remote CR1000 over TCP/IP
from flask import Flask, request, redirect
import requests
app = Flask(__name__)
@app.route('/fetch_cr1000', methods=['GET'])
def fetch_cr1000():
try:
ip = request.args.get('ip')
table = request.args.get('table')
@benfasoli
benfasoli / regression-coefficient-uncertainty.r
Last active January 5, 2018 05:02
Methods for confidence estimation for regression coefficients
# Ben Fasoli
rm(list = ls())
library(gtrendsR)
library(tidyverse)
# Get google trend data for searches for skis and ski boots
query <- c('skis', 'ski boots')
trend <- gtrends(query, geo = 'US', time = 'all')
trend_ts <- trend$interest_over_time %>%
@benfasoli
benfasoli / crop-raster-to-polygon.r
Last active January 11, 2018 03:02
Crop raster to complex polygon
library(raster)
library(rgdal)
# Load footprint from file into rasterBrick object
path_to_footprint_nc <- './footprint.nc'
footprint <- brick(path_to_footprint_nc)
# Sum values per-cell into raster object
r_all <- sum(footprint)
@benfasoli
benfasoli / map-raster-to-google-terrain.r
Last active January 25, 2018 20:45
Overlay partial transparency gridded raster to grayscale Google Map terrain layer
library(ggmap)
library(tidyverse)
# Fetch SLC-centric grayscale Google Map terrain layer
basemap <- get_googlemap(center = c(lon = -112.0, lat = 40.6), zoom = 10,
scale = 2, maptype = 'terrain', color = 'bw')
# Display downloaded map
ggmap(basemap)
<form action="https://formspree.io/info@wwtrek.com" method="POST">
<input type="text" name="name" placeholder="Name">
<input type="email" name="_replyto" placeholder="Email Address">
<textarea name="message" placeholder="Message"></textarea>
<input type="submit" value="Send">
</form>
@benfasoli
benfasoli / wait_for_slurm.r
Created May 16, 2018 21:50
Wait for rslurm::slurm_apply to complete
# Ben Fasoli
# Wait for rslurm::slurm_apply to complete
library(rslurm)
fun <- function(x) {
Sys.sleep(x)
return(T)
}