Sunday, June 11, 2017

Virtual environment path

from python command line:

>>os.environ will return the enviroment env settings

>>> os.environ
environ({'PS1': '(py35) \\[\\e[0;33m\\]\\h:\\W \\u\\$\\[\\e[m\\] ', 'USER': 'dc', 'CONDA_HOME': '/Users/dc/anaconda', 'GROOVY_HOME': '/Users/dc/groovy-2.4.6', 'PWD': '/Users/dc', 'Apple_PubSub_Socket_Render': '/private/tmp/', 'COMMAND_MODE': 'unix2003', 'VLC_PLUGIN_PATH': '/Applications/', 'LOGNAME': 'dc', 'TERM_PROGRAM': '', 'TMPDIR': '/var/folders/mb/br6t4l8d5svbdx8w4r966y1w0000gn/T/', 'JAVA_HOME': '/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/', 'LSCOLORS': 'cxFxBxDxCxegedabagacad', 'SHELL': '/bin/bash', 'COLORFGBG': '7;0', 'LANG': 'en_US.UTF-8', 'ITERM_PROFILE': 'Default', 'DISPLAY': '/private/tmp/', 'MAC_JAVA': '/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/MacOS', 'TERM_PROGRAM_VERSION': '3.0.15', 'SSH_AUTH_SOCK': '/private/tmp/', 'TERM_SESSION_ID': 'w0t0p1:6C68B3C0-5374-4E9C-B424-125BAB6B03F4', 'CONDA_PS1_BACKUP': '\\[\\e[0;33m\\]\\h:\\W \\u\\$\\[\\e[m\\] ', 'SECURITYSESSIONID': '186a8', 'ITERM_SESSION_ID': 'w0t0p1:6C68B3C0-5374-4E9C-B424-125BAB6B03F4', 'CONDA_PREFIX': '/Users/dc/anaconda/envs/py35', 'XPC_FLAGS': '0x0', 'CONDA_DEFAULT_ENV': 'py35', 'ITERM_ORIG_PS1': '(py35) \\[\\e[0;33m\\]\\h:\\W \\u\\$\\[\\e[m\\] ', 'PATH': '/Users/dc/anaconda/envs/py35/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/MacOS:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home//bin:/Users/dc/apache-maven-3.3.9/bin:/Users/dc/anaconda/bin:/Users/dc/gradle-2.11/bin:/Users/dc/groovy-2.4.6/bin:/usr/local/include:/usr/local/lib:/usr/local/Cellar/opencv/2.4.13/include:/usr/local/Cellar/opencv/2.4.13/lib', '_': '/Users/dc/anaconda/envs/py35/bin/python', 'OLDPWD': '/Users/dc', 'ITERM_PREV_PS1': '\\[\x1b]133;D;$?\x07\x1b]1337;RemoteHost=dc@localhost\x07\x1b]1337;CurrentDir=/Users/dc\x07\x1b]133;A\x07\\](py35) \\[\\e[0;33m\\]\\h:\\W \\u\\$\\[\\e[m\\] \\[\x1b]133;B\x07\\]', 'HOME': '/Users/dc', 'CLICOLOR': '1', 'CONDA_PATH_BACKUP': '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/MacOS:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home//bin:/Users/dc/apache-maven-3.3.9/bin:/Users/dc/anaconda/bin:/Users/dc/gradle-2.11/bin:/Users/dc/groovy-2.4.6/bin:/usr/local/include:/usr/local/lib:/usr/local/Cellar/opencv/2.4.13/include:/usr/local/Cellar/opencv/2.4.13/lib', 'XPC_SERVICE_NAME': '0', '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0', 'MAVEN_HOME': '/Users/dc/apache-maven-3.3.9', 'GRADLE_HOME': '/Users/dc/gradle-2.11', 'TERM': 'xterm-256color', 'SHLVL': '1'})

From the above we can see we should use echo $CONDA_PREFIX as the equivalent to $VIRTUAL_ENV

Monday, March 13, 2017

network and broadcast address calculation

