Tuesday, November 25, 2014

Installing Oracle Java 8 on Mint 17

Installed oracle java 8.

1. Resouces

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 }

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

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

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

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 }

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

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

  aString.gsub!(searchString, replaceString)

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


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  
@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)}

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.


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


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]
irb(main):001:0> 1+2
=> 3
irb(main):002:0> exit


(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.
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.
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


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.