<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Hacker Within</title>
 <link href="http://thehackerwithin.org/UoB/atom.xml" rel="self"/>
 <link href="http://thehackerwithin.org/UoB/"/>
 <updated>2019-06-22T15:52:39+00:00</updated>
 <id>http://thehackerwithin.org/UoB</id>
 <author>
   <name>Hacker Within</name>
 </author>
 
 
 <entry>
   <title>One year on: a review of THW, lessons learned and next steps</title>
   <link href="http://thehackerwithin.org/UoB/posts/2019-04-15-1st-year-review.html"/>
   <updated>2019-04-15T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/1st-year-review</id>
   <content type="html">&lt;ul&gt;
  &lt;li&gt;when: Monday 15 April, 1-2pm.&lt;/li&gt;
  &lt;li&gt;where: Murray Learning Centre UG05&lt;/li&gt;
  &lt;li&gt;what: Review of the first year of THW, lessons learned and next steps”&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;presenter&quot;&gt;Presenter&lt;/h2&gt;

&lt;p&gt;Matthew Brett, founder of THW at UoB, will be discussing “One year on: a review of THW, lessons learned and next steps”.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Applying THW lessons to a research project</title>
   <link href="http://thehackerwithin.org/UoB/posts/2019-03-18-apply-thw-lessons.html"/>
   <updated>2019-03-18T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/apply-thw-lessons</id>
   <content type="html">&lt;h2 id=&quot;-flaviu-gostin-&quot;&gt;&amp;lt;+ Flaviu Gostin +&amp;gt;&lt;/h2&gt;

&lt;p&gt;&amp;lt;+ Flaviu Gostin is a researcher. He uses X-ray diffraction to characterise corrosion products generated by titanium alloys for medical implants. +&amp;gt;&lt;/p&gt;

&lt;h2 id=&quot;-applying-the-hacker-within-lessons-to-a-research-project-&quot;&gt;&amp;lt;+ Applying The Hacker Within lessons to a research project +&amp;gt;&lt;/h2&gt;

&lt;p&gt;&amp;lt;+ In the scientific community, problems may arise when different labs cannot reproduce the work of each other.  As research nowadays involves more and more computation, it is essential to create data analysis workflows that can be reproduced by others, i.e. computational reproducibility.  Previous THW talks introduced a range of tools from the software development world, which can be used to create reproducible workflows to analyse research data.  +&amp;gt;&lt;/p&gt;

&lt;h2 id=&quot;-before-coming-to-the-talk-&quot;&gt;&amp;lt;+ Before coming to the talk +&amp;gt;&lt;/h2&gt;

&lt;p&gt;&amp;lt;+ For this talk the presenter prepared a repository on GitHub containing a workflow to analyse some example data presented in his recent paper.  One of the most important test of reproducibility is to have your workflow being reproduced by another person on a different machine. Before this talk, please try to reproduce the presenter’s workflow on your machine: just follow the instructions in his GitHub repo &lt;a href=&quot;https://github.com/craicrai/xrd_analysis_workflow&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Hacking copyright : An Anecdotal History from Saint Columba to Richard Stallman</title>
   <link href="http://thehackerwithin.org/UoB/posts/2019-01-21-hacking-copyright.html"/>
   <updated>2019-01-21T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/hacking-copyright</id>
   <content type="html">&lt;ul&gt;
  &lt;li&gt;when: Monday 21 January, 1-2pm.&lt;/li&gt;
  &lt;li&gt;where: Murray Learning Centre UG05&lt;/li&gt;
  &lt;li&gt;what: Hacking copyright&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;presenter&quot;&gt;Presenter&lt;/h2&gt;

&lt;p&gt;Chen Zhu from Birmingham Law School will be discussing “Hacking Copyright: An Anecdotal History from Saint Columba to Richard Stallman”&lt;/p&gt;

