Instantly share code, notes, and snippets.

View automation_bath.rb
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')"
View iTunes.sh
#!/bin/sh
# @(#) This script iTuunes play, pause, next track, back track and return state.
# @(#) Support macOS Mojave version.20181016
if [ -z "$1" ]; then
echo "Argument is missing!"
exit 1
elif [ "$1" == "play" ]; then
osascript -e 'tell application "iTunes" to play'
View screen.sh
#!/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
View image_trim.rb
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
View button.rb
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
View nas_status.sh
# 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/"`
View waifu2x.rb
require "ruby-progressbar"
require "shellwords"
require "find"
include Find
WAIF2X_CONVERTER_CPP_DIR = __dir__
WAIF2X_CONVERTER_CPP = WAIF2X_CONVERTER_CPP_DIR + "/waifu2x-converter-cpp"
def waifu2x
files = get_file_list(ARGV, ["jpeg","jpg"])
View animetick_counter.rb
require "pp"
require "open-uri"
require "nokogiri"
@userid = "Coro365"
@crawl_page_number = 26
@animetick_subscribes = Array.new
def animetick_crawl(page_number)
url = "http://animetick.net/users/#{@userid}?page=#{page_number}"
View auto_encode.rb
require 'fileutils'
require 'shellwords'
WD = File.dirname(File.expand_path(__FILE__))
TSDIR = "path"
MP4DIR = "path"
def recodeing? (ts)
s1 = File.size(ts)
sleep 1
View reg_rename.rb
require "find"
Dir[File.dirname(__FILE__) + "/com_lib/*.rb"].each {|file| require file}
def yesno?(ms = "")
blue "#{ms}\nPlease press y/n\n> "
i = STDIN.gets
if /^y$|^Y$|^yes$|^Yes$|^YES$/ =~ i
return true
elsif /^n$|^N$|^no$|^No$|^NO$/ =~ i