Archives For python

Regex Password Validation

I needed to find a regex pattern for validating a password for an Angular app.
The requirement were to have at least 1 lowercase character, 1 uppercase character, 1 number, and no repeating character more than 2. For the ng-pattern, I came up with is below


Breaking It Down

(?!.*([A-Za-z0-9])\1{2}) Make sure that no characters repeat more than twice

(?=.*[a-z]) requires at least one lowercase

(?=.*[A-Z]) requires at least one uppercase

(?=.*\d) requires at least one digit

Edit your ipython config file and add/edit
c.TerminalInteractiveShell.confirm_exit = False

Note: If you do not have have a config file, run ipython profile create to create one.

If you have the latest version of iPython installed >=.12 , you can reload modules automatically.

# Run the commands below in the terminal
ipython profile create # tells you where config file is located

# edit the file with vim or nano
vim ~/.ipython/profile_default/ # The file location can be different
# Change the extensions and exec_lines to include autoreload
#c.InteractiveShellApp.extensions = []
c.InteractiveShellApp.extensions = ['autoreload']
#c.InteractiveShellApp.exec_lines = []
c.InteractiveShellApp.exec_lines = ['%autoreload 2']

Now if you make edits in your code, it should reload the modules. In a testing environment, this is great, but I suggest that you do not do it in a production environment.

Remove All .pyc Files

August 16, 2013 — Leave a comment

Found a cool bash command to remove all the .pyc files from a project folder.

find . -name '*.pyc' -delete

I turned it into a bash alias in my ~/.bash_profile.

alias pyclean="find . -name '*.pyc' -delete"

easy_install ImportError

August 13, 2013 — 3 Comments

I was receiving “ImportError: Entry point (‘console_scripts’, ‘easy_install’) not found”

I removed and reinstalled the distribute tools and was able to get it working again.

  1. Check your /usr/bin and /usr/local/bin for easy_install installations and remove any old script:
  2. sudo rm /usr/bin/easy_install*
    sudo rm /usr/local/bin/easy_install*
  3. Download and run distribute:
  4. curl -O
    sudo python
    sudo rm
  5. Try again, and enjoy.
  6. sudo easy_install pip

Zipcodes have 5 integers in them and also have leading zeros. You can’t do the following:

for zipcode in xrange(0,99999):
    print zipcode

The above code will just print numbers 0-99999, when you really want 00000-99999.

To get the leading zeros, you need to use zfill().

for zipcode in xrange(10000):
    # To create zipcodes with leading 0's
    zipcode = str(zipcode).zfill(5)  
    print zipcode

Style Guides

May 21, 2013 — Leave a comment

Well-designed code is much easier to maintain, optimize, and extend, making for more efficient developers. That means more focus and energy can be spent on building great things, which makes everyone happy—users, developers, and stakeholders.

Ruby – Github Style Guide

Python – Official PEP8 Style Guide

Ruby or Python?

July 16, 2012 — Leave a comment

For those who have experience with other programming languages such as C++ and Java, you will have an easier time learning Ruby.
For those who have never coded or have very little experience, I think Python is much easier to pick up as your first programming language.

I started out with Ruby (after learning C++, Java and other various languages), but dabbled a bit into Python, and because of that dabbling, I learned how to code Ruby better and understand the fundamentals of Computer Science better.