[CentralOH] 2016-12-23 道場 Scribbles 落書/惡文? cursing recursive fibonacci lru_cache; euler 18; cjkv ken lunde; live DVDs; virtualization; instruction sets; writing compilers; coding style; banishing curly braces from C and Java; CPU emulator; bit twiddling; print dress; v R; eclipse; guis; trolls; mr. creosote

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Sat Dec 24 13:59:53 EST 2016


someone who did recursive fibonacci in school will get a laugh from:

    http://nbviewer.jupyter.org/url/colug.net/python/cohpy/20150223/cohpy-20150223-memoization.ipynb

    for real projects use lru_cache instead of memoize

        https://docs.python.org/3/library/functools.html#functools.lru_cache
        maxsize=None is nice option

euler #18
redo with
map(max, (zip([0]+m, m+[0])))
n = map(max, (zip([0]+m, m+[0])))
m = map(sum, zip(n, new_row))

wp:martin scorsese
    wp:George Harrison: Living in the Material World

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

the definitive book for CJK:
CJKV Information Processing
By Ken Lunde

wp:Hacking: The Art of Exploitation
wp:Code: The Hidden Language of Computer Hardware and Software
    wp:Charles Petzold

wp:Live CD
    wp:Knoppix
    wp:CentOS
    wp:Puppy Linux
    wp:Ubuntu (operating system)
    wp:Trinity Rescue Kit
    wp:Comparison_of_Linux_distributions#Live_media
    tomsrtbt

wp:Hardware virtualization
wp:Hardware-assisted virtualization
wp:x86 virtualization
wp:Parallels Desktop for Mac
wp:Kernel-based Virtual Machine
wp:QEMU

good
    wp:PDP-11 architecture
        decent instruction set
            good addressing modes
        good orthogonality
    wp:NS320xx
    motorola 68000 (68k)
decent
    arm
ich
    intel
        see comment in Bloom County
    worst: microchip

wp:restrictor plate racing
    compare to modern CPU's access to RAM

compiler
    much easier to write in python than C
    wp:yacc
        https://pypi.python.org/pypi?%3Aaction=search&term=yacc&submit=search
    wp:lex
        https://pypi.python.org/pypi?%3Aaction=search&term=lex&submit=search

significant linux distros to compare (that use Python)
    ubuntu (easy)
    centos (used to be serious?, fading glory?)
    debian
    mint (toy)