&lt;p&gt;Presentation:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;../slides/ZHU_THW_Birmingham_2019_Slides.pdf&quot;&gt;Slides&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;../slides/annotated-gpl-3-in-org-mode-zhu.org&quot;&gt;EMACS file&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;../slides/screenshot-gpl-3-in-org-mode-zhu.pdf&quot;&gt;screenshot file&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Compiling software on Linux - the good, the bad and the ugly</title>
   <link href="http://thehackerwithin.org/UoB/posts/2018-11-19-tbc.html"/>
   <updated>2018-11-19T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/tbc</id>
   <content type="html">&lt;ul&gt;
  &lt;li&gt;when: Monday 19 November, 1-2pm.&lt;/li&gt;
  &lt;li&gt;where: Murray Learning Centre UG05&lt;/li&gt;
  &lt;li&gt;what: Compiling software on Linux - the good, the bad and the ugly&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;presenter&quot;&gt;Presenter&lt;/h2&gt;

&lt;p&gt;James Carpenter and Andrew Edmondson from Advanced Research Computing&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Reproducible research</title>
   <link href="http://thehackerwithin.org/UoB/posts/2018-10-15-reproducible.html"/>
   <updated>2018-10-15T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/reproducible</id>
   <content type="html">&lt;ul&gt;
  &lt;li&gt;when: Monday 15 October, 1-2.30pm.&lt;/li&gt;
  &lt;li&gt;where: Murray Learning Centre UG10&lt;/li&gt;
  &lt;li&gt;what: Reproducible research&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;presenter&quot;&gt;Presenter&lt;/h2&gt;

&lt;p&gt;Simon Branford, from the Research Software Group in Advanced Research Computing.  You
can find the slides &lt;a href=&quot;../slides/20181015_TheHackerWithin_ReproducibleResearch.pdf&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>A brief introduction to data.table</title>
   <link href="http://thehackerwithin.org/UoB/posts/2018-09-17-data-table.html"/>
   <updated>2018-09-17T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/data-table</id>
   <content type="html">&lt;ul&gt;
  &lt;li&gt;when: Monday 17 September, 1-2.30pm.&lt;/li&gt;
  &lt;li&gt;where: Murray Learning Centre UG07&lt;/li&gt;
  &lt;li&gt;what: A brief introduction to data.table&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;a-brief-introduction-to-datatable-or-if-thor-was-an-r-programmer-his-hammer-would-be-datatable&quot;&gt;A brief introduction to data.table” or “If Thor was an R Programmer, His Hammer Would Be data.table”&lt;/h1&gt;

&lt;h2 id=&quot;abstract&quot;&gt;Abstract&lt;/h2&gt;

&lt;p&gt;In this 20-minutes talk, I will present basic examples of the use of
&lt;code class=&quot;highlighter-rouge&quot;&gt;data.table&lt;/code&gt; which is an R package that provides an enhanced version of
&lt;code class=&quot;highlighter-rouge&quot;&gt;data.frame&lt;/code&gt;s.  I will also share some of my experiences with &lt;code class=&quot;highlighter-rouge&quot;&gt;data.table&lt;/code&gt; and
&lt;code class=&quot;highlighter-rouge&quot;&gt;ggplot2&lt;/code&gt; for time-series analyses.  Slides and exercise are available here:
&lt;a href=&quot;https://github.com/mxochicale/thw-r-datatable&quot;&gt;https://github.com/mxochicale/thw-r-datatable&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;presenter&quot;&gt;Presenter&lt;/h2&gt;

&lt;p&gt;Miguel P Xochicale (twitter: @_mxochicale)&lt;/p&gt;

&lt;p&gt;Final Year Doctoral Researcher doing Human-Robot Interaction, Nonlinear
Dynamics, Deep Learning and Open Science.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Testing and continuous integration</title>
   <link href="http://thehackerwithin.org/UoB/posts/2018-08-20-testing-continuous-integration.html"/>
   <updated>2018-08-20T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/testing-continuous-integration</id>
   <content type="html">&lt;ul&gt;
  &lt;li&gt;when: Monday 20 July, 1-2.30pm.&lt;/li&gt;
  &lt;li&gt;where: Muirhead 112&lt;/li&gt;
  &lt;li&gt;what: Testing and continuous integration&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;stream-of-talk&quot;&gt;Stream of talk&lt;/h2&gt;

