[CentralOH] 2016-04-08 道場 Scribbles 落書/惡文? refactoring euler cohpy challenge __future__ revolv hub panama drone symphony xz v bzip2 python v sh yaml choker namedtuple database best/worst practices sqlalchemy context manager router fcc tp-link stairway to apache zepellin yhat ggplot feather arrow new relic seasons git remmina r s reactos

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Fri Apr 8 22:16:56 EDT 2016


Many little refactorings from last dojo (and more yet to come):

    http://nbviewer.jupyter.org/github/joefriedrich/Project_Euler/blob/master/Project_Euler--Problem_001.ipynb
    http://nbviewer.jupyter.org/github/joefriedrich/COhPy_Challenges/blob/master/2016-Feb-COhPy_Challenge.ipynb

all PC laptops tonight

study lp

cohpy leap day challenge https://xkcd.com/1595/

the future is now

    28.11. __future__ — Future statement definitions
    https://docs.python.org/2/library/__future__.html

Learning with Python
How to Think Like a Computer Scientist
http://www.greenteapress.com/thinkpython/thinkCSpy/

Music to Work to
    https://www.youtube.com/watch?v=F0YYoo6oFoU
8 Hour Study Mix: "Trance to Study By: All-Nighter"

A spiritual successor to Aaron Swartz is angering publishers all over again
http://arstechnica.com/tech-policy/2016/04/a-spiritual-successor-to-aaron-swartz-is-angering-publishers-all-over-again/

wp: prefix means Wikipedia
To get good answers, consider following the advice in the links below.
http://catb.org/~esr/faqs/smart-questions.html
http://web.archive.org/web/20090627155454/www.greenend.org.uk/rjk/2000/06/14/quoting.html

compare:
wp:The Prince
http://techrights.org/2016/04/03/microsoft-build-charm-offensive/

The reality of connected devices

    I can play 400 year old music,
    but I can't open a Word document from 1990.
    http://pyvideo.org/video/3681/

    My Commodore 64 still works,
    by my two year old Revolv hub
    will be dead after April 15.
    http://mashable.com/2016/04/04/revolv-smart-home-shutdown

No surprise:
The Internet of Things Is Wildly Insecure—And Often
Unpatchable
https://www.schneier.com/essays/archives/2014/01/the_internet_of_thin.html

Wall of Panama
http://english.chosun.com/site/data/html_dir/2016/04/06/2016040600577.html

Symphony drowns out drones (but not the bagpipes)
http://iq.intel.com/100-dancing-drones-set-world-record/
http://www.engadget.com/2016/01/11/intel-record-setting-drone-show/

xz compresses significantly better than bzip2,
but with considerably more CPU effort.

    dojo at 4519_n_high:~/pi/mate-ubuntu/16.04-beta2-desktop$ cat compress.py
    #!/usr/bin/env python3

    '''
    https://docs.python.org/3/library/gzip.html
    https://docs.python.org/3/library/bz2.html
    https://docs.python.org/3/library/lzma.html
    https://docs.python.org/3/library/zlib.html
    '''

    import sys
    from collections import namedtuple
    import os.path
    import shutil
    import datetime
    import timeit

    import gzip
    import bz2
    import lzma

    def compress(path, compressor):
        c = compressor

        uncompressed_size = os.path.getsize(path)  # Unit is 1 byte.
        compressed_path = '.'.join([path, c.filename_ending])
        with open(path, 'rb') as f_in:
            with c.function(compressed_path, 'wb', **c.kwargs) as f_out:
                # shutil.copyfileobj(f_in, f_out)
                try:
                    t = timeit.timeit(
                        'shutil.copyfileobj(f_in, f_out)',
                        number=1, globals=globals())
                except TypeError:
                    before = datetime.datetime.now()
                    shutil.copyfileobj(f_in, f_out)
                    after = datetime.datetime.now()
                    t = after - before
        compressed_size = os.path.getsize(compressed_path)  # Unit is 1 byte.

        print('%s %s' % (path, uncompressed_size))
        print('%s %s' % (compressed_path, compressed_size))
        print(
            '%.4s%%' %
            (100. * (float(compressed_size) / float(uncompressed_size))))
        print('elapsed time:', t)

    def main(path):
        Compressor = namedtuple('Compressor', 'function, filename_ending, kwargs')
        compressors = (
            Compressor(gzip.open,     'gz',  {}),
            Compressor(bz2.BZ2File,   'bz2', {}),
            Compressor(lzma.LZMAFile, 'xz',  {'format': lzma.FORMAT_XZ}),
        )
        
        for compressor in compressors:
            compress(path, compressor)

    if __name__ == '__main__':
        main(sys.argv[1])
    dojo at 4519_n_high:~/pi/mate-ubuntu/16.04-beta2-desktop$ ./compress.py compress.py
    compress.py 1758
    compress.py.gz 690
    39.2%
    elapsed time: 0:00:00.000096
    compress.py 1758
    compress.py.bz2 766
    43.5%
    elapsed time: 0:00:00.000058
    compress.py 1758
    compress.py.xz 752
    42.7%
    elapsed time: 0:00:00.000067
    dojo at 4519_n_high:~/pi/mate-ubuntu/16.04-beta2-desktop$ ./compress.py ubuntu-mate-16.04-beta2-desktop-armhf-raspberry-pi.img
    ubuntu-mate-16.04-beta2-desktop-armhf-raspberry-pi.img 3932160000
    ubuntu-mate-16.04-beta2-desktop-armhf-raspberry-pi.img.gz 1531627546
    38.9%
    elapsed time: 0:10:14.763755
    ubuntu-mate-16.04-beta2-desktop-armhf-raspberry-pi.img 3932160000
    ubuntu-mate-16.04-beta2-desktop-armhf-raspberry-pi.img.bz2 1425131396
    36.2%
    elapsed time: 0:13:43.507302
    ubuntu-mate-16.04-beta2-desktop-armhf-raspberry-pi.img 3932160000
    ubuntu-mate-16.04-beta2-desktop-armhf-raspberry-pi.img.xz 1112883200
    28.3%
    elapsed time: 0:38:36.826333
    dojo at 4519_n_high:~/pi/mate-ubuntu/16.04-beta2-desktop$ 

