Commits

Jorge Vargas committed ac49f0b

Adding a bunch of stuff

  • Participants
  • Parent commits bd2bb25

Comments (0)

Files changed (11)

003-some-awesome-tools.ipynb

+{
+ "metadata": {
+  "name": "003-some-awesome-tools"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "bpython\n",
+      "-------\n",
+      "\n",
+      "A Fancy Interface to the Python Interpreter\n",
+      "\n",
+      "http://pypi.python.org/pypi/bpython"
+     ]
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "ipython\n",
+      "-------\n",
+      "IPython: Productive Interactive Computing\n",
+      "\n",
+      "http://pypi.python.org/pypi/ipython"
+     ]
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "virtualenv\n",
+      "----------\n",
+      "\n",
+      "Out of the mind of Ian Bicking https://plus.google.com/+IanBicking\n",
+      "\n",
+      "http://pypi.python.org/pypi/virtualenv"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!virtualenv test"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "New python executable in test/bin/python\r\n"
+       ]
+      },
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "Installing setuptools..."
+       ]
+      },
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "....."
+       ]
+      },
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "....done.\r\n",
+        "Installing pip..."
+       ]
+      },
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "."
+       ]
+      },
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "...."
+       ]
+      },
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        ".......done.\r\n"
+       ]
+      }
+     ],
+     "prompt_number": 29
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "#source test/bin/activate"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!venv/bin/pip install html"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!ls"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!ls test"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!which pip"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!python -c \"import html;print html\""
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!pip freeze"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!pip freeze > req.txt"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!pip install -r req.txt"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "Requirement already satisfied (use --upgrade to upgrade): Pygments==1.5 in ./venv/lib/python2.7/site-packages (from -r req.txt (line 1))\r\n",
+        "Requirement already satisfied (use --upgrade to upgrade): bpython==0.11 in ./venv/lib/python2.7/site-packages (from -r req.txt (line 2))\r\n",
+        "Requirement already satisfied (use --upgrade to upgrade): html==1.16 in ./venv/lib/python2.7/site-packages (from -r req.txt (line 3))\r\n",
+        "Requirement already satisfied (use --upgrade to upgrade): ipython==0.13 in ./venv/lib/python2.7/site-packages (from -r req.txt (line 4))\r\n",
+        "Requirement already satisfied (use --upgrade to upgrade): pyzmq==2.2.0.1 in ./venv/lib/python2.7/site-packages (from -r req.txt (line 5))\r\n",
+        "Requirement already satisfied (use --upgrade to upgrade): tornado==2.4 in ./venv/lib/python2.7/site-packages (from -r req.txt (line 6))\r\n",
+        "Requirement already satisfied (use --upgrade to upgrade): wsgiref==0.1.2 in /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 (from -r req.txt (line 7))\r\n",
+        "Cleaning up...\r\n"
+       ]
+      }
+     ],
+     "prompt_number": 27
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!rm -r test"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "rm: test: No such file or directory\r\n"
+       ]
+      }
+     ],
+     "prompt_number": 32
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}

004-beautiful.ipynb

