<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Peter Kong on Medium]]></title>
        <description><![CDATA[Stories by Peter Kong on Medium]]></description>
        <link>https://medium.com/@peterkong?source=rss-a745da0fa8df------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mAUButAwN4wSX7UA.jpg</url>
            <title>Stories by Peter Kong on Medium</title>
            <link>https://medium.com/@peterkong?source=rss-a745da0fa8df------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:44:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@peterkong/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Comparison of Python documentation generators]]></title>
            <link>https://medium.com/@peterkong/comparison-of-python-documentation-generators-660203ca3804?source=rss-a745da0fa8df------2</link>
            <guid isPermaLink="false">https://medium.com/p/660203ca3804</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Peter Kong]]></dc:creator>
            <pubDate>Wed, 21 Feb 2018 20:22:01 GMT</pubDate>
            <atom:updated>2018-02-22T20:02:18.478Z</atom:updated>
            <content:encoded><![CDATA[<p>I will attempt here to compare the top Python documentation tools using publicly available information. The goal is to identify which tool will be best for generating HTML from the docstrings within the source code. Criteria include but are not limited to:</p><ul><li>Visual appeal and ease-of-use (where case studies and/or screenshots are available)</li><li>Potential dependency fragility, most importantly which versions of Python</li><li>Community size/engagement and availability of tool support</li><li>Run-time introspection vs static analysis (important only if parts of the software interface are dynamically generated)</li></ul><p>I started by looking at the list of tools here: <a href="https://wiki.python.org/moin/DocumentationTools">https://wiki.python.org/moin/DocumentationTools</a></p><p>The tools currently supported and/or in active development are:</p><ul><li>sphinx — <a href="http://www.sphinx-doc.org/en/master/index.html">http://www.sphinx-doc.org/en/master/index.html</a></li><li>pdoc — <a href="https://github.com/BurntSushi/pdoc">https://github.com/BurntSushi/pdoc</a></li><li>pydoctor — <a href="https://github.com/twisted/pydoctor">https://github.com/twisted/pydoctor</a></li><li>Doxygen — <a href="http://www.stack.nl/~dimitri/doxygen/index.html">http://www.stack.nl/~dimitri/doxygen/index.html</a></li></ul><h3>sphinx</h3><p>By far the most recommended and comprehensive documentation generator. It supports reStructuredText in docstrings and produces a HTML output with a clean visual style. Countless examples (including official Python libraries) can be found here: <a href="http://www.sphinx-doc.org/en/master/examples.html">http://www.sphinx-doc.org/en/master/examples.html</a></p><p>About the only con I could find is that setting it up requires a bit of configuration (using Makefiles) and the documentation for getting started assumes you’re working with a fresh repo. You can also run it with a quickstart script that uses default configurations but it still requires multiple steps. Works for Python 2 and 3 and loads docstrings dynamically through introspection.</p><h3>pdoc</h3><p>Probably the second-most popular Python-exclusive doc tool (Doxygen is more general) it’s got 373 stars and 12 contributors. Its code is a fraction of Sphinx’s complexity and the output is not quite as polished, but it works with zero configuration in a single step. It also supports docstrings for variables through source code parsing. Otherwise it uses introspection. Worth checking out if Sphinx is too complicated for your use case.</p><h3>pydoctor</h3><p>A successor to the popular epydoc, it works only for Python 2. Main benefit is that it traces inheritances particularly well, even for multiple interfaces. Works on static source and can pass resulting object model to Sphinx if you prefer its output style. I actually prefer the clean look of Pydoctor to Sphinx however.</p><h3>doxygen</h3><p>Not Python-exclusive and its interface is crowded and ugly. It claims to be able to generate some documentation (mostly inheritances and dependencies) from undocumented source code. Should be considered because many teams already know this tool from its wide use in multiple languages (particularly C++).</p><h3>Conclusions</h3><p>Unless your team is already using Doxygen and has a flow in place, I would recommend Pdoc for simpler projects and Sphinx for more complex ones. In most cases Sphinx will meet all your needs. That said, I’ve seen multiple reports that it is genuinely harder to set up and use than Pdoc or Pydoctor so you never know until you test it out. Happy documenting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=660203ca3804" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding Consent: First steps toward the Human API]]></title>
            <link>https://medium.com/@peterkong/coding-consent-first-steps-toward-the-human-api-edc0a804ec0c?source=rss-a745da0fa8df------2</link>
            <guid isPermaLink="false">https://medium.com/p/edc0a804ec0c</guid>
            <category><![CDATA[feminism]]></category>
            <category><![CDATA[national-security]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[consent]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Peter Kong]]></dc:creator>
            <pubDate>Thu, 16 Nov 2017 05:07:00 GMT</pubDate>
            <atom:updated>2017-11-16T05:07:00.621Z</atom:updated>
            <content:encoded><![CDATA[<p>Software architectures, including especially the internet, are premised on a base level of trust and cooperation between clients and servers. Standards like HTTP, HTML, ES6 JavaScript, and SHA are examples of how constraining our code enables freedom of information. Without security protocols, the innocent could be overwhelmed by the malicious; without data transfer protocols, the powerless could never collectively contend with the powerful. At the core of these constraints are the twin goals of security and communication.</p><p>That these goals are often in contention is most glaring in the recent Russian attack on our nation. The enemy found a weakness in our tech culture — a culture that has generally favored communication above security. Though it would be easy to assume that this tendency is innate to Silicon Valley and the industry in general, I believe that it is a cultural flaw and a fatal national security that can and MUST be corrected.</p><h3>The gap in our armor</h3><p>The recent revelations of widespread sexual harassment by powerful men should not be a surprise to any men who actually listen to women. But the tech industry is so thoroughly male-dominated that it is unsurprising how many express shock or even disbelief. People generally don’t dwell on the lived realities of people they don’t have to interact with very often.</p><p>And as my friend Hale said recently, “Clearly the internet was designed by men”. He meant that security matters the most to the vulnerable, and most men cannot honestly say they have felt vulnerable as frequently or as deeply as most women. But if tech is to advance as a force for good, not evil, we have to start to create a culture of security.</p><p>And I don’t just mean passwords and encryption. Fake news and propaganda proliferate on valid social media accounts. But they will find no purchase in a nation actively working to heal our divisions, between races, genders, and all kinds of Americans. So where do we even begin? I’d like to offer just one module in this mother of all patches.</p><h3>Promise notation and consent</h3><p>I have two goals here:</p><ol><li>Explain how promises work</li><li>Relate promises to consent culture</li></ol><p><strong>Promise notation</strong> is a way of representing asynchronous operations as chained function calls as an alternative to nesting callback functions. They exist in many languages that have a functional programming paradigm including ES6 JavaScript, which I’ll use in the coming example.</p><p><strong>Consent culture </strong>is the idea that adult human beings should only do something to or with another human being after asking and receiving explicit permission. I’ll keep this PG so for our example we’ll model the timeless activity of kissing. And we’ll start from the moment you meet your potential make out partner at a party.</p><h3>Time to find a hot stranger to kiss</h3><p>Each step takes time and requires the previous step to complete before initiating the next. Such asynchronous actions are traditionally handled with callbacks:</p><pre>meetSomeone(hotStranger =&gt; {<br>  establishAttraction(hotStranger, (rejection, hotStranger) =&gt; {<br>    if(rejection) { console.log(&#39;life goes on&#39;) }<br>    if(hotStranger !== null) {<br>      askForKiss(hotStranger, (rejection, hotStranger) =&gt; {<br>        if(rejection) { console.log(&#39;life goes on&#39;) }<br>        if(hotStranger !== null) {<br>          kiss(hotStranger);<br>        } <br>      });<br>    }<br>  });<br>});</pre><p>That’s too deeply nested for legibility, and illegible code is less secure code. And more importantly, the callbacks take parameters that can be ignored or misused very easily. For example, if establishAttraction were implemented badly (e.g. “misread signals”), it’s possible that:</p><pre>rejection !== null &amp;&amp; hotStranger !== null</pre><p>As in, the hot stranger did not signal back attraction but is also sticking around for conversation. So the above code would still result in calling <strong>askForKiss()</strong>!</p><p>And it would be easy to handle the rejection incorrectly:</p><pre>if(rejection) { console.log(&#39;life goes on&#39;) }<br>askForKiss(...)</pre><p>Because there’s nothing in the code that requires us to wrap our operations in the correct <strong>if</strong> statements or return if there is a rejection (or error).</p><h3>Keeping promises, respecting consent</h3><p>Let’s do this with promises:</p><pre>meetSomeone()<br>.then(hotStranger =&gt; {<br>  return establish_attraction(hotStranger);<br>})<br>.then(hotStranger =&gt; {<br>  return askForKiss(hotStranger);<br>})<br>.then(hotStranger =&gt; {<br>  kiss(hotStranger);<br>})<br>.catch(rejection =&gt; {<br>  console.log(&#39;life goes on&#39;)<br>})</pre><p>Immediately apparent is how much cleaner this looks. It follows chronological order without having to indent. The magic happens inside the <strong>.then().</strong></p><p>The parameters for <strong>meetSomeone()</strong> is passed to the following <strong>then()</strong>, and the return value of <strong>then()</strong> becomes the parameter of the following <strong>then()</strong>, and so on. But what about the rejection (or in most code, the “error” object)? <strong>then()</strong> will check if it exists, and if so, will skip all subsequent <strong>then()</strong> calls until it reaches <strong>catch()</strong>. If there was an error in <strong>establishAttraction()</strong>, it will never awkwardly <strong>askForKiss()</strong>. If <strong>askForKiss()</strong> comes back with “no”, it will most definitely never <strong>kiss()</strong>. And best of all, we can do this:</p><pre>.catch(rejection =&gt; {<br>  console.log(&#39;life goes on&#39;)<br>})<br>.then(() =&gt; {<br>  liveAndLearn();<br>})</pre><p><strong>liveAndLearn()</strong> will always get called.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edc0a804ec0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reactify a non-reactive express app]]></title>
            <link>https://medium.com/@peterkong/reactify-a-non-reactive-express-app-6e077a04e141?source=rss-a745da0fa8df------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e077a04e141</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Peter Kong]]></dc:creator>
            <pubDate>Thu, 26 Oct 2017 05:03:54 GMT</pubDate>
            <atom:updated>2017-10-26T14:20:40.688Z</atom:updated>
            <content:encoded><![CDATA[<p>Last Friday, with two other students from General Assembly, we completed <a href="http://kollaboscope.herokuapp.com/">our first project</a>. However, this week we dove into React.js and immediately I wanted to redo the front-end to make our app truly single-page.</p><p>Specifically, I wanted to accomplish the following:</p><ol><li>Use create-react-app to make a separate front-end app</li><li>Host it separately from the back end to get around Heroku’s restrictions on ports. This requires setting up CORS — see below</li><li>Separate our monolithic index.html into React components</li><li>Rip out all JQuery and replace with axios/react.</li><li>Implement routes to redirect between the landing and content pages.</li><li>Reconnect events to React components.</li></ol><h3>1. create-react-app</h3><p><a href="https://www.npmjs.com/package/create-react-app">Is pure magic.</a></p><h3>2. CORS</h3><p>In the course of this process I quickly discovered that hosting the front and back separately (even on localhost with different ports) is called CORS: “Cross Origin Resource Sharing” and that this is <em>disabled</em> by default! “Cross Origin” means that the two servers are not hosted on the same domain and port. Here is how to set up middleware that sets the correct headers to <em>enable</em> CORS in Express.js:</p><pre>app.use(function (req, res, next) {<br>  res.header(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);<br>  res.header(&quot;Access-Control-Allow-Methods&quot;, &quot;GET, HEAD, OPTIONS, POST, PUT&quot;);<br>  res.header(&quot;Access-Control-Allow-Headers&quot;, &quot;Origin, X-Requested-With, <br>contentType, Content-Type, Accept, Authorization&quot;);<br>  next();<br>});</pre><p>This is tedious, considering that our back end will only ever receive requests from a host that is not our own. I imagine this makes sense for authentication purposes, but we don’t have that set up for our app. Turns out, there is a <a href="https://www.npmjs.com/package/cors">CORS NPM package</a> that sums up the above code:</p><pre>const cors = require(&#39;cors&#39;);<br>app.use(cors());</pre><p>Much cleaner.</p><h3>3. Separate HTML into Components</h3><p>I won’t paste my whole index.html into this post, but basically I wrapped pieces of the HTML inside the following boilerplate:</p><pre>import React, { Component } from &#39;react&#39;;</pre><pre>class Child extends Component {<br>  render() {<br>    return(<br>      &lt;your-html-here&gt;<br>    );<br>  }<br>}</pre><pre>export default Child;</pre><p>And then imported them appropriately into their parent components:</p><pre>import React, { Component } from &#39;react&#39;;<br>import Child from &#39;./Child&#39;;</pre><pre>class Parent extends Component {<br>  render() {<br>    return(<br>      &lt;Child /&gt;<br>    );<br>  }<br>}</pre><pre>export default Parent;</pre><p>This process took very little time and in the end, my output more or less matched the previous statically served (and javascript DOM manipulated) pages. But I broke all my javascript of course.</p><h3>4. axios/react</h3><p>The main function of my event listeners was to call my back end API. Previously this was done with AJAX via jQuery, but I’m not a huge fan of jQuery. Axios, however, can turn this:</p><pre>$.ajax({<br>    method: &#39;POST&#39;,<br>    url: `/playlists`,<br>    dataType: &#39;json&#39;,<br>    data: {<br>      name: newName,<br>      description: newDescr<br>    },<br>    success: redirectFunction,<br>    error: (err) =&gt; { console.log(err); }<br>  });</pre><p>Into this:</p><pre>axios.post(&#39;<a href="http://localhost:3000/playlists&#39;">/playlists&#39;</a>, {<br>      name: newName,<br>      description: newDescr<br>    })<br>    .then(redirectFunction)<br>    .catch(err =&gt; {<br>      console.log(err);<br>    })</pre><p>We lose jQuery bloat and gain code clarity.</p><p>Stay tuned for the follow up post on hooking up events and using them to trigger redirects and UI updates!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e077a04e141" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On blockchain and creative capital]]></title>
            <link>https://medium.com/@peterkong/on-blockchain-and-creative-capital-a48d074b0359?source=rss-a745da0fa8df------2</link>
            <guid isPermaLink="false">https://medium.com/p/a48d074b0359</guid>
            <category><![CDATA[creative-economy]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[intellectual-property]]></category>
            <dc:creator><![CDATA[Peter Kong]]></dc:creator>
            <pubDate>Wed, 04 Oct 2017 16:47:58 GMT</pubDate>
            <atom:updated>2017-10-04T16:47:58.884Z</atom:updated>
            <content:encoded><![CDATA[<p>The global trend in macroeconomics is away from extractive capital toward creative capital. That is, economic value is increasingly sourced from the innovations of human beings and less from what humans can physically remove from the environment. However, the highly centralized and unequal distribution of pre-digital wealth has resulted in the same structures in the new economy. Rather than unleash a wave of small-business creation and open innovation, the current tech landscape is dominated by just a handful of corporations, particularly Google, Apple, Facebook and Amazon.</p><p>With the notable exception of Apple, these companies are innovating, but in a particularly extractive way by either:</p><ol><li>Buying up startups that are the primary source of tech innovation to nip a potential competitor in the bud or deny that technology to an established competitor.</li><li>Converting users’ eyeballs or personal data into their primary revenue stream. That is, they are “mining” our data and centralizing the profits derived.</li></ol><p>A few counter-examples exist such as Twitch’s fairly generous revenue sharing with their content-creators and Medium.com’s writer-centric business model, but ultimately they rely on brand loyalty to lock down content exclusivity. This only works if the platform is large enough to make exclusivity worthwhile, which ultimately leads to the same problems of wealth concentration posed by the worst offenders. Basically Twitch and Medium are not <em>owned</em> by the content creators, they are owned by their shareholders (or Amazon in Twitch’s case).</p><h3>How we got here</h3><p>The fundamental problem that these data extracting businesses are solving is twofold:</p><ol><li>Content curation and aggregation — people don’t have the resources to find everything for themselves</li><li>Content attribution and compensation — creators don’t have the resources to enforce their intellectual property rights</li></ol><p>Clearly they have mastered the solution to problem #1. Problem #2 will never be solved so long as they profit from #1. And this imbalance between capital and labor, as old as economics, is what will carry our season of discontent into the forseeable future. That is unacceptable.</p><p>Intellectual property blockchains offer a solution. But first, here’s <a href="https://bitcoinmagazine.com/articles/is-blockchain-powered-copyright-protection-possible-1470758430/">how they <em>won’t </em>solve the problem</a>. In summary:</p><ol><li>Hash algorithms are too sensitive to recognize that two digital works that differ only by a few bytes are actually the same work</li><li>Legal enforcement is a non-digital bottleneck that is highly resistant to change.</li></ol><h3>Smart hashing</h3><p>What if machine learning could be applied to the problem of identifying similar works? At the moment it may seem farfetched but the underlying technologies are advancing rapidly in recent years. In fact machine learning can itself be distributed via blockchain, even registering the training data, to create an end-to-end verifiable process. The computing power required will only get cheaper over time, and automated content crawlers can do the work of discovery. Solving this problem is a prerequisite for any IP blockchain implementation.</p><h3>Legal enforcement</h3><p>Just as famines do not exist where there is political will, our IP system will lag behind innovation so long as our politics are dysfunctional. Ultimately, economic facts on the ground will have to shift so far beyond the legal framework that the politics will be forced to shift or break completely. Part of the problem is a deep suspicion in this country particularly of any kind of universal ID for citizens. Without such a unique identifier there is no realistic way to tag works of art with their authors identity without widespread fraud.</p><p>Private enterprise can partially solve this problem by encouraging users to join their ecosystem in exchange for identity verification, but infringers have no incentive to join. Without a government mandate, this imbalance will make even the discovery process irrelevant.</p><p>Blockchain currencies often incentivize participation through ICOs or coin mining. But the currencies created are only as valuable as the size of the userbase, creating a chicken/egg problem. This is where a meta blockchain comes in. Essentially, what is needed is a blockchain whose transactions represent the metadata of other blockchains. The result is a sort of currency exchange ledger that automates the conversion of value from one crypto-currency to another. This is critical for the sustainability and adoption of more niche blockchains. One can imagine a future economic system wherein energy, carbon, IP, cash, computing power each have specialized blockchains that are fully convertible to each other via this meta-blockchain. Central banks and government regulators will absolutely have to be integral participants in creating these. Russia and a few smaller national economies are already moving in this direction. Will the US catch on and catch up some day?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a48d074b0359" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>