Calling a Haskell function from Ruby on Heroku - ruby

So I'd like to call a Haskell function from a Ruby app running on Heroku. I'm aware of Hubris, but it seems unlikely to work in the Heroku sandbox, so I'm thinking of automatically converting the Haskell code to Ruby. Unsurprisingly, there's no tool that will do this in one shot, but there appear to be a whole bunch of Haskell-to-X and Y-to-Ruby tools. Which would do the trick, or are there other solutions I'm missing?
And yes, I'm aware that any twice-generated code would be horribly obfuscated code spaghetti, and I'm OK with that as long as it works.

You might be able to use multi-buildpack to have an app that has both ruby and haskell. Multi-buildpack is a buildpack that allows you to compose several buildpacks into one. With this you could use both the official Heroku ruby buildpack (https://github.com/heroku/heroku-buildpack-ruby.git) and a 3rd party haskell buildpack.

Ruby and Haskell are have very different evaluation models. Unless you have a very compelling case, you'd be better off trying a different integration path.
Here is a talk from Haskell Exchange 2012 that talks about integrating haskell and ruby via ampq. https://skillsmatter.com/skillscasts/3637-integrating-haskell-using-amqp

Related

How to compile Ruby API into multiple client libraries

My team is currently creating an API that will interact with our core Ruby API.
The new API is for the public as the Ruby API is our private API. We want to be able to compile this new API into a PHP, Java, Python, etc., client libraries when we are ready to release.
Are there any gems, or other ways to write this new API so we can compile it into different client libraries?
There are several ways to think about exposing an API these days. If we're talking about creating a library in the sense of something compiled into other applications, that takes us down one path. If we're talking about providing, effectively, command line functionality callable from other contexts as system calls, that's another story. More broadly is the API is more of a service, like REST, that's different. I'll assume one of the first two.
There are several tools that will create a binary package for platforms. Look at ruby-tioolbox.com for some examples. None of these are compiling true executable code (as far as I know) but mainly provide an executable version of ruby with your code and dependencies packaged up. Perhaps the API appears callable as a system library (DLL for Windows, SO for UNIXy).
But either way, I would think you're dealing with ruby and your code loading and running as a separate process on each call. There's a library like this (not in Ruby) called ImageMagick, with a wrapper for ruby calls called MiniMagick that might be a pointer to the kind of pattern you're looking for.
If you want to run ruby and your app as a service, there are several tools for this -- this helps address the overhead of loading a process each time, and built into Ruby 1.9 is a Process class that daemonizes ruby, although presumably only on Unix. Check this SO answer
The best answer is probably that ruby, like other similar languages (e.g. Python) are really not designed to be low-level system libraries. There are likely many ways of accomplishing what you want in a given environment (notably Linux) ... but as far as I know nothing that really exposes executable codepoints to all languages.

Ruby GUI support on OSX Mavericks (Not Shoes or Ruby Motion) plus OSX app package support

This has been asked many times. Some of the answers are pretty old now. I have looked around everywhere for 2 things.This the last resort before I give up. Looking for:
Bindings that will enable GUI programming using Ruby (not Shoes) using Mavericks. I have found plenty bindings but with no activity for the past 3 or 4 years, with the exception of RubyMotion which seems very expensive while not taking advantage of Xcode features / does not have an IDE.
Way to package app for users as a regular OSX app so the user does not have to install anything by hand on OSX (if mutiplatform even better to target Windows too)
I have fallen in love with Ruby but without a means to tackle the above will be difficult to deploy for users, while I am not interested in Rails.
Feels like Rails popularity has in effect killed Ruby by putting it into a niche when it could be so much more.
Any new news on either of these 2 fronts or everything is abandoned / dead ?
Should I move on with Python / Objective-C ? (Which I like both but enjoy Ruby more)
I succesfully compiled scripts with tk, green shoes and gosu as a GUI to an executable with ocra but only have experience doing so on windows. If you want an actual, cross platform GUI try the java swing framework with jruby, here an example.
If you deploy a JAR or an executable nu further installations are needed.
I suppose you use MRI ruby now, the step to jruby is not so difficult.
require 'java'
# With the 'require' above, we can now refer to things that are part of the
# standard Java platform via their full paths.
frame = javax.swing.JFrame.new("Window") # Creating a Java JFrame
label = javax.swing.JLabel.new("Hello")
# We can transparently call Java methods on Java objects, just as if they were defined in Ruby.
frame.getContentPane.add(label) # Invoking the Java method 'getContentPane'.
frame.setDefaultCloseOperation(javax.swing.JFrame::EXIT_ON_CLOSE)
frame.pack
frame.setVisible(true)
RubyMotion is the best alternative. But if don't want to spend the money you should be able to use macruby.
Here are some resources
http://blog.phusion.nl/2010/03/12/creating-our-very-first-mac-application-with-ruby-how-exciting/
I must say that using macruby for a big project might not be a good idea. You should expect stuff breaking and few support. As of 2015, the [MacRuby page on GitHub][3] says that the project is in an indefinite hiatus due to the changes made by Apple in the Objective C garbage collection support that MacRuby depends on. They suggest using RubyMotion.
RubyMotion seems to be really good for what you want but for development the lack of a IDE is really a huge downside. Also from my experience rubymotion only comes handy if you already know the cocoa framework really well.
So my recommendation is for you to test rubymotion if you can. They give your money back in the first 30 days if you only want to try it out. So if you have the money give it a try.
If you are new to osx development and only want to develop for osx I think you should go with objective-c. The language is not that bad and you will get the best development environment available for it for free.

How reliable is JRuby?

I'm interested in promoting JRuby in our office as the platform hosting Rails applications.
But how reliable is it?
Is its performance better than MRI 1.8.7?
JRuby 1.5 states that it is 100% compatible with Ruby 1.8.7, does this mean that JRuby can run any Ruby/Rails code?
Yes, JRuby is reliable! Oracle uses JRuby for Oracle mix (http://mix.oracle.com/), Sun had used it for Kenai (http://kenai.com), and it's gonna be the next base for java.net (from kenai site: "Work is on-going for migrating the Java.net domain over to the Kenai infrastructure")!!
You can run almost every code, some gems uses native C extension and in JRuby there's a primitive support to it, but yes...rails just works.
You can deploy Rails apps in Application Servers like Tomcat or JBoss with Warbler that wraps Rails apps inside a .war file, it's pretty awesome!
update: you can see a lot of benchmarks here: http://programmingzen.com/2010/07/19/the-great-ruby-shootout-july-2010/
I am doing a lot of jruby work right now and can tell you that rails is certainly a viable option under the jruby interpreter. I've been pretty pleased and in my case have to use many native Java libraries, so jRuby is just such an awesome wrapper around that java code. I will say that I have had some technical challenges some that are worked out, some that are not yet.
unit testing: spooling up the jvm and then spooling up rails takes much longer, so your tests take longer to run - solution, potentially something like nailgun that keeps the jvm running
deployment: i have not gotten warbler to work for me, with my flavor of tomcat. this is a major issue for us.
pick your libraries, while some c extensions work, they are not all equally compatible.
if you are interested I would highly reccomend the jruby book, in beta, from Pragmantic Programmers at http://pragprog.com
JRuby rocks!! The simple reason being its portability features and integration with Java libraries. I personally use it with Netbeans and the fast debugger that comes with that seems very handly. Plus you do not want to see that native build errors and handling them. All these gems that you download for JRuby work 100% across any platform. With JRuby, you are simply bringing in the advantages of the Java's Platform independence.
Moreover, JRuby uses native threading which uses OS threads instead of Green threads as in CRuby (i think its not the case with the latest versions though)
In Gist, go JRuby!!
for windows I have found it to be much more stable than MRI when working with larger amounts of data. There are some bugs on windows still but they are actually work-around-able. Recommend.
Disclaimer: I don't use jruby in my day job - I merely experimented with running existing code using jruby.
It doesn't mean that it'll run all code successfully. For example, bioruby currently calls fork on jruby even though jruby doesn't really support it. (That's more of a bug in bioruby than a bug in jruby though)
I wouldn't call such behaviour "unreliable" though. It's fail-safe, like a plane that would not get off the ground, much less crash.

Can Ruby be used to develop simple Windows applications?

I've been developing Windows based applications for a long time and most of my present clients still desire a desktop or client/server Windows application. Is it possible to use Ruby for such applications as opposed to its primary purpose of being a Web-programming language?
Ruby is not primarily a web programming language even though Ruby on Rails is certainly suited for web development. Ruby is a general purpose scripting language.
The FXRuby and WxRuby frameworks are the most fully featured GUI frameworks for Ruby. You can write the apps in Ruby and then generate a Windows executable. The frameworks are cross-platform, so you could also run the apps written in these on other platforms, like Linux or Mac OS X.
There are also a few other less popular approaches like QtRuby and Shoes, and you can even use IronRuby (a CLR Ruby implementation) to write a .Net application.
Ruby is a general purpose object oriented scripting language. Ruby on Rails is a web application framework. Ruby predates Rails by about ten years. Don't confuse the two.
Yes, you can. Ruby is a full scripting language. You might want to start with the Ruby language homepage to see the capabilities and libraries that are available.
However, just because you can doesn't mean that you should. Before jumping in and using Ruby for a project, see if Ruby can give you things that other languages can't or if there are any disadvantages to using Ruby.
I know this thread is old, but for future reference to anyone who's looking into options for using Ruby for a GUI app, don't use QtRuby. I had developed a project for school in about a week, fully functional and pretty, only to find out that I could not release it. There was simply no way to package and distribute the application without having your users simulate your exact environment (install all the gem dependencies, build Qt development libraries etc). I tried using:
Crate: supposedly cross-platform, but I found only 1 usage example that's written in 2008 out of ~2 hours of googling, and the example basically covers a very specific subset of applications (some ssl/https authentication gem or w/e...)
Ocra: this looks like a candidate, but it's windows-only and didn't meet my requirements, as I had to target the three primary platforms
tar2rubyscript + rubyscript2exe: I had spent most of my time trying to get this to work because I've come across many who claimed that this is the way to go for distributing GUI apps built in ruby (albeit using other toolkits, Tk/GTK/wxRuby) but it didn't work either; I was endlessly faced with a cryptic error that basically breaks Qt::UiLoader functionality, in other words, you can't load .ui sheets you create with QtDesigner so...
Yes I'm angry and frustrated honestly, because I don't see the point of creating software that you just can't release for anyone to use. Now I'm left with a deadline coming up in a week, and I just hope I make it in time porting the app to C++.
So my answer is, don't use QtRuby. At least for now.
On a mac, you can use the Ruby Cocoa lib to create (what appear to be) native applications. If you want something more cross platform then you might consider a wrapper like shoes or qt.
The Qt toolkit seems the most popular way to do it. The website is http://www.darshancomputing.com/qt4-qtruby-tutorial/
I'm currently writing a little app in a wrapper called Shoes. This seems to make it as simple as pie to create windowed apps in ruby. http://shoes.heroku.com/ is the website.
At the moment Shoes looks suitable only for small personal apps. I say this because it's author recently went AWOL and it's not clear whether it will be developed further. I'm using it to write a game log parser to generate statistics from a flight sim. It's ticking along nicely.
Ruby can be used for developing GUI applications, whether Windows specific or cross-platform.
For Windows targetted you should look at the work going on with IronRuby since they have good integration with the .NET framework overall and with Silverlight, in the event you want to do apps that can bridge web and desktop. At this point IronRuby can be used to develop for Windows Presentation Foundation (WPF) or WinForms.
For cross-platform you have Ruby bindings for QT, FOX and others.
You should look at IronRuby - WPF and windows forms are both supported:

Language in a Sandbox in Rails [duplicate]

This question already has answers here:
How to run untrusted Ruby code inside a safe sandbox?
(4 answers)
Closed 8 years ago.
I've found that there WAS a sandbox gem (created by the guys that made try ruby in your browser but it was compatible only with Ruby 1.8. Another problem is that I cannot find it anymore (it seems they stop serving the gem from the servers...).
So, is there any secure way of running ruby in a sandbox (so you can run it from your browser)?
Or an easy way to run (for example lua/python) in a sandbox (no filesystem access, no creation of objects etc) and be called from Ruby (Rails 2.2)?
I want to make an application like try_ruby even without having a ruby underneath. But it has to be an easy language (I saw there was a prolog in ruby, even a lisp but I don't think they are easy to learn languages...).
So, do you have any suggestions or tips? Or should I just start creating my own DSL in Ruby (if there is a solution in creating a somewhat safe system)?
Thx
I am developing an implementation of a sandbox for ruby based on a modification of the ruby interpreter written in C, I have released recently a functional version of the gem called shikashi (rdoc documentation).
You should try embedding JRuby in the browser.
http://ruby-in-browser.googlecode.com/svn/trunk/evalruby/index.html
The guy who wrote the original gem disappeared, Keyser Söze style:
http://www.rubyinside.com/why-the-lucky-stiff-is-missing-2278.html
I've read that the JRuby gem is more current or maintained, but I've found it buggy so far. Here are some setup instructions:
http://flouri.sh/2009/4/4/how-to-set-up-the-jruby-sandbox
Overall, it looks like Ruby is lacking a solid implementation of this right now :(
I came across This article on hackety.org(dead link) this morning. Maybe it can serve you as a guide into the right direction
Another way is like codepad.org does it (VM isolation and checking the calls)
I am not sure if you want to run any language in a sandbox. But I found that JavaScript has been running as a sandbox language for a long time. The ruby racer project lets you embed the v8 engine in ruby. Hope that helps.

Resources