Zabbix3.2のグラフで日本語を表示する。(どうしてもだめな方へ)
デフォルトだと日本語のグラフがだめ。
raspi.ryo.sc
このへんでフォントいれるんだよーとか言われてやってみてもだめ。
結論
/usr/share/zabbix/include/graphs.inc.phpをいじれ。
function imageText($image, $fontsize, $angle, $x, $y, $color, $string) { mb_convert_variables("EUC-JP", "UTF-8", $string); // コレたせ。
以上です。
A Tour of Go むずい 2017/05/10
むずいわー。
Goつかいこなしたいわー
A Tour of Go むずい
むずい。辛くなってきた。
並行実装をを早くやりたい。
A Tour of Go "moretypes/26"
フィボナッチ実装に5分位かかってもう廃業しようかもと思った。
package main import "fmt" // fibonacci is a function that returns // a function that returns an int. func fibonacci() func() int { n := -1 fn := 0 fnP1 := 1 fnP2 := 0 return func() int { n += 1 if n == 0 { return 0 } else if n == 1 { return 1 } else { fnP2 = fn + fnP1 fn = fnP1 fnP1 = fnP2 return fnP2 } } } func main() { f := fibonacci() for i := 0; i < 10; i++ { fmt.Println(f()) } }
A Tour of Go "moretypes/23"
package main import ( "fmt" "golang.org/x/tour/wc" "strings" ) func WordCount(s string) map[string]int { fmt.Println(strings.Fields(s)) var m = map[string]int{} for _, v := range strings.Split(s, " ") { _, exist := m[v] if exist { m[v] += 1 } else { m[v] = 1 } } return m } func main() { wc.Test(WordCount) }
/usr/local/Cellar/go/1.8.1/libexec/bin/go run /Users/seijiro/Dropbox/code/GoglandProjects/first/10.go
[I am learning Go!]
PASS
f("I am learning Go!") =
map[string]int{"I":1, "am":1, "learning":1, "Go!":1}
[The quick brown fox jumped over the lazy dog.]
PASS
f("The quick brown fox jumped over the lazy dog.") =
map[string]int{"fox":1, "lazy":1, "dog.":1, "The":1, "quick":1, "brown":1, "jumped":1, "over":1, "the":1}
[I ate a donut. Then I ate another donut.]
PASS
f("I ate a donut. Then I ate another donut.") =
map[string]int{"another":1, "I":2, "ate":2, "a":1, "donut.":2, "Then":1}
[A man a plan a canal panama.]
PASS
f("A man a plan a canal panama.") =
map[string]int{"man":1, "a":2, "plan":1, "canal":1, "panama.":1, "A":1}
Process finished with exit code 0
XMLパースはPython速い。Ruby糞遅い。でもRubyにも希望はある。それはOx!
rubyでも試してみた。
結論
rubyは糞遅い。この差はやばいね。pure rubyだと100倍違う。nokogiriでも5秒かかるとか。
これだけ見るとrubyはもうダメだ、という結論になってしまうね。
<追記>
悔しいじゃないですかぁー。いろいろためしましたよー。
Oxというのが良いカンジ。用途によってはNokogiriより使いやすい。速い。libxmlに依存していないらしい。インストールも速い。
遅いPythonぐらいまでは来ている。Oxで良いじゃんとなる。
www.reddit.com
ライブラリを選ぶときは用途とかパフォーマンスを調べる必要がありますね。特に車輪の再開発が多いRubyでは。今回Oxというライブラリを初めて使い、今まではXMLパーサーはNokogiriしか考えたことなかったけど、ちょっと態度を改めるべきですね。っていうかNokogiriはインストールあんなに遅いし、よくインストール失敗するし、なんでRubyのデファクトスタンダードに居座っているのかしら?高機能なの?そんなみんな使いこなしているのかしら?
python
parse時間: 0.16052603721618652秒
rexml
parse時間: 16.04039192199707
nokogiri(Slop)
parse時間: 4.752880811691284
Ox
parse時間: 0.2525479793548584
おっと良いカンジ。
Oga
parse時間: 3.470038890838623
Oga(IO渡し)
parse時間: 3.2525930404663086
pure rubyのライブラリrexmlでのソース
#! /usr/bin/env ruby # coding: utf-8 # frozen_string_literal: true require 'rexml/document' class ImageInfo attr_accessor :url, :width, :height end class BookInfo attr_accessor :asin, :title, :binding, :author, :publisher, :publicationDate, :images def initialize @images = {} end end def get_text(dom, tag) if dom.elements[tag] dom.elements[tag].text else '' end end def parse_xmls(xmls) bookinfos = [] xmls.each do |xmlstring| doc = REXML::Document.new(xmlstring) image_labels = %w(SmallImage MediumImage LargeImage) doc.elements.each('ItemLookupResponse/Items/Item') do |item| bookinfo = BookInfo.new bookinfo.asin = item.elements['ASIN'].text attr = item.elements['ItemAttributes'] bookinfo.title = get_text(attr, 'Title') bookinfo.binding = get_text(attr, 'Binding') bookinfo.author = get_text(attr, 'Author') bookinfo.publisher = get_text(attr, 'Publisher') bookinfo.publicationDate = get_text(attr, 'PublicationDate') image_labels.each do |image_label| next unless item.elements[image_label] image = ImageInfo.new imgtag = item.elements[image_label] image.url = imgtag.elements['URL'].text image.width = imgtag.elements['Width'].text.to_i image.height = imgtag.elements['Height'].text.to_i bookinfo.images[image_label] = image end bookinfos << bookinfo end end bookinfos end def get_xmls xmls = [] Dir.glob('xmls/*.xml').each do |file| open(file, 'r') do |io| xmls << io.read end end xmls end xmls = get_xmls t = Time.now bookinfos = parse_xmls(xmls) duration = (Time.now.to_f - t.to_f) puts "xml数: #{xmls.size}" puts "book数: #{bookinfos.size}" puts "parse時間: #{duration}"
nokogiri
#! /usr/bin/env ruby # coding: utf-8 # frozen_string_literal: true # require 'rexml/document' require 'nokogiri' class ImageInfo attr_accessor :url, :width, :height end class BookInfo attr_accessor :asin, :title, :binding, :author, :publisher, :publicationDate, :images def initialize @images = {} end end def get_text(dom, tag) if dom.css(tag) dom.css(tag).text else '' end end def parse_xmls(xmls) bookinfos = [] xmls.each do |xmlstring| doc = Nokogiri::Slop(xmlstring) image_labels = %w[SmallImage MediumImage LargeImage] doc.css('Item').each do |item| bookinfo = BookInfo.new bookinfo.asin = item.css('ASIN').text attr = item.css('ItemAttributes') bookinfo.title = get_text(attr, 'Title') bookinfo.binding = get_text(attr, 'Binding') bookinfo.author = get_text(attr, 'Author') bookinfo.publisher = get_text(attr, 'Publisher') bookinfo.publicationDate = get_text(attr, 'PublicationDate') image_labels.each do |image_label| next unless item.css(image_label) image = ImageInfo.new imgtag = item.css(image_label) image.url = imgtag.css('URL').text image.width = imgtag.css('Width').text.to_i image.height = imgtag.css('Height').text.to_i bookinfo.images[image_label] = image end bookinfos << bookinfo end end bookinfos end def get_xmls xmls = [] Dir.glob('xmls/*.xml').each do |file| open(file, 'r') do |io| xmls << io.read end end xmls end xmls = get_xmls t = Time.now bookinfos = parse_xmls(xmls) duration = (Time.now.to_f - t.to_f) puts "xml数: #{xmls.size}" puts "book数: #{bookinfos.size}" puts "parse時間: #{duration}"
nokogiri(XML+追い込み)
#! /usr/bin/env ruby # coding: utf-8 # frozen_string_literal: false # require 'rexml/document' require 'nokogiri' class ImageInfo attr_accessor :url, :width, :height end class BookInfo attr_accessor :asin, :title, :binding, :author, :publisher, :publicationDate, :images def initialize @images = {} end end def get_text(dom, tag) if dom.css(tag).size.positive? dom.css(tag).text else '' end end def parse_xmls(xmls) bookinfos = [] xmls.each do |xmlstring| doc = Nokogiri::XML(xmlstring) image_labels = %w[SmallImage MediumImage LargeImage] doc.css('Item').each do |item| bookinfo = BookInfo.new bookinfo.asin = item.css('ASIN').text attr = item.css('ItemAttributes') bookinfo.title = get_text(attr, 'Title') bookinfo.binding = get_text(attr, 'Binding') bookinfo.author = get_text(attr, 'Author') bookinfo.publisher = get_text(attr, 'Publisher') bookinfo.publicationDate = get_text(attr, 'PublicationDate') image_labels.each do |image_label| next unless item.css(image_label).size.positive? image = ImageInfo.new imgtag = item.css(image_label)[0] image.url = imgtag.css('URL').text image.width = imgtag.css('Width').text.to_i image.height = imgtag.css('Height').text.to_i bookinfo.images[image_label] = image end bookinfos << bookinfo end end bookinfos end def get_xmls xmls = [] Dir.glob('xmls/*.xml').each do |file| open(file, 'r') do |io| xmls << io.read end end xmls end xmls = get_xmls t = Time.now bookinfos = parse_xmls(xmls) duration = (Time.now.to_f - t.to_f) puts "xml数: #{xmls.size}" puts "book数: #{bookinfos.size}" puts "parse時間: #{duration}"
Ox
#! /usr/bin/env ruby # coding: utf-8 # frozen_string_literal: false # require 'rexml/document' # require 'nokogiri' require 'ox' class ImageInfo attr_accessor :url, :width, :height end class BookInfo attr_accessor :asin, :title, :binding, :author, :publisher, :publicationDate, :images def initialize @images = {} end end def get_text(dom, tag) if dom.locate(tag).size.positive? dom.locate(tag)[0].text else '' end end def parse_xmls(xmls) bookinfos = [] xmls.each do |xmlstring| doc = Ox.parse(xmlstring) image_labels = %w[SmallImage MediumImage LargeImage] doc.locate('ItemLookupResponse/Items/Item').each do |item| bookinfo = BookInfo.new bookinfo.asin = item.ASIN.text attr = item.ItemAttributes bookinfo.title = get_text(attr, 'Title') bookinfo.binding = get_text(attr, 'Binding') bookinfo.author = get_text(attr, 'Author') bookinfo.publisher = get_text(attr, 'Publisher') bookinfo.publicationDate = get_text(attr, 'PublicationDate') image_labels.each do |image_label| next unless item.locate(image_label).size.positive? image = ImageInfo.new imgtag = item.locate(image_label)[0] image.url = imgtag.URL.text image.width = imgtag.Width.text.to_i image.height = imgtag.Height.text.to_i bookinfo.images[image_label] = image end bookinfos << bookinfo end end bookinfos end def get_xmls xmls = [] Dir.glob('xmls/*.xml').each do |file| open(file, 'r') do |io| xmls << io.read end end xmls end xmls = get_xmls t = Time.now bookinfos = parse_xmls(xmls) duration = (Time.now.to_f - t.to_f) puts "xml数: #{xmls.size}" puts "book数: #{bookinfos.size}" puts "parse時間: #{duration}"
oga
#! /usr/bin/env ruby # coding: utf-8 # frozen_string_literal: false # require 'rexml/document' # require 'nokogiri' # require 'ox' require 'oga' class ImageInfo attr_accessor :url, :width, :height end class BookInfo attr_accessor :asin, :title, :binding, :author, :publisher, :publicationDate, :images def initialize @images = {} end end def get_text(dom, tag) if dom.xpath(tag).size.positive? dom.xpath(tag)[0].text else '' end end def parse_xmls(xmls) bookinfos = [] xmls.each do |xmlstring| doc = Oga.parse_xml(xmlstring) image_labels = %w[SmallImage MediumImage LargeImage] doc.xpath('ItemLookupResponse/Items/Item').each do |item| bookinfo = BookInfo.new bookinfo.asin = item.xpath('ASIN').text bookinfo.title = get_text(item, 'ItemAttributes/Title') bookinfo.binding = get_text(item, 'ItemAttributes/Binding') bookinfo.author = get_text(item, 'ItemAttributes/Author') bookinfo.publisher = get_text(item, 'ItemAttributes/Publisher') bookinfo.publicationDate = get_text(item, 'ItemAttributes/PublicationDate') image_labels.each do |image_label| next unless item.xpath(image_label).size.positive? image = ImageInfo.new imgtag = item.xpath(image_label)[0] image.url = imgtag.xpath('URL').text image.width = imgtag.xpath('Width').text.to_i image.height = imgtag.xpath('Height').text.to_i bookinfo.images[image_label] = image end bookinfos << bookinfo end end bookinfos end def get_xmls xmls = [] Dir.glob('xmls/*.xml').each do |file| open(file, 'r') do |io| xmls << io.read end end xmls end xmls = get_xmls t = Time.now bookinfos = parse_xmls(xmls) duration = (Time.now.to_f - t.to_f) puts "xml数: #{xmls.size}" puts "book数: #{bookinfos.size}" puts "parse時間: #{duration}"
oga(IO渡し)
def get_xmls xmls = [] Dir.glob('xmls/*.xml').each do |file| xmls << open(file, 'r') end xmls end
バンドのデモ音源をpodcast配信することにした
新曲デモ追加しましたよーのメールとかめんどくさい。
指定ディレクトリ内のmp3ファイルから必要最低限のPodcast用RSSを生成する · GitHub
を参考にちょっと変えてpodcast配信することにしました。
バンド活動が多分ちょっと楽になる。
- 引数でフレキシブルに動く機能とかいらない。
- サブディレクトリにmp3が存在する状態だったので変更
- rubocop/ ruby2.3準拠
shで起動してcronで更新
#! /bin/bash export PATH="/home/hoge/.rvm/bin:$PATH" # Add RVM to PATH for scripting source /home/seijiro/.rvm/environments/ruby-2.3.0 cd /path/to/makepodcast/ ruby make_podcast.rb > /var/www/chiaki/demo.rss
まったく需要ないけど一応rssファイルのurl貼っておくー
https://lovesaemi.daemon.asia/chiaki/demo.rss