Tuesday, June 28, 2016

pip: How to install venv and pip with a python 3.4 distribution

If you are unfortunate enough to have stuck with a Python 3.4 distribution and you want to setup a virtual env, then likely you will get the ensurepip module not found error:

bash> python3.4 -m venv mypy
Error: Command '['/home/zedeng/py-dev/mypy/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1


I found someone posted a nice solution [1] to this. So first remove the dir first.
bash> rm -r mypy

Now do it again like this:
bash> python3.4 -m venv mypy --without-pip
bash> . mypy/bin/activate
 

mypy> wget https://bootstrap.pypa.io/get-pip.py
mypy> python get-pip.py

mypy> pip list 

Now the problem is solved. I believe this problem is gone if you upgrade to Python 3.5

[1] http://www.thefourtheye.in/2014/12/Python-venv-problem-with-ensurepip-in-Ubuntu.html

Monday, June 27, 2016

postgresql: Getting started with PostgreSQL database

I have been learning and using PostgreSQL recently for a Django app, and I have to say it's really GOOD! I have used quite a bit of MySQL and Oracle DB in my workplace, so I didn't find good reason to learn PostgreSQL in the past. Now I finally get a chance to start another new project with Django, so I decided to give it a try, and I wasn't disappointed. I will write up a brief getting started guide here for those impatient to get things moving.

Installing. If you are running on a Mac, the easiest way to try it out is just get the http://postgresapp.com, you just start the App, and your DB is running! No config needed!

After you have the database installed and running, you can either connect to the default "postgres" public database by (psql command), or create your own database. To create your own database, you run this command:

bash> PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
bash> createdb mydb

Now you can connect to the new database

bash> psql -d mydb

Once you connected to database, you may run SQL to create/insert/select a table:
mydb-# create table test(id serial, name varchar(200));
mydb-# insert into test(name) values('Hello');
mydb-# select * from test;

To inspect your  table columns:
mydb-# \d test;

To see all tables available:
mydb-# \dt;

To see all database available:
mydb-# \l;

To switch to another database:
mydb-# \c mydb2;

To see more help (check out \d options! it's super flexible and useful.):
mydb-# \?;

To quit the psql shell:
mydb-# \q;


To create a database user and set up password, you can do it on bash shell as well:
bash> echo "CREATE ROLE mydbuser1 WITH CREATEDB LOGIN PASSWORD 'Welcome1'" | psql
bash> echo "GRANT ALL PRIVILEGES ON DATABASE mydb TO mydbuser1" | psql


Now you may relogin again with the user. It should prompt you for password.
bash> psql -U mydbuser1 -W
 
Once you connected to your database again, you may check your user privileges:
mydb-# \dp;

These examples should be enough to get you setup a database for app development. The rest are just normal SQL access to database. The PostgresSQL documentation is excellent reference for all that you need: https://www.postgresql.org/docs/9.5/static/index.html

yum: Installing a local downloaded .rpm file

To install:
bash> sudo yum --nogpgcheck localinstall <package_name.rpm>

To verify what's in the rpm:
bash> rpm -qlp <package_name.rpm>

hg: Untrack file without deleting it

So I have created a maven based Java project using IntelliJ IDEA, and I added all files to my hg repository with this .hgignore file in place:

syntax: glob
target/

Later I learned that I shouln't track one of IDEA's workspace file, so I want to remove from my repository tracking, but I do not want it be deleted. Here is what you should do:

bash> hg forget .idea/workspace.xml
bash> echo '.idea/workspace.xml' >> .hgignore



Saturday, June 18, 2016

zoom: How to install Zoom conference on Ubuntu 14.04 LTS

1. Download latest zoom_2.0.52458.0531_amd64.deb package from https://zoom.us/download

2. Run  
bash> sudo dpkg -i zoom_2.0.52458.0531_amd64.deb

3. Even though the package installed complete, you will see error messages if you have a 64-bit OS because Zoom has other dependencies that's not met. And the above command will setup the apt-get to auto fetch the failed dependencies if you simply run the following next:
bash> sudo apt-get -f install

That's it! Your zoom should be ready to go! Try to start Zoom by press Super + A, then type in "Zoom".

Extra: To Verify Installation, you may run:
bash> dpkg -l |grep zoom

UPDATE:
The exact same steps can be used to install the Skype skype-ubuntu-precise_4.3.0.37-1_i386.deb on Ubuntu.

NOTE: If you have errors running steps above, it's very likely you have upgraded your kernel or added extra repositories into apt-get that's causing all the package dependencies conflict. Try to revert back to original Ubuntu 14.04 install state and these steps should get you running!

Friday, June 17, 2016

wls: How to manually test a DataSource connection

When you creating new DataSource in WLS, it allows you to test the connectivity. However after you have created it, the test button is kinda hidden in a non-obvious way. This is how I get to it and test an existing DataSource that have targeted a server.

1. Login to Admin Console (eg: http://localhost:7100/console)
2. On the Domain Structure left panel, click:
    <my_domain_name> (eg: DefaultDomain) > Services > Data Sources
3. On the right, Click on the DataSource name you want to test.
4. Click the "Monitoring" tab > "Testing" tab.
5. Select the server the DataSource has targeted to and then press "Test Data Source" button.

Wednesday, June 15, 2016

hg: How to setup repository on a remote server

I love using mercurial source control! It's easy to use and it works as I expected everytime I need to do something with my source repository. Here is how you can quickly create a remote repository to push your existing project into it. (use this as backup of your project or share among your team etc)

1. SSH into your remote server and create an empty repository.
ssh remote_hostname
bash> cd $HOME
bash> mkdir -p hg-repos/myproject
bash> cd hg-repos/myproject
bash> hg init

2. Back on your local machine and in your existing hg project, edit the .hg/hgrc file with the following:

[paths]
default=ssh://remote_hostname/hg-repos/myproject
[ui]
remotecmd=/usr/local/bin/hg


That's it! You don't even need hg server running in remote host to make this work! Now you may perofrm "hg push" command inside your local project to sync up to remote host

NOTE 1: This setup rely on your SSH into remote host. If you want to avoid user password promt everytime you perform "hg push", then setup Key-Based SSH login.

NOTE 2: You only need "remotecmd" part if your remote_hostname does not have a standard hg installed. Then you can specified your custom location here.

NOTE 3: If you want to use abolute path for "default" path instead, then you can use double slash after the "remote_hostname". Else the single slash is relative to your $HOME directory.