14.xhtml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * <https://y.st./>
  4. * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org./licenses/>.
  18. **/
  19. $xhtml = array(
  20. 'title' => 'Mood swings and maths',
  21. 'body' => <<<END
  22. <section id="general">
  23. <h2>General news</h2>
  24. <p>
  25. ...
  26. </p>
  27. <p>
  28. My <a href="/a/canary.txt">canary</a> still sings the tune of freedom and transparency.
  29. </p>
  30. </section>
  31. <section id="dreams">
  32. <h2>Dream journal</h2>
  33. <p>
  34. I dreamed I, along with several other people, was captured by some cruel and viscous criminals.
  35. I complied with everything they asked for and didn&apos;t make any attempts to escape.
  36. They still put my left hand in a device that looked very much like an old paper cutter, and chopped off my thumb.
  37. Strangely, while that did hurt like hell, I feel like it wasn&apos;t the worst pain I&apos;ve experienced in dreams before.
  38. Even after they took my thumb, I didn&apos;t resist them, as there wasn&apos;t a way for me to safely escape.
  39. However, they next decided to aim for my teeth.
  40. They stuck some pliers in my mouth and started tapping around to find the one they wanted to take first.
  41. In the real world, several of my teeth are broken, and in the dream, those same teeth were broken in the same ways.
  42. This is the first time I can ever remember noticing my broken teeth in a dream.
  43. In any case, as they were about to pull one of my more-broken ones, I realised somehow that it was a dream at the last minute.
  44. Now that I had a way out, I wasn&apos;t going to stay there any longer, and I forced myself to wake up.
  45. Even the extreme pain of having a thumb cut off didn&apos;t wake me, but waking myself up once I knew I was dreaming wasn&apos;t hard at all.
  46. </p>
  47. </section>
  48. <section id="mental">
  49. <h2>Mental health watch</h2>
  50. <p>
  51. I thought I was over this, but I had a severe, downward mood swing again today.
  52. It was nowhere near as bad as that time recently that caused me to want to die for a bit, but it certainly wasn&apos;t pleasant.
  53. Once I was at work though, I seemed to recover fairly quickly.
  54. It took me a bit to realise why, but I think it was my work at the register!
  55. I have this thing I do when I&apos;m on a till: I add up the price of each customer&apos;s order in my head, instead of punching it into the register before telling the customer the price of what they want.
  56. It helps prevent paperwork caused by customers changing their minds (we can&apos;t void items from an order), but mostly, it&apos;s just a simple brain exercise I enjoy.
  57. The work there is so mindless that I have to keep myself entertained, right?
  58. I might as well do it in a productive way.
  59. Anyway, I think I&apos;ve discovered the key to fighting off these mood swings.
  60. I need to exercise my logical capabilities.
  61. When I have a downward mood swing, it feels like my logical side is succumbing to my emotional side, so I just need to do some maths or programming to coerce my logical side back into temporary dominance.
  62. Being a programmer puts me in a uniquely useful position for this.
  63. Most peopl eprobably have less logic puzzles to work on, but when programming, the logic puzzles are endless.
  64. I could go on forever programming and solving problems if there was enough time.
  65. Hopefully this time, it&apos;s a real solution.
  66. The stupid handedness thing isn&apos;t as effective as I&apos;d hoped, but it&apos;s also probably not needed.
  67. I can go back to using whatever hand I feel like with one exception as far as tasks: writing.
  68. I think pumping language through the incorrect hand has been damaging my intellectual capacity, and I need to recover from that.
  69. Learning to use both hands is one thing, but people should probably stick with their naturally-good hand for writing with.
  70. One of my coworkers also suggested I try using chocolate.
  71. Supposedly, chocolate helps level out one&apos;s moods as well.
  72. </p>
  73. </section>
  74. <section id="university">
  75. <h2>University life</h2>
  76. <p>
  77. I wrote up my initial discussion post for the week:
  78. </p>
  79. <blockquote>
  80. <p>
  81. The first thing to consider when choosing which collection type to use is the most important.
  82. What do we want to use the collection for?
  83. Are we using it as a key/value store, or are we storing only values?
  84. If we&apos;re storing keys and values, we&apos;re going to want a map type of some sort.
  85. If we&apos;re storing only values, do we want duplicates preserved?
  86. If we want duplicates to be preserved, we shouldn&apos;t be using a set collection type.
  87. However, if preserving duplicates would be unwanted for our usage, a list collection type would be a bad idea.
  88. Efficiency is important, but not as important as functionality.
  89. We need to choose which sub-interface of <code>Collection</code> is has what we&apos;re looking for: <code>Set</code> or <code>List</code>.
  90. </p>
  91. <h3><code>List</code></h3>
  92. <p>
  93. If you decide that you want duplicate entries preserved, it&apos;s time to choose between a <code>LinkedList</code> and an <code>ArrayList</code>.
  94. If you think you&apos;ll need to add items to the beginning or middle of the list, a linked list is the better option.
  95. Items can be added to arbitrary locations in the list without any major overhead.
  96. When dealing with arrays, insertions and deletions anywhere but at the end of the array require copying all elements that are in the list after the item to be added or removed to a new location.
  97. Linked lists don&apos;t suffer from this weakness.
  98. Arrays show their strength when you instead need to arbitrarily access values.
  99. Random access (accessing the values out of order) is much faster and more efficient with array lists than with linked lists.
  100. </p>
  101. <p>
  102. The <code>LinkedList</code> class also has some class-specific methods not provided by the <code>List</code> interface.
  103. If you plan to use your list as a queue or stack, the added methods of <code>LinkedList</code> could make that class a better fit for you than <code>ArrayList</code>.
  104. Due to the way in which linked lists work, they&apos;re probably a better choice for the building of queues and stacks too, so again, you might choose a linked list for that.
  105. Arrays function okay as stacks sometimes, but they don&apos;t make good queue structures.
  106. </p>
  107. <h3><code>Set</code></h3>
  108. <p>
  109. If you decide you want to know which elements are in your collection, but there&apos;s no need to keep multiple copies of each item if more than one exist, you probably want a set.
  110. Now, you need to look at whether a <code>TreeSet</code> of a <code>HashSet</code> is the right option for your use case.
  111. If you need your set items to always be in order, a tree set is the right data type for you.
  112. It keeps everything organised in an efficient manner.
  113. If order doesn&apos;t matter though, a hash set provides better efficiency.
  114. In a tree, you may have to visit a few items before finding the right one, or finding if the right one is even present in the tree.
  115. In a hash set though, the correct item can always be visited the first time.
  116. The disadvantage though is that the order of the items is completely arbitrary, and no useful order can be set.
  117. </p>
  118. <p>
  119. (There&apos;s also the case of the <code>EnumSet</code> class.
  120. An <code>enum</code> class is itself sort of like a set, but sometimes, you need a subset.
  121. In this case, an actual set object could be useful.
  122. Enums are so simple that Java is able to cut out a lot of the overhead that applies to most classes, but not <code>enum</code> classes.
  123. If you need a set of objects from an <code>enum</code> class, your set should probably be of the <code>EnumSet</code> class for efficiency.
  124. This class uses an efficient bit vector to keep track of which objects are and are not in the set, which is something not possible when an unlimited number of possibilities are available for a given type.)
  125. </p>
  126. <h3><code>Map</code></h3>
  127. <p>
  128. If you decide you need a key/value store, you&apos;re going to want a map.
  129. The Java language doesn&apos;t have associative arrays, at least not as a basic data type provided by the language, but maps provide a similar feature as a class of objects.
  130. In most cases, you should probably use an object of class <code>HashMap</code>.
  131. This class uses an efficient mechanism for storing key/value pairs that involves hashing the key and using that hash to know where the value should be placed in memory or where the value has already been placed.
  132. However, a <code>TreeMap</code> does have advantages in some cases.
  133. A <code>TreeMap</code> keeps all the keys organised, so they&apos;re all in a predictable order.
  134. It&apos;s worth noting though that, strictly-speaking, maps aren&apos;t considered to be collections.
  135. As such, they don&apos;t implement the <code>Collection</code> interface.
  136. Like a list, they hold an arbitrary number of values, but variable types won&apos;t match for methods that require a collection as input.
  137. </p>
  138. </blockquote>
  139. </section>
  140. END
  141. );