Compare Python code above with long ugly shell one-liner below

    dojo at 4519_n_high:~/pi/mate-ubuntu/16.04-beta2-desktop/t$ u="ubuntu-mate-16.04-beta2-desktop-armhf-raspberry-pi.img"; ls -l "$u"; for compressor in z j J; do f="foo.t${compressor}"; time tar "c${compressor}f" "$f" "$u"; ls -l "$f";echo 'scale=1;' `stat -c %s "$f"` '*' 100 / `stat -c %s "$u"` | bc;done
    -rw-rw-r-- 1 dojo dojo 3932160000 Apr  8 16:21 ubuntu-mate-16.04-beta2-desktop-armhf-raspberry-pi.img

    real    4m26.946s
    user    3m48.084s
    sys     0m13.548s
    -rw-rw-r-- 1 dojo dojo 1537621625 Apr  8 19:06 foo.tz
    39.1

    real    13m45.200s
    user    12m51.820s
    sys     0m25.532s
    -rw-rw-r-- 1 dojo dojo 1425127910 Apr  8 19:20 foo.tj
    36.2

    real    37m45.073s
    user    37m15.136s
    sys     0m39.704s
    -rw-rw-r-- 1 dojo dojo 1112883244 Apr  8 19:58 foo.tJ
    28.3
    dojo at 4519_n_high:~/pi/mate-ubuntu/16.04-beta2-desktop/t$ 

12 memes of open source software
https://opensource.com/business/16/4/12-memes-explain-open-source-software

YAML rocks! ...
wp:YAML
http://yaml.org/type/omap.html

... but it's not clear which module to use.
    enhancedyaml v0.1.1 %YAML 1.1
    PyYAML 3.11 %YAML 1.1
    PyYAML.Yandex 3.11.1 %YAML 1.1
    yamlordereddictloader 0.1.1 %YAML ?
    aspy.yaml 0.2.1 %YAML ?
    yamly 0.1 dead
    pyaml 15.03.1 %YAML 

http://www.nytimes.com/1988/07/12/opinion/l-don-t-slap-a-choker-on-the-back-057088.html

https://docs.python.org/2/library/collections.html#collections.namedtuple

    In addition to the methods inherited from tuples, named tuples support
    three additional methods and one attribute. To prevent conflicts with
    field names, the method and attribute names start with an underscore.

http://stackoverflow.com/questions/4702728/relational-table-naming-convention/4703155#4703155

database best practices

database worst practices

column names

    http://www.c2.com/cgi/wiki?MeaningfulName
    http://www.c2.com/cgi/wiki?RelationalDatabaseFieldNames
    wp:Hungarian notation
    http://en.wikipedia.org/wiki/Leszynski_naming_convention
    http://en.wikipedia.org/wiki/Namespace
    http://en.wikipedia.org/wiki/Category:Programming_rules_of_thumb
    http://en.wikipedia.org/wiki/Category:Programming_principles
    Anti-pattern

    http://databases.about.com/od/specificproducts/a/Database-Naming-Rules.htm
        See "Don't be redundant"

Use SQLAlchemy connection for context manager.
http://stackoverflow.com/questions/17497614/sqlalchemy-core-connection-context-manager
http://www.webmasterwords.com/python-with-statement

which router is router to get these days?
    FCC frustrates open source
    http://arstechnica.com/information-technology/2016/03/tp-link-blocks-open-source-router-firmware-to-comply-with-new-fcc-rule/

ssid: Panera
no password
javascript must be enabled for:
    network-auth.com
    covelli.com

Apache Zepellin (compare with Jupyter)
    https://zeppelin.incubator.apache.org/

yhat.com
ggplot
click bait
feather
apache arrow

youtube-dl

new relic: 

four seasons in Wisconsin: Winter, June, July, and August
three reasons for being a teacher: June, July, and August

http://www.clintonvillerotary.org/

git
    https://xkcd.com/1597/
    https://xkcd.com/1296/

wp:remmina
    client only

R is ugly to program in
    from S language which was made by a statistician

wp:ReactOS
    MS Windows wannabee,
    but will always be playing catchup

soundtrack for video games
    Candice Pacheco, The Vortex
    8-bit sound
    http://www.16-bitbar.com/
        http://www.16-bitbar.com/columbus

More Android
http://www.theregister.co.uk/2016/04/08/jide_remix_os_interview/


More information about the CentralOH mailing list