Skip to content

Instantly share code, notes, and snippets.

@Coro365
Coro365 / nas_status.sh
Created August 17, 2018 14:24
Send readynas cpu temperature, fan speed, disk temperature to influxdb
# initialize
INFLUXDBADRR="http://hostname.local:8086/write?db=server"
hostname=`hostname | tr '[:upper:]' '[:lower:]'`
cpu_name="Marvell\ Armada\ 370/XP"
fan_name="main\ fan"
# get cpu temperature and fan RPM
cpu_temp=`sensors | grep CPU | sed -r "s/CPU.*?\+([0-9\.]*?)°C/\1/" | sed -e "s/[ \t]*$//"`
fan_rpm=`sensors | grep System | sed -r "s/System.*?\s([0-9]+)\ RPM.*?$/\1/"`
@Coro365
Coro365 / button.rb
Last active November 5, 2018 12:23
Emit IR signal when button is pushed
require "influxdb"
require "open3"
READ_SW_1_PIN = 1
SW_1_PIN = 2
LED_1_PIN = 3
INFLUXDB_ADRR = "http://hostname.local:8086/write?db=home-sensor"
LOCATION = 3
@Coro365
Coro365 / image_trim.rb
Created November 5, 2018 07:28
Delete the lower 14 pixels of the image
path = ARGV[0]
Dir.glob("#{path}/*") do |file|
next unless file.index(/jpeg$|jpg$|png$/)
# get image pixel size
width, hight = `identify -format "%w %h" #{file}`.split(" ")
new_file = File.basename(file) + "-trimed" + File.extname(file)
# trim
@Coro365
Coro365 / screen.sh
Created November 5, 2018 14:14
This script will turn on / off the screen of the Mac or run the screen saver and return screen status
#!/bin/sh
# @(#) This script will turn on / off the screen of the Mac or run the screen saver.
# @(#) Argument:on, off, saver and display_status. Support macOS Mojave version.20181016
if [ -z "$1" ]; then
echo "Argument is missing!"
exit 1
elif [ "$1" == "on" ]; then
caffeinate -u -t 1
@Coro365
Coro365 / iTunes.sh
Last active November 16, 2019 11:49
This script iTunes(Music.app) play, pause, next track, back track and return state.
#!/bin/sh
# @(#) This script Music.app play, pause, next track, back track and return state.
# @(#) Support macOS Catalina version.20191116
if [ -z "$1" ]; then
echo "Argument is missing!"
exit 1
elif [ "$1" == "play" ]; then
music_run=`osascript -e 'application "Music" is running'`
@Coro365
Coro365 / automation_bath.rb
Last active November 8, 2018 12:30
Automatically operate the bath light and fan
require "influxdb"
def current_value(field,location,device="none")
host = 'hostname.local'
database = 'home-sensor'
influxdb = InfluxDB::Client.new database,:host => host
# query
result = influxdb.query "select value from #{field} where location='#{location}' order by desc limit 1 tz('Japan')"
@Coro365
Coro365 / light_brightness_and_color.rb
Last active February 16, 2019 16:13
Control of brightness and color temperature in 10 steps (https://www.instagram.com/p/Bt8dhKcAxaJ/)
def initialize_state
$color_state_file = "#{__dir__}/color_state_file"
$brightness_state_file = "#{__dir__}/brightness_state_file"
update_color_state(10) unless FileTest.exist?($color_state_file)
update_brightness_state(10) unless FileTest.exist?($brightness_state_file)
$color_state = File.read($color_state_file).to_i
$brightness_state = File.read($brightness_state_file).to_i
end
@Coro365
Coro365 / air_purifier.rb
Last active January 13, 2019 06:55
Control air purifier by servo motor (Panasonic F-VX501)
def initialize_state
$mode_state_file = "#{__dir__}/mode_state_file"
$power_state_file = "#{__dir__}/power_state_file"
update_mode_state(1) unless FileTest.exist?($mode_state_file)
update_power_state(1) unless FileTest.exist?($power_state_file)
$mode_state = File.read($mode_state_file).to_i
$power_state = File.read($power_state_file).to_i
$mode_name = ["low", "mid", "high", "auto"]
end
@Coro365
Coro365 / LGBZ6100.lircd.conf
Last active November 19, 2018 15:02
Lirc configuration file for operating Panasonic light (ex:LGBZ6100)
# Please take the time to finish this file as described in
# https://sourceforge.net/p/lirc-remotes/wiki/Checklist/
# and make it available to others by sending it to
# <lirc@bartelmus.de>
#
# This config file was automatically generated
# using lirc-0.9.4c(default) on Mon Jun 25 16:59:39 2018
# Command line used: -n -d /dev/lirc0
# Kernel version (uname -r): 4.14.42-v7+
@Coro365
Coro365 / PCF-C18.lircd.conf
Last active November 19, 2018 15:08
Lirc configuration file for operating IRIS OHYAMA Fan (PCF-C18)
# Please take the time to finish this file as described in
# https://sourceforge.net/p/lirc-remotes/wiki/Checklist/
# and make it available to others by sending it to
# <lirc@bartelmus.de>
#
# This config file was automatically generated
# using lirc-0.9.4c(default) on Sat Sep 8 00:33:03 2018
# Command line used: -n -d /dev/lirc0
# Kernel version (uname -r): 4.14.52-v7+