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 / tunnel
Last active April 6, 2021 21:57
MacOS SOCKS tunnel
#!/bin/bash
# SOCKS proxy via ssh tunnel for MacOS
# Install to /usr/local/bin/tunnel with:
# curl https://gist.githubusercontent.com/benfasoli/543c14c90a4909e0305180bd8423969e/raw/ > /usr/local/bin/tunnel && chmod +x /usr/local/bin/tunnel
TARGET=$1
if [ -z "$TARGET" ]; then
echo -n "SSH target (e.g. name@server.com): "
read TARGET
fi
@benfasoli
benfasoli / WaveTrend.ts
Last active May 15, 2020 13:10
thinkorswim WaveTrend Oscillator
# Ben Fasoli
# Last updated: 12/21/2016
#
# Ported from LazyBear's Pine script port
# https://www.tradingview.com/u/LazyBear/
#
# For an introduction, watch
# https://www.youtube.com/watch?v=7vhIsk51_Ro
# https://www.youtube.com/watch?v=MqJ1czF220M
@benfasoli
benfasoli / read_grimm.py
Last active July 9, 2019 17:20
GRIMM 1.109 data logging interface
#!/usr/bin/python
# GRIMM data collection script
# Ben Fasoli
import serial as ser # serial port use
import datetime # time stamps (UTC)
import re # regular expression matching
# Path to serial device ID
serialpath = '/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0'
@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)