Sunday, February 14, 2016

Building Ruby App using GTK3 with Glade3 on Linux Mint 17.2

I have created a simple ruby program using gtk3 with Glade3.

1. References

Installing GTK3 on Linux
Installing Glade3 on Linux
How to use Glade resource with Ruby Gtk3

2. Create a Glade file

I have created a simple Glade file. For this simple test, I just added a main window ('window1') and specified a signal handler ('quit') for destroy event of the main window.
GladeTest.glade

3. Write a Ruby code using the glade file

Here is my ruby program that load the glade file that I created above and use it for user interface.
(1) Create a Gtk Builder object ('Gtk::Builder.new')
(2) Attach ui elements by loading the glade file ('add_from_file')
(3) Connect all signals to their handlers ('connect_signals {...}')
(4) Define signal handler method ('quit')
(5) Get object id for main window ('get_object')
(6) Show all widgets of the main window ('show')
(7) Finally call main loop ('Gtk.main')

glade_test.rb

4. Run the ruby program

$ ruby glade_test.rb

5. Display

Here is the window that this Ruby program displays.

6. Conclusion

I found it extremely difficult to find good tutorials or sample codes that use GTK3, especially ones with Glade3. Luckily I found one small sample codes by Gregory Romé. It turned out to be quite simple to load a glade (xml) file and use it.

Saturday, February 6, 2016

Installing Glade3 on Linux Mint 17.2

I have installed Glade3 on my Linux Mint 17.2.

1. Using Synaptic Package Manager

I used Synaptic Package Manager to install Glade.


2. Related packages installed automatically

The following two packages were installed automatically when installing Glade (3.16.10).
  • libgladeui-2-6
  • libgladeui-common

3. After Installation

Glade item appears in Menu under the Programming group


4. Test Launching Glade


5. Conclusion

Installing Glade3 on my Linux Mint 17.2 was simple and easy.

Installing gtk3 on Linux Mint 17.2

1. Check my ruby installation (Looks good)

$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]

2. Check if gtk3 is already installed (Not installed yet)

$ gem list gtk3

*** LOCAL GEMS ***

(None)

3. Check available gtk3 gems (Found one)

$ gem list gtk3 --remote

*** REMOTE GEMS ***

gtk3 (3.0.7 ruby x64-mingw32 x86-mingw32)
gtk3app (1.5.1)
gtk3assist (0.0.9)
gtk3webtable (0.0.0)

4. Install gtk3

$ gem install gtk3
Fetching...
11 gems installed

5. Test the installation (Works!)

$ irb
irb(main):001:0> require 'gtk3'  => True
irb(main):002:0> win = Gtk::Window.new
irb(main):003:0> win.signal_connect("destroy") { Gtk::main_quit }
irb(main):004:0> win.show_all
irb(main):005:0> Gtk.main      # see below

6. Result (An empty window)


7. Conclusion

Installing gtk3 on my Mint 17.2 (with Ruby 2.2) was easy and flawless.

Tuesday, May 19, 2015

Installing Bitnami Ruby Stack as root on Ubuntu 14.04

I have installed Bitnami Ruby Stack 2.2.2-0 Dev (64bit) as root user on my XUbuntu.

In order to make its installation simple, I removed previously installed PostgresSQL, MySQL, Nginx, and Apache servers from my machine. (I did not bother removing Ruby because previously installed version in this machine was 1.9x, and it should have no conflict with Ruby 2.2.x that is to be installed with this version of Ruby Stack.)

1. Resources

2. My environment

I use a 64-bit Ubuntu 14.04 (XUbuntu) machine (Core i3) for this installation.


3. Download

I downloaded Ruby Stack 2.2.2-0 Dev (64-bit) from this site:



The file was downloaded as bitnami-rubystack-2.2.2-0-dev-linux-x64-installer.run in my \Download\ directory.


4. Installation

Because I wanted to install as a root, not as a regular user, I did not run the installer by double clicking. I used the terminal window to run as a root user.

$ cd Downloads
$ sudo ./bitnami-rubystack-2.2.2-0-dev-linux-x64-installer.run

It opened a graphical installation wizard within a several seconds.



