Skip to content

Instantly share code, notes, and snippets.

View labocho's full-sized avatar

labocho

View GitHub Profile
@labocho
labocho / bundle-grep
Last active November 28, 2017 02:55
grep for all gems in Gemfile.lock
#!/usr/bin/env ruby
# Usage: bundle-grep -E "^foo"
require "bundler"
lockfile = Bundler::LockfileParser.new(File.read("Gemfile.lock"))
gem_paths = lockfile.specs.map{|lazy_spec| lazy_spec.__materialize__.full_gem_path }
command = ["find", *gem_paths, "-type", "f"].shelljoin + " | " +
["xargs", "grep", *ARGV].shelljoin
exec(command)
@labocho
labocho / bravura.html
Created March 8, 2018 05:56
Display musical symbol with Bravura web font
<!doctype html>
<meta charset="utf-8">
<!-- Please download Bravura font from https://www.smufl.org/fonts/ -->
<style>
@font-face {
font-family: "BravuraText";
src: url(BravuraText.woff);
}
.bravura {
font-family: "BravuraText";
@labocho
labocho / sort_articulation.rb
Last active March 28, 2018 12:22
Sort articulations in MuseScore .mscx file (for better playback accent (sforzato) + staccato note)
require "nokogiri"
# > (sforzato) より . (staccato) のがあとにないと音価が変わらないので sort
doc = Nokogiri.parse(ARGF.read)
doc.css("Chord").each do |chord|
sorted = chord.css("Articulation").map(&:dup).sort_by{|a| a.css("subtype").text }
chord.css("Articulation").each do |e|
e.remove
end
@labocho
labocho / inkdrop2textbundle
Created July 19, 2018 07:21
Convert Inkdrop backup file to TextBundle for importing to Bear
#!/usr/bin/env ruby
# Convert Inkdrop backup files (.json) to TextBundle v2 (.textbundle).for importing to Bear
# Usage: inkdrop2textbundle note:*.json
require "json"
require "tmpdir"
require "fileutils"
require "base64"
def inkdrop_to_textbundle(src)
@labocho
labocho / remove-blank-pages
Created July 27, 2018 02:55
Removing first blank pages from PDFs
#!/usr/bin/env ruby
# Removing first blank pages from PDFs.
# Usage: remove-blank-pages [path/to/pdf...]
# Requirements:
# identify (ImageMagick: https://www.imagemagick.org/)
# cpdf (Coherent PDF Tools: https://www.coherentpdf.com/)
require "open3"
require "tmpdir"
require "shellwords"
@labocho
labocho / sort_rubocop.rb
Last active August 27, 2018 07:12
Sort keys in .rubocop.yml (with comments)
#!/usr/bin/env ruby
# sort .rubocop.yml (with comments)
file = ARGV.first
cops = []
yaml = File.read(file)
lines = []
previous_indent = 0
@labocho
labocho / sh.rb
Created November 5, 2018 05:22
`sh` method to execute command
require "open3"
def sh(*args)
o, e, s = Open3.capture3(*args)
unless s.success?
$stderr.puts e
exit s.to_i
end
o
end
@labocho
labocho / q264to264.rb
Created November 9, 2018 02:16
Convert QVR Pro Playback API response (with gop_mode=1) to .264 file.
#!/usr/bin/env ruby
# Convert QVR Pro Playback API response (with gop_mode=1) to .264 file.
# Usage: ./q264to264 in.q264 > out.264
def assert(cond)
raise unless cond
end
def i32(f)
f.read(4).unpack("I<")[0]
# Requirements: poppler (for pdfinfo)
require "open3"
require "shellwords"
require "optparse"
PRINTER_NAME = "Officejet_7610_series"
def sh(*args)
$stderr.puts(args.first + " " + args[1..-1].shelljoin)
o, e, s = Open3.capture3(*args)
@labocho
labocho / ff_on_apple_music.md
Last active October 26, 2023 09:16
Apple Music にある Final Fantasy シリーズのサウンドトラック等