26 Kasım 2014 Çarşamba

Rails reads excel by using spreadsheet

thanks to stackoverflow.com I found this fruitful example and I share it
# load the gem
require 'spreadsheet'

# In this example the model MyFile has_attached_file :attachment
@workbook = Spreadsheet.open(MyFile.first.attachment.to_file)

# Get the first worksheet in the Excel file
@worksheet = @workbook.worksheet(0)

# It can be a little tricky looping through the rows since the variable
# @worksheet.rows often seem to be empty, but this will work:
0.upto @worksheet.last_row_index do |index|
  # .row(index) will return the row which is a subclass of Array
  row = @worksheet.row(index)

  @contact = Contact.new
  #row[0] is the first cell in the current row, row[1] is the second cell, etc...
  @contact.first_name = row[0]
  @contact.last_name = row[1]

  @contact.save
end

While saving simple_form data, rails save values as NULL problem

Problem solution is here.

The model you have are heavily populated with attr_accessorattr_accessor is a way to create "virtual attributes" in Ruby / Rails, as it defines a custom getter and setter method, which will essentially define the "attributes" for use on the system
The problem you have is attr_accessor, in the simplest of terms, will not permit your data to be saved in the database. This will be one of the bigger issues you have - you need to get rid of any attr_accessors which override your database attributes.
It should be removed the attr_accessor methods from your model

20 Kasım 2014 Perşembe

How to capture packets

While I surf the internet, I came across a web site(www.opensourceforu.com) about how to capture packets physical layer to application layer. I like this explanation:

Capturing packets means collecting data being transmitted on the network. Every time a network card receives an Ethernet frame, it checks if its destination MAC address matches its own. If it does, it generates an interrupt request. The routine that handles this interrupt is the network card’s driver; it copies the data from the card buffer to kernel space, then checks the ethertype field of the Ethernet header to determine the type of the packet, and passes it to the appropriate handler in the protocol stack. The data is passed up the layers until it reaches the user-space application, which consumes it.