ruby,tcp,zeromq , TCP tunneling through Linux tap device


TCP tunneling through Linux tap device

Question:

Tag: ruby,tcp,zeromq

I've created a tap0 device (IP 10.0.0.101), and am using zeromq's pgm pub/sub (e.g. pgm://192.168.100.2;234.5.6.7:5555) to transport Ethernet frames from the tap to the zmq subscribers and vice versa. The idea is to create a virtual network using pgm. I have 2 tap hosts on the network: 10.0.0.101, 10.0.0.11. They also have physical Ethernet adapters at 192.168.106.126, 192.168.106.55.

'The problem is that ping works, but http and ssh protocols do not.

Wireshark shows a successful TCP startup sequence, but then I start to see duplicate ACKs, retransmissions, and curl and ssh hang for a while and eventually error out.

A snippet from Wireshark is below, followed by most of the (hopefully) relevant ruby source code. This is using rb_tuntap and ffi-rzmq gems.

No.     Time               Source                Destination           Protocol Length Info
      7 11:41:45.464867000 10.0.0.11             10.0.0.101            TCP      74     51659 > 3000 [SYN] Seq=0 Win=14600 Len=0 MSS=1460 SACK_PERM=1 TSval=1953042 TSecr=0 WS=64

Frame 7: 74 bytes on wire (592 bits), 74 bytes captured (592 bits) on interface 0
Ethernet II, Src: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f), Dst: 56:c8:52:17:31:67 (56:c8:52:17:31:67)
Internet Protocol Version 4, Src: 10.0.0.11 (10.0.0.11), Dst: 10.0.0.101 (10.0.0.101)
Transmission Control Protocol, Src Port: 51659 (51659), Dst Port: 3000 (3000), Seq: 0, Len: 0

No.     Time               Source                Destination           Protocol Length Info
      8 11:41:45.464956000 10.0.0.101            10.0.0.11             TCP      74     3000 > 51659 [SYN, ACK] Seq=0 Ack=1 Win=28960 Len=0 MSS=1460 SACK_PERM=1 TSval=10191992 TSecr=1953042 WS=128

Frame 8: 74 bytes on wire (592 bits), 74 bytes captured (592 bits) on interface 0
Ethernet II, Src: 56:c8:52:17:31:67 (56:c8:52:17:31:67), Dst: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f)
Internet Protocol Version 4, Src: 10.0.0.101 (10.0.0.101), Dst: 10.0.0.11 (10.0.0.11)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 51659 (51659), Seq: 0, Ack: 1, Len: 0

No.     Time               Source                Destination           Protocol Length Info
     11 11:41:45.473101000 10.0.0.11             10.0.0.101            TCP      66     51659 > 3000 [ACK] Seq=1 Ack=1 Win=14656 Len=0 TSval=1953044 TSecr=10191992

Frame 11: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface 0
Ethernet II, Src: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f), Dst: 56:c8:52:17:31:67 (56:c8:52:17:31:67)
Internet Protocol Version 4, Src: 10.0.0.11 (10.0.0.11), Dst: 10.0.0.101 (10.0.0.101)
Transmission Control Protocol, Src Port: 51659 (51659), Dst Port: 3000 (3000), Seq: 1, Ack: 1, Len: 0

No.     Time               Source                Destination           Protocol Length Info
     12 11:41:45.473429000 10.0.0.11             10.0.0.101            HTTP     145    GET / HTTP/1.1 

Frame 12: 145 bytes on wire (1160 bits), 145 bytes captured (1160 bits) on interface 0
Ethernet II, Src: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f), Dst: 56:c8:52:17:31:67 (56:c8:52:17:31:67)
Internet Protocol Version 4, Src: 10.0.0.11 (10.0.0.11), Dst: 10.0.0.101 (10.0.0.101)
Transmission Control Protocol, Src Port: 51659 (51659), Dst Port: 3000 (3000), Seq: 1, Ack: 1, Len: 79
Hypertext Transfer Protocol

No.     Time               Source                Destination           Protocol Length Info
     13 11:41:45.473460000 10.0.0.101            10.0.0.11             TCP      66     3000 > 51659 [ACK] Seq=1 Ack=80 Win=29056 Len=0 TSval=10192001 TSecr=1953046

