Friday, October 25, 2013

How to install Pip with Red Hat Cygwin

I am going to keep this short and sweet ... so if there are any questions, I will elaborate at a later time.  I am developing on a Microsoft Windows 7 Enterprise Service Pack 1 Dell Latitude E6430 laptop.
  1. Download rhsetup.exe from http://www.redhat.com/services/custom/cygwin.
  2. Run the rhsetup.exe file and make sure to check off All > Net > ca-certificates: CA root certificates, this package is not checked off by default.
    • All the rest of defaults may stay checked off, Red Hat did a good job of making the Cygwin installer as close as possible to a fully Red Hat Linux enviroment.
  3. If you have administrator rights on your machine, perform the following commmand: ln -sT /usr/ssl /etc/ssl (reference: http://stackoverflow.com/questions/9224298/how-do-i-fix-certificate-errors-when-running-wget-on-an-https-url-in-cygwin)
  4. After installation is complete, download https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py and run the ez_setup.py Python file by peforming the following command: python ez_setup.py.
  5. Once the setuptools file is downloaded, use the tar command to convert the archive to a group of files.
  6. Change directory into the setuptools directory and perform the following command: python easy_install.py pip.
  7. Voila, pip is now installed, enjoy.
I hope to update this tutorial to be a little more comprehensive, so my apologies in advance.

Saturday, September 21, 2013

A Serious Man

Found this blog explaining what "A Serious Man" was about and after reading the review, I felt the blog authors opinion made me better understand what the movie was about.  This Coen Brothers film is a very mature adaption on if you choose to allow your life to be on autopilot, eventually you will suffer (e.g. morally, physically).

After the movie was over, I sat and tried to reflect on what this movie was about and struggled with the meaning.  Even though this is not one of my favorite Coen Brothers films, I appreciate the complex depiction of philosophy, faith and life.  The movie can be a bit slow, but that is only because the director's wanted the audience to understand the neuroses of the protagonist.  Please watch the movie and then enjoy this blog post.

Tuesday, January 29, 2013

Fink Installation Tip for OSX

I recently had to reformat my Macbook Air due to a sleepimage issue when connecting to a power source.  I am running OSX 10.8, so to install Fink 0.34.5 I had to install from source.  There is a missing step that many OSX 10.8 users may not be aware of, Fink needs the Java SDK installed prior to running the bootstrap command.  If your Mac is connected to a Internet connection, an easy way to install the Java SDK is by running javac from terminal.

Once you run this command, you will be prompted with a GUI message asking if you would like to download and install the Java SDK from Apple servers.

Voila!  Now kick off the bootstrap command and you are ready to start compiling Fink.  Further directions on how to install Fink with OSX 10.4 and later can be found here.  I found this tip by heading over to http://www.mail-archive.com/fink-beginners@lists.sourceforge.net/msg26480.html.

Wednesday, January 23, 2013

Python Fundamentals (Forking)

Forking is cloning a process (child of a process).

"The system function called fork() creates a copy of the process, which has called it. This copy runs as a child process of the calling process. The child process gets the data and the code of the parent process. The child process receives a process number (PID, Process IDentifier) of its own from the operating system. The child process runs as an independant instance, i.e. independent of the parent process. With the return value of fork() we can decide in which process we are: 0 means that we are in the child process while a positive return value means, that we are in the parent process. A negative return value means that an error occurred while trying to fork." (reference: http://www.python-course.eu/forking.php)

import os

def child():
   print 'A new child ',  os.getpid( )
   os._exit(0) # is used for child processes instead of os.exit(0)

def parent():
   while True:
      newpid = os.fork()
      if newpid == 0:
         child()
      else:
         pids = (os.getpid(), newpid)
         print "parent: %d, child: %d" % pids
      if raw_input( ) == 'q': break # will create new child process until 'q + <return>' is inputted.

parent()

Tuesday, January 22, 2013

CIDR Subnet Mask Cheatsheet

This is a direct copy from http://www.oav.net/mirrors/cidr.html.  I just want to make sure the information does not go down, so I am re-posting for reference.  Enjoy!


Netmask              Netmask (binary)                 CIDR     Notes    
_____________________________________________________________________________
255.255.255.255  11111111.11111111.11111111.11111111  /32  Host (single addr)
255.255.255.254  11111111.11111111.11111111.11111110  /31  Unuseable
255.255.255.252  11111111.11111111.11111111.11111100  /30    2  useable
255.255.255.248  11111111.11111111.11111111.11111000  /29    6  useable
255.255.255.240  11111111.11111111.11111111.11110000  /28   14  useable
255.255.255.224  11111111.11111111.11111111.11100000  /27   30  useable
255.255.255.192  11111111.11111111.11111111.11000000  /26   62  useable
255.255.255.128  11111111.11111111.11111111.10000000  /25  126  useable
255.255.255.0    11111111.11111111.11111111.00000000  /24 "Class C" 254 useable

255.255.254.0    11111111.11111111.11111110.00000000  /23    2  Class C's
255.255.252.0    11111111.11111111.11111100.00000000  /22    4  Class C's
255.255.248.0    11111111.11111111.11111000.00000000  /21    8  Class C's
255.255.240.0    11111111.11111111.11110000.00000000  /20   16  Class C's
255.255.224.0    11111111.11111111.11100000.00000000  /19   32  Class C's
255.255.192.0    11111111.11111111.11000000.00000000  /18   64  Class C's
255.255.128.0    11111111.11111111.10000000.00000000  /17  128  Class C's
255.255.0.0      11111111.11111111.00000000.00000000  /16  "Class B"
     
255.254.0.0      11111111.11111110.00000000.00000000  /15    2  Class B's
255.252.0.0      11111111.11111100.00000000.00000000  /14    4  Class B's
255.248.0.0      11111111.11111000.00000000.00000000  /13    8  Class B's
255.240.0.0      11111111.11110000.00000000.00000000  /12   16  Class B's
255.224.0.0      11111111.11100000.00000000.00000000  /11   32  Class B's
255.192.0.0      11111111.11000000.00000000.00000000  /10   64  Class B's
255.128.0.0      11111111.10000000.00000000.00000000  /9   128  Class B's
255.0.0.0        11111111.00000000.00000000.00000000  /8   "Class A"
  
254.0.0.0        11111110.00000000.00000000.00000000  /7
252.0.0.0        11111100.00000000.00000000.00000000  /6
248.0.0.0        11111000.00000000.00000000.00000000  /5
240.0.0.0        11110000.00000000.00000000.00000000  /4
224.0.0.0        11100000.00000000.00000000.00000000  /3
192.0.0.0        11000000.00000000.00000000.00000000  /2
128.0.0.0        10000000.00000000.00000000.00000000  /1
0.0.0.0          00000000.00000000.00000000.00000000  /0   IP space

Tuesday, January 15, 2013

Python Fundamentals (Functions, Classes, Objects, and Exceptions)

Functions allow sections of code to be grouped better as per functionality:

#!/usr/bin/env python

import sys

def print(printLines):

        for count in range(0,10) :
                print printLines

print(sys.argv[1])

Class example:

#!/usr/bin/env python

class Calculator:

        #constructor of the class
        def __init__(self, ina, inb):
            self.a = ina
            self.b = inb

        # define routine
        def add(self):
            return self.a + self.b

        def mul(self):
            return self.a*self.b

# Example of Class Inheritence
class Scientific(Calculator) :

        def power(self):
        # Power and logarithmic functions
            return pow(self.a, self.b)
        def quickAdd(a,b):
            return a+b

# Calling the classes to print to screen
newCalculation = Calculator(10, 20)

print 'a+b: %d'%newCalculation.add()
print 'a*b: %d'%newCalculation.mul()

newPower = Scientific(2,3)

print 'a+b: %d'%newPower.add()
print 'a*b: %d'%newPower.mul()
print 'a pow b: %d' %newPower.power()

Exception Handling by using the "ZeroDivisionError" object:


>>> try :
...     a = 0/0
... except Exception as im:
...     print im
...
integer division or modulo by zero

To see the help page for the "im" object, type:
>>> help(im)

Wednesday, January 9, 2013

Python Fundamentals (Conditional Statements)

I am pretty familiar with writing conditional statements, so this section will be a bit brief.  I just wanted to supply some examples for later reference.

If statement example:

#!/usr/bin/python

name = raw_input("What is your Name? ")
print "Your name is " + name

if name == "chris":
        print "You are chris"
        print "The computer admin"
elif name == "john":
        print "You are John"
        print "A regular user"
else :
        print "Unknown user"

While loop statement example:
#!/usr/bin/python

age = 0
while age < 5:
        print age, " is less than 5"
        age = age + 1
else :
        print age, " is equal to 5"

For loop statement example:
#!/usr/bin/python

for num in range(10,20):
        for i in range(2,num):
                if num%i == 0:
                        j=num/i
                        print '%d equals %d * %d' % (num,i,j)
                        break
        else:
                print num, 'is a prime number'


Use range in Python:
range(lower, upper, step) creates a list
range(n) - [0, ......, n-1]


>>> range(11)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>>
>>> range(1,11)
[1, 2, 3, 4, 5, 6, 7, 8, 9,10]
>>>
>>> range(1,11,2)
[1, 3, 5, 7, 9]
>>>
>>> for item in range(1,11,2) :
...     print item
...
1
3
5
7
9
>>>