<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.5.2">Jekyll</generator><link href="http://mks310.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="http://mks310.github.io/" rel="alternate" type="text/html" /><updated>2017-09-13T19:18:21+00:00</updated><id>http://mks310.github.io/</id><title type="html">MKS310.github.io</title><subtitle>Sysadmin studies Data Science</subtitle><entry><title type="html">Factorials! in python</title><link href="http://mks310.github.io/Pythonic-Factorials/" rel="alternate" type="text/html" title="Factorials! in python" /><published>2017-09-13T00:00:00+00:00</published><updated>2017-09-13T00:00:00+00:00</updated><id>http://mks310.github.io/Pythonic-Factorials</id><content type="html" xml:base="http://mks310.github.io/Pythonic-Factorials/">&lt;h2 id=&quot;simple-python-factorial-script&quot;&gt;Simple Python Factorial Script&lt;/h2&gt;

&lt;p&gt;Sure, you could &lt;code class=&quot;highlighter-rouge&quot;&gt;import math&lt;/code&gt; and use the &lt;code class=&quot;highlighter-rouge&quot;&gt;math.factorial(x)&lt;/code&gt; function, but what fun is there in that?
Here, I have a rudimentary factorial script using only the built-in functions that has some pythonic error catching (try/except) built in.&lt;/p&gt;

&lt;p&gt;##What is Pythonic Error Catching?&lt;/p&gt;

&lt;p&gt;Hold on…&lt;/p&gt;

&lt;p&gt;##What is Pythonic Code?&lt;/p&gt;

&lt;p&gt;First, what is Python Code? It is generally accepted to be code that abides by &lt;a href=&quot;https://www.python.org/dev/peps/pep-0020/&quot;&gt;The Zen of Python&lt;/a&gt;. According to the Abstract:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Long time Pythoneer Tim Peters succinctly channels the BDFL’s guiding principles for Python’s design into 20 aphorisms, only 19 of which have been written down.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Archived in the archives of Python.org is the &lt;a href=&quot;https://mail.python.org/pipermail/python-list/1999-June/001951.html&quot;&gt;original exchange&lt;/a&gt; between Tim Peters, Patrick Phalen, Fredrik Lundh and “Guido”.&lt;/p&gt;

&lt;p&gt;###The Zen of Python (originally, “The Python Way), PEP 20&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Beautiful is better than ugly.&lt;/li&gt;
  &lt;li&gt;Explicit is better than implicit.&lt;/li&gt;
  &lt;li&gt;Simple is better than complex.&lt;/li&gt;
  &lt;li&gt;Complex is better than complicated.&lt;/li&gt;
  &lt;li&gt;Flat is better than nested.&lt;/li&gt;
  &lt;li&gt;Sparse is better than dense.&lt;/li&gt;
  &lt;li&gt;Readability counts.&lt;/li&gt;
  &lt;li&gt;Special cases aren’t special enough to break the rules.&lt;/li&gt;
  &lt;li&gt;Although practicality beats purity.&lt;/li&gt;
  &lt;li&gt;Errors should never pass silently.&lt;/li&gt;
  &lt;li&gt;Unless explicitly silenced.&lt;/li&gt;
  &lt;li&gt;In the face of ambiguity, refuse the temptation to guess.&lt;/li&gt;
  &lt;li&gt;There should be one– and preferably only one –obvious way to do it.&lt;/li&gt;
  &lt;li&gt;Although that way may not be obvious at first unless you’re Dutch.&lt;/li&gt;
  &lt;li&gt;Now is better than never.&lt;/li&gt;
  &lt;li&gt;Although never is often better than &lt;em&gt;right&lt;/em&gt; now.&lt;/li&gt;
  &lt;li&gt;If the implementation is hard to explain, it’s a bad idea.&lt;/li&gt;
  &lt;li&gt;If the implementation is easy to explain, it may be a good idea.&lt;/li&gt;
  &lt;li&gt;Namespaces are one honking great idea – let’s do more of those!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;##Again, What is Pythonic Error Catching?&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;10. Errors should never pass silently&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A few decent rules of error catching from &lt;a href=&quot;https://www.joelonsoftware.com/2003/10/13/13/&quot;&gt;Joel Spolsky&lt;/a&gt; talking specifically about Java and C++:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Never throw an exception of my own&lt;/li&gt;
  &lt;li&gt;Always catch any possible exception that might be thrown by a library I’m using on the same line as it is thrown and deal with it immediately&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In my script below, I almost break Joel’s rule number one. When checking for positive numbers I was tempted to say something like
