How to run wukong examples? - ruby

Wukong looks like a pretty nice Ruby way to get into Hadoop through the streaming interface. However, after looking over the examples at the git page:
https://github.com/infochimps-labs/wukong/tree/master/examples
I have no idea how to actually run any of these and generate output.
EDIT: I tried running the following example:
$ ./word_count.rb --run=local README.txt .
This generates an error:
/Users/evanzamir/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- wukong/script (LoadError)
from /Users/evanzamir/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from ./word_count.rb:2:in `<main>'
It seems to be having an issue with the line require 'wukong/script', but I'm not sure how to fix it.

Related

Why my Telegram bot doesn't work in the terminal on my computer?

I am an absolute beginner in telegram bots.
I found a guide online at https://www.process.st/telegram-bot/ that should teach me how to build my first bot using ruby. I have followed the guide (installing ruby and bundler) but somehow I am note able to run the bot, nothing happens and the terminal display two errors:
Traceback (most recent call last):
2: from bot.rb:1:in `<main>'
1: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- telegram-bot (LoadError)
The bot directory is called telegram-bot and has 3 files inside:
Gemfile
Gemfile.lock
bot.rb
The problem occurs when I type ruby bot.rb in my terminal
The problem was the misspelling of telegram_bot, I was using the wrong spelling telegram-bot in my bot.rb file, thanks to Casper for providing me the solution

ruby cannot load file when run from LaunchControl?

I have a ruby file that runs files directly in command line via:
ruby /Users/Greg/Dropbox/source_ruby/myapp/main.rb
When I try to schedule this using LaunchControl on Mac however (using the same command line call) I get the following error?
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- watir-webdriver (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/Greg/Dropbox/source_ruby/myapp/main.rb:3:in `<main>'
This is noting the first lines of my main.rb file are:
#!/usr/bin/ruby
require 'watir-webdriver'
require 'nokogiri'
Any ideas why? (i.e. why it would run fine when I open a Terminal session, then use the same command line to run it, but when I try to schedule in LaunchControl I get the error)
actually I managed to find a post/lead that ended up working. The following line added to the beginning of my ruby script made things work:
Selenium::WebDriver::Chrome::Service.executable_path = '/usr/local/bin/chromedriver'
(not sure if one would view this as the root cause fix, c.f. workaround)

Fixing "custom_require.rb:36:in `require': no such file to load" errors

I understand that after Ruby 1.9.2, '.' is no longer in your path for security reasons. This seems to be a problem when using certain gems (ones not updated to 1.9 I imagine?), a problem that throws errors like
$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in 'require': cannot load such file -- rubylog (LoadError)
I've seen and fixed this problem once, by (perhaps naively) changing some requires into require_relatives: https://github.com/mathpunk/MongoDB_Koans/commit/e2f7898347d328450ec121d22f701508f389cc53
Now I'd like to use rubylog, and I'm getting the custom_require error, so I tried the same trick:
https://github.com/mathpunk/rubylog/commit/995e13dccc6a197d280d0783f3fb7fe50deabd02
but this time, I'm just getting the same error. What else can I try?
ETA: All this time, I've been using sudo gem install blah to install gems, and for some reason, for rubylog it's gem install rubylog that does it. (Something to do with RVM?) So now everything works. Thank you.
Your code fails at require 'rubylog' - so it can't find rubylog.rb itself. So just add dir containing rubylog.rb to load path - something like $: << 'rubylog' might help.
Just add the library directory to your LOAD_PATH:
$LOAD_PATH.unshift(File.dirname(__FILE__))
See Understanding Ruby's load paths\
Edit: I assumed you had a rubylog directory wherever your script was running from. If your script can't find rubylog then you need to add that location to your load path:
$LOAD_PATH.unshift('/path/to/rubylog')
Are you sure you have the rubylog libraries? gem install rubylog

ruby require not working

I'm new to ruby, but I'm working on my first ruby program. It currently has two files, one is a library of functions (xgync.rb stored in lib) the other is the executable xgync stored in 'bin'. (Project visible here https://bitbucket.org/jeffreycwitt/xgync/src) I've also created a symlink to my /usr/local/bin/xgync so that I can write the command xgync {arguments} from anywhere in the terminal.
The problem seems to be that bin/xgync depends on the library lib/xgync.rb. I've written this dependency in bin/xgync as follows:
$:.unshift(File.dirname(__FILE__) + '/../lib')
require "xgync"
However, i keep getting the following error:
/Users/JCWitt/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- xgync (LoadError)
from /Users/JCWitt/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/bin/xgync:4:in `<main>'
can you see anything wrong with what I've written? Could the symlink be somehow messing things up?
Thanks for your help :)
When using ruby 1.9.x you don't usually alter the path with the $:.unshift when requiring other files in your project.
Instead the best practice is to use require_relative instead.
require_relative '../lib/xgync.rb'
require_relative requires files relative to the file you are currently editing.
But the error you experience appears, because you require a file, which does not exist:
bin/xgync
lib/xgync.rb
These are the files in your project according to your question, and the code-excerpt is from bin/xgync you extended the path to look for files in lib/ but you try to require 'xgync' which is a file, that is not present in lib/, so if you wanted to use this method (instead of require_relative you would have to use require 'xgync.rb'.

Using external libraries in Ruby

I have compiled a library(GDAL) written in C/C++ with Ruby bindings.
After a ran make install it was installed under
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0/
There is a directory there called "gdal" with 4 files inside: gdal.so, gdalconst.so, ogr.so, osr.so
What I want now is to use these libraries in my project. The problem is that when I try to referense these files
require 'gdal/gdal'
I get
LoadError: no such file to load --
gdal/gdal from
:29:in
require' from
<internal:lib/rubygems/custom_require>:29:in
require' from (irb):1 from
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/bin/irb:16:in
`'
When I run ruby -e 'puts $:' I get following output:
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/vendor_ruby/1.9.1
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/vendor_ruby/1.9.1/x86_64-darwin10.6.0
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/vendor_ruby
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1
/Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/x86_64-darwin10.6.0
Any ideas why it doesn't work for me?
After make install on OS X you should have a .bundle file in your path /Users/igor/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0.
If you want to use it then, you just have to require 'gdal' and it should fine.
It looks like you are not using a extconf.rb file to help you generate your makefile.
You might want to read this tutorial and check Rice if you want to write a C++ extension. (Ruby is written in C and you need to expose a C API, Rice makes that easier).
Thank you guys for your suggestions. I've finally figured out the problem. It seems like the fact that I was using rvm to manage ruby versions was causing the problem. As soon as I switched to system default(rvm use system) everything worked out well.

Resources