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.")
4 Ağustos 2014 Pazartesi
error: device unauthorized. Please check the confirmation dialog on your device.
While encountering this error in linux shell, you could fix it by applying below instruction
- unplug your device
- (in shell) SDK_DIR=(android_sdk_directory)
- cd $SDK_DIR/platform_tools
- ./adb start-server
- plug device
- confirm authorization
Etiketler:
adb,
android sdk,
linux,
ubuntu 14.10
2 Ağustos 2014 Cumartesi
Convert pdf to image in linux
If you look for a tool in order to convert a pdf document to a image, you could use a useful command:
convert document.pdf document.png
this little tool come in handy very much.
convert document.pdf document.png
this little tool come in handy very much.
1 Ağustos 2014 Cuma
Quick ntfs format in Linux
sudo mkfs.ntfs -f /dev/sdb1
NTFS is a journaling file system.Hence Don't forget unmount your disk before unplugged.
qemu-timer.o: undefined reference to symbol 'timer_settime@@GLIBC_2.3.3'
Another good solution is here while compiling qemu.
../.././gcc/libgcc.mvars: No such file or directory
This bug struggled me for a long time. Therefore, I found a good solution in here.
Fruitful Regex Hints
Minimum 8 characters at least 1 Alphabet and 1 Number:
"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$"
Minimum 8 characters at least 1 Alphabet, 1 Number and 1 Special Character:
"^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,}$"
Minimum 8 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet and 1 Number:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$"
Minimum 8 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}"
Minimum 8 and Maximum 10 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,10}"
"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$"
Minimum 8 characters at least 1 Alphabet, 1 Number and 1 Special Character:
"^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,}$"
Minimum 8 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet and 1 Number:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$"
Minimum 8 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}"
Minimum 8 and Maximum 10 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,10}"
31 Temmuz 2014 Perşembe
How to monitor the services in Ubuntu 14.10
To oversee ubuntu linux background daemons, following command is fruitful:
sudo initctl list
There is a detailed explanation for this init control tool in here
sudo initctl list
There is a detailed explanation for this init control tool in here
30 Temmuz 2014 Çarşamba
Ruby Quick Reference
When hacking Ruby on Rails, Some strange code stick in my mind. Therefore, while searching good guide, I found this useful Ruby reference.
28 Temmuz 2014 Pazartesi
Ubuntu 14.10 MATE nm-applet appearing problem
When you install a new Ubuntu 14.10 MATE, you couldn't see network manager applet in your top panel. To be enable it, you should edit /etc/xdg/autostart/nm-applet.desktop
[Desktop Entry]
Name=Network
Comment=Manage your network connections
Icon=nm-device-wireless
Exec=nm-applet
Terminal=false
Type=Application
NoDisplay=true
NotShowIn=KDE;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=NetworkManager
X-GNOME-Bugzilla-Component=nm-applet
X-GNOME-UsesNotifications=true
#AutostartCondition=GNOME3 unless-session gnome <---Comment out
X-Ubuntu-Gettext-Domain=nm-applet
[Desktop Entry]
Name=Network
Comment=Manage your network connections
Icon=nm-device-wireless
Exec=nm-applet
Terminal=false
Type=Application
NoDisplay=true
NotShowIn=KDE;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=NetworkManager
X-GNOME-Bugzilla-Component=nm-applet
X-GNOME-UsesNotifications=true
#AutostartCondition=GNOME3 unless-session gnome <---Comment out
X-Ubuntu-Gettext-Domain=nm-applet
Furthermore, if you run below instructions in your terminal, you will enable nm-applet every log in.
mkdir -v ~/.config/autostart
cp /etc/xdg/autostart/nm-applet.desktop ~/.config/autostart
16 Temmuz 2014 Çarşamba
How to set/unset git proxy
To set proxy server with git:
http_proxy=http://$server_ip:$server_port/
git config --global http.proxy $http_proxy
To unset proxy server with git:
http_proxy=http://$server_ip:$server_port/
git config --global http.proxy $http_proxy
To unset proxy server with git:
git config --global --unset $http_proxy
Kaydol:
Yorumlar (Atom)