&lt;p&gt;Try &lt;a href=&quot;https://bham.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=7ee182bc-003d-4394-9b6b-a94200c81d6b&quot;&gt;this
link&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;getting-set-up&quot;&gt;Getting set up&lt;/h2&gt;

&lt;p&gt;Make sure you have these two things on your computer:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A Python distribution.  If you haven’t got one already, and particularly if
you are on Windows, I recommend &lt;a href=&quot;https://www.anaconda.com/distribution/&quot;&gt;the Anaconda distribution
installer&lt;/a&gt;.  Choose the Python 3.6
version, not the Python 2.7 version.  You do not need to install VSCode,
when that option comes up.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://git-scm.com/book/en/v2/Getting-Started-Installing-Git&quot;&gt;Git version control
software&lt;/a&gt;.
I suggest you choose the option to use the Nano editor by default, instead
of Vim (I use Vim, but if you are not used to it, it’s a terrible choice
for getting started as quickly as possible).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;improving-as-a-programmer&quot;&gt;Improving as a programmer&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Does an academic need to be a good programmer?&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;What is a good programmer?&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://www.norvig.com/21-days.html&quot;&gt;Teach yourself programming in 10
years&lt;/a&gt;.&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://youtu.be/DdmyUZCl75s&quot;&gt;Winning a programming competition is not what you
need&lt;/a&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;preparing-to-use-github&quot;&gt;Preparing to use Github&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Go to &lt;a href=&quot;https://github.com&quot;&gt;https://github.com&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;If you haven’t got an account, make one now.  Use your &lt;code class=&quot;highlighter-rouge&quot;&gt;.bham.ac.uk&lt;/code&gt;
address, it gives you access to some education features (if you ask for
them).&lt;/li&gt;
  &lt;li&gt;Navigate to
&lt;a href=&quot;https://github.com/matthew-brett/play-poker&quot;&gt;https://github.com/matthew-brett/play-poker&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Click on the “Fork” button just below the top right of the screen.  Wait
for a bit.  You should now be looking at your own &lt;em&gt;fork&lt;/em&gt; of my
&lt;code class=&quot;highlighter-rouge&quot;&gt;play-poker&lt;/code&gt; repository.&lt;/li&gt;
  &lt;li&gt;Select the URL of your new forked repository from the URL bar, and copy
it.  The URL will be of form
&lt;code class=&quot;highlighter-rouge&quot;&gt;https://github.com/your-user-name/play-poker&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Open the terminal (Cmd-spacebar “Terminal” on Mac, Start key “git bash”
on Windows)&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Change directory to the Desktop:&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd Desktop
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Clone your new repository with the following at the terminal:&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/your-user-name/play-poker
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;where &lt;code class=&quot;highlighter-rouge&quot;&gt;your-user-name&lt;/code&gt; is your Github username.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Change directory to the repository directory.&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd play-poker
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ready-for-poker&quot;&gt;Ready for poker&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;If you’re on Windows - press the “Start key” then type “Spyder” (no
quotes).  Press return.  The Spyder editor should start.  Click on File,
select Open, navigate to the Desktop &lt;code class=&quot;highlighter-rouge&quot;&gt;play-poker&lt;/code&gt; folder, and select
&lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt;. Click the green run (play) icon to run the file.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;On Mac, in Terminal.app, check you are in the &lt;code class=&quot;highlighter-rouge&quot;&gt;Desktop/play-poker&lt;/code&gt;
directory with:&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pwd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;Now run your &lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt; script with:&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python poker.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;You should see the printout of “Running tests”, and “Finished”.
Congratulations, you are all set for some test-driven development.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;getting-more-interactive&quot;&gt;Getting more interactive&lt;/h2&gt;

