How to parse AMF data in Ruby? - ruby

So I see that there are a few Rails plugins for serving AMF. However, is there a library that I can use in a Ruby environment to act as an AMF client: to read AMF data, and deserialize it into a Ruby object?
If not, how could I best go about using tools built in other languages? I suppose I could write something in Python or Java or whatever, and call it from Ruby directly via backticks... but I'd first like to ensure that there isn't really any better option.
Thanks!

Rocket-amf is what you're looking for. It support serialization and deserialization of AMF0 and AMF3 data directly into native ruby objects.

Related

Does exist any BoltDB Ruby gem binding?

Bolt is an amazing embedded key/value database for Go:
https://www.progville.com/go/bolt-embedded-db-golang/
https://github.com/boltdb/bolt
There is any binding (gem) for Ruby language ?
It shouldn't be a driver for any language rather than Go because as you say it's embedded e.i. it works like a Go library that just do data manipulation over a file.
What I know for sure there's HTTP or other network protocols wrappers on top of BoltDB, for example: https://github.com/skyec/boltdb-server and even with Raft: https://github.com/hashicorp/raft-boltdb. As you may see it's pretty easy create your own network layer, I've been thinking in do my own.
Maybe this's not your answer, but it's too big for a comment :)

How to store Configatron persistently, after Ruby app has run

I'm pretty new to Ruby (though not to programming) and am trying to create a persistent config. Though I thought using Configatron would automatically make my config persistent, it does not seem to be the case. How would I make this persistent throughout multiple runs? Should I store this to a file? If so, how? I would think a ~/.myapp file might be good?
Persistence in Rails
If you're using Ruby on Rails, you need to modify your initializers for this gem:
app/config/configatron/defaults.rb
app/config/configatron/{development,test,production}.rb
Persistence Without Rails
Ruby Modules
If you're using Ruby itself, rather than the Rails framework, then you need to persist your configuration as a Ruby module (e.g. require "my_configuration") or serialize the Configatron class if it can serialized. It looks like the goal of the gem is to avoid serialization, so requiring a module that contains your configuration as executable code seems to be the canonical approach for this gem.
Serialization
I don't use this gem myself, so you'll have to experiment with serializers to see if they work for your use case. For serialization, I'd recommend using one of:
YAML::Store
PStore
Marshal
However, if you're using serialization to save and load your configuration, I'm not entirely sure why you'd need this gem in the first place. Your mileage may certainly vary.

data driven development framework with Ruby

Does anybody know a good data driven development framework/library/gem for Ruby? I know a ton for Rails but I couldn't find anything for Ruby itself. I have a standalone Ruby app and I want to generate test data and write test cases for different data sets. I don't want to use fixtures. Any suggestions?
You mean something like machinist? The readme mentions it can work without Rails.

Confused about Thrift, what does it really do?

Can someone explain to me what thrift really does?
Say i have a Rails app, and I also have some code written in Scala.
Could thrift be used to generate an interface for my Scala code so that I could call it from Ruby?
Would the Scala code have to be written as a daemon for this to work?
I'm not really sure what Thrift's job is, other than it is used to link between various languages. Does it communicate over a socket?
Thrift is simply a binary serialization protocol. It is cross-language, so you can serialize in Scala, and then unserialize in Ruby.
Then you have to move the data, that's another story. You can use files, play directly with sockets, use a server, etc.
So how is this used for cross-platform development? Still not getting it!
Your Ruby and Scala code can reside on different machines running completely different OSes.

How can i use RAW Sockets in Ruby?

I'm trying to create a raw socket using Ruby.
The problem is, there isn't anything called "raw socket" there and, on the other hand, the Socket class itself is not fully documented.
Does anybody have some code samples for that kind of socket in Ruby, or maybe some kind of a documentation for that?
By the way, I already know how to work with TCPSocket and TCPServer classes, and what I need is particularly a raw socket.
Google brings up the following result: http://www.ruby-forum.com/topic/90408
Short version:
require 'socket'
rsock = Socket.open(Socket::PF_INET, Socket::SOCK_RAW, Socket::IPPROTO_RAW)
rsock.send(string, flags)
rsock.recv(1024)
More documentation on the various Socket classes: http://www.rubycentral.com/pickaxe/lib_network.html
(The whole raw sockets thing is rather nasty on unices since it usually requires root access. I did not test this code. You may need to construct the whole packet yourself if you're not using IPSocket)
Have a look at the racket gem (https://rubygems.org/gems/racket). It seems to be a bit outdated since the last version was released in 2009 but its also used in the metasploit framework.
Have a look at PacketFu. It is very well maintained and used by the Metasploit Project.

Resources