I accepted the default installation directory: /opt/rubystack-2.2.2-0/
(Note: the default directory will be different if you run the installer as a regular user, not root user).

When prompted, I entered passwords for MySQL and PostgreSQL servers.

I also selected SQLite as default data source for a sample Rails app installed.


That was all I needed to supply in order to install the RubyStack, which contained a fairly complete set of tools to run ruby/rails applications. In addition to Ruby it self (version 2.2.2p95) , it can optionally install the following items, which I accepted all.





What's interesting is that it can optionally install a bunch of php stuff, which may be convenient if I want to use phpMyAdmin and/or phpPgAdmin to manage my MySQL/PostgreSQL servers. It also gives me an environment in which I can run both ruby and php applications.


5. Test-Run

At the end of installation process, it asked me if I want to run it. I said yes. And here is the result screen (default page at http://localhost).



I clicked the link to run its sample Rails app.




6. Launch Ruby Stack Manager

The Ruby Stack Manager is a desktop application you can use to manually start/stop servers.

$ sudo /opt/rubystack-2.2.2-0/manager-linux-x64.run




7. Starting Servers Automatically At Start up

This installer for Linxu did not setup servers to start automatically. So I had to make some changes to do just that.

I found a simple instruction at http://stackoverflow.com/questions/22037222/how-to-start-bitnami-rubystack-environment-on-linux:

$ sudo -i
# cd /etc/init.d
# ln -s /opt/rubystack-2.2.2-0/ctlscript.sh bitnami-rubystack
# chmod +x bitnami-rubystack
# update-rc.d bitnami-rubystack defaults
# update-rc.d bitnami-rubystack enable
# exit
$

Now restart Ubuntu and check if its servers automatically start.

Check its webserver:
http://localhost


Check its MySQL server:
http://localhost/phpmyadmin
Check its PostgreSQL server:
http://localhost/phppgadmin



8. Set up Environment Variable PATH

Finally, I set up environment variable PATH so that newly installed Ruby and related tools are readily available on my command line.

Open rubyconsole file:
$ leafpad /opt/rubystack-2.2.2-0/rubyconsole
And copy the line that begins with PATH="/opt/rubystack-2.2.2-0/...."
Then paste it on .bashrc file.
export PATH="/opt/rubystack-2.2.2-0/...$PATH"
Restart the terminal and test Ruby on command line.
$ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
$ rails -v
Rails 4.2.0
$ irb
irb(main):001:0> 1+2
=> 3
irb(main):002:0> exit

Sunday, February 8, 2015

Installing Geany on Mint 17

I installed Geany on Mint 17. Geany is a small text-editor/IDE.

RESOURCES

INSTALLATION

  1. Open Synaptic Package Manager
  2. Search for "geany" and install it

TEST

 $
 $ geany

Sunday, February 1, 2015

Installing Ruby on Mint 17, Using Ruby-install

I installed Ruby (2.1.3 and 2.2.0), using ruby-install on my Mint 17.

1. Resources

2. Installation of ruby-install

$ wget -O ruby-install-0.5.0.tar.gz https://github.com/postmodern/ruby-install/archive/v0.5.0.tar.gz
$ tar -xzvf ruby-install-0.5.0.tar.gz
$ cd ruby-install-0.5.0/
$ sudo make install

3. Testing ruby-install

$ ruby-install --version
ruby-install: 0.5.0

$ ruby-install  # display supported rubies
Latest ruby versions:
  ruby:
    1.9.3-p547
    2.0.0-p576
    2.1.3
  jruby:
    1.7.16
  rbx:
    2.2.10
  maglev:
    1.0.0
  mruby:
    1.0.0

$ ruby-install --help
usage: ruby-install [OPTIONS] [RUBY [VERSION] [-- CONFIGURE_OPTS ...]]

Options:
 -r, --rubies-dir DIR Directory that contains other installed Rubies
 -i, --install-dir DIR Directory to install Ruby into
     --prefix DIR        Alias for -i DIR
     --system  Alias for -i /usr/local
 -s, --src-dir DIR Directory to download source-code into
 -c, --cleanup  Remove archive and unpacked source-code after installation
 -j, --jobs JOBS  Number of jobs to run in parallel when compiling
 -p, --patch FILE Patch to apply to the Ruby source-code
 -M, --mirror URL Alternate mirror to download the Ruby archive from
 -u, --url URL  Alternate URL to download the Ruby archive from
 -m, --md5 MD5  MD5 checksum of the Ruby archive
     --sha1 SHA1  SHA1 checksum of the Ruby archive
     --sha256 SHA256 SHA256 checksum of the Ruby archive
     --sha512 SHA512 SHA512 checksum of the Ruby archive
 --no-download  Use the previously downloaded Ruby archive
 --no-verify  Do not verify the downloaded Ruby archive
 --no-extract  Do not re-extract the downloaded Ruby archive
 --no-install-deps Do not install build dependencies before installing Ruby
 --no-reinstall   Skip installation if another Ruby is detected in same location
 -V, --version  Prints the version
 -h, --help  Prints this message

Examples:
 $ ruby-install ruby
 $ ruby-install ruby 2.0
 $ ruby-install ruby 2.0.0-p0
 $ ruby-install ruby -- --with-openssl-dir=...
 $ ruby-install -M https://ftp.ruby-lang.org/pub/ruby ruby
 $ ruby-install -M http://www.mirrorservice.org/sites/ftp.ruby-lang.org/pub/ruby ruby
 $ ruby-install -p https://raw.github.com/gist/4136373/falcon-gc.diff ruby 1.9.3

4. Install Latest Stable version of Ruby, using ruby-install

$ ruby-install ruby
>>> Installing ruby 2.1.3 into /home/(user)/.rubies/ruby-2.1.3 ...
>>> Installing dependencies for ruby 2.1.3 ...
.
.
>>> Successfully installed ruby 2.1.3 into /home/socrateos/.rubies/ruby-2.1.3
$ cd ~/.rubies/ruby-2.1.3/bin
$ ./ruby --version
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux] 

