Skip to content

Instantly share code, notes, and snippets.

@Coro365
Coro365 / find_duplicate_songs.rb
Last active July 20, 2019 11:59
Display the duplicate rows in the first column of the specified public Google Spread Sheet
# 指定したパブリックな Google Spread Sheet の1列目の値が重複した行を表示します
gss_url = "https://docs.google.com/spreadsheets/d/1iq_4d5ECOO6p5c3zJJg_mUMBNTPWbUzxGTxrNwGh8zs/htmlview?usp=sharing&sle=true"
def download_ggs(gss_url)
gss_html = `curl -# #{gss_url}`
ptt = /<div class="row-header-wrapper" style="line-height: 20px;">(\d*?)<\/div><\/th><td class.*?>(.*?)<\/td>/
ggs = gss_html.scan(ptt)
end
id_and_song = download_ggs(gss_url)
@Coro365
Coro365 / chapter-for-youtube-setlist.rb
Created September 1, 2019 18:54
Generate chapter.ini file for youtube comment setlist
# How to
# Meke video file and comment file and video length
# ex. ~/video.mp4 and ~/video.txt
# Run `ruby chapter-for-youtube-setlist.rb 1:23:23 video.txt`
# Generated ~/video.ini
# Run `ffmpeg -i ふろうふしのうた-Zw4bukluYcI.mp4 -i ふろうふしのうた-Zw4bukluYcI.ini -map_metadata 1 -c copy /ふろうふしのうた-Zw4bukluYcI-add-cap.mp4`
def to_ms(time)
t = time.split(":").map { |e| e.to_i }
s, m, h = t.reverse
@Coro365
Coro365 / cue-for-youtube-setlist.rb
Last active September 1, 2019 18:55
Generate cue file for youtube comment setlist
# How to
# Meke audio file and comment file
# ex. ~/audio.wav and ~/audio.txt
# Run `ruby cue-for-youtube-setlist.rb artist_name audio.wav`
# Generated ~/audio.cue
def to_index(time)
t = time.split(":").map { |e| e.to_i }
s, m, h = t.reverse
m = h * 60 + m if h
@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 / aterm-router-reboot.sh
Created December 2, 2019 06:36
Reboot aterm router (ATERM-DD3B55)
#!/bin/sh
# @(#) Reboot aterm router.
# @(#) shell script version: 20191202
# @(#) Test router is ATERM-DD3B55 (FW: 1.8.56)
user=YOUR_USERNAME
pass=YOUR_PASSWORD
domain=http://192.168.0.1
path=index.cgi/reboot_main_set
@Coro365
Coro365 / 2019_ncov_json.rb
Created February 6, 2020 00:01
Json format for 2019-nCoV from Google Spread Sheets
# 2019_ncov_json.rb create json format for 2019-nCoV from Google Spread Sheets
# Thanks
# https://docs.google.com/spreadsheets/d/1wQVypefm946ch4XDp37uZ-wartW4V7ILdg-qYiDXUHM/htmlview?usp=sharing&sle=true
# https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6
require 'open-uri'
require 'json'
require 'pp'
module GoogleSpreadSheet
@Coro365
Coro365 / README.md
Last active March 7, 2020 17:08
Show current weather icon.

Usage example DarkSky and Skycon

Show current weather icon.

Data Flow

  1. DarkSky API
  2. post_darksky_to_influxdb.rb
  3. influxdb
  4. current_weather.html

Usage

@Coro365
Coro365 / hatena-fotolife-donwloder.rb
Created March 15, 2020 02:50
Download photos from f.hatena.ne.jp
require 'open-uri'
require 'fileutils'
def set_username
return ARGV[0] if ARGV[0]
raise('Specify the user name in the argument.')
end
def get_photo_urls
@Coro365
Coro365 / add_margin_for_square.rb
Last active March 28, 2020 12:47
Adding margins to an image to make it square. (ImageMagick)
def add_margin_for_square
images = get_files_from_ARGV
images.each_with_index do |file, i|
puts("[#{i}/#{images.size}]\t#{file}")
size = get_width_hight(file)
margin = margin(size)
if margin.first.zero?
puts("#{file} is square")
# TODO: create file-squre.jpg
@Coro365
Coro365 / add_filename.rb
Created March 28, 2020 12:49
Add a file name to images.(ImageMagick)
def get_files_from_ARGV(recursive: true)
files = ARGV.map do |path|
path = File.expand_path(path)
if File.directory?(path)
if recursive
Dir.glob(File.join(path, '**', '*'))
else
Dir.glob(File.join(path, '*'))
end