+{
+ "metadata": {
+  "name": "004-beautiful"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "Beautiful is better than ugly.\n",
+      "===============================\n",
+      "\n",
+      "![beautifil](http://www.tutztutz.com/wp-content/uploads/2011/10/most-beautiful-girls24.jpg)\n",
+      "![ugly](http://cdn.ebaumsworld.com/picture/mrhahn530/FuglyChicks.png)"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}

Although practicality beats purity..ipynb

+{
+ "metadata": {
+  "name": "Although practicality beats purity."
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "Although practicality beats purity."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "import random\n",
+      "#some voodoo to make Django work from the command line\n",
+      "all_reviews=MattressReview.objects.filter(status=2).filter(rating__lte=2.5).values_list('id',flat=True)\n",
+      "print \"\\n\".join([(\"http://stage.goodbed.com/admin/reviews/mattressreview/%i\"%i) for i in random.sample(all_reviews,int(len(all_reviews)*0.1))])"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "all_reviews = range(2*4*12*5)\n",
+      "print \"\\n\".join([(\"http://stage.goodbed.com/admin/reviews/mattressreview/%i\"%i) for i in random.sample(all_reviews,int(len(all_reviews)*0.1))])"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}

Explicit is better than implicit..ipynb

+{
+ "metadata": {
+  "name": "Explicit is better than implicit."
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "Explicit is better than implicit."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "chars = \"a,b,,\\n\"\n",
+      "regexp = \",|\\n\""
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "chars.split(\",\")"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "s.split(regexp)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "import re\n",
+      "re.split(regexp,chars)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "While in Java...."
+     ]
+    },
+    {
+     "cell_type": "raw",
+     "metadata": {},
+     "source": [
+      "String chars = \"a,b,,\\n\"\n",
+      "String regexp = \",|\\n\"\n",
+      " \n",
+      ">>> chars.split(\",\")\n",
+      "['a','b','\\n']\n",
+      ">>> chars.split(regexp)\n",
+      "['a','b']"
+     ]
+    },
+    {
+     "cell_type": "raw",
+     "metadata": {},
+     "source": [
+      "apologize in advance if the code above has bugs."
+     ]
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}
+{
+ "metadata": {
+  "name": "Flat"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "Flat is better than nested. Sparse is better than dense. Readability counts."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "choices = [(field.name, field.verbose_name) for field in obj._meta.fields\n",
+      "                    if field.attname.startswith('only') and field.attname not in exclude]\n",
+      "\n",
+      "        choices = []\n",
+      "        for field in Promotion._meta.fields:\n",
+      "            if field.attname.startswith('only') and field.attname not in exclude:\n",
+      "                choices.append((field.name, field.verbose_name))\n",
+      "                if obj:\n",
+      "                    if getattr(obj,field.name):\n",
+      "                        initial.append(field.name)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "ename": "NameError",
+       "evalue": "name 'obj' is not defined",
+       "output_type": "pyerr",
+       "traceback": [
+        "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
+        "\u001b[0;32m<ipython-input-2-d45db88b61b4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m choices = [(field.name, field.verbose_name) for field in obj._meta.fields\n\u001b[0m\u001b[1;32m      2\u001b[0m                     if field.attname.startswith('only') and field.attname not in exclude]\n",
+        "\u001b[0;31mNameError\u001b[0m: name 'obj' is not defined"
+       ]
+      }
+     ],
+     "prompt_number": 2
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}
+{
+ "metadata": {
+  "name": "One way"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "There should be one-- and preferably only one --obvious way to do it."
+     ]
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "Although that way may not be obvious at first unless you're Dutch.\n",
+      "\n",
+      "![Guido](http://upload.wikimedia.org/wikipedia/commons/thumb/6/66/Guido_van_Rossum_OSCON_2006.jpg/200px-Guido_van_Rossum_OSCON_2006.jpg)\n",
+      "\n",
+      "http://en.wikipedia.org/wiki/Guido_van_Rossum"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}

Simple and Complex.ipynb

+{
+ "metadata": {
+  "name": "Simple and Complex"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "Simple is better than complex."
+     ]
+    },
+    {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "Complex is better than complicated."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}
+{
+ "metadata": {
+  "name": "Simple"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "Simple is better than complex.\n",
+      "Complex is better than complicated."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "def parse_input(rawinput):\n",
+      "        if rawinput.startswith(\"//\"):\n",
+      "                delimiter_text,numbers= rawinput.split(\"\\n\",1)\n",
+      "                return delimiter_text[2:3],numbers\n",
+      "        else:\n",
+      "                return \",\",rawinput\n",
+      "delimiter,numbers=parse_input(\"//;\\n1;2\")\n",
+      "print delimiter\n",
+      "print numbers"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        ";\n",
+        "1;2\n"
+       ]
+      }
+     ],
+     "prompt_number": 3
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "import re"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "![regexp](http://cdn.memegenerator.net/instances/250x250/23687441.jpg)"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}

hard-implementation.ipynb

+{
+ "metadata": {
+  "name": "hard-implementation"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "If the implementation is hard to explain, it's a bad idea.\n",
+      "==========================================================\n",
+      "\n",
+      "![hard_cards](cards.jpg) \n",
+      "\n",
+      "If the implementation is easy to explain, it may be a good idea.\n",
+      "=================================================================\n",
+      "\n",
+      "![easy_cards](cards2.jpg)"
+     ]
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}
+Pygments==1.5
+bpython==0.11
+html==1.16
+ipython==0.13
+pyzmq==2.2.0.1
+tornado==2.4
+wsgiref==0.1.2

special cases.ipynb

+{
+ "metadata": {
+  "name": "special cases"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "Special cases aren't special enough to break the rules."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "def is_nombre(nombre):\n",
+      "\t\"\"\"Source developers.do/index.php/unit-testing-en-python/\"\"\"\n",
+      "\tnombre = nombre.replace(\" \",\"\")\n",
+      "\tif len(nombre) == 0:\n",
+      "\t\treturn False\n",
+      "\treturn nombre.isalpha()\n",
+      "\n",
+      "print is_nombre(\"\")"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "False\n"
+       ]
+      }
+     ],
+     "prompt_number": 9
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "print \"\".isalpha()"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "False\n"
+       ]
+      }
+     ],
+     "prompt_number": 10
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "def is_nombre(nombre):\n",
+      "    return nombre.isalpha()\n",
+      "\n",
+      "is_nombre(\"\")"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "pyout",
+       "prompt_number": 11,
+       "text": [
+        "False"
+       ]
+      }
+     ],
+     "prompt_number": 11
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "construct = [0,'',\"\",None,[],{}]\n",
+      "for c in construct:\n",
+      "    print \"Element\\t:\\t{0}\\t Representation\\t:\\t{1}\\t bool({1})\\t:\\t{2}\\t \\tif({1})\\t:\\t{3}\\t\".format(c,repr(c),bool(c),bool(c)==True)\n"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "Element\t:\t0\t Representation\t:\t0\t bool(0)\t:\tFalse\t \tif(0)\t:\tFalse\t\n",
+        "Element\t:\t\t Representation\t:\t''\t bool('')\t:\tFalse\t \tif('')\t:\tFalse\t\n",
+        "Element\t:\t\t Representation\t:\t''\t bool('')\t:\tFalse\t \tif('')\t:\tFalse\t\n",
+        "Element\t:\tNone\t Representation\t:\tNone\t bool(None)\t:\tFalse\t \tif(None)\t:\tFalse\t\n",
+        "Element\t:\t[]\t Representation\t:\t[]\t bool([])\t:\tFalse\t \tif([])\t:\tFalse\t\n",
+        "Element\t:\t{}\t Representation\t:\t{}\t bool({})\t:\tFalse\t \tif({})\t:\tFalse\t\n"
+       ]
+      }
+     ],
+     "prompt_number": 32
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}