<?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 Owl on Medium]]></title>
        <description><![CDATA[Stories by Owl on Medium]]></description>
        <link>https://medium.com/@bugzeeeeee?source=rss-52e07c8a15fa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JEx4yKA4J3N-tqeWC4Ij7w.jpeg</url>
            <title>Stories by Owl on Medium</title>
            <link>https://medium.com/@bugzeeeeee?source=rss-52e07c8a15fa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 09:20:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bugzeeeeee/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[Learning an Assembly Language: Goofing around with instructions]]></title>
            <link>https://medium.com/@bugzeeeeee/learning-an-assembly-language-goofing-around-with-instructions-f6d1d709532a?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6d1d709532a</guid>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[low-level-programming]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Mon, 21 Sep 2020 04:36:27 GMT</pubDate>
            <atom:updated>2020-09-21T04:52:49.902Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>After a bit of a hiatus, I am returning to my 68K assembly adventures! This will be a short post to describe the 68K mnemonics.</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*juLdgopeYWGQsVh7ytWy4Q.png" /></figure><p>The general pattern of 68K mnemonics is:</p><blockquote>action.length object[, destination]</blockquote><p>Where “action” is the mnemonic, typically an English verb describing the action being performed, with an occasional cryptic abbreviation standing for a whole phrase.</p><p>“Length” denotes the amount of bits we’re dealing with. 68K can work with bytes (8 bit), words (16 bit) and long words (32 bit), and so “length” is one of the three letters: b for “byte”, w for “word”, or l for “long word”.</p><p>“Object” is the stuff we are manipulating. It can be raw literal data (denoted by # sign), a memory address (denoted by $ sign), or a register name. The raw literal numerical data can be expressed in decimal notation (denoted simply by # sign), binary notation (denoted by #%) or hexadecimal notation (denoted by #$).</p><p>Finally, “destination” is exactly that: it’s the place where the “object” of our “action” is headed. “Destination” is optional. You can think of it as the second operand of a binary operator. The mnemonics can be thought of as operators, too. There are “unary operators” in 68K assembly — for example, clr which sets the contents of a register or a memory address to 0. Instructions like that don’t have a “destination”, only “object”. Possible “types” here include a register name or a memory address.</p><p>Certain rules apply to many instructions with regards to compatibility of the “types” of the “object” and “destination” operands. For example, you cannot add data from a memory address to data at another memory address — you’d have to move one of them into a register first; an address register cannot be directly cleared with clr instruction, etc. I am not going to go into details — they can be found in the 68K instruction set which can be downloaded, for example, <a href="http://wpage.unina.it/rcanonic/didattica/ce1/docs/68000.pdf">here</a>.</p><p>And that’s all there is to it! Very simple. Next time, my plan is to look at how I/O is done on a 68K system!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6d1d709532a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On Spaced Repetition as a Learning Method]]></title>
            <link>https://medium.com/@bugzeeeeee/on-spaced-repetition-as-a-learning-method-ff507d84e50a?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff507d84e50a</guid>
            <category><![CDATA[skills-development]]></category>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[education]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Wed, 16 Sep 2020 03:13:07 GMT</pubDate>
            <atom:updated>2020-09-16T03:16:57.842Z</atom:updated>
            <content:encoded><![CDATA[<p>I have tried spaced repetition couple of times when I was learning Japanese. I used Mnemosine and Anki apps — for those of you who don’t know, they are basically software implementations of flashcards (and both are really great apps if that’s what you’re after — I can highly recommend either). I actually used actual flashcards too — back in the day when I was a university student and preparing for my exams.</p><p>This method didn’t work for me. I mean, it did work for the exam preparation. In fact, this was arguably one of the most effective methods to achieve that particular goal. But outside of the world of academia, for <em>actual learning</em> it didn’t. It never even quite made sense to me.</p><p>Spaced repetition as an idea definitely has its merit. This is how we learn in general over the course of our lives for sure. We forget what we don’t use and we remember very well what we use every day. And that’s where spaced repetition <em>as a learning method</em> looses me. Why would I need to artificially arrange for repetition? Am I not learning something useful? Something that I, presumably, would need to use every day? Or am I still preparing for a silly exam?</p><p>In other words, if I must simulate everyday use with software — it might mean I am learning something completely useless. And vice versa, if what I learn I actually do use if not every day but at least regularly (say, I’m watching anime in Japanese with no subtitles, or read Japanese magazines) — what on good Earth would I need spaced repetition software for?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff507d84e50a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning an Assembly Language: How the Processor Works]]></title>
            <link>https://medium.com/@bugzeeeeee/learning-an-assembly-language-how-the-processor-works-3bbc27db8543?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bbc27db8543</guid>
            <category><![CDATA[low-level-programming]]></category>
            <category><![CDATA[assembly-language]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[processors]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Mon, 03 Aug 2020 18:40:22 GMT</pubDate>
            <atom:updated>2020-08-03T19:02:33.658Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bmehNyuBQzp7M88YxzZ_cw.jpeg" /><figcaption>68K on a Sega Mega-Tech board. By <a href="https://www.arcade-projects.com/forums/index.php?user/285-yavuzg/">yavuzg</a></figcaption></figure><p>Assembly language is probably the closest you can get to hardware without loosing your mind. There are little to no high-level abstractions — you tell the processor what to do in a very literal way, so a basic understanding of how it works is required. This post is all about 68K, but really most processors work in the same or very similar way.</p><p>Processors typically have <a href="https://en.wikipedia.org/wiki/Processor_register">registers</a> — small amounts of fast storage to store the data being worked on at the moment. The processor would typically load data from RAM into the registers. 68K has two units: an integer unit and a floating point unit which can execute instructions in parallel. Each unit has its own registers. These are the integer unit registers:</p><ul><li><strong>Data registers</strong> to store data; 8 registers 32 bits each (d0- d7)</li><li><strong>Address registers</strong> to store memory addresses; 8 registers 32 bits each (a0- a7). Register a7 is a special one — it’s a stack pointer.</li><li><strong>Program counter</strong> to store address of the instruction currently being executed on the unit — it’s either incremented automatically or replaced with a new value, depending on the flow; 32 bits (pc)</li><li><strong>Condition code register</strong> to store status of operations and program/system flow; 16 bits (ccr)</li></ul><p>And these are the floating point unit registers:</p><ul><li><strong>Floating point registers</strong> to store floating point data; 8 registers 80 bits each (fp0- fp7)</li><li><strong>Floating point control register</strong> to set exception and mode settings; 16 bits are used and 16 bits are reserved (fpcr)</li><li><strong>Floating point status register</strong> to store the status of floating point operations and exceptions; 32 bits (fpsr)</li><li><strong>Floating point instruction address register</strong> to store the address of the instruction currently being executed on the unit; 32 bits (fpiar)</li></ul><p>In programs written in 68K assembly you’d refer to the registers by their names which I gave in parenthesis. The above registers are used to program user applications; it’s called <em>user mode</em>. The processor also has <em>supervisor mode</em> which has some additional registers (because it gives more access to things) and is used to program system applications. I’m not bothering with the supervisor mode because I plan to write a game 👾.</p><p>68K can handle bytes (8 bits), words (16 bits) and long words (32 bits). A random trivia fact which I didn’t know before: half a byte is called a <a href="https://en.wikipedia.org/wiki/Nibble"><em>nybble</em></a> ✨. The numbers are written in <a href="https://en.wikipedia.org/wiki/Hexadecimal">hexadecimal notation</a> most of the time, where one nybble ✨ corresponds to one hexadecimal digit — it’s the most convenient because there are 16 possible nybbles overall. You can use binary and decimal notations as well though.</p><p>As you can probably tell from the above lists of registers, the data can be basically of two types: the actual <em>data</em> and addresses in memory. In your program, you can either hard-code a value or refer to it by using its address. To people who have experience with C/C++ or Rust this might ring a bell or two.</p><p>So all that was about <em>data</em>, but what can we <em>do</em> with it and how? Let’s look at that. Each processor has a certain set of instructions it supports. Mostly it’s some kind of manipulation on the data: arithmetic, moving things from one address or register to another, etc. 68K supports around 200 instructions. Inside of your computer, all the high-level languages like JavaScript eventually get translated into those instructions the processor supports and understands. Programs that do that are called <em>compilers</em>.</p><p>Now, processors can really only understand bits, which are ones and zeroes. For example, to express my name such that a processor could understand it, you’d have to do something like this: 0100 1001 0111 0010 0110 0101 0110 0111 0110 0101. You can write that down in hexadecimal so as to not go completely crazy: 49 72 65 67 65. I think you get the idea that programming like this would not be fun, and it would be really easy to make errors. So every instruction has a human-understandable (well, kind of) way of expressing them called <em>mnemonics</em>. For example, an instruction to move value from one place to another looks like this: move. Some instructions look more cryptic than that, for example fsgldiv which means single-precision divide, but still this is much easier to read and understand than a bunch of digits.</p><p>The set of those mnemonics and general rules of expressing the instructions in a human-readable way is called <em>assembly language</em>. Assembly language and the instruction set are not the same thing as you can see, but they are still used interchangeably pretty often. The programs that convert mnemonics into actual instructions in machine code (like, the bits) are called <em>assemblers. </em>Assemblers are subset of compilers.</p><p>Finally, a fact that is unlikely news to you but which is still important to bring to your awareness is that <a href="https://en.wikipedia.org/wiki/Instruction_cycle">processors work in cycles</a>. 68K has a cycle of 4 actions:</p><ol><li>Grab next instruction from the memory</li><li>Read and understand the instruction</li><li>Execute the instruction</li><li>Rinse and repeat</li></ol><p>This is how most processors work even today (well, 68K is not entirely obsolete either — it powers some micro-controllers and the TI graphing calculators). The above actions can be done with a certain speed, or rather <em>frequency</em> — as such, it’s measured in <a href="https://en.wikipedia.org/wiki/Hertz">Hz</a> and not in km/hr 🤓. So if you ever wondered what do those 2.5GHz mean in your computer’s processor spec — that’s exactly what they mean: the frequency with which your processor goes through the above cycle.</p><p>With all this in mind, now it’s time for me to actually look at how to make the processor do something! I’ll tell you about that in the next installments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bbc27db8543" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning an Assembly Language: Setting Up]]></title>
            <link>https://medium.com/@bugzeeeeee/learning-an-assembly-language-setting-up-5bf124397810?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bf124397810</guid>
            <category><![CDATA[amiga]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[low-level-programming]]></category>
            <category><![CDATA[assembly]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Sun, 26 Jul 2020 02:45:46 GMT</pubDate>
            <atom:updated>2020-07-26T16:31:56.712Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In these series I will blog about my experience learning an assembly language — or maybe even several assembly languages, if I like it enough! Today I set up my development environment.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YfVtv-Xi6RiLIrpLVZYhvA.jpeg" /></figure><p>When I was a CS student, we had an assembly language class. Of course, I don’t even remember what kind of processor were we writing for or what kind of programs we built — all I remember about it is it went in all caps 😆</p><p>Not so long ago I actually became curious about writing something in assembly. At first, I decided to go with the modern Intel instruction set and write something for my computer. I even installed <a href="https://www.nasm.us/">nasm</a> and prepared for the <a href="https://exercism.io/">https://exercism.io/</a> tutorial. However, a coworker advised to look at <a href="https://en.wikipedia.org/wiki/Motorola_68000_series">Motorola 68000</a> instead. His reasoning:</p><ul><li>It’s simpler. You can actually hold the whole machine in your head. Our modern computers — even the likes of Raspberry Pi — are just too complex, even though they build upon the same ideas and the big picture hasn’t changed all that much.</li><li>It’s cleaner. You can compare the two with reading/writing rules in French and English — French has a certain set of rules, and you can develop an intuition on how a word can be pronounced; English not only has a much larger set of rules, but also even a larger set of exceptions from those rules which makes it highly irregular and ambiguous; the only way to deal with the ambiguity is to memorize the words by heart.</li></ul><p>Regarding the second criterion, another lovely (and open source!) alternative to Intel might be <a href="https://riscv.org/">RISC-V</a>, which is a modern processor architecture based on <a href="https://en.wikipedia.org/wiki/Reduced_instruction_set_computer">RISC design</a>. It can be viewed as royalty-free alternative to another prominent member of RISC family — ARM, which powers 35% of mobile devices today (<em>and</em> the Raspberry Pi 😉). I, however, decided to start with Motorola 68000 because I want to start simple, and out of historical interest.</p><h4>Development Environment</h4><p>There’s no need to get an actual working Commodore Amiga or Apple Macintosh to get started with 68000 assembly language. I have a regular Mac — also, I noticed that most tutorials seem to be concentrating on Windows — so I will describe the process of setting up on OS X. Here’s the list of essentials:</p><ul><li>An emulator to run the programs on. I am using <a href="https://fs-uae.net/">FS-UAE</a> which is a <a href="https://en.wikipedia.org/wiki/Amiga">Commodore Amiga</a> emulator (complete with floppy drive sounds 😊) for Windows, Linux and OS X.</li><li>An assembler and linker to build the programs: <a href="http://sun.hasenbraten.de/vasm/index.php?view=main">VASM</a> the assembler and <a href="http://sun.hasenbraten.de/vlink/index.php?view=main">VLINK</a> the linker.</li><li><a href="https://github.com/prb28/vscode-amiga-assembly/wiki">Amiga Assembly extension</a> for <a href="https://code.visualstudio.com/">VSCode</a>, which provides syntax highlighting and debugging tools. It integrates quite nicely with the FS-UAE emulator (that’s, in fact, how I found it — by going through the FS-UAE forums).</li><li>I do remember one thing about the assembly class I took at university: I had my nose in a <em>book</em> half the time. So I figured I’d need a similar book in this case, here it is: <a href="http://wpage.unina.it/rcanonic/didattica/ce1/docs/68000.pdf">68000 Instruction Set</a>.</li></ul><p>And that seems to be it! Now I’m all set and reading up on the processor itself.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bf124397810" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Random Thought]]></title>
            <link>https://medium.com/@bugzeeeeee/a-random-thought-8d7961ad3634?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d7961ad3634</guid>
            <category><![CDATA[computers]]></category>
            <category><![CDATA[art]]></category>
            <category><![CDATA[philosophy]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Fri, 14 Feb 2020 03:23:30 GMT</pubDate>
            <atom:updated>2020-02-14T03:57:27.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yn24WIJKjKGEUwnKRARP_w.jpeg" /><figcaption>Image by barcelonaphotoblog.com</figcaption></figure><p>I am into watercolor a lot, and I am a big sucker for pigments (my palette includes 7 different blues). I am currently reading this book on the art history that discusses the history of color blue (happens to be my favorite color to paint with). In the book, where it tells about medieval treatises on dyeing, I find this passage:</p><blockquote>[The medieval dyeing manuals] stress the importance of letting time to do its slow work — the desire to accelerate things is always seen as ineffective and dishonest.</blockquote><p>That is so different from us today! That passage got me wondering why did it take humankind this long to invent computers. Have you ever wondered? Is it really <em>that</em> complicated? I also remembered how Steve Jobs compared a person with a computer to a person on a bicycle, the latter being the most efficient moving thing on the planet…</p><p>It seems to me we tend to view history as progress, some improvement. As if, say, Middle Ages was humankind’s childhood… I don’t recall a single history book questioning that notion or even wondering if we’re actually moving backwards (if moving at all in the first place). Maybe people didn’t come up with computers earlier because they didn’t<em> want</em> to?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d7961ad3634" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cryptographic Adventures: EC2 Instance Identity Verification in JavaScript]]></title>
            <link>https://medium.com/@bugzeeeeee/cryptographic-adventures-ec2-instance-identity-verification-in-javascript-b0edfad09de9?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0edfad09de9</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Sun, 11 Aug 2019 06:54:30 GMT</pubDate>
            <atom:updated>2019-08-13T06:12:04.974Z</atom:updated>
            <content:encoded><![CDATA[<p>How long does it take you to write four lines of code? What is your sad record?</p><p>Mine is a week. These are the lines:</p><pre>const crypto = require(&#39;crypto&#39;);</pre><pre>const verifier = crypto.createVerify(&#39;sha256&#39;);<br>verifier.update(document.toString());</pre><pre>verifier.verify(pubKey.toString(), signature.toString(), &#39;base64&#39;);</pre><p>You might be wondering why it took me so long to copy-paste this from Node.js documentation. You might also be wondering where are document , pubKey and signature defined. Let me tell you about the latter.</p><p>A bit of background information: I am working on <a href="https://github.com/taskcluster">Taskcluster</a>, which is <a href="https://ccooper.github.io/taskcluster/why_taskcluster.html">Mozilla’s very own CI system</a>. In particular, these past weeks I have been building a thing that spins up instances in AWS. Those instances are then inhabited by our pieces of software called workers, who run the tasks for us and report the results back. Those workers need credentials of varying levels of sensitivity. The thing that I am building is supposed to give out the credentials. However, we want to make sure that the thing doesn’t give them just to anybody, so how do we make sure that it’s our workers that request credentials? This also needs to be something scalable, because we need a <em>lot</em> of instances, so we can’t bow to each individual instance, one secret token at a time.</p><p>So we decided to use instance identity documents for the purpose. The workers would call the special EC2 instance identity endpoints, send over the document and the signature; we check these against the public key, and then against our database, and if everything checks out — we can conclude that it’s probably indeed our worker is asking for credentials. Amazon has excellent documentation, checking a signature is a simple task. How hard can it be?</p><p>I probably have to pause here a bit and explain how electronic signatures work (I personally had thought that I knew how they work, but my knowledge proved to be too fuzzy for the task, so I’d like to define some terms for other folks who are also fuzzy. If you are far from fuzzy on the matters of cryptography, you can just skip the next four paragraphs).</p><p>Let me start by saying that there are two types of hiding data: one-way and two-way. The one-way (what is hidden, cannot be revealed) — is called <strong>hashing</strong>.<strong> </strong>The algorithms that do it are called <strong>hashing algorithms</strong> or <strong>hashing functions</strong>. The output of a hashing function is called a <strong>hash</strong>, or a <strong>digest</strong>. Not all hashing algorithms are created equal — some of them (such as SHA1 or MD5) can easily be hacked.</p><p>The two-way methods (what is hidden, can be revealed) — are called <strong>cryptographic systems</strong>. Cryptographic systems use cryptographic algorithms, which need keys to produce output. These systems can be symmetric and asymmetric. In a <strong>symmetric cryptographic system</strong>, all keys are equal (in fact, they can even be identical). Data can be encrypted with any key, and then decrypted with any key (or with the same key). PGP is an example of such system. In an <strong>asymmetric system</strong> (or <strong>public-key system</strong>), there is one private key and one or more public keys. Data that was encrypted with a private key, can only be decrypted with a public key, and vice versa. Data encrypted with a public key, cannot be decrypted with another public key — only the private key will work. Since there’s only one private key in the system, encrypting with it is equivalent to confirming identity; therefore, encryption with a private key is called <strong>signing</strong>, and the output of such encryption is called <strong>signature</strong>. Some cryptography algorithms can be used for both symmetric and asymmetric systems (like RSA), and some are more specialized. The algorithms that can only be used in asymmetric systems are also called <strong>signing algorithms</strong> (an example would be DSA).</p><p>Now let’s look how cryptography is used for identity verification. If you have electronic data you need to sign, you want not only to confirm your identity as the author or sender of the document, but also that the document wasn’t changed after it was signed. So electronic signature is created using the document itself. First, it’s <strong>hashed</strong>. Then the digest is <strong>encrypted using the private key</strong>, or signed. The result is your signature (the hashing step can be omitted, but is considered a good practice, if not standard).</p><p>In order for somebody else to verify the authenticity of the signed data, they need the public key, the unencrypted data itself, and the signature. They also need to know which hashing function was used. For that, the key is often put into a public <strong>certificate</strong>, which is a document that contains the key itself and a bunch of useful information about the signer, key expiry date, <em>key serial number</em>, the hashing function etc. First step of verification process is to <strong>decrypt the digest using the public key</strong>. However, nothing can be done with the digest, because it’s impossible (well, supposedly, anyways) to decrypt. So the second step is to run the original unencrypted data through the same hashing function and then <strong>compare the two digests</strong>. Hashing functions produce deterministic output, so if the digests are identical, the verification is deemed successful.</p><p>With all this in mind, let’s return to the EC2 instance identity documentation. Turns out, <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html">said documentation</a> leaves somewhat to be desired. <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-dynamic-data-retrieval">It appears that</a> there are several endpoints related to instance identity:</p><pre><strong>http://169.254.169.254/latest/dynamic/instance-identity/</strong>document</pre><p>This endpoint gives you the actual document, which is nothing special — just a JSON object with information about instance (region, id, AMI id etc.)</p><pre><strong>http://169.254.169.254/latest/dynamic/instance-identity/</strong>signature</pre><p>This one looks like it’s a signature. However, the above instance identity documentation mentions this endpoint just in passing and doesn’t provide any information on it. I can tell you that this is a <em>the RSA-signed SHA256 digest </em>(in a form of a base64-encoded string).</p><pre><strong>http://169.254.169.254/latest/dynamic/instance-identity/</strong>pkcs7</pre><p>This one is actually well documented, with a nice example on how to verify it. The public key can also be found right there in the documentation. It’s worth noting, however, that this is a <em>PKCS7 document containing the DSA-signed SHA1 digest</em>.</p><pre><strong>http://169.254.169.254/latest/dynamic/instance-identity/</strong>rsa2048</pre><p>This one mentioned in passing in the instance metadata documentation. I found no explanation on it anywhere, but this is a <em>PKCS7 document containing the RSA-signed SHA256 digest</em>. You can guess the size of the key from the name of the endpoint.</p><pre><strong>http://169.254.169.254/latest/dynamic/instance-identity/</strong>dsa2048</pre><p>This is another endpoint mentioned just in passing in the instance metadata documentation, and it actually doesn’t work at all. You can imagine the algorithm and the key size though.</p><p>Now you might be wondering where the keys for signature and rsa2048 endpoints are. The former is similar to the pkcs7 endpoint’s key in that it’s the same across all accounts and all regions, and it can be found on the Internet, it also can be requested from AWS support. The latter is region-specific, and as far as I know, it can only be requested from AWS support. A thing to note here is that the public key for signature endpoint hasn’t changed since at least 2017. The rsa2048 keys are more interesting. Our team already requested these keys from AWS support a year ago, and only one of those keys work. I wasn’t able to confirm with AWS support, but to me it’s a sign that either the keys for this endpoint are rotated more frequently, or that the support just has no clue. Or both.</p><p>Another part of the equation is libraries used to verify signatures. This differs from language to language, obviously. Taskcluster is written in JavaScript, as you might have noticed. Node.js has a built-in crypto library that can be used to sign things and verify signatures. However, the library doesn’t work with PKCS7 format. It allegedly can be combined with <a href="https://www.npmjs.com/package/node-forge">forge library</a> but I was not able to make this work (I suspect because of the encoding of the strings, but I was running out of time for experiments).</p><p>Another way to go about signature verification in Node.js is to just shell out openssl which is a suite of command line tools for cryptography. It comes built-in to all the major operating systems. This essentially means either writing a mini-library (because you need the tests, the error handling etc. etc.) or fishing something out of the depths of npm — and the latter might not prove as easy as you would think.</p><p>Finally, you can implement your own library in C or C++ because these languages actually have some built-in tools, and because JavaScript can work with C/C++ modules and libraries — not without a minor headache here and there, but still. In fact, our team had built <a href="https://www.npmjs.com/package/iid-verify">such a library</a> a year ago. Keep in mind that it’s a single-purpose library that is tailored for EC2 instance identity verification, so if Google fed you this post because you are desperately searching for a JS library that works with PKCS7 for some other purposes, don’t get excited.</p><p>Of course, using crypto would be ideal because it would mean no external dependencies, so I made that my primary target. After tons of experiments and exchanges with AWS support, I finally established that crypto is happy with the format of the signature endpoint’s output, and I even figured out how to make them work together. You saw the four lines of code at the beginning.</p><p>All of this took me a week, and it was a great week in that I learned a lot from the experience. My takeaways:</p><ul><li><em>If you are fuzzy on the basics, get the basics</em>. Just stop being fuzzy on things! My understanding of openssl man pages (and of the cryptographic libraries, and of what I was trying to do) greatly improved after I looked up all the terminology. In fact, I was feeling pretty overwhelmed, and for that writing down all the questions I had and then looking up and writing down answers helped a lot.</li><li><em>When using a library for cryptography, create your own key pair and get the library to work with that key pair first</em>. There might be undocumented quirks (for example, crypto favors base64-encoded strings, but a buffer has to be binary — I would never know if my verification was failing because I neglected to convert my base64-encoded buffer to a string and indicate the encoding or because the key is wrong).</li><li><em>The certificate might be wrong, but the key in it might be correct</em>. The certificate that AWS gives for signature endpoint indicates SHA1 hashing, but the signature is actually SHA256-hashed. The key extracted from the certificate is correct, however. So if you use something like crypto or the openssl dgst tool, do try other hash functions just to make sure.</li><li><em>If you have the luxury of working with PKCS7 and certificates, check if the serial numbers match</em>. You probably remember that I mentioned serial numbers contained in certificates and PKCS7 documents. You don’t actually need to attempt verification to check if you have the right certificate — all you need to do is to check the serials. For that, you can either use a decoder tool <a href="https://redkestrel.co.uk/products/decoder/">like this one</a>, or run commands like this (things you feed into these commands must have correct PEM format):</li></ul><pre>openssl pkcs7 &lt;&lt; cat PKCS7_SIGNATURE -print | grep serial</pre><pre>openssl x509 -in CERT_FILE -text -noout | grep serial</pre><ul><li><em>If you plan to do the same and use AWS EC2 as identity provider, I recommend using</em> signature <em>endpoint</em>. It uses good hashing function (and not SHA1 like the well-documented pkcs7 ); it has stable public key which is not account- or region-specific (you can sense simpler logic of your app); said public key can be found on the Internet — you don’t even need to contact the support, but even if you do — you need to do it just once; if you also happen to use JavaScript, you don’t need external dependencies and you don’t need to shell out openssl because the output of this endpoint is not in PKCS7 format.</li></ul><p>I hope this was useful! If you notice any mistakes, or if you have anything to add, please don’t hesitate to comment :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0edfad09de9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to write tests]]></title>
            <link>https://medium.com/@bugzeeeeee/how-to-write-tests-f2e5fd9be567?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2e5fd9be567</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Mon, 31 Dec 2018 17:15:52 GMT</pubDate>
            <atom:updated>2019-01-17T07:27:52.153Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Write Tests</h3><p>“<em>How do I write unit tests, and where do I even start?</em>”, “<em>How do I make sure I don’t miss anything?</em>”, “<em>I saw some examples of test suites in your other code bases, but I’m not sure how to set up my own tests, how do I do it?</em>” — those are familiar questions, aren’t they? You either had them yourself or heard them (or both). I myself definitely was asking these questions at a certain point, so I spent a bit of time studying software testing. In this post, I’ll try to summarize everything I have learned about testing so far — from books, testing courses, experience, and my colleagues.</p><p><strong>Testing, just like coding, starts with the requirements </strong>(or specification). What is this thing supposed to do? How is it supposed to do it (the how doesn’t refer to the implementation details, but rather either to the user experience, or the way parts of the system work together)? Those need to be written down (nothing fancy, bullet points in a note taking app will do — I actually use paper journals), and consulted with during development and writing tests. An enormous help are <strong>decision tables</strong>, which help you document what needs to be happening under which conditions (in many cases it’s very difficult to hold multiple conditions in your head, and very easy to miss something).</p><p>Test-driven development has been very popular for quite a while now. I personally didn’t find it terribly helpful when dealing with unfamiliar things — whether you’re new on a project, or you’re new to the technology, or you don’t really know the domain all that well etc. I was once supposed to implement an API endpoint for uploading files to AWS S3 using multipart formpost request in Dropwizard framework — I knew nothing about any of the three, so there was no point for me in starting with the tests. In order to write a test, you need to know how it’s working in the first place. So instead of writing unit/integration tests, I was performing <strong>functional white-box testing</strong> while developing — something I still find most helpful when dealing with the unfamiliar. Writing actual unit tests once the work is finished is then easy: you just code the test cases you used for the functional testing. I guess you could call it “test-driven development” if you squint hard enough.</p><p>A side note related to speed of your work, and something I learned from experience: Don’t ever hesitate to spend some time planning your work, writing down requirements and putting together your decision tables when you’re about to embark on a more than a tiny project or when you deal with the unfamiliar or the unknown. In programming, things tend to take longer than was expected. Armed with the plan and the documentation, you’ll be able to finish your work faster than you would otherwise, or return to the work quicker after having been pulled to another project; also, writing tests will be much easier.</p><p>Back to writing tests, it’s a good idea to <strong>start with positive test cases</strong> (meaning, test cases that assert that your thing does what it’s supposed to do if the inputs are sensical — i.e. what you would expect them to be). Then you need some realistic negative test cases (meaning, test cases asserting on how your thing is supposed to behave if the inputs are nonsensical — which they are surprisingly often, especially if the source of the input is a human). These are harder to come up with (especially in the case of the human input — programs’ behavior is easier to predict), but you can reflect on your experiences as a user: what error messages have you gotten from a similar thing? Why did you get them? What went wrong? What can easily go wrong? What if the person has malicious intent?</p><p>Which brings me to a very important concept in software testing called <strong>equivalence partitioning</strong>. Equivalence partitioning means dividing the set of possible inputs into subsets of inputs that would produce similar results and are, therefore, equivalent to each other in that sense. You can immediately see why we need that technique: there’s an unbounded set of possible inputs, but you don’t need to write an unbounded set of test cases. All you need is a single test case for each partition, and two test cases for each boundary between the partitions (so-called “corner cases” or “edge cases”). If you’re in a hurry, you can probably just write <em>n</em> of the boundary test cases (where <em>n</em> is the number of partitions — I mean, all the elements of the partitions <em>are</em> equivalent, aren’t they?) and call it a day.</p><p>To give you a simple example on equivalence partitioning: imagine, if you will, a form field for entering a month. Requirements: format — two digits, padded with zero, no default value, incorrect input should not be allowed. What are the partitions in this case? Three: a set of integers (−∞; 0], a set of integers [1; 12], and a set of integers [13; +∞) (it might also make sense to consider the fourth partition of non-numerical characters). There are two boundaries. Inputs around the first boundary would be 0 and 1; inputs around the upper boundary would be 12 and 13. You need to write test cases for 0, 13, and either 1 or 12. Testing for padding with a zero: two partitions — single-digit numbers and the rest of the numbers in [1; 12]. One test case for each (probably 9 and 10). Finally, some sort of assertion on the absence of a default value somewhere among those test cases. The above is called <strong>boundary analysis</strong>.</p><p>You probably noticed that tests can be a form of documentation of what the code is supposed to be doing. (Actually, I think that’s the primary function of tests. <a href="https://youtu.be/34_L7t7fD_U?t=943">I like the way Rich Hickey looks at tests, when talking about “guardrail programming” — watch until 17:13</a>. For the same reason I say: when writing tests, don’t be afraid to miss something… because you will.) It’s often the more up-to-date form of documentation, because for every change in requirements there will be a change in tests, but not necessarily in the documentation (especially when done in a hurry). Often, the documentation is simply not good enough (ambiguous, difficult to read and/or understand, difficult to find, incomplete, completely absent etc.), so often other programmers will rely, among other things, on your tests to understand your code. So you need to <strong>write tests for people to read</strong>.</p><p>What does it mean? For example, if you’re writing tests for a front-end component, don’t write assertions like “Renders correctly”. What does <em>correctly</em> mean? Assertions like that don’t bring any light into the world. <strong>Be specific</strong>: “Renders with no default value” etc. At the same time, you want <strong>broad assertions</strong>: it might be a good idea to assert on the whole thing rather than its part. For example, if the function returns an object — assert on the whole thing, don’t pick properties one by one.</p><p>Speaking of assertions, another important point is: <strong>assertions must be made in the language of the domain</strong>, not in the language of… oh, I don’t know, arrays having certain number of elements, for example. It should be easy to understand the <em>why</em> of the array having certain number of elements, and what the business need for that requirement was (or what was the bug that was fixed). Who knows, maybe you’re working on a feature and struggle to get that test passing, but that business need is not even there anymore.</p><p>I heard from a number of developers I admire that it’s best to <strong>use the smallest possible test</strong>. I personally favor integration tests where you can test several things at once, and not just things separately but the whole flow — but those are usually difficult to set up and change, it may be difficult to locate the exact reason for the test failure, and they can be expensive to run on every commit. I do think that smallest possible test is a good rule, as long as it’s the largest possible chunk of a public API.</p><p>I like the idea of <strong>testing public interfaces only</strong>. Implementation details can be left alone (meaning, if your interface function uses some utility function — you don’t need to test the utility function. How the interface function arrives at the result is not important, as long as it conforms to the requirements, i.e. works correctly.) Like I said — testing and coding start with the requirements, which come from the domain and are expressed in the high-level language of the domain problem you are supposed to solve. Besides, the implementation details can be changed, but public interfaces are a commitment. Having bazillion of tests in the code base is not always good. Better to have less, but covering all the important test cases and requirements.</p><p>Finally, <strong>segregate fixtures </strong>(fixtures are the dummy inputs and dummy starting state you use in your tests). That will make the tests easier to change. The functions that set things up for the tests are typically written last. First you write your tests as if you have everything you need, and then you take a look and see what variables are undefined and how to define them. Don’t forget to tear things down and start every unit test <em>tabula rasa </em>or always with the same state — otherwise you might end up with really flaky tests.</p><p>I hope this was helpful. If you are interested in learning more about testing, I recommend researching resources on functional testing — understanding the nuts and bolts of the testing profession really helps here. Besides, developers do an awful ton of manual and automated testing themselves (especially in places that don’t hire actual testers). You can skip parts on the tester-specific documentation (test plans, test design etc. — although those might come in handy when writing acceptance tests for the system)(ability to write a good bug report is good skill for a developer to have too) or parts you already know. Unfortunately, I cannot recommend anything specific at the moment because the resources I used are in Russian, but as I encounter good things in English, I’ll add them here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2e5fd9be567" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Professor Frisby’s Mostly Adequate Guide to Functional Programming: Book Review]]></title>
            <link>https://medium.com/@bugzeeeeee/professor-frisbys-mostly-adequate-guide-to-functional-programming-book-review-d08051302597?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/d08051302597</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[book-review]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[monads]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Fri, 23 Nov 2018 18:21:01 GMT</pubDate>
            <atom:updated>2018-11-23T18:21:01.197Z</atom:updated>
            <content:encoded><![CDATA[<p>At my previous job, we had a couple of Haskell programmers on the team, so our code base was rich with functional programming trips and ticks. I felt the need to learn the paradigm, and chose this book as my starting point because it doesn’t add the complexity of learning a new language — and a useless one at that (our codebase was JavaScript and Kotlin) — to the task.</p><p>At the time of writing this, the book contained 12 chapters, all of which I had studied. “Studied” means I read them, took notes, quizzed myself, and solved the problems at the end. There also is a draft of Chapter 13, which I haven’t read. It’s important, I think, to stress that I got first exposed to functional production code, and only then started learning the paradigm more formally with this book.</p><p>I absolutely loved the language of the book. It’s funny and very easy to understand. The author doesn’t delve into technicalities (i.e. the category theory) too deep, and doesn’t indulge in oversimplified analogies either. The text is enhanced with quite a lot of references to North American culture, so being a newcomer here, I spent a lot of time googling unrelated stuff while working through the book. Whether that was the consequence of me being naturally curious person, or was understanding of the analogies essential to getting the author’s point, I don’t remember.</p><p>The problems at the end of each chapter were a bit of a disappointment — I found them to be too easy to my taste. They do, however, help the material to sink in (I am the kind of person who learns better by doing) — except maybe the last chapter or two, where the exercises were easy almost to the point of uselessness. Also, the reliance on Ramda seems to be excessive at times. An unrelated trivia fact: the book is <a href="https://github.com/MostlyAdequate">open source</a>.</p><p>Much more fun presents Chapter 6, where the project is. My advice on this chapter: The best way to proceed here is to use it as an asynchronous pair programming. Each code snippet is preceded with the description of what it does. Don’t hurry to read the code! Read the description first, then try to write it yourself. After you’re done, look at the code in the book and compare with yours.</p><p>Unfortunately, the project doesn’t utilize functors at all — they are introduced later, in Chapter 8. You can return to the project, however, and embellish it with functors on your own.</p><p>To sum up, I highly recommend this book not only to anyone who is curious about functional programming, but to any programmer in general, because even if you don’t use functional paradigm (at least not to the point of functors) in your work, the book still teaches you a useful thing or two (Chapter 2, for example). Incidentally, I am very pleased to see a good functional programming book that uses a practical, mainstream language.</p><p>The book can be found here: <a href="https://mostly-adequate.gitbooks.io/mostly-adequate-guide/">https://mostly-adequate.gitbooks.io/mostly-adequate-guide/</a></p><p>Also: <a href="https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript">https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d08051302597" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PyCon Canada 2018]]></title>
            <link>https://medium.com/@bugzeeeeee/pycon-canada-2018-42a2b241dd3c?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/42a2b241dd3c</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[conference]]></category>
            <category><![CDATA[pycon]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Sun, 18 Nov 2018 04:30:14 GMT</pubDate>
            <atom:updated>2018-11-18T23:27:34.771Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rK37lkucrSLWsKkF8Q9urw.jpeg" /></figure><p>This weekend I attended my first PyCon! This year it was held in Toronto, where it was so cold as if it’s November or something; it was even snowing on Saturday morning. Incidentally, the conference swag included pom tuques — quite handy.</p><p>I spent most of my time doing the hallway track — something way outside my comfort zone, so I’m very happy to report that I managed to have lots of interesting conversations and a wonderful Saturday dinner with the folks I met. The latter was a self-organized 6-people event because the conference didn’t organize anything officially. Next time I will equip myself with stickers, and also I will try delaying my retreat to the airport till the day after the conference — I think I missed the Sunday outing because I flew out so early.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*8G1Byaj71Y4fZhvueyMqTA.png" /></figure><p>I do think that making new friends among other programmers is the most important part of any conference. Most conferences put the talks online afterwards anyway… and the recordings, as I realized, can be further used to socialize with colleagues because it’s possible to organize some sort of a “watching group” (analogous with reading groups), where people watch a talk and discuss it afterwards.</p><p>Speaking of talks, this year’s rendition of PyCon featured a fairly wide array of important topics, including, but not limited to, machine learning and Russian trolls on Twitter (admittedly, I haven’t spotted a single blockchain talk for some reason — most likely just didn’t look properly). The walrus operator and Guido’s leaving generated the most buzz in the community, and <a href="https://2018.pycon.ca/talks/talk-PC-55520/">both</a> the <a href="https://2018.pycon.ca/talks/talk-PC-53534/">talks</a> on the subjects were highly praised by most of the people I met.</p><p>As a bit of a detour on the people I met — I kept bumping into vancouverites, which surprised me so much that I developed a strong impression that there is no other place in Canada so swarmed with people from Vancouver but Toronto.</p><p>Getting back to talks, the one I anticipated the most was “<a href="https://2018.pycon.ca/talks/talk-PC-55571/">The landscape of Quantum Computing in Python</a>”. I was curious about the current practical applications of quantum computing, where (if any) can I actually try it out, and where the online communities can be found. I wasn’t disappointed! The speaker briefly described the three kinds of quantum computing, named the companies that utilize and research them, and provided links to some of the projects. After the talk I chatted a bit with the speaker, and he was kind enough to give me some additional resources on the subject. It was fantastic!</p><p>Another talk that I liked was given by the manager of the Mozilla release engineering team (I recently started working at Mozilla, and release engineering are our team’s neighbors). He gave a very good overview of the Firefox release pipeline for potential contributors, mentioned the Python projects and the challenges in them. For me, the talk provided a nice summary of <a href="https://wiki.mozilla.org/Taskcluster">Taskcluster</a> in Context and Perspective, and became a bit of an onboarding experience — just as I expected. (Mozilla was a sponsor for the event, by the way.)</p><p>If there was a prize for the most fabulous talk, that would go to Holden Karau and her PySpark keynote. It would be enough to say that the slides contained a lot of cat pictures, the speaker stand contained plush pandas, and Holden herself was contained in a coat with flashing lights! She spoke about big data and distributed systems — not exactly what I work with, but it was nevertheless interesting (not to mention entertaining); I plan to watch it again.</p><p>All the talks were recorded and will be available online sometime soon. I loved the timings — most talks were 15–20 minutes long, which is long enough to get to the point but short enough to avoid being boring.</p><p>That was my PyCon experience, and I am very happy and grateful I had it. I think the best thing about python is that the community is very welcoming and friendly; our local PyLadies meetup is also quite lovely. In other words, the conference is definitely a must-go — I hope to attend again!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42a2b241dd3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Get Quality Sleep]]></title>
            <link>https://medium.com/@bugzeeeeee/how-to-get-quality-sleep-2e2f22aba568?source=rss-52e07c8a15fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e2f22aba568</guid>
            <category><![CDATA[health]]></category>
            <category><![CDATA[sleep]]></category>
            <category><![CDATA[mindfulness]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Owl]]></dc:creator>
            <pubDate>Mon, 23 Jul 2018 20:37:17 GMT</pubDate>
            <atom:updated>2018-07-23T20:37:17.742Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*04AuGvRkL1mrB7PLwrK49Q.jpeg" /></figure><p>This may be a weird article in a developer’s blog, but I think good quality sleep is fundamental when it comes to work that requires a lot of thinking and creativity.</p><p>I used to struggle with insomnia for quite a while. Besides that, I am a “night owl” — somebody who likes stay up late at night. I don’t think there is such thing as “night owls” and “early birds” though. I am convinced it’s a matter of habit, and modern life just calls for a “night owl” way. I know that because I have changed my sleeping habits numerous times in the course of my life. I also learned that insomnia can be fought successfully, too.</p><p>The first thing I discovered was that if you want to change your sleeping pattern, the most important thing to watch out for is the time when you get up. Not even wake up, but physically extract yourself from under your warm and cozy duvet. The time you went to bed isn’t as critical — in fact, if you stick to your desired getting up time, your body will adjust and regulate so that you’d be sleepy by the right time to get the right amount of sleep. Obviously, you would do well if you heed to your sleepiness :) Basically though, if you want to change your sleeping schedule, getting up time is the thing to change and track.</p><p>To help your body be sufficiently sleepy in the evening, you can use something like the <a href="https://justgetflux.com/">Flux app</a>, which will yellow your device’s screen at a certain time of night. Blue light that a typical screen emits tends to keep us awaken and alert. Besides, the app yellows your screen gradually, and at the peak time the screen becomes so dim and yellow that the device is barely usable. That would be your Q :) Often at night I would turn my computer off altogether and just read a book under a yellow lamp before going to bed. I found that to be the least disruptive for my sleep.</p><p>Physical activity is crucial as well; however, there is a danger of having too much of it, especially if you’re into weight training. Too much of physical or mental tiredness disrupt sleep for me. Everybody is different, and there is no certain answer as to how much exercise a week or how many hours of programming a day will induce insomnia for you. I actually kept a sleep journal for a while, where I tracked things like hours of mental work (including my hobbies and programming on the side), physical activity, eating habits, amount of coffee I had, stress etc. — everything that could affect my sleep.</p><p>On the same note as keeping a journal I can highly recommend meditation. I heard some research says it can have positive effects on sleep, but for me its primary benefit lies in its ability to teach you taking a note of yourself — how you feel, what happens to you, what affects you and so on. In other words, meditation teaches you to be present with your life (which we aren’t 90% of the time).</p><p>My last advice would be to resist as much as possible various aids like sleeping pills or ear plugs — those might make things even worse. Wearing ear plugs for a nearly a year aggravated my sensitivity and made my sleep really fragile. When ear plugs were not available, the tiniest noise would wake me up. Worried, I stopped using ear plugs altogether. After initial sleepless period, my body tuned its noise sensitivity down a bit, and everything was back to normal!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e2f22aba568" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>