&lt;p&gt;When we are writing tests, we often want to experiment with code, and look at
variables.  The best tool to do this is the &lt;a href=&quot;https://ipython.org&quot;&gt;IPython&lt;/a&gt;
interactive Python prompt.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Windows: if you are using Spyder, you already have this - it’s the bottom
right pane in your Spyder window arrangement.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Mac: first check you have IPython installed by typing:&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python -m IPython --version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;If this gives an error, type:&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip install --user ipython
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;Now type:&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python -m IPython
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you will have a prompt of form &lt;code class=&quot;highlighter-rouge&quot;&gt;In [1]: &lt;/code&gt;.  Type &lt;code class=&quot;highlighter-rouge&quot;&gt;2 + 3&lt;/code&gt; and press return.
This should execute and return 5.&lt;/p&gt;

&lt;h2 id=&quot;start-with-a-failing-test&quot;&gt;Start with a failing test&lt;/h2&gt;

&lt;p&gt;This is the key element of test first developement - write a failing test,
then fix it.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Edit &lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt;.  In Windows, you probably already have Spyder open.  On
Mac, start a new tab in Terminal, with the Shell menu, New Tab option.  In
this new tab, type &lt;code class=&quot;highlighter-rouge&quot;&gt;nano poker.py&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;We are going to start by generating a new desk of cards.  To do this, we
imagine a &lt;code class=&quot;highlighter-rouge&quot;&gt;make_new_deck&lt;/code&gt; function, that returns a fresh unshuffled deck
of cards.  We start by imagining what that should return.  It should
probably be something that has 52 cards in it, at least.   Imagining
further, replace &lt;code class=&quot;highlighter-rouge&quot;&gt;test_new_deck&lt;/code&gt; like this&lt;/p&gt;

    &lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# We will test the `make_new_deck` function&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;make_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;52&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;Note the four space indentation for the stuff inside the function.&lt;/p&gt;

    &lt;p&gt;Now run the file - Windws: click Run / Play in Spyder; Mac: switch back to
the original tab, running IPython and run &lt;code class=&quot;highlighter-rouge&quot;&gt;run poker.py&lt;/code&gt;.&lt;/p&gt;

    &lt;p&gt;It fails, because we haven’t written &lt;code class=&quot;highlighter-rouge&quot;&gt;make_new_deck&lt;/code&gt; yet.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Put a new function called &lt;code class=&quot;highlighter-rouge&quot;&gt;make_new_deck&lt;/code&gt; into &lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt;.  It returns 52
None values.&lt;/p&gt;

    &lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;make_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;52&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;Run the tests again.  They pass.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;working-out-the-design-by-testing&quot;&gt;Working out the design by testing&lt;/h2&gt;

&lt;p&gt;Now we have 52 “cards”, but the cards are Python’s special &lt;code class=&quot;highlighter-rouge&quot;&gt;None&lt;/code&gt; value.  We
have to decide what a card should be.&lt;/p&gt;

&lt;p&gt;Let’s say one card is a string, of form “7 of Spades” or “Jack of Hearts”.&lt;/p&gt;

&lt;p&gt;Let’s also say that a new deck will be not-shuffled, so the first card will be
the 2 of Hearts.  Expand your test function like this:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# We will test the `make_new_deck` function&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;make_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;52&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;first_card&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first_card&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;2 of Hearts&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run the file.  It fails because the first card is currently &lt;code class=&quot;highlighter-rouge&quot;&gt;None&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;experimenting-as-you-go&quot;&gt;Experimenting as you go&lt;/h2&gt;

&lt;p&gt;Now we will write a proper function to generate the new deck of cards.&lt;/p&gt;

&lt;p&gt;To do this, we would like to try various things at the interactive IPython
prompt.&lt;/p&gt;

&lt;p&gt;Try typing this at the IPython prompt:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s&quot;&gt;'2 3 4 5 6 7 8 9 10 Jack Queen King Ace'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You should see a length 13 list with the card values.&lt;/p&gt;