5. Install Latest version of Ruby (2.2.0), using ruby-install


$ ruby-install ruby 2.2.0
>>> Installing ruby 2.2.0 into /home/socrateos/.rubies/ruby-2.2.0 ...
>>> Installing dependencies for ruby 2.2.0 ...
.
.
>>> Successfully installed ruby 2.2.0 into /home/socrateos/.rubies/ruby-2.2.0
$ cd ~/.rubies/ruby-2.2.0/bin
$ ./ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]

5. Change PATH environment variable


$ gedit ~/.profile
export PATH="$PATH:$HOME/.rubies/ruby-2.2.0/bin/"

Relogin and check.


$ ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
$ irb
irb(main):001:0> RUBY_VERSION
=> "2.2.0"

Installing Amazon Kindle Reader on Mint 17

1. Resources

2. Preparation

Since there is no native Kindle application for Linux, you have to install Wine/PlayOnLinux first. See my installation notes: Installing PlayOnLinux on Mint 17

3. Install Amazon Kindle Reader for PC

Download installer file:

$ cd ~/Downloads
$ wget http://kindleforpc.amazon.com/40514/KindleForPC-installer.exe

Open PlayOnLinux and Click "+ Install" button.

Wait for some updates. It took for several minutes for me. It will open a "Wizard" screen to lead the installation step by step.

First, search for "Amaz". When found, select "Amazon Kindle" from the list box and click "Install" button.

Next, select "Use a set-up file on my computer" in the list and click "Next" button.

When prompted, select the installer file (KindleForPC-installer.exe) you downloaded earlier. Then click "Next" button.

When the installation is complete, it will open a familiar Kindle screen.

4. Run Amazon Kindle Reader

Launch "PlayOnLinux". Select "Amazon Kindle" from the list and click "Run". It will open Kindle reader.

5. Notes

  • When I clicked "+ Install" button for the first time, it did a lengthy update, including (looks like) re-installing of Wine 1.6.2. before the Wizard window appeared on screen.
  • Installer wizard does not close until you quit the Kindle Application it opened at the end of installation process.

Saturday, January 31, 2015

Installing PlayOnLinux on Mint 17

I installed PlayOnLinux on Mint 17. It is a software (GUI for Wine) that allows to run Windows applications on Linux.