Frame 13: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface 0
Ethernet II, Src: 56:c8:52:17:31:67 (56:c8:52:17:31:67), Dst: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f)
Internet Protocol Version 4, Src: 10.0.0.101 (10.0.0.101), Dst: 10.0.0.11 (10.0.0.11)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 51659 (51659), Seq: 1, Ack: 80, Len: 0

No.     Time               Source                Destination           Protocol Length Info
     15 11:41:45.491555000 10.0.0.101            10.0.0.11             TCP      717    [TCP segment of a reassembled PDU]

Frame 15: 717 bytes on wire (5736 bits), 717 bytes captured (5736 bits) on interface 0
Ethernet II, Src: 56:c8:52:17:31:67 (56:c8:52:17:31:67), Dst: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f)
Internet Protocol Version 4, Src: 10.0.0.101 (10.0.0.101), Dst: 10.0.0.11 (10.0.0.11)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 51659 (51659), Seq: 1, Ack: 80, Len: 651

No.     Time               Source                Destination           Protocol Length Info
     16 11:41:45.491599000 10.0.0.101            10.0.0.11             TCP      1514   [TCP segment of a reassembled PDU]

Frame 16: 1514 bytes on wire (12112 bits), 1514 bytes captured (12112 bits) on interface 0
Ethernet II, Src: 56:c8:52:17:31:67 (56:c8:52:17:31:67), Dst: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f)
Internet Protocol Version 4, Src: 10.0.0.101 (10.0.0.101), Dst: 10.0.0.11 (10.0.0.11)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 51659 (51659), Seq: 652, Ack: 80, Len: 1448

No.     Time               Source                Destination           Protocol Length Info
     21 11:41:45.496998000 10.0.0.11             10.0.0.101            TCP      66     51659 > 3000 [ACK] Seq=80 Ack=652 Win=17536 Len=0 TSval=1953058 TSecr=10192019

Frame 21: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface 0
Ethernet II, Src: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f), Dst: 56:c8:52:17:31:67 (56:c8:52:17:31:67)
Internet Protocol Version 4, Src: 10.0.0.11 (10.0.0.11), Dst: 10.0.0.101 (10.0.0.101)
Transmission Control Protocol, Src Port: 51659 (51659), Dst Port: 3000 (3000), Seq: 80, Ack: 652, Len: 0

No.     Time               Source                Destination           Protocol Length Info
     22 11:41:45.497026000 10.0.0.101            10.0.0.11             HTTP     231    HTTP/1.1 200 OK   (text/html)

Frame 22: 231 bytes on wire (1848 bits), 231 bytes captured (1848 bits) on interface 0
Ethernet II, Src: 56:c8:52:17:31:67 (56:c8:52:17:31:67), Dst: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f)
Internet Protocol Version 4, Src: 10.0.0.101 (10.0.0.101), Dst: 10.0.0.11 (10.0.0.11)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 51659 (51659), Seq: 2100, Ack: 80, Len: 165
[3 Reassembled TCP Segments (2264 bytes): #15(651), #16(1448), #22(165)]
Hypertext Transfer Protocol
Line-based text data: text/html

No.     Time               Source                Destination           Protocol Length Info
     25 11:41:45.502736000 10.0.0.11             10.0.0.101            TCP      78     [TCP Dup ACK 21#1] 51659 > 3000 [ACK] Seq=80 Ack=652 Win=17536 Len=0 TSval=1953061 TSecr=10192019 SLE=2100 SRE=2265

Frame 25: 78 bytes on wire (624 bits), 78 bytes captured (624 bits) on interface 0
Ethernet II, Src: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f), Dst: 56:c8:52:17:31:67 (56:c8:52:17:31:67)
Internet Protocol Version 4, Src: 10.0.0.11 (10.0.0.11), Dst: 10.0.0.101 (10.0.0.101)
Transmission Control Protocol, Src Port: 51659 (51659), Dst Port: 3000 (3000), Seq: 80, Ack: 652, Len: 0

No.     Time               Source                Destination           Protocol Length Info
     26 11:41:45.504245000 10.0.0.101            10.0.0.11             TCP      1514   [TCP Retransmission] 3000 > 51659 [ACK] Seq=652 Ack=80 Win=29056 Len=1448 TSval=10192032 TSecr=1953061[Reassembly error, protocol TCP: New fragment overlaps old data (retransmission?)]

Frame 26: 1514 bytes on wire (12112 bits), 1514 bytes captured (12112 bits) on interface 0
Ethernet II, Src: 56:c8:52:17:31:67 (56:c8:52:17:31:67), Dst: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f)
Internet Protocol Version 4, Src: 10.0.0.101 (10.0.0.101), Dst: 10.0.0.11 (10.0.0.11)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 51659 (51659), Seq: 652, Ack: 80, Len: 1448
[Reassembly error, protocol TCP: New fragment overlaps old data (retransmission?)]

