Skip to content

Instantly share code, notes, and snippets.

View starbuck93's full-sized avatar
:bowtie:

Adam Starbuck starbuck93

:bowtie:
View GitHub Profile
@starbuck93
starbuck93 / get_pi_zero_stock.php
Created December 31, 2015 00:48
Gets the Raspberry Pi Zero stock from Adafruit and returns json data to use at endpoints like this: {"stock":"0"}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.adafruit.com/products/2885"); //https://www.adafruit.com/products/2817
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
$find = '<meta name="twitter:data2" content="';
$find2 = '">';
$outOfStock = "OUT OF STOCK";
@starbuck93
starbuck93 / index.php
Last active March 22, 2016 07:02
echos the single DS18B20 on your linux system as a REST string. if you have two, see my other gists
<?php
$command = "find /sys/bus/w1/devices -name '28-*'";
$path = exec($command);
$fullpath = $path . "/w1_slave";
$filename1 = $fullpath;
$handle1 = fopen($filename1, "r") or die("Unable to open file!");
$myString1 = fread($handle1,filesize($filename1));
fclose($handle1);
$tempC1 = ((float) substr($myString1, strpos($myString1,"t=")+2))/1000;
$tempF1 = ($tempC1*(9.0 / 5.0)) + 32.0;
#LAMP server and web apps setup for host [servername]
#Rob Byrd
#created January 29, 2014 for hosted VM on Rackspace using Ubuntu 14.04 as OS
#updated January 15, 2016
# ************************ Pre LAMP setup ************************
#IMPORTANT** search this file and replace "abc12a" with your server non-root username
# and replace "123.123.123.123" with your server IP address
#also change the email addresses to your own
#!/bin/bash
DISKAVAILABLE=$(df / | awk '{ a = $3 } END { print a }');
DISKUSED=$(df / | awk '{ a = $2 } END { print a }');
DISKTOTAL=$((DISKAVAILABLE+DISKUSED));
DISKPERCENTUSED=$(df / | awk '{ a = $5 } END { print a }');
MEMUSE=$(free -m | head -n 2 | tail -n 1 | awk {'print $3'});
MEMTOTAL=$(free -m | head -n 2 | tail -n 1 | awk {'print $2'});
SWAPUSE=$(free -m | head -n 3 | tail -n 1 | awk {'print $3'});
SWAPTOTAL=$(free -m | head -n 3 | tail -n 1 | awk {'print $2'});
# TODO - Execute curl command once per day via cron, cat file here
@starbuck93
starbuck93 / pihut_pi_zero_in_stock.js
Created March 1, 2016 21:38 — forked from MxAshUp/pihut_pi_zero_in_stock.js
Checks for Pi Zero availability on Adafruit, Pimoroni, and Pi Hut, sends alerts to Pushbullet
var requestjson = require('request-json');
var request = require('request');
var PushBullet = require('pushbullet');
var pusher = new PushBullet('PUSHBULLET_API_KEY');
var cheerio = require('cheerio');
var stores = [
{name:"The Pi Hut",url:'http://thepihut.com/products/raspberry-pi-zero',in_stock:check_pihut_inventory
},
{name:"Adafruit",url:'https://www.adafruit.com/products/2816',in_stock:check_adafruit_inventory
@starbuck93
starbuck93 / index.php
Created March 22, 2016 07:03
raspberry pi two ds18b20 temperature sensors
<?php
$paths = array();
$command = "find /sys/bus/w1/devices -name '28-*'";
exec($command,$paths);
$fullpath1 = $paths[0] . "/w1_slave";
$fullpath2 = $paths[1] . "/w1_slave";
$filename1 = $fullpath1;
$filename2 = $fullpath2;
//----- get first one -----//
$handle1 = fopen($filename1, "r") or die("Unable to open file!");
#!/bin/bash
# GUI-related packages
#pkgs="
#xserver-xorg-video-fbdev
#xserver-xorg xinit
#gstreamer1.0-x gstreamer1.0-omx gstreamer1.0-plugins-base
#gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-alsa
#gstreamer1.0-libav
#epiphany-browser
@starbuck93
starbuck93 / is_the_ac_running.py
Last active July 4, 2018 20:51
is the ac running based on if the temperature is rising or falling
import homeassistant.remote as remote
import time
import math
import sys
def updateState(previous,current):
settings = {"device_class": "cold", "friendly_name": "Is the AC Running"}
if previous.state != current.state and math.fabs(float(previous.state)-float(current.state)) > .2: #if the absolute value delta is between 0 and 0.2 then we don't want to update the state to prevent false positives
if previous.state > current.state: #air temp is falling
print(":: ",current.state,"AC is running")
@starbuck93
starbuck93 / index.php
Created August 14, 2018 14:31
Quick script to echo the CPU temperature in F and C of a Raspberry Pi Zero, in my case
<?php
$command = "cat /sys/class/thermal/thermal_zone0/temp";
$temp = exec($command);
$tempC1 = ((float) $temp)/1000;
$tempF1 = ($tempC1*(9.0 / 5.0)) + 32.0;
$str = '{"cpu_temperature_F":'.number_format($tempF1,2).',"cpu_temperature_C":'.number_format($tempC1,2).'}';
echo $str;
?>
@starbuck93
starbuck93 / main.py
Last active January 11, 2019 15:14
DoorLaser -- using a garage door laser beam to detect people walking through a doorway
#borrowed from https://www.hackster.io/hardikrathod/pir-motion-sensor-with-raspberry-pi-415c04
#and https://raspberrypihq.com/use-a-push-button-with-raspberry-pi-gpio/
import RPi.GPIO as GPIO
import time
#import sys
#from influxdb import InfluxDBClient
import requests
import automationhat