Nov. 7th, 2011

henry_flower: A melancholy wolf (Default)
This shit drives me crazy: https://github.com/rubygems/rubygems/issues/104
Every time I type 'gem rdoc blah-blah' I want to whack someone.

Or

# gem doc --no-ri activesupport
[several pages of rdoc warnings about itself]
Installing RDoc documentation for activesupport-3.1.1...
ERROR: While generating documentation for activesupport-3.1.1
... MESSAGE: error generating ActiveSupport/Inflector.html: incompatible encoding regexp match (UTF-8 regexp with KOI8-U string) (Encoding::CompatibilityError)
... RDOC args: --op /usr/local/lib/ruby/gems/1.9/doc/activesupport-3.1.1/rdoc lib --title activesupport-3.1.1 Documentation --quiet

Permalink: https://plus.google.com/115290581164606462017/posts/4DY8wpGQBK8

henry_flower: A melancholy wolf (Default)
Какой же я все-таки идиот. Надо мне было при генерации файлов из темплейтов генерировать штук 10-30 нечто типа uuid (по одному на каждый файл), но чтобы не трогать uuidgen(1), потому шо мозга нет этож икспенсив!

И я написал такое:

...
def self.uuidgen_fake
loop {
r = '%08X_%04X_%04X_%04X_%12X' % [
rand(0x0000100000000),
rand(0x0000000010000),
rand(0x0000000010000),
rand(0x0000000010000),
rand(0x1000000000000)
]
return r if r[0] !~ /\d/
}
end

Но вдруг, совершенно неожиданно, uuidgen_fake начала возвращать строчки типа B44928EB_8371_4765_D5BD_ 9795B456176 (пробел перед последним блоком).

Ыыы.

uuidgen(1) все таки опять решил не трогать. Поменял на:

require 'securerandom'
...
def self.uuidgen_fake
loop {
r = ('%s_%s_%s_%s_%s' % [
SecureRandom.hex(4),
SecureRandom.hex(2),
SecureRandom.hex(2),
SecureRandom.hex(2),
SecureRandom.hex(6),
]).upcase
return r if r[0] !~ /\d/
}
end

В 1.9.3 вроде работает. Правда, не очень быстро. 1536 штук генерирует за 0.46 с.
Comments:
  1. Nihad Abbasov, 2011-11-24T18:37:26.875Z

    а почему не SecureRandom.uuid?

  2. Henry Flower, 2011-11-24T18:53:03.293Z

    ггг, потому, что поленился посмотреть в securerandom.rb. спасибо за наводку.

    (впрочем, мне все равно нужен был такой uid чтобы годился как лексема сишного препроцессора.)


Permalink: https://plus.google.com/115290581164606462017/posts/YtP9HumccMY