Switch between python 2.7 and python 3.5 on Mac OS X

I generally use Python 2.7 but recently installed Python 3.5 using Miniconda on Mac OS X. Different libraries have been installed for these two versions of python. Now, the entering either of the keywords ‘python’ or ‘python3’ in terminal invokes python 3.5, and ‘python2’ returns ‘-bash: python2: command not found’. How can I now invoke … Read more

How to remove all non-numeric characters from a string in Bash?

Example: file=”123 hello” How can I edit the string file such that it only contains the numbers and the text part is removed? So, echo $file should print 123 only. Answer This is one way with sed: $ echo $file | sed ‘s/[^0-9]*//g’ 123 $ echo “123 he23llo” | sed ‘s/[^0-9]*//g’ 12323 Or with pure … Read more

Web Services vs EJB vs RMI, advantages and disadvantages?

My web server would be overloaded quickly if all the work were done there. I’m going to stand up a second server behind it, to process data. What’s the advantage of EJB over RMI, or vice versa? What about web services (SOAP, REST)? Answer EJBs are built on top of RMI. Both imply Java clients … Read more

How do I kill this tomcat process in Terminal?

Using ps -ef | grep tomcat I found a tomcat server that is running. I tried kill -9 {id} but it returns “No such process.” What am I doing wrong? Here’s an example: Admins-MacBook-Pro:test-parent tom.maxwell$ ps -ef | grep tomcat 2043706342 39707 39695 0 3:40PM ttys000 0:00.00 grep tomcat Admins-MacBook-Pro:test-parent tom.maxwell$ kill -9 39707 -bash: … Read more

How to terminate process from Python using pid?

I’m trying to write some short script in python which would start another python code in subprocess if is not already started else terminate terminal & app (Linux). So it looks like: #!/usr/bin/python from subprocess import Popen text_file = open(“.proc”, “rb”) dat = text_file.read() text_file.close() def do(dat): text_file = open(“.proc”, “w”) p = None if … Read more

Problems using subl command in terminal: “Command not found” & “No such file or directory”

I want to apologize in advance that this is a newbie question! I’ve spent the last 2 hours trying to find a solution. I have two problems (I’m sure related). Background: This is what my $PATH looks like: /Users/Sponsi/.rvm/gems/ruby-1.9.3-p194/bin:/Users/Sponsi/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/Sponsi/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/Sponsi/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin Problem #1 I am trying to use the command-line command “subl” to launch Sublime Text 2 … Read more

What does sudo -H do?

After trying to install virtualenv with pip $ pip install virtualenv I got a permission denied error IOError: [Errno 13] Permission denied: ‘/Library/Python/2.7/site-packages/virtualenv.py’ So I used sudo to install virtualenv $ sudo pip install virtualenv But then a warning showed up: The directory ‘/Users/petertao/Library/Caches/pip/http’ or its parent directory is not owned by the current user … Read more

How to write stdout to file with colors?

A lot of times (not always) the stdout is displayed in colors. Normally I keep every output log in a different file too. Naturally in the file, the colors are not displayed anymore. I’d like to know if there’s a way (in Linux) to write the output to a file with colors. I’m trying to … Read more