The reason is mainly that I wanted to read (on my Mint box) Kindle e-books that I have already purchased over the years. Generally I use my (non-kindle) tablet to read e-books, but some of books are about Ruby programming and I want to read them on my Mint box while doing some programming. From now on, I am going to avoid buying Kindle books unless it is absolutely necessary.

1. Resources

2. Installation

  1. Open Synaptic Package Manager.
  2. Search for and install "playonlinux".
It installed following packages, including Wine itself (1.6).

curl (7.35.0-1ubuntu2.3)
icoutils (0.31.0-2)
imagemagick (8:6.7.7.10-6ubuntu3)
imagemagick-common (8:6.7.7.10-6ubuntu3)
libencode-locale-perl (1.03-1)
libfile-listing-perl (6.04-1)
libhtml-parser-perl (3.71-1build1)
libhtml-tagset-perl (3.20-2)
libhtml-tree-perl (5.03-1)
libhttp-cookies-perl (6.00-2)
libhttp-date-perl (6.02-1)
libhttp-message-perl (6.06-1)
libhttp-negotiate-perl (6.00-2)
libio-html-perl (1.00-1)
liblcms2-2:i386 (2.5-0ubuntu4)
liblqr-1-0 (0.4.1-2ubuntu1)
liblwp-mediatypes-perl (6.02-1)
liblwp-protocol-https-perl (6.04-2ubuntu0.1)
libmagickcore5 (8:6.7.7.10-6ubuntu3)
libmagickwand5 (8:6.7.7.10-6ubuntu3)
libnet-http-perl (6.06-1)
libwww-perl (6.05-2)
libwww-robotrules-perl (6.01-1)
libwxbase2.8-0 (2.8.12.1+dfsg-2ubuntu2)
libwxgtk-media2.8-0 (2.8.12.1+dfsg-2ubuntu2)
libwxgtk2.8-0 (2.8.12.1+dfsg-2ubuntu2)
ocl-icd-libopencl1 (2.1.3-4)
ocl-icd-libopencl1:i386 (2.1.3-4)
p7zip-full (9.20.1~dfsg.1-4)
playonlinux (4.2.2-1)
python-wxgtk2.8 (2.8.12.1+dfsg-2ubuntu2)
python-wxversion (2.8.12.1+dfsg-2ubuntu2)
wine (1:1.6.2-0ubuntu4)
wine1.6 (1:1.6.2-0ubuntu4)
wine1.6-amd64 (1:1.6.2-0ubuntu4)
wine1.6-i386:i386 (1:1.6.2-0ubuntu4)

The installer created a new menu group "Wine". But it did not create menu item for PlayOnLinux. So I added a new menu item for "PlayOnLinux" and placed under "Wine" menu group.

3. Test

First, I opened "Notepad" from the Wine menu.

Before opening Note window, it found missing a couple packages and automatically installed them though it failed once during the installation. I just kept clicking "Install" button and it finally opened Notepad window.

Then, I clicked "Browse C: Drive" from the Wine menu. It showed the following window.

Finally, I clicked "PlayOnLinux" menu item I have created to open "PlayOnLinux".

It seems that Wine/PlayInLinux is playing fine.

4. Notes

Even though I read instructions in the PlayInLinux home page's download page, I did not follow. It warns: "Ubuntu Precise (and superior) users : You must install the package wine:i386 to get PlayOnLinux working".

I searched for an instruction for Mint 17 because of this warning but did not find any. So I decided to use Synaptic Package Manager to install because it automatically finds and shows all related packages that are required. Yes, it did install "wine1.6-i386:i386 (1:1.6.2-0ubuntu4)"

Friday, January 30, 2015

Installing git on Mint 17

1. References

2. Pre-installation

$ git --version
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git

3. Installation

$ sudo apt-get install git
.
.
The following NEW packages will be installed
  git git-man liberror-perl
.
.
Setting up liberror-perl (0.17-1.1) ...
Setting up git-man (1:1.9.1-1ubuntu0.1) ...
Setting up git (1:1.9.1-1ubuntu0.1) ...
$ git --version
git version 1.9.1

4. Configuration

$ git config --global user.name "myname"
$ git config --global user.email "myname@myhost.com"
$ git config --global color.ui auto # colorize command line

Sunday, January 4, 2015

