Does exist any BoltDB Ruby gem binding? - ruby

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 :)

Related

Simple pagination in redis using ohm ruby library

Hi guys I am trying to learn the sinatra framework and would like to use it as the backend for simple web services. I am also attempting to get my hands dirty with no-sequel solutions and for some reasons decided to learn to work with redis. As for the ruby library to be used I have selected Ohm since it seems like a minimal, no fuss library that I could easily use.
However, looking around and researching, I cannot find sample implementation where there is pagination for Ohm. I have also read a bit and redis and I know that you can specify ranges in the query. The question is, how do I use this with the Ohm ruby library?
Any help or any guide would be greatly appreciated.
Last time I wanted that combination I found this here: https://github.com/sinefunc/pagination
Otherwise use https://github.com/mislav/will_paginate whcih will not work with ohm though but you can use datamapper with redis.
If you want to use mongodb you could use mongomapper which has pagination built in but then that is a completely different situation.

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 to parse AMF data in 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.

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.

Ruby support for XML namespaces

I work at a small company and our production system uses a hand-rolled RESTful API, implemented in Java with JAXB. We now find that we're taking on customers who use Ruby on Rails, and I have to come up with a reference implementation to show customers how to use our API in Ruby. I'd love to be able to just tell them to use ActiveResource, but the XML required by our API uses (and absolutely requires) namespaces. Unfortunately, we've already got a number of other customers who've already integrated this API, so removing the usage of namespaces is out of the question. What's the best way to generate XML with namespaces in Ruby ?
"Best" obviously depends on your needs.
The fastest way to generate any XML in ruby is to use libxml-ruby - link to rdoc.
If your server gets any kind of load at all, this will be the way to go.
The easiest way to generate any XML in ruby is to use REXML as it's part of the standard library and therefore it "just works". If your XML generation is something that hardly ever gets used, it's probably easier to just go with rexml.
Both support XML namespaces - check the rdocs to find out how to set and get namespaces
I find myself in almost an identical situation as yours (RESTful API done with JAXB w/ namespaces).
I think the most promising project for working with XML in Ruby is HappyMapper. It is a kind of XML binding library (along the lines of an early JAXB-type implementation). It has been gaining a lot of traction recently, and a few of us have been working on providing good namespace support.
The project resides here:
http://happymapper.rubyforge.org/
with the source here:
http://github.com/jnunemaker/happymapper/tree/master
The project currently doesn't support creation of XML from Ruby Objects, and the original author has expressed no desire to provide that support, but I'll be committing some functionality for that in my fork:
http://github.com/jimmyz/happymapper/tree/master
Hope this helps.
--
Jimmy Zimmerman

Resources