To simplify that article: network is the lowest possible address in the range of ip addresses left over from the netmask. broadcast is the highest numbered ip address in that range. The "range of ip addresses left over from the netmask" is known as the local network.
"The network" typically means everyone above you, including the Internet. To get to "the network", the network address is used. In reality, most people call "the network" anything with ethernet cables that can talk to each other.
Example: your ISP gives you info to type into a wireless router: a static IP address of and your netmask is Now you're wanting to set up an ubuntu firewall and need to set up your public interface:
Calculate network IP address: -> last octet = E0
 99.  1. 81.209 -> last octet = D1
Logical AND the mask and your ip: 
E0 & D1 = C0 = 192
--> network =

Calculate broadcast address: : E0 -> there are 1F = 31,
-> broadcast = + .31 =
The other way...
Calculate broadcast address: -> last octet = E0
 99.  1. 81.209 -> last octet = D1
Hosts' IPs = 1F 
Logical OR the hosts ips with your ip:
1F | D6 = DF = 223 
--> broadcast =
Often, you'll see networks described with a /. Here's this network: is the netmask, add up the "1" bits:
 8 + 8 + 8 + 3  = 27
so "this network" gets /27 notation
and can be described as
BROADCAST=`ip address show $DEV | grep 'inet .* brd ' | head -1 | sed -e 's/^.* brd \([0-9\.]*\) .*$/\1/'`
dc@dc-Precision-T7600:/etc/network$ echo $BROADCAST

Sunday, February 12, 2017

github emote: error: GH001: Large files detected.

After changing .gitignore and removing from cache this error message still shows up. Instead of hard reset clear file from git commit history with: 

git gc --prune=now --aggressive

Wednesday, February 1, 2017

ImportError: cannot import name imread cs231n

ImportError                               Traceback (most recent call last)
 in ()
      3 import random
      4 import numpy as np
----> 5 from cs231n.data_utils import load_CIFAR10
      6 import matplotlib.pyplot as plt

/Users/dc/cs231n/assignment1/cs231n/ in ()
      2 import numpy as np
      3 import os
----> 4 from scipy.misc import imread
      6 def load_CIFAR_batch(filename):

ImportError: cannot import name imread

pip install pillow

Monday, January 30, 2017

ubuntu 16.04 install python 2.7 and 3.5

conda create -n python2 python=2.7 anaconda
source activate python2
Repeat for python 3.5 or leave 3.5 as default and deactivate python2

Tuesday, January 10, 2017

remote connection to ipython server

For deep learning to TitanX box:

On  Server:  home user project directory where you are running ipython:
 ipython notebook --no-browser --port=8080 or a port which has been port forwarded
On the remote laptop: 
ssh -N -f -L localhost:8888:localhost:8080 remote_user@remote_host
Browser: localhost:8888
if error: bind: Address already in use channel_setup_fwd_listener_tcpip: cannot listen to port: 8888 Could not request local forwarding.
run lsof to find which processes are using the port:
localhost:~ dc$ lsof -ti:8888

Then sudo kill -9 325 1764

Friday, January 6, 2017

OpenCV Mouse handler Mac Apple

# simple mouse capture demo on video creating image

#notes to myself:
# 1) destroyAllWindows works only if cv2.waitKey(1) placed after destroyAllWindows()
# 2) mouse click in global space cv2!!

#apple trackpad 1 finger left mouse button
# 2 fingers right mouse button. How is that intuitive?

import cv2
import numpy as np

def mouse_capture(event, x, y, flags, param):
    if event==cv2.EVENT_LBUTTONDOWN:
        print 'left mouse button'
    elif event==cv2.EVENT_RBUTTONDOWN:
        print 'right mouse button'

vc = cv2.VideoCapture('/Users/dc/videodemos/')

ret_code, first_frame =

cv2.setMouseCallback('show_firstFrame', mouse_capture)

print first_frame
while True:
    cv2.imshow('show_firstFrame', first_frame)
    waitKey = cv2.waitKey(10000) & 0xFF
    if waitKey == ord('q'):


print 'done'