No.     Time               Source                Destination           Protocol Length Info
     33 11:41:45.711324000 10.0.0.101            10.0.0.11             TCP      1514   [TCP Retransmission] 3000 > 51659 [ACK] Seq=652 Ack=80 Win=29056 Len=1448 TSval=10192239 TSecr=1953061[Reassembly error, protocol TCP: New fragment overlaps old data (retransmission?)]

Frame 33: 1514 bytes on wire (12112 bits), 1514 bytes captured (12112 bits) on interface 0
Ethernet II, Src: 56:c8:52:17:31:67 (56:c8:52:17:31:67), Dst: 3a:e2:d5:f3:8e:6f (3a:e2:d5:f3:8e:6f)
Internet Protocol Version 4, Src: 10.0.0.101 (10.0.0.101), Dst: 10.0.0.11 (10.0.0.11)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 51659 (51659), Seq: 652, Ack: 80, Len: 1448
[Reassembly error, protocol TCP: New fragment overlaps old data (retransmission?)]

Ruby code:

def run

    stop = false

    Signal.trap("SIGINT")  {
        stop=true
    }

    tap.up

    #binding.pry
    pids = []
    begin

        # tap => zmq_pub 
        pids << Thread.new do
            while !stop do
                read_and_pub
            end
        end

        # zmq_sub => tap
        pids << Thread.new do
            while !stop do
                sub_and_write
            end
        end

    rescue
        stop=true
    end

    pids.each { |pid| pid.join }

    tap.down
    tap.close
    self.tap = nil

    zmq_pub.close
    zmq_sub.close
    zmq_ctx.terminate

end # run

def read_and_pub

    selected = IO.select([tap.to_io],nil,nil,1)
    if !selected.nil? and !selected[0].nil? and selected[0].length>0 then
        msg = tap.to_io.sysread(tap.mtu)
        if !msg.nil? && msg.length > 0 then
            sent = zmq_pub.send_string(msg) 
            if sent != msg.length
                puts "**** published #{sent}/#{msg.length} ****"
            end
            print_packet msg, tap
        else
            puts "IO.select returned #{selected} but msg is #{msg}"
        end
    end
end

def sub_and_write
    msg = ''
    zmq_sub.recv_string msg
    if !msg.nil? && msg.length > 0 then
        sent = tap.to_io.syswrite(msg)
        if sent != msg.length
            puts "**** wrote #{sent}/#{msg.length} ****"
        end
        print_packet msg, zmq_sub
    end
end

Answer:

The problem is here: tap.to_io.sysread(tap.mtu). It seems that tap.mtu is not necessarily the maximum number of bytes that sysread will receive, and unread bytes seem to be disarded from a tap interface. I changed the code to tap.to_io.sysread(10000) and http and ssh work as expected. The largest frame I received was 1514.


Related:


rails - NameError (undefined local variable or method while using has_many :through


ruby-on-rails,ruby,ruby-on-rails-4
My rails app gives following error: NameError (undefined local variable or method 'fac_allocs' for #): app/models/room.rb:4:in '' app/models/room.rb:1:in '' app/controllers/rooms_controller.rb:3:in 'index' room.rb file class Room < ActiveRecord::Base has_many :bookings has_many :fac_allocs has_many :facs, :through => fac_allocs end ...

Ruby: How to copy the multidimensional array in new array?


ruby-on-rails,arrays,ruby,multidimensional-array
seating_arrangement [ [:first, :second, :none], [:first, :none, :second], [:second, :second, :first], ] I need to copy this array into new array. I tried to do it by following code: class Simulator @@current_state def initialize(seating_arrangement) @@current_state = seating_arrangement.dup end But whenever I am making any changes to seating_arrangement current_state changes automatically....

Saying there are 0 arguments when I have 2? Trying to open a CSV file to write into


ruby,file,csv,dir
I'm trying to read from a CSV file and codify people into groups using an equation. I append the name of their group they fall into to the end of the array that their row creates. Then I write it to a new file so I don't overwrite the original...

Iterating over EncryptedDataBagItem in Chef Recipe


ruby,json,chef,devops
I would like to decrypt a chef data bag item (named passwords) and store all of its attributes in a temporary JSON file which is read (and then deleted) by a node.js app. Is there a way to iterate over attributes of a data bag ITEM and get their values?...

Same enum values for multiple columns


ruby-on-rails,ruby,enums
I need to do something like this: class PlanetEdge < ActiveRecord::Base enum :first_planet [ :earth, :mars, :jupiter] enum :second_planet [ :earth, :mars, :jupiter] end Where my table is a table of edges but each vertex is an integer. However, it seems the abvove is not possible in rails. What might...

How to get return value from a forked / spawned process in Ruby?


ruby,process,output,fork,spawn
My simple test program: pid = Process.spawn("sleep 10;date") How can I place the output (eg stdout) of the "date" command in a variable when it is available? I don't want to use a file for the data exchange....

Ruby boolean logic: some amount of variables are true


ruby
Let say I have 3 variables: a, b, c. How can I check that just zero or one of them is true?...

Loop until i get correct user


ruby,redis
I have users stored in Redis and want to be able to call only certain subsets from a set, if i don't get the correct user back i want to put it back in the set and then try again until i get one of the desired users @redis =...

Keep leading zeroes when converting string to integer


ruby
For no particular reason, I am trying to add a #reverse method to the Integer class: class Integer def reverse self.to_s.reverse.to_i end end puts 1337.reverse # => 7331 puts 1000.reverse # => 1 This works fine except for numbers ending in a 0, as shown when 1000.reverse returns 1 rather...

Make instance variable accessible through hash in Ruby


ruby-on-rails,ruby,ruby-on-rails-4,activerecord
In Rails, ActiveRecord objects, attributes are accessible via method as well as through Hash. Example: user = User.first # Assuming User to be inheriting from ActiveRecord::Base user.name # Accessing attribute 'name' via method user[:name] # Attribute 'name' is accessible via hash as well How to make instance variables accessible through...

.split and regular expression in Ruby


ruby,regex
I want to split my string by (',') but ignore ',' if they are inside quotes. For example " 2,2,4,'hello', 'world', 'hi, there' " I want to split it so 'hi, there' will not be split into two different array elements in ruby. How can I do that? Probably use...

Get value from string representing local variable [duplicate]


ruby,local-variables
This question already has an answer here: Is there a 'variable_get' method? If not, how can I create my own? 2 answers I have a local variable name as a string, and need to get its value. variable = 22 "variable".to_variable? How can I get the value 22 form...

Dividing by half in ruby to create an effective calculator


ruby,calculator
For the past while I've been working on a calculator, but have run into problems when needing to divide by a half. I'll add the offending bit of code along with a loop to keep it open below. on = true while on == true do half = 1.0 /...

Rails Association Guidance [on hold]


ruby-on-rails,ruby,ruby-on-rails-4,ruby-on-rails-3.2
I am new to rails 4. I have gone through lots of tutorials and trying to solve below scenario. But still no success. Can anybody point me in the right direction. How to handle associations for below scenario. Scenario: 1. Patient can have many surgeries. 2. Surgery has two types...

Heroku RAM not increasing with upgraded dynos


ruby-on-rails,ruby,ruby-on-rails-3,memory,heroku
I have a massive function i have been calling manually through the heroku rails console. I have been receiving the error rapid fire in my logs: 2015-06-22T14:56:42.940517+00:00 heroku[run.9877]: Process running mem=575M(112.4%) 2015-06-22T14:56:42.940517+00:00 heroku[run.9877]: Error R14 (Memory quota exceeded) A 1X dyno is suppose to have 512 MB of RAM. I...

Call method to generate arguments in ruby works in 1.8.7 but not 1.9.3


ruby-on-rails,ruby,ruby-1.9.3
This is something that I had working in ruby 1.8.7, but no longer works in 1.9.3, and I am not sure what changes make this fail. Previously, I had something like this myFunction(submitArgs()) where submitArgs was a helper method that could be called with some options def submitArgs(args={}) #Some logic/manipulations...

Rails shared controller actions


ruby-on-rails,ruby,ruby-on-rails-4
I am having trouble building a controller concern. I would like the concern to extend the classes available actions. Given I have the controller 'SamplesController' class SamplesController < ApplicationController include Searchable perform_search_on(Sample, handle: [ClothingType, Company, Collection, Color]) end I include the module 'Searchable' module Searchable extend ActiveSupport::Concern module ClassMethods def...

Can't map a range of dates in Ruby/Rails


ruby-on-rails,ruby
I'm trying to map a range of dates and pass them to my view as an array, as follows: from, to = Date.parse("2014-01-01"), Date.yesterday date_range = (from..to) @mapped_dates = date_range.map {|date| date.strftime("%b %e")} I reference them in some JS in my view as follows: dateLabels = <%= raw @mapped_dates.to_json %>;...

Tornado behind Nginx, should I use TCP nodelay config in python or nginx.conf?


nginx,tcp,websocket,tornado
I have a Tornado server running behind Nginx reverse proxy. The proxy is configured with tcp_nodelay: on. I see there's also an option to call WebSocketHandler.set_nodelay(True) on a WebSocket instance once it's connected. Do these two create the same effect? Are there pro's con's for using one over the other?...

regex to pull in number with decimal or comma


ruby,regex
This is my line of code: col_value = line_item[column].scan(/\d+./).join().to_i When I enter 30,000 into the textfield, col_value is 30. I want it to bring in any number: 30,000 30.5 30.55 30000 Any of these are valid... Is there a problem with the scan and or join which would cause it...

Ruby access words in string


ruby
I don't understand the best method to access a certain word by it's number in a string. I tried using [] to access a word but instead it returns letter. puts s # => I went for a walk puts s[3] # => w ...

Get X days out of an Array


ruby,ruby-on-rails-4
I have an array filled with Datetime objects: [Mon, 22 Jun 2015, Tue, 23 Jun 2015, Wed, 24 Jun 2015, Thu, 25 Jun 2015, Fri, 26 Jun 2015, Sat, 27 Jun 2015, Sun, 28 Jun 2015] I know how to select what I want from the array ex: week.select{|x|x.monday? ||...

On rendering from controller, current_page method does not seem to work


ruby-on-rails,ruby,ruby-on-rails-4,model-view-controller
I have a navigation bar included in application.html.erb. Because for some pages, such as the signup page, I need to place additional code inside the navigation bar, I have excluded those pages for showing the navigation bar through application.html.erb and instead included it in their respective view pages. See code...

How to pivot array into another array in Ruby


arrays,ruby,csv
I have a multidimensional array like this one : myArray = [["Alaska","Rain","3"],["Alaska","Snow","4"],["Alabama","Snow","2"],["Alabama","Hail","1"]] I would like to end up with CSV output like this. State,Snow,Rain,Hail Alaska,4,3,nil Alabama,2,nil,1 I know that to get this outputted to CSV the way I want it I have to have output array like this: outputArray =[["State","Snow","Rain","Hail"],["Alaska",4,3,nil],["Alabama",2,nil,1]]...

Stack level too deep because recursion


ruby-on-rails,ruby,ruby-on-rails-4,twitter
I have a model named Tweet. The columns of the Tweet model are: -id -content -user_id -picture -group -original_tweet_id Every tweet can have one or multiple retweets. The relation happens with the help of original_tweet_id. All the tweets have original_tweet_id nil , whilst the retweets contain the id of the...

Heroku rake db:migrate failing - uninitialized constant


ruby-on-rails,ruby,heroku
My app is working fine locally and my push to Heroku was successful. But, when I run heroku run rake db:migrate, I get the following error: NameError: uninitialized constant AddWeightToExercises Here is the failed migration: class AddWeightToExercise < ActiveRecord::Migration def change add_column :exercises, :weight, :float end end edit: Thanks for...

RSpec test for rake task


ruby-on-rails,ruby,rspec,rake-task
I have created a custom rake task that deletes all items that are >= 7 days old. I am trying to write a RSpec test for this new task but it seems like my task isn't really running in the test. I have tested the task manually and it works...

In Ruby how to put multiple lines in one guard clause?


ruby-on-rails,ruby
I have the following line of code : if params[:"available_#{district.id}"] == 'true' @deliverycharge = @product.deliverycharges.create!(districtrate_id: district.id) delivery_custom_price(district) end Rubocop highlight it and asks me to use a guard clause for it. How can I do it? EDIT : Rubocop highlighted the first line and gave this message Use a guard...

How could I padding spaces to a fix length


ruby
I need all strings' length with 5 Original [477, 4770,] Expected ["477 ", "4770 "] How could I do it with Ruby ?...

How to handle backslash “\” escape characters in q string and heredocument


ruby
Ruby Newbie here. I do not understand why Ruby looks inside %q and escapes the \. I am using Ruby to generate Latex code. I need to generate \\\hline which is used in Latex for table making. I found \\\hline as input generated \hline even though the string was inside...

Using Ruby Pathname to access relative directory


ruby,path,pathname
Given I have a relative path pointing to a directory how can I use it with Ruby's Pathname or File library to get the directory itself? p = Pathname.new('dir/') p.dirname => . p.directory? => false I have tried './dir/', 'dir/', 'dir'. What I want is p.dirname to return 'dir'. I...

Ruby on Rails - Help Adding Badges to Application


ruby-on-rails,ruby,rest,activerecord,one-to-many
I'm creating a rails application that is a backend for a mobile application. The backend is implemented with a RESTful web API. Currently I am trying to add gamification to the platform through the use of badges that can be earned by the user. Right now the badges are tied...

Error when trying to install app with mysql2 gem


mysql,ruby-on-rails,ruby,ruby-on-rails-4
Im trying to install an open source rails 3.2.21 application that uses the mysql2 gem, but when i try and run the bundle commant I get the following error: Fetching: mysql2-0.3.18.gem (100%) Building native extensions. This could take a while... p ERROR: Error installing mysql2: ERROR: Failed to build gem...

Rails basic auth not working properly


ruby-on-rails,ruby,authentication
I am building a small API that uses basic authentication. What I have done, is that a user can generate a username and password, that could be used to authenticate to the API. However I have discovered that it is not working 100% as intended. It appears that a request...

edit first line of multiple files in place with a ruby one-liner


ruby
I can edit multiple files in place using the -p -i -e command line options: ruby -pi -e 'sub(/a/,"b")' file* How can I edit only the first line of each file? This works for one file only: ruby -pi -e 'sub(/^/,"New line goes at top\n") if $. == 1' file1...

Rails less url path change


ruby-on-rails,ruby,url,path,less
Developing a Rails application with the less-rails gem I found something unusual : // app/assets/common/css/desktop/typo.less @font-face{ font-family:'SomeFont'; src:url("fonts/db92e416-da16-4ae2-a4c9-378dc24b7952.eot?#iefix"); // ... } The requested font is app/assets/common/css/fonts/db92e416-da16-4ae2-a4c9-378dc24b7952.eot This font is compiled with less and the results is : @font-face { font-family: 'SomeFont'; src: url("desktop/fonts/db92e416-da16-4ae2-a4c9-378dc24b7952.eot?#iefix"); //... } Do you know why is...

Ruby- get a xml node value


ruby,xml
can someone help me in extracting the node value for the element "Name". Type 1: I am able to extract the "name" value for the below xml by using the below code <Element> <Details> <ID>20367</ID> <Name>Ram</Name> <Name>Sam</Name> </Details> </Element> doc = Nokogiri::XML(response.body) values = doc.xpath('//Name').map{ |node| node.text}.join ',' puts values...

is there an equivalent of the ruby any method in javascript?


javascript,arrays,ruby,iteration
Is there an equivalent of ruby's any method for arrays but in javascript? I'm looking for something like this: arr = ['foo','bar','fizz', 'buzz'] arr.any? { |w| w.include? 'z' } #=> true I can get a similar effect with javascript's forEach method but it requires iterating through the entire array rather...

Allowing some enabled and disabled option on collection_select


ruby-on-rails,ruby
I am trying to populate a dropdown box on a view that has all the states. This works just fine: <%= f.collection_select :state_id, @states, :id, :name %> Now, I need to make the following: Some states are going to be disabled for choosing, but they still have to appear on...

Rails - link_to path based on object's name + refactoring multiple custom actions


ruby-on-rails,ruby,refactoring
I'm looking to simplify the link_to path based on thr object's name and also am looking into refactoring multiple custom actions. I've managed to get this working below. <% ServiceMenu.all.each do |menu| %> <tr class=" <%= cycle('odd', 'even') %>"> <td><%= link_to menu.name, ("tech/""#{menu.name.parameterize}") %></td> </tr> <% end %> I feel...

String#scan not capturing all occurences


ruby,regex
I'm facing a very strange behaviour with ruby String#scan method return. I have this code below and I can't find out why "scan" doesn't return 2 elements. str = "10011011001" regexp = "0110" p str.scan(/(#{regexp})/) ==> [["0110"]] String "str" clearly contains 2 occurences of pattern "0110". I want to fetch...

For loop with flexible stop variable


ruby
I need to write a loop for x in (1..y) where the y variable can be changed somehow. How can I do that? For example: for x in (1..y/x) But it does not work. ...

Appending an element to a page in VoltRb


html,ruby,opalrb,voltrb
I'm trying to append an element to one of my pages in a Volt project, via opal-browser, like so: if RUBY_PLATFORM == 'opal' require 'browser' $document.body << my_dom_element.to_n end # controller code below Unfortunately, I'm getting an error: [Error] TypeError: null is not an object (evaluating 'value.nodeType') (anonymous function) (main.js,...

Get the actual value of a boolean attribute


ruby,page-object-gem,rspec3,rspec-expectations
I have the span: <span disabled="disabled">Edit Member</span> When I try to get the value of the disabled attribute: page.in_iframe(:id => 'MembersAreaFrame') do |frame| expect(page.span_element(:xpath => "//span[text()='Edit Member']", :frame => frame).attribute('disabled')).to eq("disabled") end I get: expected: "disabled" got: "true" How do I get the value of specified attribute instead of a...

How to flatten a structure of embedded Set and Hash


ruby,recursion
I would like to convert an embedding structure into a flat one. An embedding structure is a set of 0 or more objects, such as: a string or a hash having some string as key and some other embedding structure as value. A flat structure is a set of arrays...

Seeding fails validation for nested tables (validates_presence_of)


ruby-on-rails,ruby,validation,ruby-on-rails-4,associations
An Organization model has a 1:many association with a User model. I have the following validation in my User model file: belongs_to :organization validates_presence_of :organization_id, :unless => 'usertype==1' If usertype is 1, it means the user will have no organization associated to it. For a different usertype the presence of...

What is Rack::Utils.multipart_part_limit within Rails and what function does it perform?


ruby-on-rails,ruby,rack,multipart
Rack::Utils.multipart_part_limit is set to 128 by default. What purpose does the value have and what effect does it have within the Rails system?...

Ruby gsub group parameters do not work when preceded by escaped slashes


ruby,regex
I am trying to perform a trivial substitution, that in any other language I have come across, work as per the documentation. However, my substitution fails for some reason. The documentation examples list: "hello".gsub(/[aeiou]/, '*') #=> "h*ll*" "hello".gsub(/([aeiou])/, '<\1>') #=> "h<e>ll<o>" "hello".gsub(/./) {|s| s.ord.to_s + ' '} #=> "104 101...

Split an array into slices, with groupings


arrays,ruby,enumerable
I've got some Ruby code here, that works, but I'm certain I'm not doing it as efficiently as I can. I have an Array of Objects, along this line: [ { name: "foo1", location: "new york" }, { name: "foo2", location: "new york" }, { name: "foo3", location: "new york"...

Map with accumulator on an array


ruby,inject
I'm looking to create a method for Enumerable that does map and inject at the same time. For example, calling it map_with_accumulator, [1,2,3,4].map_with_accumulator(:+) # => [1, 3, 6, 10] or for strings ['a','b','c','d'].map_with_accumulator {|acc,el| acc + '_' + el} # => ['a','a_b','a_b_c','a_b_c_d'] I fail to get a solution working. I...