<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Geocoding service</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
#panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latlng
}
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
var address_array =
[
"Shop 3-5, G/F, Po Fung Building, 1-7 Hop Yick Road, Yuen Long ",
"Rm 401, 4/F, Sincere House, 83 Argyle Street, Mong Kok ",
"Shop M001, Long Ping Commercial Complex, Long Ping Estate, Yuen Long ",
"Shop G06, G/F, Spot, 48 Lung Sum Avenue, Shek Wu Hui, Sheung Shui ",
"Unit 3, 2/F, United Success Commercial Centre, 508 Jaffe Road, Causeway
Bay "
];
count = 0
function codeAddress() {
//var address = document.getElementById('address').value;
var address = address_array[count];
if(typeof(address) == 'undefined') {
alert("Map completed.");
clearInterval(intervalID);
return;
}
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
//alert("OVER_QUERY_LIMIT, just press ok to continue :) ");
count--;
} else {
the_index = address.indexOf(',');
if(the_index > 0) {
address_array.push(address.substring(the_index + 1,
address.length));
}
//alert('Geocode was not successful for the following reason: '
+ status);
//var error_messages = $('#messages').html() + status + " --- "
+ address + "<br/>"
//$('#messages').html(error_messages);
}
}
});
count++;
}
google.maps.event.addDomListener(window, 'load', initialize);
$(document).ready(function() {
//var intervalID = window.setInterval(codeAddress(), 1000);
start_map();
});
</script>
<script>
var intervalID;
function start_map() {
intervalID = window.setInterval(function(){codeAddress()}, 1000);
}
</script>
</head>
<body>
<div id="panel">
<!--
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Geocode" onclick="start_map()">
-->
</div>
<div id="map-canvas" ></div>
<div id="messages" style='font-family:arial;' >The following
addresses cannot be marked: <br/></div>
</body>
</html>
Wednesday, July 9, 2014
Monday, June 23, 2014
Rails - Make Delayed job work with Rspec in tests
Turn off the queuing and let delayed job to run:
Delayed::Worker.delay_jobs = false
Delayed::Worker.delay_jobs = false
Friday, June 20, 2014
Rails override Time.now to return Time.zone.now
In initializer, add this:
class << Time
alias :system_now :now
def now
ActiveSupport::TimeWithZone.new(self.system_now.utc, Time.zone)
end
end
class << Time
alias :system_now :now
def now
ActiveSupport::TimeWithZone.new(self.system_now.utc, Time.zone)
end
end
Tuesday, June 17, 2014
Nagios create plugins
On monitoring host:
Create plugin in /usr/lib/nagios/plugins (in C/Perl/Script/etc)
Enable plugin by:
1. define comment in /etc/nagios-plugins/config/somefile.cfg
2. edit /etc/nagios/conf.d/localhost_nagios2.cfg
Restart:
sudo service nagios3 restart
Create plugin in /usr/lib/nagios/plugins (in C/Perl/Script/etc)
Enable plugin by:
1. define comment in /etc/nagios-plugins/config/somefile.cfg
2. edit /etc/nagios/conf.d/localhost_nagios2.cfg
Restart:
sudo service nagios3 restart
Thursday, June 12, 2014
Reviewed Ubuntu Server monitoring tools
Tried:
1. Nagios
2. Munin
3. Cacti
4. Zabbix
Turn out I like both Nagios and Zabbix.
1. Nagios
2. Munin
3. Cacti
4. Zabbix
Turn out I like both Nagios and Zabbix.
Wednesday, June 11, 2014
Setup Nagios on Ubuntu 12.10
sudo apt-get update
sudo apt-get install nagios3 nagios-nrpe-plugin
sudo apt-get install nagios3 nagios-nrpe-plugin
If you have other web pages or apps running on the same server, the following information might be useful to separate Nagios as it's own Apache virtual host on a non-standard port (for example 43326 here).
Remove standard config and create Apache virtual host;
sudo cp /etc/apache2/conf.d/nagios.conf /etc/apache2/sites-available/nagio s3 sudo rm /etc/apache2/conf.d/nagios.conf sudo vi /etc/apache2/sites-available/nagios3
To beginning of file add;
Listen 43326 <VirtualHost *:43326> ServerAdmin webmaster@localhost DocumentRoot /var/www/nagios3
To the end of the file add;
</VirtualHost>
Enable the new site;
sudo a2ensite nagios3
If you run a firewall (UFW), open the port;
sudo ufw allow 43326
Restart Apache
sudo service apache2 restart
Linux system monitoring
http://www.linuxscrew.com/2012/03/22/linux-monitoring-tools/
http://www.tecmint.com/command-line-tools-to-monitor-linux-performance/
http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html
http://www.thegeekstuff.com/2011/12/linux-performance-monitoring-tools/
http://www.opensourceforu.com/2013/12/look-top-three-network-monitoring-tools/
http://www.tecmint.com/command-line-tools-to-monitor-linux-performance/
http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html
http://www.thegeekstuff.com/2011/12/linux-performance-monitoring-tools/
http://www.opensourceforu.com/2013/12/look-top-three-network-monitoring-tools/
Tuesday, June 3, 2014
Wednesday, May 21, 2014
Rails: Specify Time.zone in delayed job
Add the following code to the project's config/initializers/delayed_job.rb
The method_missing chain will add the current Time.zone.name to the
function's argument.
The Time.zone.name will be popped by the PerformableMethod.perform chain.
Delayed::DelayProxy.class_eval do
# Embed the current time zone name to delayed job's arguments when
# adding delayed job from delay() method.
def method_missing_with_custom_time_zone(method, *args)
raise "Time zone is nil" if Time.zone.nil?
args << {:custom_time_zone => Time.zone.name}
result = method_missing_without_custom_time_zone(method, *args)
result
end
alias_method_chain :method_missing, :custom_time_zone
end
Delayed::PerformableMethod.class_eval do
# Read time zone from job's argument.
def perform_with_custom_time_zone
if self.args.last.is_a?(Hash) &&
!self.args.last[:custom_time_zone].nil?
Time.zone = args.pop[:custom_time_zone]
else
raise "Custom time zone is missing from the arguments."
end
perform_without_custom_time_zone
end
alias_method_chain :perform, :custom_time_zone
end
The method_missing chain will add the current Time.zone.name to the
function's argument.
The Time.zone.name will be popped by the PerformableMethod.perform chain.
Delayed::DelayProxy.class_eval do
# Embed the current time zone name to delayed job's arguments when
# adding delayed job from delay() method.
def method_missing_with_custom_time_zone(method, *args)
raise "Time zone is nil" if Time.zone.nil?
args << {:custom_time_zone => Time.zone.name}
result = method_missing_without_custom_time_zone(method, *args)
result
end
alias_method_chain :method_missing, :custom_time_zone
end
Delayed::PerformableMethod.class_eval do
# Read time zone from job's argument.
def perform_with_custom_time_zone
if self.args.last.is_a?(Hash) &&
!self.args.last[:custom_time_zone].nil?
Time.zone = args.pop[:custom_time_zone]
else
raise "Custom time zone is missing from the arguments."
end
perform_without_custom_time_zone
end
alias_method_chain :perform, :custom_time_zone
end
Friday, May 16, 2014
Rails test with method that invoke delayed job
class Klass
def some_function
self.delay.time_consuming_function
end
def time_consuming_function
...
end
end
class KlassTest
test "some_function" do
Delayed::Job.all.each { |job| job.destroy }
Klass.new.some_function
Delayed::Job.all.each { |job| job.invoke_job }
assert ...
end
end
def some_function
self.delay.time_consuming_function
end
def time_consuming_function
...
end
end
class KlassTest
test "some_function" do
Delayed::Job.all.each { |job| job.destroy }
Klass.new.some_function
Delayed::Job.all.each { |job| job.invoke_job }
assert ...
end
end
Monday, May 5, 2014
Postgresql server config files location
/etc/postgresql/[version]/main/
e.g. to set the listened port or location
/etc/postgresql/9.3/main/postgresql.conf
e.g. to set the listened port or location
/etc/postgresql/9.3/main/postgresql.conf
Wednesday, April 23, 2014
Tuesday, April 22, 2014
Single sign on for web applications
Trial on Atlassian Crowd
current application on
1. Ruby on rails - using devise gem
2. Java EE application.
to be cont....
current application on
1. Ruby on rails - using devise gem
2. Java EE application.
to be cont....
Thursday, April 3, 2014
Postgresql kill process
select * from pg_stat_activity;
select pg_cancel_backend([procpid]);
select pg_cancel_backend([procpid]);
What if you revoke an SSL cert?
After revoke, client may see on firefox (may not be the case on Chrome):