Installing Sublime Text 3 on Mint 17

I have installed Sublime Text 3 on Mint 17.

1. Resources

Sublime Home Page: http://www.sublimetext.com/

2. Installation

I installed it using Synaptic Package Manager since it had a latest version (build 3065). See Download site for to confirm latest version: http://www.sublimetext.com/3

a. Open Synaptic Package Manager.
b. Search and install "sublime-text".
c. After installation, the sublime-text appears in the Programming menu.

Installing Bitnami Ruby Stack on Mint 17

I have installed Bitnami Ruby Stack on my Mint 17. Bitnami Ruby Stack is a complete ruby development environment that includes Ruby, Rails, SQLite, MySQL, PostgreSql, Apache, Nginx (for Linux), Git, Subversion, RVM, PHP, Node.js, etc. This is one of the easiest single click installation methods for ruby development environment.

1. Sources

Bitnami Ruby Stack Isntaller download site: https://bitnami.com/stack/ruby/installer

2. Download

I downloaded "Ruby Stack 2.1.5-1 Dev (64-bit)" from https://bitnami.com/stack/ruby/installer

3. Installation

a. First make the downloaded file (bitnami-rubystack-2.1.5-1-dev-linux-x64-installer.run) executable.

(1) Right click on the downloaded file and open its Properties window.
(2) Goto Permission tab and turn on Executable check box.

b. Now execute the file to install.

(1) Double click to execute the installation file. (You have to wait for several seconds before seeing welcome screen.)
(2) I selected all features that include:

(3) I made a change to the destination: home/socrateos/rubystack/rubystack-2.1.5-1 (instead of suggested home/socrateos/rubystack-2.1.5-1) so that I may be able to install future version(s) in the same common directory "rubystack".

(4) Server manager shows initial servers that are running.

3. Create Short cuts

I have created desktop short cuts for the following files:

a. manager-linux-x64.run - to launch server manager (stop & start web and db servers)

b. rubyconsole - to launch terminal with all ruby path set up temporarily. Bitnami ruby does not interfere with normally installed ruby.

(1) Test ruby console. Double click to open the Ruby console
(2) Run a ruby command:

$ ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]

Tuesday, November 25, 2014

Installing Oracle Java 8 on Mint 17

Installed oracle java 8.

1. Resouces
http://askubuntu.com/questions/521145/how-to-install-oracle-java-on-ubuntu-14-04

2. Installation

Find current java version.


$ java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)

