apperceive
13 Aralık 2014 Cumartesi
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_accessor. attr_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 model20 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.
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.
26 Ağustos 2014 Salı
Google Chrome using with proxy in Linux
If you also reach internet via proxy, you can encounter this problem in Linux. Although you set up proxy server in console, you couldn't connect internet over Google Chrome. So you open a command prompt(especially bash) and write this command:
linux@linux:~/$chromium-browser --proxy-server=*.*.*.*:*
*.*.*.*:* = your proxy server ip and port
linux@linux:~/$chromium-browser --proxy-server=*.*.*.*:*
*.*.*.*:* = your proxy server ip and port
22 Ağustos 2014 Cuma
How to check whether a string contains a substring in Ruby
If you look for a method in order to use while searching a string contains a substring, you could use this method;
a = "Skill"
if a.include? "ll"
puts "exist"
end
a = "Skill"
if a.include? "ll"
puts "exist"
end
20 Ağustos 2014 Çarşamba
How to get exact number in a string with using ruby
When I search a useful code block so as to find exact number in a string, I come accross this fruitful function in Ruby:
- str.delete("^0-9.")
Kaydol:
Yorumlar (Atom)