&lt;p&gt;Try this:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s&quot;&gt;'Hearts Diamonds Clubs Spades'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This should be a four element list of suit names.&lt;/p&gt;

&lt;p&gt;We can put these at the top of our &lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt; file, like this:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;VALUES&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'2 3 4 5 6 7 8 9 10 Jack Queen King Ace'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;SUITS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Hearts Diamonds Clubs Spades'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run the file from IPython with:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;run poker.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now check the variables look right by showing their contents.  At the IPython
prompt:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;VALUES&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;SUITS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s try making the first card in IPython.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;VALUES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;' of '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SUITS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To make the full deck of cards, we cycle through all the suits, then all the
values, and combine the value with the suit, to make 52 cards:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;make_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;cards&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;suit&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SUITS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VALUES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;card&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;' of '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;suit&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;cards&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;card&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cards&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run the tests.  Do they pass?&lt;/p&gt;

&lt;h2 id=&quot;extend-the-tests&quot;&gt;Extend the tests&lt;/h2&gt;

&lt;p&gt;We just did a lot of code, and our tests only test the first card.  We should
add some more tests to check our &lt;code class=&quot;highlighter-rouge&quot;&gt;make_new_deck&lt;/code&gt; function is doing the right
thing.&lt;/p&gt;

&lt;p&gt;Add these lines to your &lt;code class=&quot;highlighter-rouge&quot;&gt;test_new_deck&lt;/code&gt; function.  Be careful to keep the same
indentation as the lines above:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Ace of Hearts&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;2 of Diamonds&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;26&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;2 of Clubs&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Ace of Spades&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;making-a-poker-hand&quot;&gt;Making a poker hand&lt;/h2&gt;

&lt;p&gt;To make a poker hand, we shuffle the cards, and then give out five cards from
the shuffled deck.  What would a shuffled deck look like?&lt;/p&gt;

&lt;p&gt;First we write a failing test.&lt;/p&gt;

&lt;p&gt;A shuffled deck will virtually never have the same order as a fresh deck.
Let’s put that in as a test, expecting it to fail one time in 52 x 51 x 50 x
49 etc, and that is basically never.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_shuffled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ordered_deck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;make_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;to_shuffle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;make_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;shuffled_deck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shuffled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_shuffle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shuffled_deck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ordered_deck&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You’ll also need to add this function call to your &lt;code class=&quot;highlighter-rouge&quot;&gt;if __name__&lt;/code&gt; block:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;__main__&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Running tests&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;test_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;test_shuffled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Finished&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run the file.  It fails.  We are going to fix it.&lt;/p&gt;

&lt;p&gt;First consider this really bad shuffle function:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shuffled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# A really bad shuffle function&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;re_ordered&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# Reverse the order&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;re_ordered&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re_ordered&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That would always return a deck with the ‘Ace of Spades’ first and the ‘2 of
Hearts’ last.  But our test would still pass.  Put that function into
&lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Run the tests - they pass.  Oops.  We need to test more.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;shuffled&lt;/code&gt; needs to do more than return something different from an ordered
deck.  It needs to return something different each time.&lt;/p&gt;

&lt;p&gt;We add some new lines to &lt;code class=&quot;highlighter-rouge&quot;&gt;test_shuffled&lt;/code&gt; that will do 1000 shuffles, and makes
sure each one is different.  We take the opportunity to fold in the check that
the deck is not ordered.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_shuffled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;decks&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# Put an ordered deck into the list of decks&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;decks&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;make_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;make_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;shuffled_deck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shuffled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# Compare this deck to all previous ones.  Do any match?&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shuffled_deck&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;decks&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;decks&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shuffled_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run the tests.  They should fail.&lt;/p&gt;

