News for hackers. Stuff that matters.
Re:Pstore: Ruby Built-In Hash Persistence by e12e on Thursday September 22, 2022 @01:49PM (#32942308)
> use the Ox gem

The main thing is that it's part of the standard library. If you import a gem anyway, often you'd be well off with sqlite.

As for storage format, there's also:

https://ruby-doc.org/stdlib-3.1.2/libdoc/yaml/rdoc/YAML/Stor...

Re:Pstore: Ruby Built-In Hash Persistence by brunno on Thursday September 22, 2022 @03:15PM (#32943383)
I love the simplicity of YAML::Store. It was introduced in Ruby 1.8, almost 20 years ago (https://github.com/ruby/ruby/commit/55f4dc4c9a5345c28d0da750...).

I even created a little gem when I was starting with Ruby, 10 years ago, that was a very thin wrapper around it so that I could play around using an ActiveRecord like syntax (https://github.com/brunnogomes/active_yaml). I used in some pet projects so I could do stuff like:

  p = Post.new
  p.title = "Great post!"
  p.body = "Lorem ipsum..."
  p.save

  Post.all # => [#<Post:0x895bb38 @title="Great post!", @body="Lorem ipsum...", @id=1>]

  Post.find(1) # => #<Post:0x954bc69 @title="Great post!", @body="Lorem ipsum...", @id=1>

  Post.where(author: 'Brunno', visibility: 'public')
  # => [#<Post:0x895bb38 @author="Brunno", @visibility="public", @id=1>, #<Post:0x457pa36 @author="Brunno", @visibility="public", @id=2>]
And have access to the data directly in the YAML files.

Good times!

Re:Pstore: Ruby Built-In Hash Persistence by 3pt14159 on Thursday September 22, 2022 @05:04PM (#32944613)
The problem with YAML is that meaningful whitespace means that the size grows quickly for highly nested documents. I don't love XML, but there is a reason I recommended Ox. I've used it for real projects and it never fell over like so many of the alternatives I've tried where databases were not in the cards.
Re:Pstore: Ruby Built-In Hash Persistence by fny on Thursday September 22, 2022 @08:58PM (#32946654)
The problem with XML is that angle bracket expressions take up too much space because you need to duplicate element names. I don't love JSON, but there is a reason I recommend OJ.

...

The problem with JSON is that the keys take up too much space because they are duplicated. I don't love BSON, but there's a reason why I recommend bson-ruby.

And I could keep going... ;)

The benefit of using YAML is precisely that there's meaningful whitespace. Different strokes for different folks.

Re:Pstore: Ruby Built-In Hash Persistence by Fire-Dragon-DoL on Friday September 23, 2022 @12:11PM (#32953836)
I don't get the value of "it's in the standard library". Ruby has the amazing (fir scripts) require "bundler/inline" that allows you to use a single file for code and Gemfile, as well as auto installing the dependencies, so going for standard library doesn't seem to provide any practical value except offline support
Re:Pstore: Ruby Built-In Hash Persistence by e12e on Friday September 23, 2022 @06:59PM (#32958069)
I used pstore for an ad-hoc monitoring service on an outdated windows server running an outdated ruby version - it was easy to set it up to run from task scheduler every five minutes and check resident memory of an old ruby service - logging the ram, and killing/restarting it if it was over 1 GB (this all on 32bit ruby with the limits of 4gb address space per process).

Sure there are many things that "should" have been fixed above - but just having any old ruby version on hand was enough to help check for a memory leak and mitigate it - while taking the time to figure out if the leak could be plugged.

And offline support (a server in dmz/locked down wrt new software) is big too!