Install a java installer: ppa::webupd8team/java
Go to System > Administration > Software Sources > ppa
Then add ppa::webupd8team/java. $ sudo apt-get update $ sudo apt-get install oracle-java8-installer (Follow the instructions when prompted.) $ java -version java version "1.8.0_25" Java(TM) SE Runtime Environment (build 1.8.0_25-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Removing ALL ppa repositories from Ubuntu 14.04 / Mint 17

I wanted to remove several ppa repositories from my Mint 17 because I started to get error every time when I ran apt-get update after one of ppa installations failed.

The following attempts failed to remove ppa due to some errors.

(1) Using add-apt-get --remove (or -r) options
(2) Using ppa-purge command
The one worked for me was this:
Go to System > Administration > Software Sources > ppa
Then select one you want to remove and click the remove button.

Installing ppa-purge

I have installed ppa-purge on my Mint 17. 1. Open Synaptic Package Manager. 2. Search for "ppa". 3. Check ppa-purge and apply installation.

Sunday, October 26, 2014

Ruby Sample Codes to Replace String in Files

I collected sample Ruby codes for replacing string in file.

1. http://stackoverflow.com/questions/1274605/ruby-search-file-text-for-a-pattern-and-replace-it-with-a-given-value

file_names = ['foo.txt', 'bar.txt']

file_names.each do |file_name|
  text = File.read(file_name)
  new_contents = text.gsub(/search_regexp/, "replacement string")

  # To merely print the contents of the file, use:
  puts new_contents

  # To write changes to the file, use:
  File.open(file_name, "w") {|file| file.puts new_contents }
end

2. http://stackoverflow.com/questions/7290871/ruby-how-to-replace-text-in-a-file

replace="100"
filename = "xmlfile_in"
outdata = File.read(filename).gsub(/\d+<\/appId>/, "#{replace}")

File.open(filename, 'w') do |out|
  out << outdata
end

3. http://stackoverflow.com/questions/21762209/how-to-search-and-replace-strings-in-all-of-the-files-in-my-directory-using-ruby

# Set the variables for find/replace
# you can use regular variables here
original_string_or_regex = /Card Sort/
replacement_string = "CardSort"

# Dir.glob will take care of the recursivity for you
# do not use ~ but rather Dir.home
Dir.glob("#{Dir.home}/Desktop/macshapa_v2/*") do |file_name|
  text = File.read(file_name)
  replace = text.gsub!(original_string_or_regex, replacement_string)
  File.open(file_name, "w") { |file| file.puts replace }
end

4. http://www.java2s.com/Code/Ruby/File-Directory/Replacestringinafile.htm

def stringReplace(searchString, replaceString, fileName)
  aFile = File.open(fileName, "r")
  aString = aFile.read
  aFile.close

  aString.gsub!(searchString, replaceString)

  File.open(fileName, "w") { |file| file << aString }
end

stringReplace(*ARGV)

5. http://stackoverflow.com/questions/8063121/how-to-search-and-replace-string-in-ruby

text = File.read("reporttestphp2.xml").gsub("]]>*/-->","*/-->")
File.open("out.xml", "w").write(text)

6. http://blog.hulihanapplications.com/browse/view/30-recursive-text-replacement-with-ruby-linux

#!/usr/bin/env ruby  
  
require "eregex"  
  
# Recursive String Replacement, starting in current dir.  
# Author: Dave Hulihan  
  
if ARGV.length < 2  
        puts "Usage: recursive_replace [string1] [string2]"  
        exit 0  
end  
  
@string1 = ARGV[0]  
@string2 = ARGV[1]  
  
puts "Replacing #{@string1} with #{@string2}..."  
  
@string1 = Regexp.escape(@string1) # escape any special characters  
@string2 = Regexp.escape(@string2)  
  
exec("find ./ -type f | xargs sed -i 's/#{@string1}/#{@string2}/g'")  
  
puts "Done!"  
- See more at: http://blog.hulihanapplications.com/browse/view/30-recursive-text-replacement-with-ruby-linux#sthash.ez8BMRmJ.dpuf

7. http://archive.railsforum.com/viewtopic.php?id=28378

path = '/home/sthapit/workspace/socialect'
extensions = %w(.rb .css .erb .builder .rjs .js)
    
require 'find'
Find.find(path) do |f|
  if extensions.include? File.extname(f)
    buffer = File.new(f,'r').read.gsub(/slog/,'post').gsub(/Slog/,'Post')
    File.open(f,'w') {|fw| fw.write(buffer)}
  end
end

Wednesday, October 15, 2014

no talloc stackframe at ../source3/param/loadparm.c:4864, leaking memory

After upgrading my Ubuntu to 14.04, I started to get an error whenever I try to do sudo...
no talloc stackframe at ../source3/param/loadparm.c:4864, leaking memory
1. Resources
How to fix

2. Fix
(1) Execute: $ pam-auth-update
(2) Uncheck "SMB password syncronization"
(3) Save the change

Saturday, October 11, 2014

Upgraded my Ubuntu from 13.10 to 14.04

I have upgraded my Ubuntu from 13.10 to 14.04 right after upgrading 13.04 to 13.10


$ sudo do-release-upgrade -d
$ lsb_release -a   # check the version
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty

Upgraded my Ubuntu from 13.04 to 13.10

I have just upgraded my Ubuntu from 13.04 to 13.10


$ sudo do-release-upgrade -d
I found a minor problem after the installation. It was failing to make a network connection. But after rebooting my router and my Ubuntu, everything was OK.

Thursday, April 17, 2014

Installing Ruby (1.9.3) on my Windows 8.1

I installed Ruby on my Windows 8.1. I installed version 1.9.3 because 2.x is said to be not fully ready on Windows platform. I also installed related software packages: DevKit and an editor/IDE RubyMine.

1. REFERENCES

RubyIntaller for Windows: http://rubyinstaller.org/downloads/
WampServer:  http://www.wampserver.com/en/
Ruby on Windows Guides: http://rubyonwindowsguides.github.io/book/ch02-04.html


2. INSTALLING RUBY

I used RubyInstaller to install Ruby. I installed 1.9x because 2.x was not mature for Windows at this time.

Download RubyInstaller and DevKit from http://rubyinstaller.org/downloads/

Double click the downloaded executable (rubyinstaller-1.9.3-p545.exe) to install Ruby.

Test it in the command line terminal.
C:\>ruby --version
ruby 1.9.3p545 (2014-02-24) [i386-mingw32]
C:\>irb
irb(main):001:0> 1+2
=> 3
irb(main):002:0> exit


3. INSTALLING DEVKIT

(I downloaded a self-extracting DevKit when I downloaded RubyInstaller above. Since I am using Ruby 1.9x, rather than 2.x, I downloaded DevKit for that version.)

Install DevKit by double clicking downloaded self-extracting executable (DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe) in to my installation directory, which I decided to use "C:\DevKit".



Now run the following three programs to complete DevKit installation.
C:\DevKit>devkitvars.bat
Adding the DevKit to PATH...

C:\DevKit>ruby dk.rb init
[INFO] found RubyInstaller v1.9.3 at C:/Ruby193
Initialization complete!
Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

C:\DevKit>ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/Ruby193'
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'

Let's test.
C:\DevKit>bash
bash-3.1$ gcc --version
gcc.exe (tdm-1) 4.5.2
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software...
bash-3.1$ exit
exit

4. INSTALL RUBY EDITOR: RUBYMINE

I installed RubyMine, a Ruby editor/IDE. It is not a free but reasonably priced. I was looking for a Ruby editor/IDE that includes a visual debugger, and RubyMine is one of few that have this feature.
First, download its latest installer from http://www.jetbrains.com/ruby/download/.
Then double click the installer (RubyMine-6.3.exe) to install.

In order to use its debugger, I also installed the following GEMs.

C:\>gem install linecache19
Fetching: linecache19-0.5.12.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed linecache19-0.5.12
1 gem installed
Installing ri documentation for linecache19-0.5.12...
Installing RDoc documentation for linecache19-0.5.12...

C:\>gem install ruby-debug-base19x --pre
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed ruby-debug-base19x-0.11.30.pre15
1 gem installed
Installing ri documentation for ruby-debug-base19x-0.11.30.pre15...
Installing RDoc documentation for ruby-debug-base19x-0.11.30.pre15...

C:\>gem install ruby-debug-ide
Fetching: ruby-debug-ide-0.4.22.gem (100%)
Building native extensions.  This could take a while...
Successfully installed ruby-debug-ide-0.4.22
1 gem installed
Installing ri documentation for ruby-debug-ide-0.4.22...
Installing RDoc documentation for ruby-debug-ide-0.4.22...

I did a simple test. Launched Rubymine by double clicking its desktop icon. Created a project "firstproject". Created a new file "hello.rb" Then wrote a hello code as follows and ran.

Friday, November 1, 2013

Installing SQLite3 on Ubuntu/Xubuntu 13.04

1. Installing SQLite3
$ sudo apt-get install sqlite3
Test the installation.
$ mkdir sqlprj
cd sqlprj/
$ sqlite3 test.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
sqlite> .exit

2. Installing sqliteman (GUI app to manage SQLite)
sudo apt-get install sqliteman
Test the installation by launching it from menu and creating a table and inserting a few rows.


3. Installing ruby gem for SQLite3 
$ sudo apt-get install libsqlite3-dev
$ sudo gem install sqlite3
Test the installation.
#!/usr/bin/ruby
#
# test.rb
#  
# based on samples in 
# http://zetcode.com/db/sqliteruby/
#

require 'sqlite3'

begin
    
    db = SQLite3::Database.open "test.db"
    
    stm = db.prepare "SELECT * FROM party" 
    rs = stm.execute 
    
    rs.each do |row|
        puts row.join "\s"
    end
           
rescue SQLite3::Exception => e 
    puts "Exception occured"
    puts e
ensure
    stm.close if stm
    db.close if db    
end
$ ruby test.rb
1 Doe, John per
2 Big Company org