&lt;p&gt;How to make this work correctly?  Let’s experiment in IPython:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;random&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Use tab completion to explore the &lt;code class=&quot;highlighter-rouge&quot;&gt;random&lt;/code&gt; module, by typing &lt;code class=&quot;highlighter-rouge&quot;&gt;random.&lt;/code&gt; (notice
appended period) and then pressing tab.  We find &lt;code class=&quot;highlighter-rouge&quot;&gt;random.shuffle&lt;/code&gt;.  Here is a
not-shuffled deck:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;make_new_deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# First 10 cards&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now shuffle:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shuffle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# New order shows in first 10 cards&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We will use &lt;code class=&quot;highlighter-rouge&quot;&gt;random.shuffle&lt;/code&gt; for our &lt;code class=&quot;highlighter-rouge&quot;&gt;shuffled&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Type &lt;code class=&quot;highlighter-rouge&quot;&gt;import random&lt;/code&gt; at the top of &lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt;.  Replace the bad version of
&lt;code class=&quot;highlighter-rouge&quot;&gt;shuffled&lt;/code&gt; with this version:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shuffled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# A proper shuffle function&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;re_ordered&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;deck&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shuffle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;re_ordered&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re_ordered&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run the tests.  They should pass.&lt;/p&gt;

&lt;h2 id=&quot;a-better-way-to-run-the-tests&quot;&gt;A better way to run the tests&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://pytest.readthedocs.io&quot;&gt;pytest&lt;/a&gt; is a Python package that makes it
easier to write tests and run them.&lt;/p&gt;

&lt;p&gt;So far we’ve been running the tests by running our Python module &lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt;.
We had to add a call to our test functions in the &lt;code class=&quot;highlighter-rouge&quot;&gt;if __name__&lt;/code&gt; block.&lt;/p&gt;

&lt;p&gt;Pytest finds tests in &lt;code class=&quot;highlighter-rouge&quot;&gt;.py&lt;/code&gt; files automatically, and then runs the tests.&lt;/p&gt;

&lt;p&gt;If you installed Anaconda, you have Pytest installed already.&lt;/p&gt;

&lt;p&gt;If not, open a terminal window, and type:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python -m pytest --version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you get &lt;code class=&quot;highlighter-rouge&quot;&gt;No module named pytest&lt;/code&gt;, then:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip install --user pytest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now check you can run the tests with:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python -m pytest poker.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is an efficient way to find tests and run them.&lt;/p&gt;

&lt;h2 id=&quot;commit-your-changes&quot;&gt;Commit your changes&lt;/h2&gt;

&lt;p&gt;Open Git (go back to git bash in Windows; open a new Terminal tab on Mac).&lt;/p&gt;

&lt;p&gt;First check that Git knows your name and email.  Type:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git config user.name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It should show your name.  If it doesn’t show anything, type:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git config user.name &quot;Your Name&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now check:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git config user.email
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If that shows nothing:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git config user.email &quot;my.name@bham.ac.uk&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now you are ready to prepare and make a new commit.  Type:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git status
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You should see that &lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt; has been modified.&lt;/p&gt;

&lt;p&gt;Put it in Git’s &lt;em&gt;staging area&lt;/em&gt; ready for the next commit:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git add poker.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Use &lt;code class=&quot;highlighter-rouge&quot;&gt;git status&lt;/code&gt; to show that the changes in &lt;code class=&quot;highlighter-rouge&quot;&gt;poker.py&lt;/code&gt; are now in the
“Changes to be committed”.&lt;/p&gt;

&lt;p&gt;Do the commit with:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git commit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Your text editor should open for you to type a commit message.  Save the
message to finish the commit.&lt;/p&gt;

&lt;h2 id=&quot;continuous-integration&quot;&gt;Continuous integration&lt;/h2&gt;

&lt;p&gt;Notice the
&lt;a href=&quot;https://github.com/matthew-brett/play-poker/blob/master/.travis.yml&quot;&gt;.travis.yml&lt;/a&gt;
file in the repository.  This is a configuration file for the free
&lt;a href=&quot;https://www.travis-ci.com&quot;&gt;Travis-CI&lt;/a&gt; continuous integration service.&lt;/p&gt;