https://www.kernel.org/doc/Documentation/CodingStyle

    Heretic people all over the world have claimed that this inconsistency
    is ...  well ...  inconsistent, but all right-thinking people know that
    (a) K&R are **right** and (b) K&R are right.  Besides, functions are
    special anyway (you can't nest them in C).

    wp:Indent_Style#K.26R_style

Of course, it would be better to avoid the stinking curly braces altogether.
Take out all the curly braces from a C program.
Write a program (in Python of course)
that reads a C program that does not have curly braces,
and outputs the same C program, with added curly braces
depending on changes in indentation.

put that in your Makefile to automate it

    wp:Make (software)

wp:Off-side rule
wp:Curly_bracket_programming_language#Curly-bracket_languages

write a software emulator for something with a simple instruction set
    PDP-8?

    write it first in Python. then write it in C and Java.

    which is easiest to understand?
    which is easiest to write?
    what are C and Java versions good at?

    Is emulating I/O devices harder than emulating the instruction set?

C:
    int x;
    int y;
    ...
    x ^= y;
    y ^= x;
    x ^= y;

python:
    x, y = y, x

C is a low level language
Java is a medium level language
Python is a high level language

    watch
    Beyond PEP 8 -- Best practices for beautiful intelligible code
    http://pyvideo.org/pycon-us-2015/beyond-pep-8-best-practices-for-beautiful-inte.html

Using Blender and Python to 3D print a dress
https://opensource.com/article/16/12/blender-python-3D-dress

Python versus R for machine learning and data analysis
https://opensource.com/article/16/11/python-vs-r-machine-learning-data-analysis

How to use Python to hack your Eclipse IDE
https://opensource.com/life/16/2/how-use-python-hack-your-ide

Python vs. C/C++ in embedded systems
https://opensource.com/life/16/8/python-vs-cc-embedded-systems

3 open source Python GUI frameworks
https://opensource.com/life/16/5/open-source-python-gui-frameworks

Supreme Court Will Hear A Case That Could Finally Shut Down East Texas As The Patent Troll Mecca
https://www.techdirt.com/articles/20161215/00283936281/supreme-court-will-hear-case-that-could-finally-shut-down-east-texas-as-patent-troll-mecca.shtml?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed

https://blog.pandorafms.org/network-tools/

How Linux got to be Linux: Test driving 1993-2003 distros
https://opensource.com/article/16/12/yearbook-linux-test-driving-distros
I wonder what Python was like then.

Open education is about improving lives, not taking tests
https://opensource.com/open-organization/16/12/make-sharing-rule-not-exception

bit twiddling

C

    #define LED_ON_MASK (1<<2)

    port |= LED_ON_MASK;
    port &= ~LED_ON_MASK;
    port ^= LED_ON_MASK;

python

    LED_ON_MASK = (1<<2)

    port |= LED_ON_MASK
    port &= ~LED_ON_MASK
    port ^= LED_ON_MASK

Remote Logging With Syslog, Part 4: Log Rotation
https://www.linux.com/learn/remote-logging-syslog-part-1-basics
https://www.linux.com/learn/sysadmin/remote-logging-syslog-part-2-main-config-file
https://www.linux.com/learn/sysadmin/remote-logging-syslog-part-3-logfile-rules
https://www.linux.com/learn/sysadmin/remote-logging-syslog-part-4-log-rotation

Submiton./ucp.php?mode=login&return_to=%2Fservices%2Fx%2Fa.php%3Fpath%3D%2Finformation-technology%2F2016%2F12%2Fsignal-does-not-replace-pgp%2F%26s%3D1/services/x/a.php?path=%2Finformation-technology%2F2016%2F12%2Fsignal-does-not-replace-pgp%2F&s=1

Op-ed: Why I’m not giving up on PGP
http://arstechnica.com/information-technology/2016/12/signal-does-not-replace-pgp/

wp:Mr Creosote
Better keep a bucket nearby while reading the following code.

    doj at 4519_n_high:~/20161223$ cat hello.c
    #include <stdlib.h>
    #include <stdio.h>

    int main(int argc, char *argv)
    {
        printf("hello world\n");
    }
    doj at 4519_n_high:~/20161223$ cat hello.unbraced
    #include <stdlib.h>
    #include <stdio.h>

    int main(int argc, char *argv)
        printf("hello world\n");
    doj at 4519_n_high:~/20161223$ cat enbrace.py
    #!/usr/bin/env python3

    import sys
    import re

    WHITESPACE_WIDTH = {' ': 1, '\t': 8}
    WHITESPACE = {' ', '\t'}

    def main():
        old_indentation = 0
        for i, line in enumerate(sys.stdin):
            new_indentation = 0
            # Simplify following with len() of re stuff.
            # Better yet, expand to multiple of WHITESPACE_WIDTH column.
            for c in line:
                if c not in WHITESPACE:
                    break
                new_indentation += 1

            if new_indentation > old_indentation:
                print('{' * (new_indentation - old_indentation), end='')
            elif new_indentation < old_indentation:
                print('}' * (old_indentation - new_indentation), end='')
            # nasty: print(
            # nasty:     '{' if new_indentation > old_indentation else '}' *
            # nasty:     abs(new_indentation - old_indentation), end='')
            print(line, end='')
            old_indentation = new_indentation
            # print(i, new_indentation, line, end='')

        if old_indentation:
            print('}' * (old_indentation))

    if __name__ == '__main__':
        main()
    doj at 4519_n_high:~/20161223$ ./enbrace.py <hello.unbraced | tee hello.braced.c
    #include <stdlib.h>
    #include <stdio.h>

    int main(int argc, char *argv)
    {{{{    printf("hello world\n");
    }}}}
    doj at 4519_n_high:~/20161223$ rm hello.braced
    doj at 4519_n_high:~/20161223$ make hello.braced
    cc     hello.braced.c   -o hello.braced
    doj at 4519_n_high:~/20161223$ ./hello.braced
    hello world
    doj at 4519_n_high:~/20161223$

The extra curly braces are rediculous, but cause no problem.
Since the code with curly braces is just a temporary intermediate file
that one would normally not read,
the ugly placement of the curly braces does not matter.
Write a better version of enbrace that sticks in fewest curly braces.
Could it work for Java code also?

just two folks tonight


More information about the CentralOH mailing list