ubuntu - Translating strings in file to hexadecimal (Ruby) Part II

I'm new to Ruby and trying to convert a text file containing DNA sequences into a hexadecimal output. I am currently using a hash to match strings with hex-values.A sample input file might contain ctgcagccgc cgactgaaat. In that case, the output should be 79259 61E03.What can I do to properly to hash the file to output the hash table key value from string to hexadecimal or another string value?Below is what I have so far:#dna_sequencing.rbsequence_dna = { "aa" => 0, "ac" => 1, "ag" => 2, "at" => 3, "ca" => 4, "cc" => 5, "cg"...Read more

ruby - How to get all message history from Hipchat for a room via the API?

I was using the Hipchat API (v2) a bit today and ran into an odd issue where I was not able to really pull up all of the history for a room. It seemed as though when I queried a specific date, for example, it would only retrieve a fraction of the history for that date given. I had had plans to simply iterate across all of the dates for a Room to extract the history in a format that I could use, but ended up hitting this and am now unsure if it is really possible to pull out the history fully.I realize that this is a bit clunky. It is pulling...Read more

creating a slack bot using slack-api ruby gem not responding back as a DM

I have set up a slack bot using slack-api and the real-time-messaging api.Here is the abbreviated setup:client.on :message do |data| d {data} bot_response = BotResponse.get_bot_response(data['text'], "session_slack") Slack.chat_postMessage channel: data['user'], text: "#{bot_response}"endclient.startWith this version of the postMessage, the response comes from Slackbot, not my bot (named kaya).Goal: I want to respond to come as a DM from the bot it was sent to.When I change the channel to data['channel'], the response comes as DM from my bot...Read more

slack - Ruby append to string if error contains string

I have a Slack Bot that needs to respond in an error condition. If the error has certain text in it, I want to append some additional information to the return message. This block of code works fine if I comment out the message += line but breaks if I do not. When I try to replicate this in irb everything works fine too. Does something look obviously wrong here?begin scan = @nsc.scan_devices(devices)rescue Nexpose::APIError => e puts "[!] API ERROR: Most likely caused by an orphaned asset (#{device_ids})" puts "[!] #{e}" $slackbot_logg...Read more

ruby - chef: how to get a timestamp at *convergence* rather than *compile* time

Please consider this code at the end of my deploy_to_tomcat recipe: unless Chef::Config[:solo] chat_message "Deployed #{artifact_name} `#{"%Y-%m-%d %H:%M")}`" endIt posts a message to chat: Deployed my-web-app 2016-11-03 12:31However, I notice the timestamp from is a little out - it seems to be the timestamp when the recipe was compiled, rather than when the resources coverged and ran, a couple of minutes later.So I tried this, but it didn't work (timeNow was still undefined when message was posted to chat) time...Read more

windows - What is the difference between Ruby win32api and win32ole?

A piece of ruby code using win32olerequire 'win32ole'ie ='InternetExplorer.Application')ie.visible = trueie.gohomeSome code using win32apirequire "Win32API"message = "This is a sample Windows message box generated using Win32API"title = "Win32API from Ruby"api ='user32', 'MessageBox',['L', 'P', 'P', 'L'],'I'),message,title,0)First one opens up internet explorer and the second one displays a message box.Simply saying both seems to be able to access the OS and make it do stuff. Is win32ole a subset of win32ap...Read more

Ruby BasicObject methods

while going through Ruby, i encountered that BasicObject is the top most superclass of Class. When I tried BasicObject.methods, i get list of these methods[:method_missing, :singleton_method_added, :singleton_method_undefined, :singleton_method_removed, :new, :become_java!, :allocate, :superclass, :java_class, :class_variables, :<=, :public_instance_methods, :prepend, :class_variable_get, :public_constant, :singleton_class?, :instance_methods, :freeze, :instance_method, :const_defined?, :to_s, :constants, :ancestors, :private_instance_method...Read more

ruby - Why methods to_i and to_f are not appearing in String.methods?

I thought the #methods method would list all methods in a class.Why aren't to_i and to_f appearing when I type String.methods.sort?to_i is supposed to convert a String into an integer and to_f - convert a string into a float.String.methods.sort[:!, :!=, :!~, :<, :<=, :<=>, :==, :===, :=~, :>, :>=, :__id__,:__send__, :allocate, :ancestors, :autoload, :autoload?, :class,:class_eval, :class_exec, :class_variable_defined?,:class_variable_get, :class_variable_set, :class_variables, :clone,:const_defined?, :const_get, :const_missing...Read more

ruby - Convert from format date string to unix (epoch) time value

How can I convert from a formatted time string (e.g. 3/17/98) to a Unix time stamp (i.e. num. seconds from Jan 1, 1970 00:00:00)?I can find many methods of converting into a date string in the Ruby "date" library, but none to go back the other way. While this won't be a problem in later builds, my proof of concept application is using a SQLite database which does not support the "DATE" type format....Read more

Ruby on Rails view iterrates through object even when object is nil

I am a beginner when it comes to ROR and programming in general. I was working through the basic getting started guide in the documentation and am working on creating a comments view for a blog. I have the following code in my view to render all comments on an article - <% @article.comments.each do |comment| %> <p> <strong>Commenter: </strong> <%= comment.commenter %> </p> <p> <strong>Comment: </strong> <%= comment.body %> </p><% end %>I am having trouble un...Read more

ruby - Error installing cf-uaac on OSX El Capitan

Trying to install the cf-uaac gem on OS X El Capitan.$ gem install cf-uaacResult:Fetching: cf-uaa-lib-3.2.5.gem (100%)Successfully installed cf-uaa-lib-3.2.5Fetching: highline-1.6.21.gem (100%)Successfully installed highline-1.6.21ERROR: Error installing cf-uaac: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rbmkmf.rb can’t find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/include/ruby.hextconf failed, exit code 1...Read more