&lt;p&gt;Now we ask Travis-CI to run our tests each time we do a new commit to the
repository.&lt;/p&gt;

&lt;p&gt;Go to the &lt;a href=&quot;https://www.travis-ci.com&quot;&gt;https://www.travis-ci.com&lt;/a&gt; front page.
Click on the green button “Sign up with Github”.  Click on the green button at
the bottom of the page: “Authorize travis-pro”. Select the &lt;code class=&quot;highlighter-rouge&quot;&gt;play-poker&lt;/code&gt;
repository.&lt;/p&gt;

&lt;p&gt;All done.  The next time you send a commit to the &lt;code class=&quot;highlighter-rouge&quot;&gt;play-poker&lt;/code&gt; repository,
Travis-CI will run the tests for you.&lt;/p&gt;

&lt;p&gt;Let’s do that:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git push origin master --set-upstream
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now go to the &lt;a href=&quot;https://travis-ci.com&quot;&gt;https://travis-ci.com&lt;/a&gt; site. You should
see that Travis-CI is running or has run your tests for you.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Git and version control</title>
   <link href="http://thehackerwithin.org/UoB/posts/2018-07-16-git-version-control.html"/>
   <updated>2018-07-16T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/git-version-control</id>
   <content type="html">&lt;ul&gt;
  &lt;li&gt;when: Monday 16 July, 1-2pm.&lt;/li&gt;
  &lt;li&gt;where: Nuffield G13&lt;/li&gt;
  &lt;li&gt;what: Git and version control&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mark Slater talked about version control using the &lt;a href=&quot;https://git-scm.com&quot;&gt;Git&lt;/a&gt; package including an overview of what git does under the hood. You
can find the slides &lt;a href=&quot;../slides/slater_git_THW_20180716.pdf&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Language Gallery</title>
   <link href="http://thehackerwithin.org/UoB/posts/2018-06-25-language-gallery.html"/>
   <updated>2018-06-25T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/language-gallery</id>
   <content type="html">&lt;ul&gt;
  &lt;li&gt;when: Monday 25th June, 1-2pm.&lt;/li&gt;
  &lt;li&gt;where: Murray Learning Centre UG07&lt;/li&gt;
  &lt;li&gt;what: Language Gallery&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We’ve been talking about different languages used for academic computing, and one topic that has come up several times is - which language should I use?&lt;/p&gt;

&lt;p&gt;In this meeting, we talk about these 4 popular languages, each of which are
more or less essential in their own niche:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.python.org/about&quot;&gt;Python&lt;/a&gt; - Warrick Ball. &lt;a href=&quot;../slides/ball_python_THW_20180625.pdf&quot;&gt;Get Warrick’s
slides&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.r-project.org/about.html&quot;&gt;R&lt;/a&gt; - Murray Hoggett.  &lt;a href=&quot;https://github.com/Murray2015/UoB/tree/language_gallery_R/R_language_gallery&quot;&gt;Get example
code and data
files&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.javascript.com&quot;&gt;Javascript&lt;/a&gt; - David Madden.  &lt;a href=&quot;../slides/madden_javascript.pdf&quot;&gt;Get David’s
slides&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://uk.mathworks.com/products/matlab.html&quot;&gt;Matlab&lt;/a&gt; - Dietmar Heinke.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There was a 10 minute talk on each, in which someone who uses the language said
something about what the language is good for, why it’s good, and when it’s not
so good.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Good Software Practices</title>
   <link href="http://thehackerwithin.org/UoB/posts/2018-05-21-good-software-practices.html"/>
   <updated>2018-05-21T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/good-software-practices</id>
   <content type="html">&lt;p&gt;The third meeting of The Hacker Within at the University of Birmingham was:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;when: Monday 21st May, 1-2.30pm.&lt;/li&gt;
  &lt;li&gt;where: Room UG07, Murray Learning Centre&lt;/li&gt;
  &lt;li&gt;what: Good Software Practices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Talk by Andrew (Ed) Edmondson.&lt;/p&gt;

