Tuesday, December 24, 2013

Friday, December 13, 2013

Rails - Define class method in module file

module PicturePartials
module Cse

def self.included(base)
base.extend ClassMethods
end

module ClassMethods
def find_by_picture_id(picture_id)
Picture.joins(:picture).where('picture_id = ?', picture_id).first
end
end


end
end

Thursday, November 28, 2013

Ubuntu upgrade postgresql server from 8.4 to 9.2

Thursday, November 14, 2013

Restart network interface

sudo /etc/init.d/networking restart

Ubuntu find versions

uname -a (for kernel version)

lsb_release -a (for ubuntu version)

sudo fdisk -l (for partition info)

Wednesday, October 23, 2013

Ubuntu start Tomcat on boot

Automatic Starting

To make tomcat automatically start when we boot up the computer, you can
add a script to make it auto-start and shutdown.

sudo vi /etc/init.d/tomcat

Now paste the following content:

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun

case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0
You'll need to make the script executable by running the chmod command:

sudo chmod 755 /etc/init.d/tomcat

The last step is actually linking this script to the startup folders
with a symbolic link. Execute these two commands and we should be on our
way.

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat

sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

Tuesday, October 15, 2013

Install webmin on Ubuntu

1. Download from http://www.webmin.com
2. sudo dpkg -i webmin_x.xxxx_all.deb  (with error)
3. sudo apt-get install -f (will fix the error)
4. https://xxx.xxx:1000
DONE

Tuesday, October 8, 2013

diagnostic cap deploy permission denied public key

Problem:

xxxxx@xxxxx:~/RubyProjects/xxxxx$ bundle exec cap xxxxx deploy:migrations
/usr/local/rvm/gems/ree-1.8.7-2012.02@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:211: warning: Insecure world writable dir /usr/local/rvm/gems in PATH, mode 042777
/usr/local/rvm/gems/ree-1.8.7-2012.02@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:211: warning: Insecure world writable dir /usr/local/rvm/gems in PATH, mode 042777
  * executing `xxxxx'
    triggering start callbacks for `deploy:migrations'
  * executing `multistage:ensure'
  * executing `eighties_bands:ensure'
  * executing `deploy:migrations'
  * executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote git@xxxxx.unfuddle.com:xxx/xxxxx.git xxxxx-4"
    command finished in 4746ms
  * executing "if [ -d /home/xxxxx/deploy/shared/cached-copy ]; then cd /home/xxxxx/deploy/shared/cached-copy && git fetch -q origin && git reset -q --hard b40a43e351c2107de5c6bc8dae0c70de86465305 && git clean -q -d -x -f; else git clone -q  git@xxx.unfuddle.com:xxx/xxxxx.git /home/xxxxx/deploy/shared/cached-copy && cd /home/xxxxx/deploy/shared/cached-copy && git checkout -q -b deploy b40a43e351c2107de5c6bc8dae0c70de86465305; fi"
    servers: ["115.160.152.28"]
    [115.160.152.28] executing command
 ** [115.160.152.28 :: err] Permission denied (publickey).
 ** [115.160.152.28 :: err] fatal: The remote end hung up unexpectedly
    command finished in 13024ms
failed: "sh -c 'if [ -d /home/xxxxx/deploy/shared/cached-copy ]; then cd /home/xxxxx/deploy/shared/cached-copy && git fetch -q origin && git reset -q --hard b40a43e351c2107de5c6bc8dae0c70de86465305 && git clean -q -d -x -f; else git clone -q  git@xxx.unfuddle.com:xxx/xxxxx.git /home/xxxxx/deploy/shared/cached-copy && cd /home/xxxxx/deploy/shared/cached-copy && git checkout -q -b deploy b40a43e351c2107de5c6bc8dae0c70de86465305; fi'" on 115.160.152.28

Reason:
  git login failed on target machine.

Checkings:
ssh -v git@xxx.unfuddle.com
  • Check this on deployment machine and target server
  • If success, should see this: Authentication succeded (publickey).
  • If denied, will see this: debug1: Authentications that can continue: publickey
    • This means the connection to git server is denied.
Solution:
On deployment machine,

  • ForwardAgent yes (.ssh/config)
  • Check if ssh-agent is running
    • ps aux | grep ssh
  • Add key to ssh:
    • ssh-add ~/.ssh/id_rsa
  • Check key:
    • ssh-add -l
  • Done

Tuesday, September 24, 2013

Change ubuntu apt-get mirror site

sudo vi /etc/apt/sources.list

deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu precise main restricted
universe multiverse
deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu precise main restricted
universe multiverse

deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu precise-updates main
restricted universe multiverse
deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu precise-updates main
restricted universe multiverse

:wq

sudo apt-get update

(e.g.) sudo apt-get install maven

Allow remote access to postgres sql

edit /etc/postgresql/9.1/main/postgresql.conf

listen_address = '*'

edit /etc/postgresql/9.1/main/pg_hba.conf

replace the config with:

host all all 0.0.0.0/0 md5

Check 32 bit or 64 bit Ubuntu version

uname -a

Result for 32-bit Ubuntu:

Linux discworld 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC
2011 i686 i686 i386 GNU/Linux

whereas the 64-bit Ubuntu will show:

Linux discworld 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC
2011 x86_64 x86_64 x86_64 GNU/Linux

Wednesday, September 4, 2013

Backup postgresql using pgdump

>sudo su - postgres
>pg_dump some_database_name > somename.sql

Tuesday, July 23, 2013

Mysql dump backup and restore all database

Backup:

  mysqldump --flush-privileges --all-database -p > mysqldump.all.database.20130723.sql


Restore:

  mysql -u root -p < mysqldump.all.database.20130723.sql

Monday, July 22, 2013

Solved: apt-get install 404 Not Found

sudo apt-get update

Solve: apache You don't have permission to access / on this server

In httpd.conf

<Directory />
    #Options FollowSymLinks
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>

Thursday, May 2, 2013

Ubuntu change name/ hostname


# vim /etc/hostname
內容改為自己要的名字
# vim /etc/hosts
這邊最好也要改,免得有些 service 會出錯
# /etc/init.d/hostname.sh or # sudo service hostname restart
重新啟動
# hostname
驗證是否已經修改完畢。

Tuesday, April 30, 2013

postgresql create drop user

Postgresql server start

Use the following command (from terminal) to control the PostgreSQL server
Start the service : /etc/init.d/postgresql start
Stop the service : /etc/init.d/postgresql stop
Know the status : /etc/init.d/postgresql status
Restart the service : /etc/init.d/postgresql restart

Read more: http://linuxpoison.blogspot.tw/2012/01/how-to-install-configure-postgresql.html#ixzz2RutcjeNH

Thursday, April 25, 2013

ubuntu fix ip

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

File: /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static


address 192.168.8.188
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.225
gateway 192.168.8.1
dns-nameservers 192.168.8.201 202.130.97.65

sudo /etc/init.d/networking restart


mac hosts file

sudo vi /private/etc/hosts

Install apache for ruby on rails on Ubuntu

  1. Install apache2
    1. sudo apt-get update
    2. sudo apt-get install apache2
  2. Enable https
    1. sudo a2enmod ssl
      sudo a2ensite default-ssl

      sudo service apache2 restart
  3. Install Passenger
    1. gem install passenger
    2. passenger-install-apache2-module
    3. sudo apt-get install libcurl4-openssl-dev
    4. rvmsudo rvm get head && rvm reload && rvm repair all
    5. Permission denied -> chmod 777...

Install passenger on ubuntu

Ubuntu: Curl development headers with SSL support

By: Richard26-11-2010computing
Share
Just been trying to install Passenger on a new Ubuntu EC2 instance and
passenger is giving me the error:


* Curl development headers with SSL support... not found


Took some digging around but turns out I was just missing the
libcurl4-openssl-dev package:


sudo apt-get install libcurl4-openssl-dev

Solve Apache2 permission problem.

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>

Monday, April 15, 2013

vim binary mode

To binary mode -- :%!xxd
To normal mode -- :%!xxd -r

Sunday, April 14, 2013

Git move master to branch

git checkout target_branch
git merge --strategy==ours --no-commit master
git commit -m "Move master to this branch..."
git checkout master
git merge target_branch

Git command history

>git reflog

Friday, April 5, 2013

Linux - Bash encrypt and decrypt file

openssl des3 -salt -in unencrypted-data.file \
-out encrypted-data.file.des3

openssl des3 -d -salt -in encrypted-data.file.des3 \
-out unencrypted-data.file

Thursday, March 14, 2013

Wednesday, March 13, 2013

Migrate Atlassian Confluence local version 4.0 to OnDemand version 5.0

  1. Backup current wiki data to XML.
  2. Upgrade local 4.0 to 5.0 version.
  3. Subscribe Confluence OnDemand service.
  4. Export space from local wiki, one by one, since OnDemand version cannot restore the whole backup in one click.
  5. Import spaces to OnDemand.
  6. Done.

Tuesday, March 12, 2013

Mac reset password

1. Press and Hold Command-R when startup.
2. Open terminal.
3. >resetpassword

Friday, March 8, 2013

Thursday, March 7, 2013

Monday, March 4, 2013

Rails - update attr_readonly field from sql

The easiest way to update field with attr_readonly is to update by
database sql.

$> psql -d xxx -U xxx
xxx> update ... set ... where ...

Wednesday, February 27, 2013

Thursday, February 21, 2013

Rails - Caution on adding new column and assign value to it in the same db migration - reset_column_information

This happens on staging/production rails env.

If you add a new column 'xxx' and assign value to it in the same migration,

Then, you may get error like this: undefined method 'xxx'

You should do a column reset after add column:

e.g. User.reset_column_information


Tuesday, February 19, 2013

selenium ide - AssertConfirmation wildcard *

AssertConfirmation *

Postgresql - show version

psql --version

OR

postgres=# select version();

Postgresql - list users

\du

Git global config

git config --global user.name "Your Name"
git config --global user.email you@example.com

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.log auto

Mac enable root user

How to enable the root user

OS X Lion

  1. From the Apple menu choose System Preferences....
  2. From the View menu choose Users & Groups.
  3. Click the lock and authenticate as an administrator account.
  4. Click Login Options....
  5. Click the "Edit..." or "Join..." button at the bottom right.
  6. Click the "Open Directory Utility..." button.
  7. Click the lock in the Directory Utility window.
  8. Enter an administrator account name and password, then click OK.
  9. Choose Enable Root User from the Edit menu.
  10. Enter the root password you wish to use in both the Password and Verify fields, then click OK.


http://support.apple.com/kb/HT1528?viewlocale=en_US

Monday, February 18, 2013

Edit hosts file on Mac OS

$> sudo vi /private/etc/hosts

115.160.xxx.12 staging
115.160.xxx.11 production

Friday, February 15, 2013

Rails - Solved - relation 'xxx' does not exist

ActiveRecord::StatementInvalid: PGError: ERROR: relation "xxx" does not
exist
LINE 1: DELETE FROM "xxx"
^
: DELETE FROM "xxx"


Solution:

Remove test/fixture/xxx.yml if exists.

Friday, February 1, 2013

Thursday, January 24, 2013

Friday, January 11, 2013

Management - Request agile developer to submit a feature spec and design spec before beginning a new story

In an agile development environment, developer will collect story owner feature requirement and then design the way to implement. To overview the job to be carry out by developer, team leader have to get a sense of what has been requested and what is being prepared and designed.

Git - Find changes of a file within all local branches

git log --all -- somefile_fullpath

Thursday, January 10, 2013

Tuesday, January 8, 2013

Linux - rsync from local to remote

rsync -au /var/www/confluence/confluence-data/backups -e 'ssh -p 1337' your_name@some_ip:/home/your_name/backups/wiki_backups

Saturday, January 5, 2013

Apache supporting multiple domain websites with single IP

Listen 443
NameVirtualHost *:443
SSLStrictSNIVHostCheck off
<VirtualHost *:443>
DocumentRoot /srv/www/example1.com/
ServerName www.example1.com
...
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /srv/www/example2.com/
ServerName www.example2.com
...
</VirtualHost>

Thursday, January 3, 2013

Create a SSL Cert, sign by Godaddy.com, install on Apache

  • Login VPS, root@ubuntu:~# openssl req -new -newkey rsa:2048 -nodes -keyout your_domain.key -out your_domain.csr
  • Godaddy.com
    • Product > SSL Cert
      • Basic SSL Cert
      • 3 yrs
    • Add to cart
    • Checkout
    • Payment
    • Account > SSL Cert
      • Setup
      • Launch
    • Current Certificates
      • Credits
        • Refresh
      • Request Certificate
        • Choose 3rd party
        • Paste your_domain.csr content to form
        • submit
  • Wait for email.
  • Download cert from Godaddy.com.
    • Select Apache.
  • Copy your_domain.crt and gd_bundle.crt (the CA's bundle file) to VPS, e.g. /etc/ssl/private/
  • Edit /etc/apache2/sites-available/default.ssl
    • SSLCertificateFile /etc/ssl/private/your_domain_com.crt
    • SSLCertificateKeyFile /etc/ssl/private/private.key
    • SSLCACertificateFile /etc/ssl/private/gd_bundle.crt
  • Restart apache.  $> sudo service apache2 restart
  • Done


References:
http://support.godaddy.com/help/article/5269/generating-a-certificate-signing-request-csr-apache-2x
http://support.godaddy.com/help/article/562/requesting-standard-and-wildcard-ssl-certificates
http://support.godaddy.com/help/article/5238/installing-an-ssl-certificate-in-apache

https://help.ubuntu.com/12.04/serverguide/httpd.html
http://www.geocerts.com/install/apache_2

Tuesday, January 1, 2013

Toolbox - Zabbix

Zabbix is the ultimate open source availability and performance
monitoring solution. Zabbix offers advanced monitoring, alerting, and
visualization features today which are missing in other monitoring
systems, even some of the best commercial ones.