Search
Archive

You are currently browsing the archives for the TechTips category.

Categories
Ad

Archive for the ‘TechTips’ Category

Stop installing rubygems to your home directory when you don’t “sudo”

Thursday, August 6th, 2009

Problem

You don’t want to install rubygems under your home direcotry(~/.gem/ruby/1.x/) when you just forgot to “sudo” and don’t have right permissions to write to system directories.

Solution

First, You need to install rubygems newer than 1.3.2. To check the version, type as

gem -v
1.3.1

To update your gems itself, type as

sudo gem update --system

Next, you need to edit your ~/.gemrc file. Add

gem:  --no-user-install

at the bottom of the file.

Now, if you forgot to “sudo” when installing new rubygems, gem will simply fail with permission erros, like

tomoya@hongkong% gem install sequel
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /opt/local/lib/ruby/gems/1.8 directory.

No response of Sudo on Fedora 11

Tuesday, August 4th, 2009

Problem

On Fedora11 installed via Vmware, sudo does not respond for thirty or fourty secs.

Solution

The cause is that sudo is looking up your hostname to DNS, and waiting until TIMEOUT event is fired. You can fix this problem by just adding your hostname to /etc/hosts

 su -
 nano /etc/hosts
 127.0.0.1       localhost localhost.localdomain <yourhost> <yourhost>.localdomain localhost4 localhost4.localdomain

Upgrading Ubuntu using CUI: From 7.10 Gusty to 9.04 Jounty

Wednesday, July 15th, 2009

Problem

You want to uprade Ubuntu Linux to the latest version. (9.04 at this time)

Solution

to 8.04 Hardy

If your version is old enough that when you type

>sudo apt-get upgrade

and you will see 404 Errors, then You have to edit your sources.list like this.

$ sudo -s
# mv /etc/apt/sources.list /etc/apt/sources.list.gusty
# sed -e 's/gusty/hardy/g' /etc/apt/sources.list.gusty > /etc/apt/sources.list
# apt-get update
# apt-get upgrade

Then, install update-manager.

$ sudo apt-get install update-manager-core

to 8.10 Intrepid

$ sudo -s
# mv /etc/apt/sources.list /etc/apt/sources.list.hardy
# sed -e 's/hardy/intrepid/g' /etc/apt/sources.list.hardy > /etc/apt/sources.list
# apt-get update
# apt-get dist-upgrade

Intrepid to Jounty

sudo apt-get update
sudo apt-get upgrade
sudo do-release-upgrade

Finally, you can check your Ubuntu version like this.

cat /etc/lsb-release

Checking Ubuntu Version

Wednesday, July 15th, 2009

Problem

You want to check the Ubuntu version from a CUI terminal

Solution

You can find the version info here.

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.04
DISTRIB_CODENAME=jaunty
DISTRIB_DESCRIPTION="Ubuntu 9.04"

Sending ISO-2022-JP Mail from Ruby1.8

Thursday, July 9th, 2009

Problem

You want to send Japanese mail encodded in ISO-2022-JP from Ruby

Solution

I wrote a small class called Hog for this purpose.

Customizing the Explorer Menu

Thursday, July 9th, 2009

Problem

Right clicking on the Windows Explorer tends to be so slow, since the Windows needs to scan through the Registry to collect “extra menus” extended by some installed applications.

Solution (or, Suggestion)

If you do not want to change the registry by your hand, Lopesoft’s FileMenuTools is recommended. This application lists up all the extended menus and offers to toggle the visiblity of them.

using UTF8 in MySQL5

Monday, July 6th, 2009

Problem

You want to set the default character encoding to UTF8 everywhere in your MySQL

Solution

Edit my.cnf.

On Debian or Ubuntu Linux, you can find my.cnf at /etc/mysql/my.cnf. Add those lines below.

[mysqld]
default-character-set=utf8
 
[mysql]
default-character-set=utf8
 
[mysqldump]
default-character-set=utf8

On MacOSX, when you installed MySQL via MacPorts, you have to create one at /opt/local/etc/mysql5/my.cnf.

[mysqld]
default-character-set=utf8
socket=/opt/local/var/run/mysql5/mysqld.sock
 
[mysql]
default-character-set=utf8
 
[mysqldump]
default-character-set=utf8
 
[client]
socket=/opt/local/var/run/mysql5/mysqld.sock

overlay contents over flash object

Wednesday, July 1st, 2009

Problem

You want to show some overlay contents (e.g. dropdown menu items) over Flash objects.

Solution

You can enable z-index features of HTML to Flash objects by adding some parameters.

<object ...>
<param name="wmode" value="transparent" /
<embed ... wmode="transparent"/
</object>

g++ on RHEL 5

Wednesday, June 17th, 2009

Problem

g++ is not installed on your Redhat EL 5 at default.

Solution

Try;

% yum install gcc-c++ compat-gcc-*
% which g++

If you still not find g++, maybe g++ is saved as g++32 in /usr/bin. If so, create a symbolic link to g++32.

% ln -s /usr/bin/g++32 /usr/bin/g++

Fail to compile Ruby1.9 on VPS because of the RAM size.

Wednesday, June 17th, 2009

Problem

You want to compile ruby1.9, but failed with errors:

gcc -I. -I.ext/include/i686-linux -I./include -I. -D_FILE_OFFSET_BITS=64  -DONIG_ENC_REGISTER=rb_enc_register -fPIC  -O2 -g -Wall -Wno-parentheses  -o enc/trans/gb18030.o -c ./enc/trans/gb18030.c
virtual memory exhausted: Cannot allocate memory
make[1]: *** [enc/trans/gb18030.o] Error 1
make[1]: Leaving directory `/home/roiadmin/tmp/ruby-1.9.1-p129'
make: *** [trans] Error 2

You maybe tried changing ulimit values or add gcc-min-heapsize parameters, but all failed in vain.

Solution

The best way to do so is remove gb18030.c from compilation packages. Hope you are not planning to use Chinese GB18030 encoded-strings in Ruby.
The compile instructions are written in “enc.mk”. So all you need to do is delete all lines about gb18030 in “enc.mk”.

If you are compileing 1.9.1-p129, you can use this patch file.

*** enc.mk.org	Wed Jun 17 21:36:49 2009
--- enc.mk	Wed Jun 17 21:38:44 2009
***************
*** 79,85 ****
  	  enc/euc_kr.$(OBJEXT) \
  	  enc/euc_tw.$(OBJEXT) \
  	  enc/gb2312.$(OBJEXT) \
- 	  enc/gb18030.$(OBJEXT) \
  	  enc/gbk.$(OBJEXT) \
  	  enc/iso_8859_1.$(OBJEXT) \
  	  enc/iso_8859_2.$(OBJEXT) \
--- 79,84 ----
***************
*** 113,119 ****
  	 $(ENCSODIR)/euc_kr.$(DLEXT) \
  	 $(ENCSODIR)/euc_tw.$(DLEXT) \
  	 $(ENCSODIR)/gb2312.$(DLEXT) \
- 	 $(ENCSODIR)/gb18030.$(DLEXT) \
  	 $(ENCSODIR)/gbk.$(DLEXT) \
  	 $(ENCSODIR)/iso_8859_1.$(DLEXT) \
  	 $(ENCSODIR)/iso_8859_2.$(DLEXT) \
--- 112,117 ----
***************
*** 147,153 ****
  TRANSCSRCS = enc/trans/big5.c \
  	     enc/trans/chinese.c \
  	     enc/trans/escape.c \
- 	     enc/trans/gb18030.c \
  	     enc/trans/gbk.c \
  	     enc/trans/iso2022.c \
  	     enc/trans/japanese.c \
--- 145,150 ----
***************
*** 161,167 ****
  	    enc/trans/big5.$(OBJEXT) \
  	    enc/trans/chinese.$(OBJEXT) \
  	    enc/trans/escape.$(OBJEXT) \
- 	    enc/trans/gb18030.$(OBJEXT) \
  	    enc/trans/gbk.$(OBJEXT) \
  	    enc/trans/iso2022.$(OBJEXT) \
  	    enc/trans/japanese.$(OBJEXT) \
--- 158,163 ----
***************
*** 175,181 ****
  	   $(ENCSODIR)/trans/big5.$(DLEXT) \
  	   $(ENCSODIR)/trans/chinese.$(DLEXT) \
  	   $(ENCSODIR)/trans/escape.$(DLEXT) \
- 	   $(ENCSODIR)/trans/gb18030.$(DLEXT) \
  	   $(ENCSODIR)/trans/gbk.$(DLEXT) \
  	   $(ENCSODIR)/trans/iso2022.$(DLEXT) \
  	   $(ENCSODIR)/trans/japanese.$(DLEXT) \
--- 171,176 ----
***************
*** 267,276 ****
  	@$(MAKEDIRS) "$(@D)"
  	$(LDSHARED) -o $@ enc/gb2312.$(OBJEXT) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
 
- $(ENCSODIR)/gb18030.$(DLEXT): enc/gb18030.$(OBJEXT)
- 	@$(MAKEDIRS) "$(@D)"
- 	$(LDSHARED) -o $@ enc/gb18030.$(OBJEXT) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
- 
  $(ENCSODIR)/gbk.$(DLEXT): enc/gbk.$(OBJEXT)
  	@$(MAKEDIRS) "$(@D)"
  	$(LDSHARED) -o $@ enc/gbk.$(OBJEXT) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
--- 262,267 ----
***************
*** 383,392 ****
  	@$(MAKEDIRS) "$(@D)"
  	$(LDSHARED) -o $@ enc/trans/escape.$(OBJEXT) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
 
- $(ENCSODIR)/trans/gb18030.$(DLEXT): enc/trans/gb18030.$(OBJEXT)
- 	@$(MAKEDIRS) "$(@D)"
- 	$(LDSHARED) -o $@ enc/trans/gb18030.$(OBJEXT) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
- 
  $(ENCSODIR)/trans/gbk.$(DLEXT): enc/trans/gbk.$(OBJEXT)
  	@$(MAKEDIRS) "$(@D)"
  	$(LDSHARED) -o $@ enc/trans/gbk.$(OBJEXT) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
--- 374,379 ----
***************
*** 451,460 ****
  	-@$(MAKEDIRS) "$(@D)"
  	$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(encsrcdir)/gb2312.c
 
- enc/gb18030.$(OBJEXT): $(encsrcdir)/gb18030.c
- 	-@$(MAKEDIRS) "$(@D)"
- 	$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(encsrcdir)/gb18030.c
- 
  enc/gbk.$(OBJEXT): $(encsrcdir)/gbk.c
  	-@$(MAKEDIRS) "$(@D)"
  	$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(encsrcdir)/gbk.c
--- 438,443 ----
***************
*** 567,576 ****
  	-@$(MAKEDIRS) "$(@D)"
  	$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(encsrcdir)/trans/escape.c
 
- enc/trans/gb18030.$(OBJEXT): $(encsrcdir)/trans/gb18030.c
- 	-@$(MAKEDIRS) "$(@D)"
- 	$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(encsrcdir)/trans/gb18030.c
- 
  enc/trans/gbk.$(OBJEXT): $(encsrcdir)/trans/gbk.c
  	-@$(MAKEDIRS) "$(@D)"
  	$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(encsrcdir)/trans/gbk.c
--- 550,555 ----

Enjoy!