&lt;p&gt;Please see &lt;a href=&quot;https://intranet.birmingham.ac.uk/it/teams/infrastructure/research/bear/rsg/Software-Resources/GoodCodingPractices.pdf&quot;&gt;Ed’s
slides&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>The Hacker Toolkit, and What to Learn and What to Teach</title>
   <link href="http://thehackerwithin.org/UoB/posts/2018-04-16-the-hacker-toolkit.html"/>
   <updated>2018-04-16T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/the-hacker-toolkit</id>
   <content type="html">&lt;p&gt;The second meeting of The Hacker Within at the University of Birmingham was:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;when: Monday 16th April, 1-2.30pm.&lt;/li&gt;
  &lt;li&gt;where: Room 118 Muirhead&lt;/li&gt;
  &lt;li&gt;what: The Hacker Toolkit, and What to Learn and What to Teach.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don’t need to book, please, just turn up.&lt;/p&gt;

&lt;p&gt;There will be two parts to this, our second meeting:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Talk: The Hacker Toolkit.  The basic tools of a Hacker’s working life; how
to choose your tools; how to learn new ones.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Discussion: What would you like to learn?  What would you like to teach?&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are the:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/matthew-brett/thw-toolkit/blob/master/thw_toolkit.pdf&quot;&gt;talk
slides&lt;/a&gt;;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://bham.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=e0a70311-c006-e996-3e9b-3ed6c372ae28&quot;&gt;Panopto video of the talk&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We recorded the various topics that people wanted to hear about on the
whiteboard: &lt;img src=&quot;../images/thw_what_to_learn.jpg&quot; alt=&quot;Photo of the whiteboard listing
topics&quot; /&gt;.&lt;/p&gt;

&lt;p&gt;Look at &lt;a href=&quot;https://github.com/matthew-brett/thw-toolkit&quot;&gt;the Github repository&lt;/a&gt;
for the source material to generate the slides, including copyright
information.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Introduction, and what to Learn and Teach for Spring 2018</title>
   <link href="http://thehackerwithin.org/UoB/posts/2018-03-19-what-to-learn-and-teach.html"/>
   <updated>2018-03-19T00:00:00+00:00</updated>
   <id>http://thehackerwithin.org/UoB/posts/what-to-learn-and-teach</id>
   <content type="html">&lt;p&gt;The first meeting of The Hacker Within at the University of Birmingham will be:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;when: Monday 19th March, 1-2pm.&lt;/li&gt;
  &lt;li&gt;where: Room 118 Muirhead&lt;/li&gt;
  &lt;li&gt;what: Introduction to the Hacker Within; discussion suggestions and voting
about what to learn and what to teach.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don’t need to book, please, just turn up.&lt;/p&gt;

&lt;p&gt;Here are the &lt;a href=&quot;https://github.com/matthew-brett/thw-intro/blob/master/thw_uob.pdf&quot;&gt;talk
slides&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Look at &lt;a href=&quot;https://github.com/matthew-brett/thw-intro&quot;&gt;the Github repository&lt;/a&gt;
for the source material to generate the slides, including copyright
information.&lt;/p&gt;

&lt;p&gt;After the talk, I mentioned our &lt;a href=&quot;http://www.jarrodmillman.com/rcsds&quot;&gt;Berkeley course on reproducible
science&lt;/a&gt;.  If you want to see what the
students managed to do in their final projects, have a look at the course
&lt;a href=&quot;https://github.com/berkeley-stat159&quot;&gt;Github organization&lt;/a&gt; for the students
project repositories, beginning with &lt;code class=&quot;highlighter-rouge&quot;&gt;project-&lt;/code&gt;.  For example
&lt;a href=&quot;https://github.com/berkeley-stat159/project-alpha&quot;&gt;project-alpha&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 
</feed>