```python
if num &amp;lt; 0:
    raise MyException(“Positive Integers only…”)
``
Obviously, I found I better way!&lt;/p&gt;

&lt;p&gt;Although my script has room for improvement in the way of best practices for programming, I do believe I met &lt;strong&gt;Pythonic Code&lt;/strong&gt; criteria number 10.&lt;/p&gt;

&lt;p&gt;##Check it out and enjoy!&lt;/p&gt;

&lt;p&gt;```python
def factorial(val):
    try:
        f = 1 
        for i in list(range(1,val+1)):
            f = f*i
        return f
    except:
        print(“Whoa! Please try again….”)&lt;/p&gt;

&lt;p&gt;def get_factorial(val):
        try:
            if( val == 0 ):
                return 1
            else:
                return factorial(val)
        except Exception:
            print(“Not sure what you did! Please try again….”)
def main():
    while True:
        try:
            num = int(input(“Enter an integer:”))
            if num &amp;gt;= 0:
                print(get_factorial(num))
            else:
                print(“Positive integers only…”)
        except Exception:
            print(“No valid integer! Please try again….”)
main()     &lt;br /&gt;
``&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Enter an integer:6
720
Enter an integer:5
120
Enter an integer:-5
Positive integers only...
Enter an integer:0
1
Enter an integer:er
No valid integer! Please try again....
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content><author><name></name></author><summary type="html">Simple Python Factorial Script</summary></entry><entry><title type="html">Hardware and Software Guide to Data Science at Home</title><link href="http://mks310.github.io/DS-Setup/" rel="alternate" type="text/html" title="Hardware and Software Guide to Data Science at Home" /><published>2017-09-10T00:00:00+00:00</published><updated>2017-09-10T00:00:00+00:00</updated><id>http://mks310.github.io/DS-Setup</id><content type="html" xml:base="http://mks310.github.io/DS-Setup/">&lt;h1 id=&quot;hardware-and-software-guide&quot;&gt;Hardware and Software Guide!!&lt;/h1&gt;

&lt;p&gt;I was buying another external harddrive the other day and began thinking about how I could optimize my at-home data-science set-up. Where should I store my data? Should I use cloud resources? how do I stay organized? How do I optimize the processing power that I have? Do I need more? How is my hardware limiting my number crunching activities?&lt;/p&gt;

&lt;h2 id=&quot;set-up-your-hardware&quot;&gt;Set Up Your Hardware&lt;/h2&gt;

&lt;p&gt;Let’s start from the bottom up, with your hardware. You need to be able to process large amounts of data locally. Sure, you can use cloud resources, which we will talk about, but you want to be able to do some of the heavy lifting yourself. If you rely 100% on cloud resources, you will be at the mercy of having a network connection, and your wallet. Cloud computing is not expensive, but you don’t want to pay for it unless you have to and definitely not for just playing around with data.&lt;/p&gt;

&lt;p&gt;###Considerations
-laptop or desktop&lt;/p&gt;

&lt;p&gt;-dual core or quad core&lt;/p&gt;

&lt;p&gt;-RAM&lt;/p&gt;

&lt;p&gt;-r/w operations on SSD&lt;/p&gt;

&lt;p&gt;-GPU considerations for intense graphical analysis?&lt;/p&gt;

&lt;h3 id=&quot;recomendations&quot;&gt;Recomendations&lt;/h3&gt;

&lt;p&gt;https://www.analyticsvidhya.com/blog/2015/08/ready-data-science-resources-common-questions-answered/&lt;/p&gt;

&lt;p&gt;Tune your machine&lt;/p&gt;</content><author><name></name></author><summary type="html">Hardware and Software Guide!!</summary></entry></feed>