To by-pass the checking in firefox, do this but not recommended:

Uncheck the checking option under validation button.


To by-pass the checking in firefox, do this but not recommended:

Uncheck the checking option under validation button.

Thursday, March 6, 2014
Tuesday, February 11, 2014
Ubuntu boot startup time log graph
BootCharting: https://wiki.ubuntu.com/BootCharting
Thursday, February 6, 2014
Check installed software on windows
wmic
wmic:root\cli>/output:C:\InstallList.txt product get name, version
wmic:root\cli>exit
wmic:root\cli>/output:C:\InstallList.txt product get name, version
wmic:root\cli>exit
Monday, January 20, 2014
Monday, January 6, 2014
Ubuntu: Change the waiting time on network configuration
/etc/init/failsafe.conf
Thursday, January 2, 2014
IT Director Responsibilities and Duties
IT Director Responsibilities and Duties
Coordinate with management in developing business strategic plans and operating policies.
Coordinate with business teams to analyze project contracts, proposals, requirements, and service level agreements.
Assist in developing project budgets and timelines.
Utilize project management experience to lead various global and regional projects.
Evaluate and revise project plan to meet changing project demands.
Manage project planning, staffing, schedule and expenses.
Oversee everyday project operations to ensure timely delivery.
Oversee the availability of application and infrastructure for project execution.
Identify and assign resources to IT projects.
Organize project status meetings with customers and team members.
Interact with customers to design and execute business solutions.
Ensure project deliverables meet highest quality standards and customer requirements.
Develop departmental standards and ensure that staffs adhere to these standards.
Provide analytical and technical assistance to project team.
Collaborate with management on application development, enhancement, and deployment activities.
Evaluate project proposals and change requests and make necessary recommendations for approval or rejection of proposals.
Coordinate with management in developing business strategic plans and operating policies.
Coordinate with business teams to analyze project contracts, proposals, requirements, and service level agreements.
Assist in developing project budgets and timelines.
Utilize project management experience to lead various global and regional projects.
Evaluate and revise project plan to meet changing project demands.
Manage project planning, staffing, schedule and expenses.
Oversee everyday project operations to ensure timely delivery.
Oversee the availability of application and infrastructure for project execution.
Identify and assign resources to IT projects.
Organize project status meetings with customers and team members.
Interact with customers to design and execute business solutions.
Ensure project deliverables meet highest quality standards and customer requirements.
Develop departmental standards and ensure that staffs adhere to these standards.
Provide analytical and technical assistance to project team.
Collaborate with management on application development, enhancement, and deployment activities.
Evaluate project proposals and change requests and make necessary recommendations for approval or rejection of proposals.
Tuesday, December 24, 2013
Revisit OOP fundumentals
Inheritance
Polymorphism
Abstraction
Encapsulation
Polymorphism
Abstraction
Encapsulation
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
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
- backup database: pg_dumpall > dump.sql
- http://wiki.postgresql.org/wiki/Apt
- Create /etc/apt/sources.list.d/pgdg.list
- Put this in the file:
- deb http://apt.postgresql.org/pub/repos/apt/ [code]-pgdg main
- where [code] can be found by lsb_release -c
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- sudo apt-get update
- ps -C postgres
- sudo apt-get purge postgresql-8.4
- Create database user
- Restore database
- Done
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)
lsb_release -a (for ubuntu version)
sudo fdisk -l (for partition info)
Tuesday, November 5, 2013
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
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
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
On deployment machine,
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
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.
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
Wednesday, September 25, 2013
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
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
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
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
Friday, September 6, 2013
Wednesday, September 4, 2013
Backup postgresql using pgdump
>sudo su - postgres
>pg_dump some_database_name > somename.sql
>pg_dump some_database_name > somename.sql
Wednesday, August 28, 2013
Tuesday, August 13, 2013
Tuesday, August 6, 2013
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
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>
Tuesday, May 7, 2013
Thursday, May 2, 2013
Ubuntu change name/ hostname
# vim /etc/hostname
內容改為自己要的名字
內容改為自己要的名字
# vim /etc/hosts
這邊最好也要改,免得有些 service 會出錯
這邊最好也要改,免得有些 service 會出錯
# /etc/init.d/hostname.sh or # sudo service hostname restart
重新啟動
重新啟動
# hostname
驗證是否已經修改完畢。
驗證是否已經修改完畢。
Tuesday, April 30, 2013
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
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
# 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
Install apache for ruby on rails on Ubuntu
- Install apache2
- sudo apt-get update
- sudo apt-get install apache2
- Enable https
- sudo a2enmod ssl
sudo a2ensite default-ssl
sudo service apache2 restart - Install Passenger
- gem install passenger
- passenger-install-apache2-module
- sudo apt-get install libcurl4-openssl-dev
- rvmsudo rvm get head && rvm reload && rvm repair all
- 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
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>
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
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 merge --strategy==ours --no-commit master
git commit -m "Move master to this branch..."
git checkout master
git merge target_branch
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
-out encrypted-data.file.des3
openssl des3 -d -salt -in encrypted-data.file.des3 \
-out unencrypted-data.file
Thursday, March 14, 2013
Mysql - backup all databases
$ mysqldump -u root -p --all-databases > alldb_backup.sql
Wednesday, March 13, 2013
Migrate Atlassian Confluence local version 4.0 to OnDemand version 5.0
- Backup current wiki data to XML.
- Upgrade local 4.0 to 5.0 version.
- Subscribe Confluence OnDemand service.
- Export space from local wiki, one by one, since OnDemand version cannot restore the whole backup in one click.
- Import spaces to OnDemand.
- Done.
Tuesday, March 12, 2013
Mac reset password
1. Press and Hold Command-R when startup.
2. Open terminal.
3. >resetpassword
2. Open terminal.
3. >resetpassword
Friday, March 8, 2013
Windows 7 hosts file
C:\Windows\System32\driven\etc\hosts
Thursday, March 7, 2013
Git - remove or delete tag and remote tag
git tag -d 12345 git push origin :refs/tags/12345
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 ...
database sql.
$> psql -d xxx -U xxx
xxx> update ... set ... where ...
Wednesday, February 27, 2013
Rails - Cap deploy solve the problem on Permission denied (publickey)
Run "$>ssh-add" to add private key identities to authentication agent.
Solved.
Solved.
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
Wednesday, February 20, 2013
Rails - check routes in rails console
puts Rails.application.routes
Rails - Functional test directly calls the controller without using the routes.rb
Note that the functional tests bypass the router will not capture the
effect of changing HTTP verb.
effect of changing HTTP verb.
Tuesday, February 19, 2013
selenium ide - AssertConfirmation wildcard *
AssertConfirmation *
Postgresql - show version
psql --version
OR
postgres=# select version();
OR
postgres=# select version();
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
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
- From the Apple menu choose System Preferences....
- From the View menu choose Users & Groups.
- Click the lock and authenticate as an administrator account.
- Click Login Options....
- Click the "Edit..." or "Join..." button at the bottom right.
- Click the "Open Directory Utility..." button.
- Click the lock in the Directory Utility window.
- Enter an administrator account name and password, then click OK.
- Choose Enable Root User from the Edit menu.
- Enter the root password you wish to use in both the Password and Verify fields, then click OK.
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
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.
exist
LINE 1: DELETE FROM "xxx"
^
: DELETE FROM "xxx"
Solution:
Remove test/fixture/xxx.yml if exists.
Friday, February 1, 2013
Wednesday, January 30, 2013
Monday, January 28, 2013
Friday, January 25, 2013
Java Garbage Collection
PermGen, Garbage collection.
http://blog.takipi.com/garbage-collectors-serial-vs-parallel-vs-cms-vs-the-g1-and-whats-new-in-java-8/
RMI -> Web services
Servlet, Applet, JSP -> Spring
http://blog.takipi.com/garbage-collectors-serial-vs-parallel-vs-cms-vs-the-g1-and-whats-new-in-java-8/
RMI -> Web services
Servlet, Applet, JSP -> Spring
Thursday, January 24, 2013
Ruby - Catch or rescue multiple exceptions on the same line.
begin
...
rescue ExceptionType1, ExceptionType2 => e
...
end
...
rescue ExceptionType1, ExceptionType2 => e
...
end
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
Practice - Keep a source code map in wiki
For new joined developers to quickly locate the source code.
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
Monday, January 7, 2013
Development steps for Facebook integration - website app
- Register a Facebook account.
- Register as a Facebook developer.
- Create new app.
- Follow samples or demo on Facebook site.
References:
http://developers.facebook.com/docs/guides/web/
https://www.facebook.com/help/403653596349195/
https://developers.facebook.com/apps
https://developers.facebook.com/docs/guides/appcenter/
http://developers.facebook.com/docs/samples/
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>
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.
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.
Monday, December 31, 2012
Selenium - Get current date
<tr>
<td>storeEval</td>
<td>var d=new Date(); d.getDate()+'-'+((d.getMonth()+1))
+'-'+d.getFullYear();</td>
<td>date2</td>
</tr>
<tr>
<td>echo</td>
<td>${date2}</td>
<td></td>
</tr>
<td>storeEval</td>
<td>var d=new Date(); d.getDate()+'-'+((d.getMonth()+1))
+'-'+d.getFullYear();</td>
<td>date2</td>
</tr>
<tr>
<td>echo</td>
<td>${date2}</td>
<td></td>
</tr>
Rails solved - Capistrano change repository
- Remove deploy/shared/cached-copy
- (remove .ssh/known_hosts) <- optional
- ssh git@xxx.unfuddle.com
- (config.rb add: default_run_options[:pty] = true) <- optional
Known Hosts bug
If you are not using agent forwarding, the first time you deploy may fail due to Capistrano not prompting with this message:
# The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?
To fix this, ssh into your server as the user you will deploy with, run ssh git@github.com and confirm the prompt.
Sunday, December 30, 2012
Git tips - create an empty commit
git commit --allow-empty -m '[empty] initial commit'
Git tips - search a string on all revisions
git rev-list --all | (
while read revision; do
git grep -F 'Your search string' $revision
done
)
Friday, December 28, 2012
Linux - use rsync to backup local directory
$> rsync -au /home/source /home/target
Tuesday, December 25, 2012
Cloud server vs VPS
http://forums.eukhost.com/f45/cloud-server-vs-vps-virtual-private-server-11356/#.UNkQBpNevKw
2010
Cloud hosting offers many advantages over normal VPS or Semi-Dedicated server hosting services due to the number of servers that are being used for a single cluster, and if you or your business rely greatly on your website, Cloud hosting is the best suitable option for you. The enhanced architecture powering Cloud hosting solution utilize groups of high specification servers, network attached storage devices to reliably serve every web page, and image of a website. Inside each storage device, drives are replicated to each other in a RAID configuration to create a first level of redundancy.
With Virtual Private server, you will not get guaranteed resources that you will pay for, which means other user of the VPS node could squeeze in on your allotted resources but this is not case with Cloud server, you will get the guaranteed amount of resources you are paying for and it's always available when you need them. In addition to all these features, you will also get the ability to customize the resources of Cloud server anytime. VPS is not at all reliable when compared to Cloud server because VPS is based on software virtualization platform. Each platform of servers have their merits and demerits but here there are no demerits of Cloud server, so now it depends on you whether to choose VPS or Cloud server after understanding the needs and the service that you are looking.
http://www.vps.net/blog/2012/08/20/vps-vs-cloud-server/
Cloud Servers have three primary advantages over a traditional VPS.
Near limitless flexibility with resource sizes.
On the fly resource upgrades, sometimes without even requiring a reboot.
Significantly better redundancy
Centralized redundant storage
2010
Cloud hosting offers many advantages over normal VPS or Semi-Dedicated server hosting services due to the number of servers that are being used for a single cluster, and if you or your business rely greatly on your website, Cloud hosting is the best suitable option for you. The enhanced architecture powering Cloud hosting solution utilize groups of high specification servers, network attached storage devices to reliably serve every web page, and image of a website. Inside each storage device, drives are replicated to each other in a RAID configuration to create a first level of redundancy.
With Virtual Private server, you will not get guaranteed resources that you will pay for, which means other user of the VPS node could squeeze in on your allotted resources but this is not case with Cloud server, you will get the guaranteed amount of resources you are paying for and it's always available when you need them. In addition to all these features, you will also get the ability to customize the resources of Cloud server anytime. VPS is not at all reliable when compared to Cloud server because VPS is based on software virtualization platform. Each platform of servers have their merits and demerits but here there are no demerits of Cloud server, so now it depends on you whether to choose VPS or Cloud server after understanding the needs and the service that you are looking.
http://www.vps.net/blog/2012/08/20/vps-vs-cloud-server/
Cloud Servers have three primary advantages over a traditional VPS.
Near limitless flexibility with resource sizes.
On the fly resource upgrades, sometimes without even requiring a reboot.
Significantly better redundancy
Centralized redundant storage
VPS - not quite reliable on stability
Today, our web hosting on VPS is down. Called the technical support for
the reason saying that VPS down is common.
the reason saying that VPS down is common.
Mac shortcut symbols
Monday, December 24, 2012
Ruby - Notes on using Yardoc
List Options
$> yard help doc
Add additional tags:
>$ yardoc --tag data_source:"Data Source"
where data_source is the tag in comment. e.g. # @datasource The data is gathered by client collection.
"Data Source" is the string that appears on the generated document.
OR
Create a .yardopts file in project root, add the line --tag data_source:"Data Source"
Then >$yardoc
https://rubydoc.tenderapp.com/kb/getting-started-with-rubydocinfo/setting-up-a-yardopts-file
$> yard help doc
Add additional tags:
>$ yardoc --tag data_source:"Data Source"
where data_source is the tag in comment. e.g. # @datasource The data is gathered by client collection.
"Data Source" is the string that appears on the generated document.
OR
Create a .yardopts file in project root, add the line --tag data_source:"Data Source"
Then >$yardoc
https://rubydoc.tenderapp.com/kb/getting-started-with-rubydocinfo/setting-up-a-yardopts-file
Thursday, December 20, 2012
Ruby yardoc - Remove view source from generated document
1. Create a file like
.../your_project_directory/doc/my_template/default/method_details/setup.rb
2. $>yardoc -p ./doc/my_template
.../your_project_directory/doc/my_template/default/method_details/setup.rb
2. $>yardoc -p ./doc/my_template
Ruby on Rails documentation
YARD
Yay! A Ruby Documentation Tool
http://yardoc.org/
http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
http://rubydoc.info/docs/yard/file/docs/Tags.md#taglist
(rake doc:app hanged on processing one of the class)
Yay! A Ruby Documentation Tool
http://yardoc.org/
http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
http://rubydoc.info/docs/yard/file/docs/Tags.md#taglist
(rake doc:app hanged on processing one of the class)
Rails Solve : You have already activated ... , but your Gemfile requires ...
Solution 1:
Use gems version as in Gemfile.lock $> bundle exec ...
Solution 2:
1. Include e.g. gem "rake", [some_version] in Gemfile
2. Update Gemfile.lock by $> bundle update
Use gems version as in Gemfile.lock $> bundle exec ...
Solution 2:
1. Include e.g. gem "rake", [some_version] in Gemfile
2. Update Gemfile.lock by $> bundle update
Subscribe to:
Posts (Atom)