all repos — gemini-redirect @ 4b2eb72da66a6d23b376a45dfac13262352b4e60

blog/atom.xml (view raw)

   1<?xml version="1.0" encoding="UTF-8"?>
   2<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
   3	<title>Lonami&#x27;s Site - My Blog</title>
   4	<link href="https://lonami.dev/blog/atom.xml" rel="self" type="application/atom+xml"/>
   5  <link href="https://lonami.dev/blog/"/>
   6	<generator uri="https://www.getzola.org/">Zola</generator>
   7	<updated>2021-02-07T00:00:00+00:00</updated>
   8	<id>https://lonami.dev/blog/atom.xml</id>
   9	<entry xml:lang="en">
  10		<title>Writing our own Cheat Engine: Introduction</title>
  11		<published>2021-02-07T00:00:00+00:00</published>
  12		<updated>2021-02-07T00:00:00+00:00</updated>
  13		<link href="https://lonami.dev/blog/woce-1/" type="text/html"/>
  14		<id>https://lonami.dev/blog/woce-1/</id>
  15		<content type="html">&lt;p&gt;This is part 1 on the &lt;em&gt;Writing our own Cheat Engine&lt;&#x2F;em&gt; series.&lt;&#x2F;p&gt;
  16&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;cheatengine.org&#x2F;&quot;&gt;Cheat Engine&lt;&#x2F;a&gt; is a tool designed to modify single player games and contains other useful tools within itself that enable its users to debug games or other applications. It comes with a memory scanner, (dis)assembler, inspection tools and a handful other things. In this series, we will be writing our own tiny Cheat Engine capable of solving all steps of the tutorial, and diving into how it all works underneath.&lt;&#x2F;p&gt;
  17&lt;p&gt;Needless to say, we&#x27;re doing this for private and educational purposes only. One has to make sure to not violate the EULA or ToS of the specific application we&#x27;re attaching to. This series, much like cheatengine.org, does not condone the illegal use of the code shared.&lt;&#x2F;p&gt;
  18&lt;p&gt;Cheat Engine is a tool for Windows, so we will be developing for Windows as well. However, you can also &lt;a href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;q&#x2F;12977179&#x2F;4759433&quot;&gt;read memory from Linux-like systems&lt;&#x2F;a&gt;. &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;scanmem&#x2F;scanmem&quot;&gt;GameConqueror&lt;&#x2F;a&gt; is a popular alternative to Cheat Engine on Linux systems, so if you feel adventurous, you could definitely follow along too! The techniques shown in this series apply regardless of how we read memory from a process. You will learn a fair bit about doing FFI in Rust too.&lt;&#x2F;p&gt;
  19&lt;p&gt;We will be developing the application in Rust, because it enables us to interface with the Windows API easily, is memory safe (as long as we&#x27;re careful with &lt;code&gt;unsafe&lt;&#x2F;code&gt;!), and is speedy (we will need this for later steps in the Cheat Engine tutorial). You could use any language of your choice though. For example, &lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;ctypes-and-windows&#x2F;&quot;&gt;Python also makes it relatively easy to use the Windows API&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
  20&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cheat-engine&#x2F;cheat-engine&#x2F;&quot;&gt;Cheat Engine&#x27;s source code&lt;&#x2F;a&gt; is mostly written in Pascal and C. And it&#x27;s &lt;em&gt;a lot&lt;&#x2F;em&gt; of code, with a very flat project structure, and files ranging in the thousand lines of code each. It&#x27;s daunting&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;. It&#x27;s a mature project, with a lot of knowledge encoded in the code base, and a lot of features like distributed scanning or an entire disassembler. Unfortunately, there&#x27;s not a lot of comments. For these reasons, I&#x27;ll do some guesswork when possible as to how it&#x27;s working underneath, rather than actually digging into what Cheat Engine is actually doing.&lt;&#x2F;p&gt;
  21&lt;p&gt;With that out of the way, let&#x27;s get started!&lt;&#x2F;p&gt;
  22&lt;h2 id=&quot;welcome-to-the-cheat-engine-tutorial&quot;&gt;Welcome to the Cheat Engine Tutorial&lt;&#x2F;h2&gt;
  23&lt;details open&gt;&lt;summary&gt;Cheat Engine Tutorial: Step 1&lt;&#x2F;summary&gt;
  24&lt;blockquote&gt;
  25&lt;p&gt;This tutorial will teach you the basics of cheating in video games. It will also show you foundational aspects of using Cheat Engine (or CE for short). Follow the steps below to get started.&lt;&#x2F;p&gt;
  26&lt;ol&gt;
  27&lt;li&gt;Open Cheat Engine if it currently isn&#x27;t running.&lt;&#x2F;li&gt;
  28&lt;li&gt;Click on the &amp;quot;Open Process&amp;quot; icon (it&#x27;s the top-left icon with the computer on it, below &amp;quot;File&amp;quot;.).&lt;&#x2F;li&gt;
  29&lt;li&gt;With the Process List window now open, look for this tutorial&#x27;s process in the list. It will look something like &amp;gt; &amp;quot;00001F98-Tutorial-x86_64.exe&amp;quot; or &amp;quot;0000047C-Tutorial-i386.exe&amp;quot;. (The first 8 numbers&#x2F;letters will probably be different.)&lt;&#x2F;li&gt;
  30&lt;li&gt;Once you&#x27;ve found the process, click on it to select it, then click the &amp;quot;Open&amp;quot; button. (Don&#x27;t worry about all the &amp;gt; other buttons right now. You can learn about them later if you&#x27;re interested.)&lt;&#x2F;li&gt;
  31&lt;&#x2F;ol&gt;
  32&lt;p&gt;Congratulations! If you did everything correctly, the process window should be gone with Cheat Engine now attached to the &amp;gt; tutorial (you will see the process name towards the top-center of CE).&lt;&#x2F;p&gt;
  33&lt;p&gt;Click the &amp;quot;Next&amp;quot; button below to continue, or fill in the password and click the &amp;quot;OK&amp;quot; button to proceed to that step.)&lt;&#x2F;p&gt;
  34&lt;p&gt;If you&#x27;re having problems, simply head over to forum.cheatengine.org, then click on &amp;quot;Tutorials&amp;quot; to view beginner-friendly &amp;gt; guides!&lt;&#x2F;p&gt;
  35&lt;&#x2F;blockquote&gt;
  36&lt;&#x2F;details&gt;
  37&lt;h2 id=&quot;enumerating-processes&quot;&gt;Enumerating processes&lt;&#x2F;h2&gt;
  38&lt;p&gt;Our first step is attaching to the process we want to work with. But we need a way to find that process in the first place! Having to open the task manager, look for the process we care about, noting down the process ID (PID), and slapping it in the source code is not satisfying at all. Instead, let&#x27;s enumerate all the processes from within the program, and let the user select one by typing its name.&lt;&#x2F;p&gt;
  39&lt;p&gt;From a quick &lt;a href=&quot;https:&#x2F;&#x2F;ddg.gg&#x2F;winapi%20enumerate%20all%20processes&quot;&gt;DuckDuckGo search&lt;&#x2F;a&gt;, we find an official tutorial for &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;psapi&#x2F;enumerating-all-processes&quot;&gt;Enumerating All Processes&lt;&#x2F;a&gt;, which leads to the &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;api&#x2F;psapi&#x2F;nf-psapi-enumprocesses&quot;&gt;&lt;code&gt;EnumProcesses&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; call. Cool! Let&#x27;s slap in the &lt;a href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;winapi&quot;&gt;&lt;code&gt;winapi&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; crate on &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;, because I don&#x27;t want to write all the definitions by myself:&lt;&#x2F;p&gt;
  40&lt;pre&gt;&lt;code class=&quot;language-toml&quot; data-lang=&quot;toml&quot;&gt;[dependencies]
  41winapi = { version = &amp;quot;0.3.9&amp;quot;, features = [&amp;quot;psapi&amp;quot;] }
  42&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
  43&lt;p&gt;Because &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;api&#x2F;psapi&#x2F;nf-psapi-enumprocesses&quot;&gt;&lt;code&gt;EnumProcesses&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; is in &lt;code&gt;Psapi.h&lt;&#x2F;code&gt; (you can see this in the online page of its documentation), we know we&#x27;ll need the &lt;code&gt;psapi&lt;&#x2F;code&gt; crate feature. Another option is to search for it in the &lt;a href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;winapi&#x2F;&quot;&gt;&lt;code&gt;winapi&lt;&#x2F;code&gt; documentation&lt;&#x2F;a&gt; and noting down the parent module where its stored.&lt;&#x2F;p&gt;
  44&lt;p&gt;The documentation for the method has the following remark:&lt;&#x2F;p&gt;
  45&lt;blockquote&gt;
  46&lt;p&gt;It is a good idea to use a large array, because it is hard to predict how many processes there will be at the time you call &lt;strong&gt;EnumProcesses&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
  47&lt;&#x2F;blockquote&gt;
  48&lt;p&gt;&lt;em&gt;Sidenote: reading the documentation for the methods we&#x27;ll use from the Windows API is extremely important. There&#x27;s a lot of gotchas involved, so we need to make sure we&#x27;re extra careful.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
  49&lt;p&gt;1024 is a pretty big number, so let&#x27;s go with that:&lt;&#x2F;p&gt;
  50&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;use std::io;
  51use std::mem;
  52use winapi::shared::minwindef::{DWORD, FALSE};
  53
  54pub fn enum_proc() -&amp;gt; io::Result&amp;lt;Vec&amp;lt;u32&amp;gt;&amp;gt; {
  55    let mut pids = Vec::&amp;lt;DWORD&amp;gt;::with_capacity(1024);
  56    let mut size = 0;
  57    &#x2F;&#x2F; SAFETY: the pointer is valid and the size matches the capacity.
  58    if unsafe {
  59        winapi::um::psapi::EnumProcesses(
  60            pids.as_mut_ptr(),
  61            (pids.capacity() * mem::size_of::&amp;lt;DWORD&amp;gt;()) as u32,
  62            &amp;amp;mut size,
  63        )
  64    } == FALSE
  65    {
  66        return Err(io::Error::last_os_error());
  67    }
  68
  69    todo!()
  70}
  71&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
  72&lt;p&gt;We allocate enough space&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#2&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt; for 1024 &lt;code&gt;pids&lt;&#x2F;code&gt; in a vector&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#3&quot;&gt;3&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;, and pass a mutable pointer to the contents to &lt;code&gt;EnumProcesses&lt;&#x2F;code&gt;. Note that the size of the array is in &lt;em&gt;bytes&lt;&#x2F;em&gt;, not items, so we need to multiply the capacity by the size of &lt;code&gt;DWORD&lt;&#x2F;code&gt;. The API likes to use &lt;code&gt;u32&lt;&#x2F;code&gt; for sizes, unlike Rust which uses &lt;code&gt;usize&lt;&#x2F;code&gt;, so we need a cast.&lt;&#x2F;p&gt;
  73&lt;p&gt;Last, we need another mutable variable where the amount of bytes written is stored, &lt;code&gt;size&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
  74&lt;blockquote&gt;
  75&lt;p&gt;If the function fails, the return value is zero. To get extended error information, call &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;api&#x2F;errhandlingapi&#x2F;nf-errhandlingapi-getlasterror&quot;&gt;&lt;code&gt;GetLastError&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
  76&lt;&#x2F;blockquote&gt;
  77&lt;p&gt;That&#x27;s precisely what we do. If it returns false (zero), we return the last OS error. Rust provides us with &lt;a href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;std&#x2F;io&#x2F;struct.Error.html#method.last_os_error&quot;&gt;&lt;code&gt;std::io::Error::last_os_error&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which essentially makes that same call but returns a proper &lt;code&gt;io::Error&lt;&#x2F;code&gt; instance. Cool!&lt;&#x2F;p&gt;
  78&lt;blockquote&gt;
  79&lt;p&gt;To determine how many processes were enumerated, divide the &lt;em&gt;lpcbNeeded&lt;&#x2F;em&gt; value by &lt;code&gt;sizeof(DWORD)&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
  80&lt;&#x2F;blockquote&gt;
  81&lt;p&gt;Easy enough:&lt;&#x2F;p&gt;
  82&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;let count = size as usize &#x2F; mem::size_of::&amp;lt;DWORD&amp;gt;();
  83&#x2F;&#x2F; SAFETY: the call succeeded and count equals the right amount of items.
  84unsafe { pids.set_len(count) };
  85Ok(pids)
  86&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
  87&lt;p&gt;Rust doesn&#x27;t know that the memory for &lt;code&gt;count&lt;&#x2F;code&gt; items were initialized by the call, but we do, so we make use of the &lt;a href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;std&#x2F;vec&#x2F;struct.Vec.html#method.set_len&quot;&gt;&lt;code&gt;Vec::set_len&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; call to indicate this. The Rust documentation even includes a FFI similar to our code!&lt;&#x2F;p&gt;
  88&lt;p&gt;Let&#x27;s give it a ride:&lt;&#x2F;p&gt;
  89&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;fn main() {
  90    dbg!(enum_proc().unwrap().len());
  91}
  92&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
  93&lt;pre&gt;&lt;code&gt;&amp;gt;cargo run
  94   Compiling memo v0.1.0
  95    Finished dev [unoptimized + debuginfo] target(s) in 0.20s
  96     Running `target\debug\memo.exe`
  97[src\main.rs:27] enum_proc().unwrap().len() = 178
  98&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
  99&lt;p&gt;It works! But currently we only have a bunch of process identifiers, with no way of knowing which process they refer to.&lt;&#x2F;p&gt;
 100&lt;blockquote&gt;
 101&lt;p&gt;To obtain process handles for the processes whose identifiers you have just obtained, call the &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;api&#x2F;processthreadsapi&#x2F;nf-processthreadsapi-openprocess&quot;&gt;&lt;code&gt;OpenProcess&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; function.&lt;&#x2F;p&gt;
 102&lt;&#x2F;blockquote&gt;
 103&lt;p&gt;Oh!&lt;&#x2F;p&gt;
 104&lt;h2 id=&quot;opening-a-process&quot;&gt;Opening a process&lt;&#x2F;h2&gt;
 105&lt;p&gt;The documentation for &lt;code&gt;OpenProcess&lt;&#x2F;code&gt; also contains the following:&lt;&#x2F;p&gt;
 106&lt;blockquote&gt;
 107&lt;p&gt;When you are finished with the handle, be sure to close it using the &lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;woce-1&#x2F;closehandle&quot;&gt;&lt;code&gt;CloseHandle&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; function.&lt;&#x2F;p&gt;
 108&lt;&#x2F;blockquote&gt;
 109&lt;p&gt;This sounds to me like the perfect time to introduce a custom &lt;code&gt;struct Process&lt;&#x2F;code&gt; with an &lt;code&gt;impl Drop&lt;&#x2F;code&gt;! We&#x27;re using &lt;code&gt;Drop&lt;&#x2F;code&gt; to cleanup resources, not behaviour, so it&#x27;s fine. &lt;a href=&quot;https:&#x2F;&#x2F;internals.rust-lang.org&#x2F;t&#x2F;pre-rfc-leave-auto-trait-for-reliable-destruction&#x2F;13825&quot;&gt;Using &lt;code&gt;Drop&lt;&#x2F;code&gt; to cleanup behaviour is a bad idea&lt;&#x2F;a&gt;. But anyway, let&#x27;s get back to the code:&lt;&#x2F;p&gt;
 110&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;use std::ptr::NonNull;
 111use winapi::ctypes::c_void;
 112
 113pub struct Process {
 114    pid: u32,
 115    handle: NonNull&amp;lt;c_void&amp;gt;,
 116}
 117
 118impl Process {
 119    pub fn open(pid: u32) -&amp;gt; io::Result&amp;lt;Self&amp;gt; {
 120        todo!()
 121    }
 122}
 123
 124impl Drop for Process {
 125    fn drop(&amp;amp;mut self) {
 126        todo!()
 127    }
 128}
 129&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 130&lt;p&gt;For &lt;code&gt;open&lt;&#x2F;code&gt;, we&#x27;ll want to use &lt;code&gt;OpenProcess&lt;&#x2F;code&gt; (and we also need to add the &lt;code&gt;processthreadsapi&lt;&#x2F;code&gt; feature to the &lt;code&gt;winapi&lt;&#x2F;code&gt; dependency in &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;). It returns a &lt;code&gt;HANDLE&lt;&#x2F;code&gt;, which is a nullable mutable pointer to &lt;code&gt;c_void&lt;&#x2F;code&gt;. If it&#x27;s null, the call failed, and if it&#x27;s non-null, it succeeded and we have a valid handle. This is why we use Rust&#x27;s &lt;a href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;std&#x2F;ptr&#x2F;struct.NonNull.html&quot;&gt;&lt;code&gt;NonNull&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
 131&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&#x2F;&#x2F; SAFETY: the call doesn&#x27;t have dangerous side-effects.
 132NonNull::new(unsafe { winapi::um::processthreadsapi::OpenProcess(0, FALSE, pid) })
 133    .map(|handle| Self { pid, handle })
 134    .ok_or_else(io::Error::last_os_error)
 135&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 136&lt;p&gt;&lt;code&gt;NonNull&lt;&#x2F;code&gt; will return &lt;code&gt;Some&lt;&#x2F;code&gt; if the pointer is non-null. We map the non-null pointer to a &lt;code&gt;Process&lt;&#x2F;code&gt; instance with &lt;code&gt;Self { .. }&lt;&#x2F;code&gt;. &lt;code&gt;ok_or_else&lt;&#x2F;code&gt; converts the &lt;code&gt;Option&lt;&#x2F;code&gt; to a &lt;code&gt;Result&lt;&#x2F;code&gt; with the error builder function we provide if it was &lt;code&gt;None&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
 137&lt;p&gt;The first parameter is a bitflag of permissions we want to have. For now, we can leave it as zero (all bits unset, no specific permissions granted). The second one is whether we want to inherit the handle, which we don&#x27;t, and the third one is the process identifier. Let&#x27;s close the resource handle on &lt;code&gt;Drop&lt;&#x2F;code&gt; (after adding &lt;code&gt;handleapi&lt;&#x2F;code&gt; to the crate features):&lt;&#x2F;p&gt;
 138&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&#x2F;&#x2F; SAFETY: the handle is valid and non-null.
 139unsafe { winapi::um::handleapi::CloseHandle(self.handle.as_mut()) };
 140&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 141&lt;p&gt;&lt;code&gt;CloseHandle&lt;&#x2F;code&gt; can actually fail (for example, on double-close), but given our invariants, it won&#x27;t. You could add an &lt;code&gt;assert!&lt;&#x2F;code&gt; to panic if this is not the case.&lt;&#x2F;p&gt;
 142&lt;p&gt;We can now open processes, and they will be automatically closed on &lt;code&gt;Drop&lt;&#x2F;code&gt;. Does any of this work though?&lt;&#x2F;p&gt;
 143&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;fn main() {
 144    let mut success = 0;
 145    let mut failed = 0;
 146    enum_proc().unwrap().into_iter().for_each(|pid| match Process::open(pid) {
 147        Ok(_) =&amp;gt; success += 1,
 148        Err(_) =&amp;gt; failed += 1,
 149    });
 150
 151    eprintln!(&amp;quot;Successfully opened {}&#x2F;{} processes&amp;quot;, success, success + failed);
 152}
 153&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 154&lt;pre&gt;&lt;code&gt;&amp;gt;cargo run
 155   Compiling memo v0.1.0
 156    Finished dev [unoptimized + debuginfo] target(s) in 0.36s
 157     Running `target\debug\memo.exe`
 158Successfully opened 0&#x2F;191 processes
 159&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 160&lt;p&gt;…nope. Maybe the documentation for &lt;code&gt;OpenProcess&lt;&#x2F;code&gt; says something?&lt;&#x2F;p&gt;
 161&lt;blockquote&gt;
 162&lt;p&gt;&lt;code&gt;dwDesiredAccess&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
 163&lt;p&gt;The access to the process object. This access right is checked against the security descriptor for the process. This parameter can be &lt;strong&gt;one or more&lt;&#x2F;strong&gt; of the process access rights.&lt;&#x2F;p&gt;
 164&lt;&#x2F;blockquote&gt;
 165&lt;p&gt;One or more, but we&#x27;re setting zero permissions. I told you, reading the documentation is important&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#4&quot;&gt;4&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;! The &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;procthread&#x2F;process-security-and-access-rights&quot;&gt;Process Security and Access Rights&lt;&#x2F;a&gt; page lists all possible values we could use. &lt;code&gt;PROCESS_QUERY_INFORMATION&lt;&#x2F;code&gt; seems to be appropriated:&lt;&#x2F;p&gt;
 166&lt;blockquote&gt;
 167&lt;p&gt;Required to retrieve certain information about a process, such as its token, exit code, and priority class&lt;&#x2F;p&gt;
 168&lt;&#x2F;blockquote&gt;
 169&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;OpenProcess(winapi::um::winnt::PROCESS_QUERY_INFORMATION, ...)
 170&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 171&lt;p&gt;Does this fix it?&lt;&#x2F;p&gt;
 172&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&amp;gt;cargo run
 173   Compiling memo v0.1.0
 174    Finished dev [unoptimized + debuginfo] target(s) in 0.36s
 175     Running `target\debug\memo.exe`
 176Successfully opened 69&#x2F;188 processes
 177&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 178&lt;p&gt;&lt;em&gt;Nice&lt;&#x2F;em&gt;. It does solve it. But why did we only open 69 processes out of 188? Does it help if we run our code as administrator? Let&#x27;s search for &lt;code&gt;cmd&lt;&#x2F;code&gt; in the Windows menu and right click to Run as administrator, then &lt;code&gt;cd&lt;&#x2F;code&gt; into our project and try again:&lt;&#x2F;p&gt;
 179&lt;pre&gt;&lt;code&gt;&amp;gt;cargo run
 180    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
 181     Running `target\debug\memo.exe`
 182Successfully opened 77&#x2F;190 processes
 183&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 184&lt;p&gt;We&#x27;re able to open a few more, so it does help. In general, we&#x27;ll want to run as administrator, so normal programs can&#x27;t sniff on what we&#x27;re doing, and so that we have permission to do more things.&lt;&#x2F;p&gt;
 185&lt;h2 id=&quot;getting-the-name-of-a-process&quot;&gt;Getting the name of a process&lt;&#x2F;h2&gt;
 186&lt;p&gt;We&#x27;re not done enumerating things just yet. To get the &amp;quot;name&amp;quot; of a process, we need to enumerate the modules that it has loaded, and only then can we get the module base name. The first module is the program itself, so we don&#x27;t need to enumerate &lt;em&gt;all&lt;&#x2F;em&gt; modules, just the one is enough.&lt;&#x2F;p&gt;
 187&lt;p&gt;For this we want &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;api&#x2F;psapi&#x2F;nf-psapi-enumprocessmodules&quot;&gt;&lt;code&gt;EnumProcessModules&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;api&#x2F;psapi&#x2F;nf-psapi-getmodulebasenamea&quot;&gt;&lt;code&gt;GetModuleBaseNameA&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;. I&#x27;m using the ASCII variant of &lt;code&gt;GetModuleBaseName&lt;&#x2F;code&gt; because I&#x27;m too lazy to deal with UTF-16 of the &lt;code&gt;W&lt;&#x2F;code&gt; (wide, unicode) variants.&lt;&#x2F;p&gt;
 188&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;use std::mem::MaybeUninit;
 189use winapi::shared::minwindef::HMODULE;
 190
 191pub fn name(&amp;amp;self) -&amp;gt; io::Result&amp;lt;String&amp;gt; {
 192    let mut module = MaybeUninit::&amp;lt;HMODULE&amp;gt;::uninit();
 193    let mut size = 0;
 194    &#x2F;&#x2F; SAFETY: the pointer is valid and the size is correct.
 195    if unsafe {
 196        winapi::um::psapi::EnumProcessModules(
 197            self.handle.as_ptr(),
 198            module.as_mut_ptr(),
 199            mem::size_of::&amp;lt;HMODULE&amp;gt;() as u32,
 200            &amp;amp;mut size,
 201        )
 202    } == FALSE
 203    {
 204        return Err(io::Error::last_os_error());
 205    }
 206
 207    &#x2F;&#x2F; SAFETY: the call succeeded, so module is initialized.
 208    let module = unsafe { module.assume_init() };
 209    todo!()
 210}
 211&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 212&lt;p&gt;&lt;code&gt;EnumProcessModules&lt;&#x2F;code&gt; takes a pointer to an array of &lt;code&gt;HMODULE&lt;&#x2F;code&gt;. We could use a &lt;code&gt;Vec&lt;&#x2F;code&gt; of capacity one to hold the single module, but in memory, a pointer a single item can be seen as a pointer to an array of items. &lt;code&gt;MaybeUninit&lt;&#x2F;code&gt; helps us reserve enough memory for the one item we need.&lt;&#x2F;p&gt;
 213&lt;p&gt;With the module handle, we can retrieve its base name:&lt;&#x2F;p&gt;
 214&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;let mut buffer = Vec::&amp;lt;u8&amp;gt;::with_capacity(64);
 215&#x2F;&#x2F; SAFETY: the handle, module and buffer are all valid.
 216let length = unsafe {
 217    winapi::um::psapi::GetModuleBaseNameA(
 218        self.handle.as_ptr(),
 219        module,
 220        buffer.as_mut_ptr().cast(),
 221        buffer.capacity() as u32,
 222    )
 223};
 224if length == 0 {
 225    return Err(io::Error::last_os_error());
 226}
 227
 228&#x2F;&#x2F; SAFETY: the call succeeded and length represents bytes.
 229unsafe { buffer.set_len(length as usize) };
 230Ok(String::from_utf8(buffer).unwrap())
 231&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 232&lt;p&gt;Similar to how we did with &lt;code&gt;EnumProcesses&lt;&#x2F;code&gt;, we create a buffer that will hold the ASCII string of the module&#x27;s base name&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#5&quot;&gt;5&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;. The call wants us to pass a pointer to a mutable buffer of &lt;code&gt;i8&lt;&#x2F;code&gt;, but Rust&#x27;s &lt;code&gt;String::from_utf8&lt;&#x2F;code&gt; wants a &lt;code&gt;Vec&amp;lt;u8&amp;gt;&lt;&#x2F;code&gt;, so instead we declare a buffer of &lt;code&gt;u8&lt;&#x2F;code&gt; and &lt;code&gt;.cast()&lt;&#x2F;code&gt; the pointer in the call. You could also do this with &lt;code&gt;as _&lt;&#x2F;code&gt;, and Rust would infer the right type, but &lt;code&gt;cast&lt;&#x2F;code&gt; is neat.&lt;&#x2F;p&gt;
 233&lt;p&gt;We &lt;code&gt;unwrap&lt;&#x2F;code&gt; the creation of the UTF-8 string because the buffer should contain only ASCII characters (which are also valid UTF-8). We could use the &lt;code&gt;unsafe&lt;&#x2F;code&gt; variant to create the string, but what if somehow it contains non-ASCII characters? The less &lt;code&gt;unsafe&lt;&#x2F;code&gt;, the better.&lt;&#x2F;p&gt;
 234&lt;p&gt;Let&#x27;s see it in action:&lt;&#x2F;p&gt;
 235&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;fn main() {
 236    enum_proc()
 237        .unwrap()
 238        .into_iter()
 239        .for_each(|pid| match Process::open(pid) {
 240            Ok(proc) =&amp;gt; match proc.name() {
 241                Ok(name) =&amp;gt; println!(&amp;quot;{}: {}&amp;quot;, pid, name),
 242                Err(e) =&amp;gt; println!(&amp;quot;{}: (failed to get name: {})&amp;quot;, pid, e),
 243            },
 244            Err(e) =&amp;gt; eprintln!(&amp;quot;failed to open {}: {}&amp;quot;, pid, e),
 245        });
 246}
 247&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 248&lt;pre&gt;&lt;code&gt;&amp;gt;cargo run
 249   Compiling memo v0.1.0
 250    Finished dev [unoptimized + debuginfo] target(s) in 0.32s
 251     Running `target\debug\memo.exe`
 252failed to open 0: The parameter is incorrect. (os error 87)
 253failed to open 4: Access is denied. (os error 5)
 254...
 255failed to open 5940: Access is denied. (os error 5)
 2565608: (failed to get name: Access is denied. (os error 5))
 257...
 2581704: (failed to get name: Access is denied. (os error 5))
 259failed to open 868: Access is denied. (os error 5)
 260...
 261&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 262&lt;p&gt;That&#x27;s not good. What&#x27;s up with that? Maybe…&lt;&#x2F;p&gt;
 263&lt;blockquote&gt;
 264&lt;p&gt;The handle must have the &lt;code&gt;PROCESS_QUERY_INFORMATION&lt;&#x2F;code&gt; and &lt;code&gt;PROCESS_VM_READ&lt;&#x2F;code&gt; access rights.&lt;&#x2F;p&gt;
 265&lt;&#x2F;blockquote&gt;
 266&lt;p&gt;…I should&#x27;ve read the documentation. Okay, fine:&lt;&#x2F;p&gt;
 267&lt;pre&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;use winapi::um::winnt;
 268OpenProcess(winnt::PROCESS_QUERY_INFORMATION | winnt::PROCESS_VM_READ, ...)
 269&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 270&lt;pre&gt;&lt;code&gt;&amp;gt;cargo run
 271   Compiling memo v0.1.0 (C:\Users\L\Desktop\memo)
 272    Finished dev [unoptimized + debuginfo] target(s) in 0.35s
 273     Running `target\debug\memo.exe`
 274failed to open 0: The parameter is incorrect. (os error 87)
 275failed to open 4: Access is denied. (os error 5)
 276...
 2779348: cheatengine-x86_64.exe
 2783288: Tutorial-x86_64.exe
 2798396: cmd.exe
 2804620: firefox.exe
 2817964: cargo.exe
 28210052: cargo.exe
 2835756: memo.exe
 284&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 285&lt;p&gt;Hooray 🎉! There&#x27;s some processes we can&#x27;t open, but that&#x27;s because they&#x27;re system processes. Security works!&lt;&#x2F;p&gt;
 286&lt;h2 id=&quot;finale&quot;&gt;Finale&lt;&#x2F;h2&gt;
 287&lt;p&gt;That was a fairly long post when all we did was print a bunch of pids and their corresponding name. But in all fairness, we also laid out a good foundation for what&#x27;s coming next.&lt;&#x2F;p&gt;
 288&lt;p&gt;You can &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;lonami&#x2F;memo&quot;&gt;obtain the code for this post&lt;&#x2F;a&gt; over at my GitHub. At the end of every post, the last commit will be tagged, so you can &lt;code&gt;git checkout step1&lt;&#x2F;code&gt; to see the final code for any blog post.&lt;&#x2F;p&gt;
 289&lt;p&gt;In the next post, we&#x27;ll tackle the second step of the tutorial: Exact Value scanning.&lt;&#x2F;p&gt;
 290&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;&#x2F;h3&gt;
 291&lt;div class=&quot;footnote-definition&quot; id=&quot;1&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;1&lt;&#x2F;sup&gt;
 292&lt;p&gt;You could say I simply love reinventing the wheel, which I do, but in this case, the codebase contains &lt;em&gt;far&lt;&#x2F;em&gt; more features than we&#x27;re interested in. The (apparent) lack of structure and documentation regarding the code, along with the unfortunate &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cheat-engine&#x2F;cheat-engine&#x2F;issues&#x2F;60&quot;&gt;lack of license&lt;&#x2F;a&gt; for the source code, make it a no-go. There&#x27;s a license, but I think that&#x27;s for the distributed program itself.&lt;&#x2F;p&gt;
 293&lt;&#x2F;div&gt;
 294&lt;div class=&quot;footnote-definition&quot; id=&quot;2&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;2&lt;&#x2F;sup&gt;
 295&lt;p&gt;If it turns out that there are more than 1024 processes, our code will be unaware of those extra processes. The documentation suggests to perform the call again with a larger buffer if &lt;code&gt;count == provided capacity&lt;&#x2F;code&gt;, but given I have under 200 processes on my system, it seems unlikely we&#x27;ll reach this limit. If you&#x27;re worried about hitting this limit, simply use a larger limit or retry with a larger vector.&lt;&#x2F;p&gt;
 296&lt;&#x2F;div&gt;
 297&lt;div class=&quot;footnote-definition&quot; id=&quot;3&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;3&lt;&#x2F;sup&gt;
 298&lt;p&gt;C code would likely use &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;api&#x2F;winbase&#x2F;nf-winbase-globalalloc&quot;&gt;&lt;code&gt;GlobalAlloc&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; here, but Rust&#x27;s &lt;code&gt;Vec&lt;&#x2F;code&gt; handles the allocation for us, making the code both simpler and more idiomatic. In general, if you see calls to &lt;code&gt;GlobalAlloc&lt;&#x2F;code&gt; when porting some code to Rust, you can probably replace it with a &lt;code&gt;Vec&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
 299&lt;&#x2F;div&gt;
 300&lt;div class=&quot;footnote-definition&quot; id=&quot;4&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;4&lt;&#x2F;sup&gt;
 301&lt;p&gt;This will be a recurring theme.&lt;&#x2F;p&gt;
 302&lt;&#x2F;div&gt;
 303&lt;div class=&quot;footnote-definition&quot; id=&quot;5&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;5&lt;&#x2F;sup&gt;
 304&lt;p&gt;…and similar to &lt;code&gt;EnumProcesses&lt;&#x2F;code&gt;, if the name doesn&#x27;t fit in our buffer, the result will be truncated.&lt;&#x2F;p&gt;
 305&lt;&#x2F;div&gt;
 306</content>
 307	</entry>
 308	<entry xml:lang="en">
 309		<title>Data Mining, Warehousing and Information Retrieval</title>
 310		<published>2020-07-03T00:00:00+00:00</published>
 311		<updated>2020-07-03T00:00:00+00:00</updated>
 312		<link href="https://lonami.dev/blog/university/" type="text/html"/>
 313		<id>https://lonami.dev/blog/university/</id>
 314		<content type="html">&lt;p&gt;During university, there were a few subjects where I had to write blog posts for (either as evaluable tasks or just for fun). I thought it was really fun and I wanted to preserve that work here, with the hopes it&#x27;s interesting to someone.&lt;&#x2F;p&gt;
 315&lt;p&gt;The posts series were auto-generated from the original HTML files and manually anonymized later.&lt;&#x2F;p&gt;
 316&lt;ul&gt;
 317&lt;li&gt;&lt;a href=&quot;&#x2F;blog&#x2F;mdad&quot;&gt;Data Mining and Data Warehousing&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
 318&lt;li&gt;&lt;a href=&quot;&#x2F;blog&#x2F;ribw&quot;&gt;Information Retrieval and Web Search&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
 319&lt;&#x2F;ul&gt;
 320</content>
 321	</entry>
 322	<entry xml:lang="en">
 323		<title>My new computer</title>
 324		<published>2020-06-19T00:00:00+00:00</published>
 325		<updated>2020-07-03T00:00:00+00:00</updated>
 326		<link href="https://lonami.dev/blog/new-computer/" type="text/html"/>
 327		<id>https://lonami.dev/blog/new-computer/</id>
 328		<content type="html">&lt;p&gt;This post will be mostly me ranting about setting up a new laptop, but I also just want to share my upgrade. If you&#x27;re considering installing Arch Linux with dual-boot for Windows, maybe this post will help. Or perhaps you will learn something new to troubleshoot systems in the future. Let&#x27;s begin!&lt;&#x2F;p&gt;
 329&lt;p&gt;Last Sunday, I ordered a Asus Rog Strix G531GT-BQ165 for 900€ (on a 20% discount) with the following specifications:&lt;&#x2F;p&gt;
 330&lt;ul&gt;
 331&lt;li&gt;Intel® Core i7-9750H (6 cores, 12MB cache, 2.6GHz up to 4.5GHz, 64-bit)&lt;&#x2F;li&gt;
 332&lt;li&gt;16GB RAM (8GB*2) DDR4 2666MHz&lt;&#x2F;li&gt;
 333&lt;li&gt;512GB SSD M.2 PCIe® NVMe&lt;&#x2F;li&gt;
 334&lt;li&gt;Display 15.6&amp;quot; (1920x1080&#x2F;16:9) 60Hz&lt;&#x2F;li&gt;
 335&lt;li&gt;Graphics NVIDIA® GeForce® GTX1650 4GB GDDR5 VRAM&lt;&#x2F;li&gt;
 336&lt;li&gt;LAN 10&#x2F;100&#x2F;1000&lt;&#x2F;li&gt;
 337&lt;li&gt;Wi-Fi 5 (802.11ac) 2x2 RangeBoost&lt;&#x2F;li&gt;
 338&lt;li&gt;Bluetooth 5.0&lt;&#x2F;li&gt;
 339&lt;li&gt;48Wh battery with 3 cells&lt;&#x2F;li&gt;
 340&lt;li&gt;3 x USB 3.1 (GEN1)&lt;&#x2F;li&gt;
 341&lt;&#x2F;ul&gt;
 342&lt;p&gt;I was mostly interested in a general upgrade (better processor, disk, more RAM), although the graphics card is a really nice addition which will allow me to take some time off on more games. After using it for a bit, I really love the feel of the keyboard, and I love the lack of numpad! (No sarcasm, I really don&#x27;t like numpads.)&lt;&#x2F;p&gt;
 343&lt;p&gt;This is an upgrade from my previous laptop (Asus X554LA-XX822T), which I won in a competition before entering university in a programming challenge. It has served me really well for the past five years, and had the following specifications:&lt;&#x2F;p&gt;
 344&lt;ul&gt;
 345&lt;li&gt;Intel® Core™ i5-5200U&lt;&#x2F;li&gt;
 346&lt;li&gt;4GB RAM DDR3L 1600MHz (which I upgraded to have 8GB)&lt;&#x2F;li&gt;
 347&lt;li&gt;1TB HDD&lt;&#x2F;li&gt;
 348&lt;li&gt;Display 15.6&amp;quot; (1366x768&#x2F;16:9)&lt;&#x2F;li&gt;
 349&lt;li&gt;Intel® HD Graphics 4400&lt;&#x2F;li&gt;
 350&lt;li&gt;LAN 10&#x2F;100&#x2F;1000&lt;&#x2F;li&gt;
 351&lt;li&gt;Wifi 802.11 bgn&lt;&#x2F;li&gt;
 352&lt;li&gt;Bluetooth 4.0&lt;&#x2F;li&gt;
 353&lt;li&gt;Battery 2 cells&lt;&#x2F;li&gt;
 354&lt;li&gt;1 x USB 2.0&lt;&#x2F;li&gt;
 355&lt;li&gt;2 x USB 3.0&lt;&#x2F;li&gt;
 356&lt;&#x2F;ul&gt;
 357&lt;p&gt;Prior to this one, I had a Lenovo (also won in the same competition of the previous year), and prior to that (just for the sake of history), it was HP Pavilion, AMD A4-3300M processor, which unfortunately ended with heating problems. But that&#x27;s very old now.&lt;&#x2F;p&gt;
 358&lt;h2 id=&quot;laptop-arrival&quot;&gt;Laptop arrival&lt;&#x2F;h2&gt;
 359&lt;p&gt;The laptop arrived 2 days ago at roughly 19:00, which I put charged for 3 hours as the book said. The day after, nightmares began!&lt;&#x2F;p&gt;
 360&lt;p&gt;Trying to boot it the first two times was fun, as it comes with a somewhat loud sound on boot. I don&#x27;t know why they would do this, and I immediately turned it off in the BIOS.&lt;&#x2F;p&gt;
 361&lt;h2 id=&quot;installation-journey&quot;&gt;Installation journey&lt;&#x2F;h2&gt;
 362&lt;p&gt;I spent all of yesterday trying to setup Windows and Arch Linux (and didn&#x27;t even finish, it took me this morning too and even now it&#x27;s only half functional). I absolutely &lt;em&gt;hate&lt;&#x2F;em&gt; the amount of partitions the Windows installer creates on a clean disk. So instead, I first went with Arch Linux, and followed the &lt;a href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;index.php&#x2F;Installation_guide&quot;&gt;installation guide on the Arch wiki&lt;&#x2F;a&gt;. Pre-installation, setting up the wireless network, creating the partitions and formatting them went all good. I decided to avoid GRUB at first and go with rEFInd, but alas I missed a big warning on the wiki and after reboot (I would later find out) it was not mounting root properly, so all I had was whatever was in the Initramfs. Reboot didn&#x27;t work, so I had to hold the power button.&lt;&#x2F;p&gt;
 363&lt;p&gt;Anyway, once the partitions were created, I went to install Windows (there was a lot of back and forth burning different &lt;code&gt;.iso&lt;&#x2F;code&gt; images on the USB, which was a bit annoying because it wasn&#x27;t the fastest thing in the world). This was pretty painless, and the process was standard: select advanced to let me choose the right partition, pick the one, say &amp;quot;no&amp;quot; to everything in the services setup, and done. But this was the first Windows &lt;code&gt;.iso&lt;&#x2F;code&gt; I tried. It was an old revision, and the drivers were causing issues when running (something weird about their &lt;code&gt;.dll&lt;&#x2F;code&gt;, manually installing the &lt;code&gt;.ini&lt;&#x2F;code&gt; driver files seemed to work?). The Nvidia drivers didn&#x27;t want to be installed on such an old revision, after updating everything I could via Windows updates. So back I went to burning a newer Windows &lt;code&gt;.iso&lt;&#x2F;code&gt; and going through the same process again…&lt;&#x2F;p&gt;
 364&lt;p&gt;Once Windows was ready and I verified that I could boot to it correctly, it was time to have a second go at Arch Linux. And I went through the setup at least three times, getting it wrong every single time, formatting root every single time, redownloading the packages every single pain. If only had I known earlier what the issue was!&lt;&#x2F;p&gt;
 365&lt;p&gt;Why bother with Arch? I was pretty happy with Linux Mint, and I lowkey wanted to try NixOS, but I had used Arch before and it&#x27;s a really nice distro overall (up-to-date, has AUR, quite minimal, imperative), except for trying to install rEFInd while chrooted…&lt;&#x2F;p&gt;
 366&lt;p&gt;In the end I managed to get something half-working, I still need to properly configure WiFi and pulseaudio in my system but hey it works.&lt;&#x2F;p&gt;
 367&lt;p&gt;I like to be able to dual-boot Windows and Linux because Linux is amazing for productivity, but unfortunately, some games only work fine on Windows. Might as well have both systems and use one for gaming, while the other is my daily driver.&lt;&#x2F;p&gt;
 368&lt;h2 id=&quot;setting-up-arch-linux&quot;&gt;Setting up Arch Linux&lt;&#x2F;h2&gt;
 369&lt;p&gt;This is the process I followed to install Arch Linux in the end, along with a brief explanation on what I think the things are doing and why we are doing them. I think the wiki could do a better job at this, but I also know it&#x27;s hard to get it right for everyone. Something I do dislike is the link colour, after opening a link it becomes gray and it&#x27;s a lot easier to miss the fact that it is a link in the first place, which was tough when re-reading it because some links actually matter a lot. Furthermore, important information may just be a single line, also easy to skim over. Anyway, on to the installation process…&lt;&#x2F;p&gt;
 370&lt;p&gt;The first thing we want to do is configure our keyboard layout or else the keys won&#x27;t correspond to what we expect:&lt;&#x2F;p&gt;
 371&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;loadkeys es
 372&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 373&lt;p&gt;Because we&#x27;re on a recent system, we want to verify that UEFI works correctly. If we see files listed, then it works fine:&lt;&#x2F;p&gt;
 374&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;ls &#x2F;sys&#x2F;firmware&#x2F;efi&#x2F;efivars
 375&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 376&lt;p&gt;The next thing we want to do is configure the WiFi, because I don&#x27;t have any ethernet cable nearby. To do this, we check what network interfaces our laptop has (we&#x27;re looking for the one prefixed with &amp;quot;w&amp;quot;, presumably for wireless, such as &amp;quot;wlan0&amp;quot; or &amp;quot;wlo1&amp;quot;), we set it up, scan for available wireless network, and finally connect. In my case, the network has WPA security so we rely on &lt;code&gt;wpa_supplicant&lt;&#x2F;code&gt; to connect, passing the SSID (network name) and password:&lt;&#x2F;p&gt;
 377&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;ip link
 378ip link set &amp;lt;IFACE&amp;gt; up
 379iw dev &amp;lt;IFACE&amp;gt; scan | less
 380wpa_supplicant -B -i &amp;lt;IFACE&amp;gt; -c &amp;lt;(wpa_passphrase &amp;lt;SSID&amp;gt; &amp;lt;PASS&amp;gt;)
 381&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 382&lt;p&gt;After that&#x27;s done, pinging an IP address like &amp;quot;1.1.1.1&amp;quot; should Just Work™, but to be able to resolve hostnames, we need to also setup a nameserver. I&#x27;m using Cloudflare&#x27;s, but you could use any other:&lt;&#x2F;p&gt;
 383&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;echo nameserver 1.1.1.1 &amp;gt; &#x2F;etc&#x2F;resolv.conf
 384ping archlinux.org
 385^C
 386&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 387&lt;p&gt;If the ping works, then network works! If you still have issues, you may need to &lt;a href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;index.php&#x2F;Network_configuration#Static_IP_address&quot;&gt;manually configure a static IP address&lt;&#x2F;a&gt; and add a route with the address of your, well, router. This basically shows if we have any address, adds a static address (so people know who we are), shows what route we have, and adds a default one (so our packets know where to go):&lt;&#x2F;p&gt;
 388&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;ip address show
 389ip address add &amp;lt;YOUR ADDR&amp;gt;&#x2F;24 broadcast + dev &amp;lt;IFACE&amp;gt;
 390ip route show
 391ip route add default via &amp;lt;ROUTER ADDR&amp;gt; dev &amp;lt;IFACE&amp;gt;
 392&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 393&lt;p&gt;Now that we have network available, we can enable NTP to synchronize our system time (this may be required for network operations where certificates have a validity period, not sure; in any case nobody wants a wrong system time):&lt;&#x2F;p&gt;
 394&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;timedatectl set-ntp true
 395&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 396&lt;p&gt;After that, we can manage our disk and partitions using &lt;code&gt;fdisk&lt;&#x2F;code&gt;. We want to define partitions to tell the system where it should live. To determine the disk name, we first list them, and then edit it. &lt;code&gt;fdisk&lt;&#x2F;code&gt; is really nice and reminds you at every step that help can be accessed with &amp;quot;m&amp;quot;, which you should constantly use to guide you through.&lt;&#x2F;p&gt;
 397&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;fdisk -l
 398fdisk &#x2F;dev&#x2F;&amp;lt;DISK&amp;gt;
 399&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 400&lt;p&gt;The partitions I made are the following:&lt;&#x2F;p&gt;
 401&lt;ul&gt;
 402&lt;li&gt;A 100MB one for the EFI system.&lt;&#x2F;li&gt;
 403&lt;li&gt;A 32GB one for Linux&#x27; root &lt;code&gt;&#x2F;&lt;&#x2F;code&gt; partition.&lt;&#x2F;li&gt;
 404&lt;li&gt;A 200GB one for Linux&#x27; home &lt;code&gt;&#x2F;home&lt;&#x2F;code&gt; partition.&lt;&#x2F;li&gt;
 405&lt;li&gt;The rest was unallocated for Windows because I did this first.&lt;&#x2F;li&gt;
 406&lt;&#x2F;ul&gt;
 407&lt;p&gt;I like to have &lt;code&gt;&#x2F;home&lt;&#x2F;code&gt; and &lt;code&gt;&#x2F;&lt;&#x2F;code&gt; separate because I can reinstall root without losing anything from home (projects, music, photos, screenshots, videos…).&lt;&#x2F;p&gt;
 408&lt;p&gt;After the partitions are made, we format them in FAT32 and EXT4 which are good defaults for EFI, root and home. They need to have a format, or else they won&#x27;t be usable:&lt;&#x2F;p&gt;
 409&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;mkfs.fat -F32 &#x2F;dev&#x2F;&amp;lt;DISK&amp;gt;&amp;lt;PART1&amp;gt;
 410mkfs.ext4 &#x2F;dev&#x2F;&amp;lt;DISK&amp;gt;&amp;lt;PART2&amp;gt;
 411mkfs.ext4 &#x2F;dev&#x2F;&amp;lt;DISK&amp;gt;&amp;lt;PART3&amp;gt;
 412&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 413&lt;p&gt;Because the laptop was new, there was no risk to lose anything, but if you&#x27;re doing a install on a previous system, be very careful with the partition names. Make sure they match with the ones in &lt;code&gt;fdisk -l&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
 414&lt;p&gt;Now that we have usable partitions, we need to mount them or they won&#x27;t be accessible. We can do this with &lt;code&gt;mount&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
 415&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;mount &#x2F;dev&#x2F;&amp;lt;DISK&amp;gt;&amp;lt;PART2&amp;gt; &#x2F;mnt
 416mkdir &#x2F;mnt&#x2F;efi
 417mount &#x2F;dev&#x2F;&amp;lt;DISK&amp;gt;&amp;lt;PART1&amp;gt; &#x2F;mnt&#x2F;efi
 418mkdir &#x2F;mnt&#x2F;home
 419mount &#x2F;dev&#x2F;&amp;lt;DISK&amp;gt;&amp;lt;PART3&amp;gt; &#x2F;mnt&#x2F;home
 420&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 421&lt;p&gt;Remember to use the correct partitions while mounting. We mount everything so that the system knows which partitions we care about, which we will let know about later on.&lt;&#x2F;p&gt;
 422&lt;p&gt;Next step is to setup the basic Arch Linux system on root, which can be done with &lt;code&gt;pacstrap&lt;&#x2F;code&gt;. What follows the directory is a list of packages, and you may choose any you wish (at least add &lt;code&gt;base&lt;&#x2F;code&gt;, &lt;code&gt;linux&lt;&#x2F;code&gt; and &lt;code&gt;linux-firmware&lt;&#x2F;code&gt;). These can be installed later, but I&#x27;d recommend having them from the beginning, just in case:&lt;&#x2F;p&gt;
 423&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;pacstrap &#x2F;mnt base linux linux-firmware sudo vim-minimal dhcpcd wpa_supplicant man-db man-pages intel-ucode grub efibootmgr os-prober ntfs-3g
 424&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 425&lt;p&gt;Because my system has an intel CPU, I also installed &lt;code&gt;intel-ucode&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
 426&lt;p&gt;Next up is generating the &lt;code&gt;fstab&lt;&#x2F;code&gt; file, which we tell to use UUIDs to be on the safe side through &lt;code&gt;-U&lt;&#x2F;code&gt;. This file is important, because without it the system won&#x27;t know what partitions exist and will happily only boot with the initramfs, without anything of what we just installed at root. Not knowing this made me restart the entire installation process a few times.&lt;&#x2F;p&gt;
 427&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;genfstab -U &#x2F;mnt &amp;gt;&amp;gt; &#x2F;mnt&#x2F;etc&#x2F;fstab
 428&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 429&lt;p&gt;After that&#x27;s done, we can change our root into our mount point and finish up configuration. We setup our timezone (so DST can be handled correctly if needed), synchronize the hardware clock (to persist the current time to the BIOS), uncomment our locales (exit &lt;code&gt;vim&lt;&#x2F;code&gt; by pressing ESC, then type &lt;code&gt;:wq&lt;&#x2F;code&gt; and press enter), generate locale files (which some applications need), configure language and keymap, update the hostname of our laptop and what indicate what &lt;code&gt;localhost&lt;&#x2F;code&gt; means…&lt;&#x2F;p&gt;
 430&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;ln -sf &#x2F;usr&#x2F;share&#x2F;zoneinfo&#x2F;&amp;lt;REGION&amp;gt;&#x2F;&amp;lt;CITY&amp;gt; &#x2F;etc&#x2F;localtime
 431hwclock --systohc
 432vim &#x2F;etc&#x2F;locale.gen
 433locale-gen
 434echo LANG=es_ES.UTF-8 &amp;gt; &#x2F;etc&#x2F;locale.conf
 435echo KEYMAP=es &amp;gt; &#x2F;etc&#x2F;vconsole.conf
 436echo &amp;lt;HOST&amp;gt; &#x2F;etc&#x2F;hostname
 437cat &amp;lt;&amp;lt;EOF &amp;gt; &#x2F;etc&#x2F;hosts
 438127.0.0.1 localhost
 439::1 localhost
 440127.0.1.1 &amp;lt;HOST&amp;gt;.localdomain &amp;lt;HOST&amp;gt;
 441EOF
 442&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 443&lt;p&gt;Really, we could&#x27;ve done all of this later, and the same goes for setting root&#x27;s password with &lt;code&gt;passwd&lt;&#x2F;code&gt; or creating users (some of the groups you probably want are &lt;code&gt;power&lt;&#x2F;code&gt; and &lt;code&gt;wheel&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
 444&lt;p&gt;The important part here is installing GRUB (which also needed the &lt;code&gt;efibootmgr&lt;&#x2F;code&gt; package):&lt;&#x2F;p&gt;
 445&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;grub-install --target=x86_64-efi --efi-directory=&#x2F;efi --bootloader-id=GRUB
 446&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 447&lt;p&gt;If we want GRUB to find our Windows install, we also need the &lt;code&gt;os-prober&lt;&#x2F;code&gt; and &lt;code&gt;ntfs-3g&lt;&#x2F;code&gt; packages that we installed earlier with &lt;code&gt;pacstrap&lt;&#x2F;code&gt;, and with those we need to mount the Windows partition somewhere. It doesn&#x27;t matter where. With that done, we can generate the GRUB configuration file which lists all the boot options:&lt;&#x2F;p&gt;
 448&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;mkdir &#x2F;windows
 449mount &#x2F;dev&#x2F;&amp;lt;DISK&amp;gt;&amp;lt;PART5&amp;gt; &#x2F;windows
 450grub-mkconfig -o &#x2F;boot&#x2F;grub&#x2F;grub.cfg
 451&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 452&lt;p&gt;(In my case, I installed Windows before completing the Arch install, which created an additional partition in between).&lt;&#x2F;p&gt;
 453&lt;p&gt;With GRUB ready, we can exit the chroot and reboot the system, and if all went well, you should be greeted with a choice of operating system to use:&lt;&#x2F;p&gt;
 454&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;exit
 455reboot
 456&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 457&lt;p&gt;If for some reason you need to find what mountpoints were active prior to rebooting (to &lt;code&gt;unmount&lt;&#x2F;code&gt; them for example), you can use &lt;code&gt;findmnt&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
 458&lt;p&gt;Before GRUB I tried rEFInd, which as I explained had issues with for missing a warning. Then I tried systemd-boot, which did not pick up Arch at first. That&#x27;s where the several reinstalls come from, I didn&#x27;t want to work with a half-worked system so I mostly redid the entire process quite a few times.&lt;&#x2F;p&gt;
 459&lt;h2 id=&quot;migrating-to-the-new-laptop&quot;&gt;Migrating to the new laptop&lt;&#x2F;h2&gt;
 460&lt;p&gt;I had a external disk formatted with NTFS. Of course, after moving every file I cared about from my previous Linux install caused all the permissions to reset. All my &lt;code&gt;.git&lt;&#x2F;code&gt; repositories, dirty with file permission changes! This is going to take a while to fix, or maybe I should just &lt;code&gt;git config core.fileMode false&lt;&#x2F;code&gt;. Here is a &lt;a href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;2083563&quot;&gt;lovely command&lt;&#x2F;a&gt; to sort them out on a per-repository basis:&lt;&#x2F;p&gt;
 461&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;git diff --summary | grep --color &#x27;mode change 100644 =&amp;gt; 100755&#x27; | cut -d&#x27; &#x27; -f7- | xargs -d&#x27;\n&#x27; chmod -x
 462&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 463&lt;p&gt;I never realized how much I had stored over the years, but it really was a lot. While moving things to the external disk, I tried to do some cleanup, such as removing some build artifacts which needlessly occupy space, or completely skipping all the binary application files. If I need those I will install them anyway. The process was mostly focused on finding all the projects and program data that I did care about, or even some game saves. Nothing too difficult, but definitely time consuming.&lt;&#x2F;p&gt;
 464&lt;h2 id=&quot;tuning-arch&quot;&gt;Tuning Arch&lt;&#x2F;h2&gt;
 465&lt;p&gt;Now that our system is ready, install &lt;code&gt;pacman-contrib&lt;&#x2F;code&gt; to grab a copy of the &lt;code&gt;rankmirrors&lt;&#x2F;code&gt; speed. It should help speed up the download of whatever packages you want to install, since it will help us &lt;a href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;index.php&#x2F;Mirrors#List_by_speed&quot;&gt;rank the mirrors by download speed&lt;&#x2F;a&gt;. Making a copy of the file is important, otherwise whenever you try to install something it will fail saying it can&#x27;t find anything.&lt;&#x2F;p&gt;
 466&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;cp &#x2F;etc&#x2F;pacman.d&#x2F;mirrorlist &#x2F;etc&#x2F;pacman.d&#x2F;mirrorlist.backup
 467sed -i &#x27;s&#x2F;^#Server&#x2F;Server&#x2F;&#x27; &#x2F;etc&#x2F;pacman.d&#x2F;mirrorlist.backup
 468rankmirrors -n 6 &#x2F;etc&#x2F;pacman.d&#x2F;mirrorlist.backup | tee &#x2F;etc&#x2F;pacman.d&#x2F;mirrorlist
 469&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 470&lt;p&gt;This will take a while, but it should be well worth it. We&#x27;re using &lt;code&gt;tee&lt;&#x2F;code&gt; to see the progress as it goes.&lt;&#x2F;p&gt;
 471&lt;p&gt;Some other packages I installed after I had a working system in no particular order:&lt;&#x2F;p&gt;
 472&lt;ul&gt;
 473&lt;li&gt;&lt;code&gt;xfce4&lt;&#x2F;code&gt; and &lt;code&gt;xorg-server&lt;&#x2F;code&gt;. I just love the simplicity of XFCE.&lt;&#x2F;li&gt;
 474&lt;li&gt;&lt;code&gt;xfce4-whiskermenu-plugin&lt;&#x2F;code&gt;, a really nice start menu.&lt;&#x2F;li&gt;
 475&lt;li&gt;&lt;code&gt;xfce4-pulseaudio-plugin&lt;&#x2F;code&gt; and &lt;code&gt;pavucontrol&lt;&#x2F;code&gt;, to quickly adjust the audio with my mouse.&lt;&#x2F;li&gt;
 476&lt;li&gt;&lt;code&gt;xfce4-taskmanager&lt;&#x2F;code&gt;, a GUI alternative I generally prefer to &lt;code&gt;htop&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
 477&lt;li&gt;&lt;code&gt;pulseaudio&lt;&#x2F;code&gt; and &lt;code&gt;pulseaudio-alsa&lt;&#x2F;code&gt; to get nice integration with XFCE4 and audio mixing.&lt;&#x2F;li&gt;
 478&lt;li&gt;&lt;code&gt;firefox&lt;&#x2F;code&gt;, which comes with fonts too. A really good web browser.&lt;&#x2F;li&gt;
 479&lt;li&gt;&lt;code&gt;git&lt;&#x2F;code&gt;, to commit &lt;del&gt;crimes&lt;&#x2F;del&gt; code.&lt;&#x2F;li&gt;
 480&lt;li&gt;&lt;code&gt;code&lt;&#x2F;code&gt;, a wonderful editor which I used to write this blog entry.&lt;&#x2F;li&gt;
 481&lt;li&gt;&lt;code&gt;nano&lt;&#x2F;code&gt;, so much nicer to write a simple commit message.&lt;&#x2F;li&gt;
 482&lt;li&gt;&lt;code&gt;python&lt;&#x2F;code&gt; and &lt;code&gt;python-pip&lt;&#x2F;code&gt;, my favourite language to toy around ideas or use as a calculator.&lt;&#x2F;li&gt;
 483&lt;li&gt;&lt;code&gt;telegram-desktop&lt;&#x2F;code&gt;, for my needs on sharing memes.&lt;&#x2F;li&gt;
 484&lt;li&gt;&lt;code&gt;cmus&lt;&#x2F;code&gt; and &lt;code&gt;mpv&lt;&#x2F;code&gt;, a simple terminal music player and media player.&lt;&#x2F;li&gt;
 485&lt;li&gt;&lt;code&gt;openssh&lt;&#x2F;code&gt;, to connect into any VPS I have access to.&lt;&#x2F;li&gt;
 486&lt;li&gt;&lt;code&gt;base-devel&lt;&#x2F;code&gt;, necessary to build most projects I&#x27;ll find myself working with (or even compiling some projects Rust which I installed via &lt;code&gt;rustup&lt;&#x2F;code&gt;).&lt;&#x2F;li&gt;
 487&lt;li&gt;&lt;code&gt;flac&lt;&#x2F;code&gt;, &lt;code&gt;libmad&lt;&#x2F;code&gt;, &lt;code&gt;opus&lt;&#x2F;code&gt;, and &lt;code&gt;libvorbis&lt;&#x2F;code&gt;, to be able to play more audio files.&lt;&#x2F;li&gt;
 488&lt;li&gt;&lt;code&gt;inkscape&lt;&#x2F;code&gt;, to make random drawings.&lt;&#x2F;li&gt;
 489&lt;li&gt;&lt;code&gt;ffmpeg&lt;&#x2F;code&gt;, to convert media or record screen.&lt;&#x2F;li&gt;
 490&lt;li&gt;&lt;code&gt;xclip&lt;&#x2F;code&gt;, to automatically copy screenshots to my clipboard.&lt;&#x2F;li&gt;
 491&lt;li&gt;&lt;code&gt;gvfs&lt;&#x2F;code&gt;, needed by Thunar to handle mounting and having a trash (perma-deletion by default can be nasty sometimes).&lt;&#x2F;li&gt;
 492&lt;li&gt;&lt;code&gt;noto-fonts&lt;&#x2F;code&gt;, &lt;code&gt;noto-fonts-cjk&lt;&#x2F;code&gt;, &lt;code&gt;noto-fonts-extra&lt;&#x2F;code&gt; and &lt;code&gt;noto-fonts-emoji&lt;&#x2F;code&gt;, if you don&#x27;t want missing gliphs everywhere.&lt;&#x2F;li&gt;
 493&lt;li&gt;&lt;code&gt;xfce4-notifyd&lt;&#x2F;code&gt; and &lt;code&gt;libnotify&lt;&#x2F;code&gt;, for notifications.&lt;&#x2F;li&gt;
 494&lt;li&gt;&lt;code&gt;cronie&lt;&#x2F;code&gt;, to be able to &lt;code&gt;crontab -e&lt;&#x2F;code&gt;. Make sure to &lt;code&gt;system enable cronie&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
 495&lt;li&gt;&lt;code&gt;xarchiver&lt;&#x2F;code&gt; (with &lt;code&gt;p7zip&lt;&#x2F;code&gt;, &lt;code&gt;zip&lt;&#x2F;code&gt;, &lt;code&gt;unzip&lt;&#x2F;code&gt; and &lt;code&gt;unrar&lt;&#x2F;code&gt;) to uncompress stuff.&lt;&#x2F;li&gt;
 496&lt;li&gt;&lt;code&gt;xreader&lt;&#x2F;code&gt; to read &lt;code&gt;.pdf&lt;&#x2F;code&gt; files.&lt;&#x2F;li&gt;
 497&lt;li&gt;&lt;code&gt;sqlitebrowser&lt;&#x2F;code&gt; is always nice to tinker around with SQLite databases.&lt;&#x2F;li&gt;
 498&lt;li&gt;&lt;code&gt;jre8-openjdk&lt;&#x2F;code&gt; if you want to run Java applications.&lt;&#x2F;li&gt;
 499&lt;li&gt;&lt;code&gt;smartmontools&lt;&#x2F;code&gt; is nice with a SSD to view your disk statistics.&lt;&#x2F;li&gt;
 500&lt;&#x2F;ul&gt;
 501&lt;p&gt;After that, I configured my Super L key to launch &lt;code&gt;xfce4-popup-whiskermenu&lt;&#x2F;code&gt; so that it opens the application menu, pretty much the same as it would on Windows, moved the panels around and configured them to my needs, and it feels like home once more.&lt;&#x2F;p&gt;
 502&lt;p&gt;I made some mistakes while &lt;a href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;index.php&#x2F;Systemd-networkd&quot;&gt;configuring systemd-networkd&lt;&#x2F;a&gt; and accidentally added a service that was incorrect, which caused boot to wait for it to timeout before completing. My boot time was taking 90 seconds longer because of this! &lt;a href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;archlinux&#x2F;comments&#x2F;4nv9yi&#x2F;my_arch_greets_me_now_with_a_start_job&#x2F;&quot;&gt;The solution was to remove said service&lt;&#x2F;a&gt;, so this is something to look out for.&lt;&#x2F;p&gt;
 503&lt;p&gt;In order to find what was taking long, I had to edit the &lt;a href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;index.php&#x2F;kernel_parameters&quot;&gt;kernel parameters&lt;&#x2F;a&gt; to remove the &lt;code&gt;quiet&lt;&#x2F;code&gt; option. I prefer seeing the output on what my computer is doing anyway, because it gives me a sense of progress and most importantly is of great value when things go wrong. Another interesting option is &lt;code&gt;noauto,x-systemd.automount&lt;&#x2F;code&gt;, which makes a disk lazily-mounted. If you have a slow disk, this could help speed things up.&lt;&#x2F;p&gt;
 504&lt;p&gt;If you see a service taking long, you can also use &lt;code&gt;systemd-analyze blame&lt;&#x2F;code&gt; to see what takes the longest, and &lt;code&gt;systemctl list-dependencies&lt;&#x2F;code&gt; is also helpful to find what services are active.&lt;&#x2F;p&gt;
 505&lt;p&gt;My &lt;code&gt;locale charmap&lt;&#x2F;code&gt; was spitting out a bunch of warnings:&lt;&#x2F;p&gt;
 506&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;$ locale charmap
 507locale: Cannot set LC_CTYPE to default locale: No such file or directory
 508locale: Cannot set LC_MESSAGES to default locale: No such file or directory
 509locale: Cannot set LC_ALL to default locale: No such file or directory
 510ANSI_X3.4-1968
 511&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 512&lt;p&gt;…ANSI encoding? Immediately I added the following to &lt;code&gt;~&#x2F;.bashrc&lt;&#x2F;code&gt; and &lt;code&gt;~&#x2F;.profile&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
 513&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;export LC_ALL=en_US.UTF-8
 514export LANG=en_US.UTF-8
 515export LANGUAGE=en_US.UTF-8
 516&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 517&lt;p&gt;For some reason, I also had to edit &lt;code&gt;xfce4-terminal&lt;&#x2F;code&gt;&#x27;s preferences in advanced to change the default character encoding to UTF-8. This also solved my issues with pasting things into the terminal, and also proper rendering! I guess pastes were not working because it had some characters that could not be encoded.&lt;&#x2F;p&gt;
 518&lt;p&gt;To have working notifications, I added the following to &lt;code&gt;~&#x2F;.bash_profile&lt;&#x2F;code&gt; after &lt;code&gt;exec startx&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
 519&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;systemctl --user start xfce4-notifyd.service
 520&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 521&lt;p&gt;I&#x27;m pretty sure there&#x27;s a better way to do this, or maybe it&#x27;s not even necessary, but this works for me.&lt;&#x2F;p&gt;
 522&lt;p&gt;Some of the other things I had left to do was setting up &lt;code&gt;sccache&lt;&#x2F;code&gt; to speed up Rust builds:&lt;&#x2F;p&gt;
 523&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;cargo install sccache
 524echo export RUSTC_WRAPPER=sccache &amp;gt;&amp;gt; ~&#x2F;.bashrc
 525&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 526&lt;p&gt;Once I had &lt;code&gt;cargo&lt;&#x2F;code&gt; ready, installed &lt;code&gt;hacksaw&lt;&#x2F;code&gt; and &lt;code&gt;shotgun&lt;&#x2F;code&gt; with it to perform screenshots.&lt;&#x2F;p&gt;
 527&lt;p&gt;I also disabled the security delay when downloading files in Firefox because it&#x27;s just annoying, in &lt;code&gt;about:config&lt;&#x2F;code&gt; setting &lt;code&gt;security.dialog_enable_delay&lt;&#x2F;code&gt; to &lt;code&gt;0&lt;&#x2F;code&gt;, and added the &lt;a href=&quot;https:&#x2F;&#x2F;alisdair.mcdiarmid.org&#x2F;kill-sticky-headers&#x2F;&quot;&gt;Kill sticky headers&lt;&#x2F;a&gt; to my bookmarks (you may prefer &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;t-mart&#x2F;kill-sticky&quot;&gt;the updated version&lt;&#x2F;a&gt;).&lt;&#x2F;p&gt;
 528&lt;p&gt;The &lt;code&gt;utils-linux&lt;&#x2F;code&gt; comes with a &lt;code&gt;fstrim&lt;&#x2F;code&gt; utility to &lt;a href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;index.php&#x2F;Solid_state_drive#Periodic_TRIM&quot;&gt;trim the SSD weekly&lt;&#x2F;a&gt;, which I want enabled via &lt;code&gt;systemctl enable fstrim.timer&lt;&#x2F;code&gt; (you may also want to &lt;code&gt;start&lt;&#x2F;code&gt; it if you don&#x27;t reboot often). For more SSD tips, check &lt;a href=&quot;https:&#x2F;&#x2F;easylinuxtipsproject.blogspot.com&#x2F;p&#x2F;ssd.html&quot;&gt;How to optimize your Solid State Drive&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
 529&lt;p&gt;If the sound is funky prior to reboot, try &lt;code&gt;pulseaudio --kill&lt;&#x2F;code&gt; and &lt;code&gt;pulseaudio --start&lt;&#x2F;code&gt;, or delete &lt;code&gt;~&#x2F;.config&#x2F;pulse&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
 530&lt;p&gt;I haven&#x27;t been able to get the brightness keys to work yet, but it&#x27;s not a big deal, because scrolling on the power manager plugin of Xfce does work (and also &lt;code&gt;xbacklight&lt;&#x2F;code&gt; works, or writing directly to &lt;code&gt;&#x2F;sys&#x2F;class&#x2F;backlight&#x2F;*&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
 531&lt;h2 id=&quot;tuning-windows&quot;&gt;Tuning Windows&lt;&#x2F;h2&gt;
 532&lt;p&gt;On the Windows side, I disabled the annoying Windows defender by running (&lt;kbd&gt;Ctrl+R&lt;&#x2F;kbd&gt;) &lt;code&gt;gpedit.msc&lt;&#x2F;code&gt; and editing:&lt;&#x2F;p&gt;
 533&lt;ul&gt;
 534&lt;li&gt;&lt;em&gt;Computer Configuration &amp;gt; Administrative Templates &amp;gt; Windows Components &amp;gt; Windows Defender » Turn off Windows Defender » Enable&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
 535&lt;li&gt;&lt;em&gt;User Configuration &amp;gt; Administrative Templates &amp;gt; Start Menu and Taskbar » Remove Notifications and Action Center » Enable&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
 536&lt;&#x2F;ul&gt;
 537&lt;p&gt;I also updated the &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;WindowsLies&#x2F;BlockWindows&#x2F;raw&#x2F;master&#x2F;hosts&quot;&gt;&lt;code&gt;hosts&lt;&#x2F;code&gt; file&lt;&#x2F;a&gt; (located at &lt;code&gt;%windir%\system32\Drivers\etc\hosts&lt;&#x2F;code&gt;) with the hope that it will stop some of the telemetry.&lt;&#x2F;p&gt;
 538&lt;p&gt;Last, to have consistent time on Windows and Linux, I changed the following registry key for a &lt;code&gt;qword&lt;&#x2F;code&gt; with value &lt;code&gt;1&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
 539&lt;pre&gt;&lt;code&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal
 540&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 541&lt;p&gt;(The key might not exist, but you can create it if that&#x27;s the case).&lt;&#x2F;p&gt;
 542&lt;p&gt;All this time, my laptop had the keyboard lights on, which have been quite annoying. Apparently, they also can cause &lt;a href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;ValveIndex&#x2F;comments&#x2F;cm6pos&#x2F;psa_uninstalldisable_aura_sync_lighting_if_you&#x2F;&quot;&gt;massive FPS drops&lt;&#x2F;a&gt;. I headed over to &lt;a href=&quot;https:&#x2F;&#x2F;rog.asus.com&#x2F;downloads&#x2F;&quot;&gt;Asus Rog downloads&lt;&#x2F;a&gt;, selected Aura Sync…&lt;&#x2F;p&gt;
 543&lt;pre&gt;&lt;code class=&quot;language-md&quot; data-lang=&quot;md&quot;&gt;# Not Found
 544
 545The requested URL &#x2F;campaign&#x2F;aura&#x2F;us&#x2F;Sync.html was not found on this server.
 546
 547Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
 548&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 549&lt;p&gt;…great! I&#x27;ll just find the &lt;a href=&quot;https:&#x2F;&#x2F;www.asus.com&#x2F;campaign&#x2F;aura&#x2F;global&#x2F;&quot;&gt;Aura site&lt;&#x2F;a&gt; somewhere else…&lt;&#x2F;p&gt;
 550&lt;pre&gt;&lt;code class=&quot;language-md&quot; data-lang=&quot;md&quot;&gt;# ASUS
 551
 552# We&#x27;ll be back.
 553
 554Hi, our website is temporarily closed for service enhancements.
 555
 556We&#x27;ll be back shortly.Thank you for your patience!
 557&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 558&lt;p&gt;Oh come on. After waiting for the next day, I headed over, downloaded their software, tried to install it and it was an awful experience. It felt like I was purposedly installing malware. It spammed and flashed a lot of &lt;code&gt;cmd&lt;&#x2F;code&gt;&#x27;s on screen as if it was a virus. It was stuck at 100% doing that and then, Windows blue-screened with &lt;code&gt;KERNEL_MODE_HEAP_CORRUPTION&lt;&#x2F;code&gt;. Amazing. How do you screw up this bad?&lt;&#x2F;p&gt;
 559&lt;p&gt;Well, at least rebooting worked. I tried to &lt;a href=&quot;https:&#x2F;&#x2F;answers.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;forum&#x2F;all&#x2F;unable-to-uninstall-asus-aura-sync-utility&#x2F;e9bec36c-e62f-4773-80be-88fb68dace16&quot;&gt;uninstall Aura, but of course that failed&lt;&#x2F;a&gt;. Using the &lt;a href=&quot;https:&#x2F;&#x2F;support.microsoft.com&#x2F;en-us&#x2F;help&#x2F;17588&#x2F;windows-fix-problems-that-block-programs-being-installed-or-removed&quot;&gt;troubleshooter to uninstall programs&lt;&#x2F;a&gt; helped me remove most of the crap that was installed.&lt;&#x2F;p&gt;
 560&lt;p&gt;After searching around how to disable the lights (because &lt;a href=&quot;https:&#x2F;&#x2F;rog.asus.com&#x2F;forum&#x2F;showthread.php?112786-Option-to-Disable-Aura-Lights-on-Strix-G-series-(G531GT)-irrespective-of-OSes&quot;&gt;my BIOS did not have this setting&lt;&#x2F;a&gt;), I stumbled upon &lt;a href=&quot;https:&#x2F;&#x2F;rog.asus.com&#x2F;us&#x2F;innovation&#x2F;armoury_crate&#x2F;&quot;&gt;&amp;quot;Armoury Crate&amp;quot;&lt;&#x2F;a&gt;. Okay, fine, I will install that.&lt;&#x2F;p&gt;
 561&lt;p&gt;The experience wasn&#x27;t much better. It did the same thing with a lot of consoles flashing on screen. And of course, it resulted in another blue-screen, this time &lt;code&gt;KERNEL_SECURITY_CHECK_FAILURE&lt;&#x2F;code&gt;. To finish up, the BSOD kept happening as I rebooted the system. &lt;del&gt;Time to reinstall Windows once more.&lt;&#x2F;del&gt; After booting and crashing a few more times I could get into secure mode and perform the reinstall from there, which saved me from burning the &lt;code&gt;.iso&lt;&#x2F;code&gt; again.&lt;&#x2F;p&gt;
 562&lt;p&gt;Asus software might be good, but the software is utter crap.&lt;&#x2F;p&gt;
 563&lt;p&gt;After trying out &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;wroberts&#x2F;rogauracore&quot;&gt;rogauracore&lt;&#x2F;a&gt; (which didn&#x27;t list my model), it worked! I could disable the stupid lights from Linux, and &lt;a href=&quot;https:&#x2F;&#x2F;gitlab.com&#x2F;CalcProgrammer1&#x2F;OpenRGB&#x2F;-&#x2F;wikis&#x2F;home&quot;&gt;OpenRGB&lt;&#x2F;a&gt; also works on Windows which may be worth checking out too.&lt;&#x2F;p&gt;
 564&lt;p&gt;Because &lt;code&gt;rougauracore&lt;&#x2F;code&gt; helped me and they linked to &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;linuxhw&#x2F;hw-probe&#x2F;blob&#x2F;master&#x2F;README.md#appimage&quot;&gt;hw-probe&lt;&#x2F;a&gt;, I decided to &lt;a href=&quot;https:&#x2F;&#x2F;linux-hardware.org&#x2F;?probe=0e3e48c501&quot;&gt;run it on my system&lt;&#x2F;a&gt;, with the hopes it is useful for other people.&lt;&#x2F;p&gt;
 565&lt;h2 id=&quot;closing-words&quot;&gt;Closing words&lt;&#x2F;h2&gt;
 566&lt;p&gt;I hope the installation journey is at least useful to someone, or that you enjoyed reading about it all. If not, sorry!&lt;&#x2F;p&gt;
 567</content>
 568	</entry>
 569	<entry xml:lang="en">
 570		<title>Tips for Outpost</title>
 571		<published>2020-05-10T00:00:00+00:00</published>
 572		<updated>2020-05-22T00:00:00+00:00</updated>
 573		<link href="https://lonami.dev/blog/tips-outpost/" type="text/html"/>
 574		<id>https://lonami.dev/blog/tips-outpost/</id>
 575		<content type="html">&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;store.steampowered.com&#x2F;app&#x2F;1127110&#x2F;Outpost&#x2F;&quot;&gt;Outpost&lt;&#x2F;a&gt; is a fun little game by Open Mid Interactive that has popped in recently in my recommended section of Steam, and I decided to give it a try.&lt;&#x2F;p&gt;
 576&lt;p&gt;It&#x27;s a fun tower-defense game with progression, different graphics and random world generation which makes it quite fun for a few hours. In this post I want to talk about some tips I found useful to get past night 50.&lt;&#x2F;p&gt;
 577&lt;h2 id=&quot;build-pattern&quot;&gt;Build Pattern&lt;&#x2F;h2&gt;
 578&lt;p&gt;At first, you may be inclined to design a checkerboard pattern like the following, where &amp;quot;C&amp;quot; is the Crystal shrine, &amp;quot;S&amp;quot; is a stone launcher and &amp;quot;B&amp;quot; is a booster:&lt;&#x2F;p&gt;
 579&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;tips-outpost&#x2F;outpost-bad-pattern.svg&quot; alt=&quot;Bad Outpost build pattern&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
 580&lt;p&gt;Indeed, this pattern will apply &lt;strong&gt;4&lt;&#x2F;strong&gt; boosts to every turret, but unfortunately, the other 4 slots of the booster are wasted! This is because boosters are able to power 8 different towers, and you really want to maximize that. Here&#x27;s a better design:&lt;&#x2F;p&gt;
 581&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;tips-outpost&#x2F;outpost-good-pattern.svg&quot; alt=&quot;Good Outpost build pattern&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
 582&lt;p&gt;The shrine&#x27;s tower does get boosted, but it&#x27;s still not really worth it to boost it. This pattern works good, and it&#x27;s really easy to tile: just repeat the same 3x3 pattern.&lt;&#x2F;p&gt;
 583&lt;p&gt;Nonetheless, we can do better. What if we applied multiple boosters to the same tower while still applying all 8 boosts?&lt;&#x2F;p&gt;
 584&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;tips-outpost&#x2F;outpost-best-pattern.svg&quot; alt=&quot;Best Outpost build pattern&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
 585&lt;p&gt;That&#x27;s what peak performance looks like. You can actually apply multiple boosters to the same tower, and it works great.&lt;&#x2F;p&gt;
 586&lt;p&gt;Now, is it really worth it building anywhere except around the shrine? Not really. You never know where a boss will come from, so all sides need a lot of defense if you want to stand a chance.&lt;&#x2F;p&gt;
 587&lt;p&gt;The addition of traps in 1.6 is amazing. You want to build these outside your strong &amp;quot;core&amp;quot;, mostly to slow the enemies down so your turrets have more time to finish them off. Don&#x27;t waste boosters on the traps, and build them at a reasonable distance from the center (the sixth tile is a good spot):&lt;&#x2F;p&gt;
 588&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;tips-outpost&#x2F;outpost-trap-pattern.svg&quot; alt=&quot;Trap Outpost build pattern&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
 589&lt;p&gt;If you gather enough materials, you can build more trap and cannon layers outside, roughly at enough distance to slow them for enough duration until they reach the next layer of traps, and so on. Probably a single gap of &amp;quot;cannon, booster, cannon&amp;quot; is enough between trap layers, just not in the center where you need a lot of fire power.&lt;&#x2F;p&gt;
 590&lt;h2 id=&quot;talents&quot;&gt;Talents&lt;&#x2F;h2&gt;
 591&lt;p&gt;Talents are the way progression works in the game. Generally, after a run, you will have enough experience to upgrade nearly all talents of roughly the same tier. However, some are worth upgrading more than others (which provide basically no value).&lt;&#x2F;p&gt;
 592&lt;p&gt;The best ones to upgrade are:&lt;&#x2F;p&gt;
 593&lt;ul&gt;
 594&lt;li&gt;Starting supplies. Amazing to get good tools early.&lt;&#x2F;li&gt;
 595&lt;li&gt;Shrine shield. Very useful to hold against tough bosses.&lt;&#x2F;li&gt;
 596&lt;li&gt;Better buildings (cannon, boosters, bed and traps). They&#x27;re a must to deal the most damage.&lt;&#x2F;li&gt;
 597&lt;li&gt;Better pickaxe. Stone is limited, so better make good use of it.&lt;&#x2F;li&gt;
 598&lt;li&gt;Better chests. They provide an insane amount of resources early.&lt;&#x2F;li&gt;
 599&lt;li&gt;Winter slow. Turrets will have more time to deal damage, it&#x27;s perfect.&lt;&#x2F;li&gt;
 600&lt;li&gt;More time. Useful if you&#x27;re running out, although generally you enter nights early after having a good core anyway.&lt;&#x2F;li&gt;
 601&lt;li&gt;More rocks. Similar to a better pickaxe, more stone is always better.&lt;&#x2F;li&gt;
 602&lt;&#x2F;ul&gt;
 603&lt;p&gt;Some decent ones:&lt;&#x2F;p&gt;
 604&lt;ul&gt;
 605&lt;li&gt;In-shrine turret. It&#x27;s okay to get past the first night without building but not much beyond that.&lt;&#x2F;li&gt;
 606&lt;li&gt;Better axe and greaves. Great to save some energy and really nice quality of life to move around.&lt;&#x2F;li&gt;
 607&lt;li&gt;Tree growth. Normally there&#x27;s enough trees for this not to be an issue but it can save some time gathering wood.&lt;&#x2F;li&gt;
 608&lt;li&gt;Wisps. They&#x27;re half-decent since they can provide materials once you max out or max out expensive gear.&lt;&#x2F;li&gt;
 609&lt;&#x2F;ul&gt;
 610&lt;p&gt;Some okay ones:&lt;&#x2F;p&gt;
 611&lt;ul&gt;
 612&lt;li&gt;Extra XP while playing. Generally not needed due to the way XP scales per night, but can be a good boost.&lt;&#x2F;li&gt;
 613&lt;li&gt;Runestones. Not as reliable as chests but some can grant more energy per day.&lt;&#x2F;li&gt;
 614&lt;&#x2F;ul&gt;
 615&lt;p&gt;Some crap ones:&lt;&#x2F;p&gt;
 616&lt;ul&gt;
 617&lt;li&gt;Boosts for other seasons. I mean, winter is already the best, no use there.&lt;&#x2F;li&gt;
 618&lt;li&gt;Bow. The bow is very useless at the moment, it&#x27;s not worth your experience.&lt;&#x2F;li&gt;
 619&lt;li&gt;More energy per bush. Not really worth hunting for bushes since you will have enough energy to do well.&lt;&#x2F;li&gt;
 620&lt;&#x2F;ul&gt;
 621&lt;h2 id=&quot;turrets&quot;&gt;Turrets&lt;&#x2F;h2&gt;
 622&lt;p&gt;Always build the highest tier, there&#x27;s no point in anything lower than that. You will need to deal a lot of damage in a small area, which means space is a premium.&lt;&#x2F;p&gt;
 623&lt;h2 id=&quot;boosters&quot;&gt;Boosters&lt;&#x2F;h2&gt;
 624&lt;p&gt;If you&#x27;re very early in the game, I recommend alternating both the flag and torch in a checkerboard pattern where the boosters should go in the pattern above. This way your towers will get extra speed and extra range, which works great.&lt;&#x2F;p&gt;
 625&lt;p&gt;When you&#x27;re in mid-game (stone launchers, gears and campfires), I do not recommend using campfires. The issue is their range boost is way too long, and the turrets will miss quite a few shots. It&#x27;s better to put all your power into fire speed for increased DPS, at least near the center. If you manage to build too far out and some of the turrets hardly ever shoot, you may put campfires there.&lt;&#x2F;p&gt;
 626&lt;p&gt;In end-game, of course alternate both of the highest tier upgrades. They are really good, and provide the best benefit &#x2F; cost ratio.&lt;&#x2F;p&gt;
 627&lt;h2 id=&quot;gathering-materials&quot;&gt;Gathering Materials&lt;&#x2F;h2&gt;
 628&lt;p&gt;It is &lt;strong&gt;very&lt;&#x2F;strong&gt; important to use all your energy every day! Otherwise it will go to waste, and you will need a lot of materials.&lt;&#x2F;p&gt;
 629&lt;p&gt;As of 1.6, you can mine two things at once if they&#x27;re close enough! I don&#x27;t know if this is intended or a bug, but it sure is great.&lt;&#x2F;p&gt;
 630&lt;p&gt;Once you&#x27;re in mid-game, your stone-based fort should stand pretty well against the nights on its own. After playing for a while you will notice, if your base can defend a boss, then it will have no issue carrying you through the nights until the next boss. You can (and should!) spend the nights gathering materials, but only when you&#x27;re confident that the night won&#x27;t run out.&lt;&#x2F;p&gt;
 631&lt;p&gt;Before the boss hits (every fifth night), come back to your base and use all of your materials. This is the next fort upgrade that will carry it the five next nights.&lt;&#x2F;p&gt;
 632&lt;p&gt;You may also speed up time during night, but make sure you use all your energy before hand. And also take care, in the current version of the game speeding up time only speeds up monster movement, not the fire rate or projectile speed of your turrets! This means they will miss more shots and can be pretty dangerous. If you&#x27;re speeding up time, consider speeding it up for a little bit, then go back to normal until things are more calm, and repeat.&lt;&#x2F;p&gt;
 633&lt;p&gt;If you&#x27;re in the end-game, try to rush for chests. They provide a huge amount of materials which is really helpful to upgrade all your tools early so you can make sure to get the most out of every rock left in the map.&lt;&#x2F;p&gt;
 634&lt;p&gt;In the end-game, after all stone has been collected, you don&#x27;t really need to use all of your energy anymore. Just enough to have enough wood to build with the remaining stone. This will also be nice with the bow upgrades, which admitedly can get quite powerful, but it&#x27;s best to have a strong fort first.&lt;&#x2F;p&gt;
 635&lt;h2 id=&quot;season&quot;&gt;Season&lt;&#x2F;h2&gt;
 636&lt;p&gt;In my opinion, winter is just the best of the seasons. You don&#x27;t &lt;em&gt;really&lt;&#x2F;em&gt; need that much energy (it gets tiresome), or extra tree drops, or luck. Slower movement means your turrets will be able to shoot enemies for longer, dealing more damage over time, giving them more chance to take enemies out before they reach the shrine.&lt;&#x2F;p&gt;
 637&lt;p&gt;Feel free to re-roll the map a few times (play and exit, or even restart the game) until you get winter if you want to go for The Play.&lt;&#x2F;p&gt;
 638&lt;h2 id=&quot;gear&quot;&gt;Gear&lt;&#x2F;h2&gt;
 639&lt;p&gt;In my opinion, you really should rush for the best pickaxe you can afford. Stone is a limited resource that doesn&#x27;t regrow like trees, so once you run out, it&#x27;s over. Better to make the best use out of it with a good pickaxe!&lt;&#x2F;p&gt;
 640&lt;p&gt;You may also upgrade your greaves, we all known faster movement is a &lt;em&gt;really&lt;&#x2F;em&gt; nice quality of life improvement.&lt;&#x2F;p&gt;
 641&lt;p&gt;Of course, you will eventually upgrade your axe to chop wood (otherwise it&#x27;s wasted energy, really), but it&#x27;s not as much of a priority as the pickaxe.&lt;&#x2F;p&gt;
 642&lt;p&gt;Now, the bow is completely useless. Don&#x27;t bother with it. Your energy is better spent gathering materials to build permanent turrets that deal constant damage while you&#x27;re away, and the damage adds up with every extra turret you build.&lt;&#x2F;p&gt;
 643&lt;p&gt;With regards to items you carry (like sword, or helmet), look for these (from best to worst):&lt;&#x2F;p&gt;
 644&lt;ul&gt;
 645&lt;li&gt;Less minion life.&lt;&#x2F;li&gt;
 646&lt;li&gt;Chance to not consume energy.&lt;&#x2F;li&gt;
 647&lt;li&gt;+1 turret damage.&lt;&#x2F;li&gt;
 648&lt;li&gt;Extra energy.&lt;&#x2F;li&gt;
 649&lt;li&gt;+1 drop from trees or stones.&lt;&#x2F;li&gt;
 650&lt;li&gt;+1 free wood or stone per day.&lt;&#x2F;li&gt;
 651&lt;&#x2F;ul&gt;
 652&lt;p&gt;Less minion life, nothing to say. You will need it near end-game.&lt;&#x2F;p&gt;
 653&lt;p&gt;The chance to not consume energy is better the more energy you have. With a 25% chance not to consume energy, you can think of it as 1 extra energy for every 4 energy you have on average.&lt;&#x2F;p&gt;
 654&lt;p&gt;Turret damage is a tough one, it&#x27;s &lt;em&gt;amazing&lt;&#x2F;em&gt; mid-game (it basically doubles your damage) but falls short once you unlock the cannon where you may prefer other items. Definitely recommended if you&#x27;re getting started. You may even try to roll it on low tiers by dying on the second night, because it&#x27;s that good.&lt;&#x2F;p&gt;
 655&lt;p&gt;Extra energy is really good, because it means you can get more materials before it gets too rough. Make sure you have built at least two beds in the first night! This extra energy will pay of for the many nights to come.&lt;&#x2F;p&gt;
 656&lt;p&gt;The problem with free wood or stone per day is that you have, often, five times as much energy per day. By this I mean you can get easily 5 stone every day, which means 5 extra stone, whereas the other would provide just 1 per night. On a good run, you will get around 50 free stone or 250 extra stone. It&#x27;s a clear winner.&lt;&#x2F;p&gt;
 657&lt;p&gt;In end-game, more quality of life are revealing chests so that you can rush them early, if you like to hunt for them try to make better use of the slot.&lt;&#x2F;p&gt;
 658&lt;h2 id=&quot;closing-words&quot;&gt;Closing words&lt;&#x2F;h2&gt;
 659&lt;p&gt;I hope you enjoy the game as much as I do! Movement is sometimes janky and there&#x27;s the occassional lag spikes, but despite this it should provide at least a few good hours of gameplay. Beware however a good run can take up to an hour!&lt;&#x2F;p&gt;
 660</content>
 661	</entry>
 662	<entry xml:lang="en">
 663		<title>Python ctypes and Windows</title>
 664		<published>2019-06-19T00:00:00+00:00</published>
 665		<updated>2019-06-19T00:00:00+00:00</updated>
 666		<link href="https://lonami.dev/blog/ctypes-and-windows/" type="text/html"/>
 667		<id>https://lonami.dev/blog/ctypes-and-windows/</id>
 668		<content type="html">&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.python.org&#x2F;&quot;&gt;Python&lt;&#x2F;a&gt;&#x27;s &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;ctypes.html&quot;&gt;&lt;code&gt;ctypes&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; is quite a nice library to easily load and invoke C methods available in already-compiled &lt;a href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Dynamic-link_library&quot;&gt;&lt;code&gt;.dll&lt;&#x2F;code&gt; files&lt;&#x2F;a&gt; without any additional dependencies. And I &lt;em&gt;love&lt;&#x2F;em&gt; depending on as little as possible.&lt;&#x2F;p&gt;
 669&lt;p&gt;In this blog post, we will walk through my endeavors to use &lt;code&gt;ctypes&lt;&#x2F;code&gt; with the &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;api&#x2F;&quot;&gt;Windows API&lt;&#x2F;a&gt;, and do some cool stuff with it.&lt;&#x2F;p&gt;
 670&lt;p&gt;We will assume some knowledge of C&#x2F;++ and Python, since we will need to read and write a bit of both. Please note that this post is only an introduction to &lt;code&gt;ctypes&lt;&#x2F;code&gt;, and if you need more information you should consult the &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;ctypes.html&quot;&gt;Python&#x27;s documentation for &lt;code&gt;ctypes&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
 671&lt;p&gt;While the post focuses on Windows&#x27; API, the code here probably applies to unix-based systems with little modifications.&lt;&#x2F;p&gt;
 672&lt;h2 id=&quot;basics&quot;&gt;Basics&lt;&#x2F;h2&gt;
 673&lt;p&gt;First of all, let&#x27;s learn how to load a library. Let&#x27;s say we want to load &lt;code&gt;User32.dll&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
 674&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;import ctypes
 675
 676ctypes.windll.user32
 677&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 678&lt;p&gt;Yes, it&#x27;s that simple. When you access an attribute of &lt;code&gt;windll&lt;&#x2F;code&gt;, said library will load. Since Windows is case-insensitive, we will use lowercase consistently.&lt;&#x2F;p&gt;
 679&lt;p&gt;Calling a function is just as simple. Let&#x27;s say you want to call &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;api&#x2F;winuser&#x2F;nf-winuser-setcursorpos&quot;&gt;&lt;code&gt;SetCursorPos&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which is defined as follows:&lt;&#x2F;p&gt;
 680&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;BOOL SetCursorPos(
 681    int X,
 682    int Y
 683);
 684&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 685&lt;p&gt;Okay, it returns a &lt;code&gt;bool&lt;&#x2F;code&gt; and takes two inputs, &lt;code&gt;x&lt;&#x2F;code&gt; and &lt;code&gt;y&lt;&#x2F;code&gt;. So we can call it like so:&lt;&#x2F;p&gt;
 686&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;ctypes.windll.user32.SetCursorPos(100, 100)
 687&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 688&lt;p&gt;Try it! Your cursor will move!&lt;&#x2F;p&gt;
 689&lt;h2 id=&quot;funky-stuff&quot;&gt;Funky Stuff&lt;&#x2F;h2&gt;
 690&lt;p&gt;We can go a bit more crazy and make it form a spiral:&lt;&#x2F;p&gt;
 691&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;import math
 692import time
 693
 694for i in range(200):
 695    x = int(500 + math.cos(i &#x2F; 5) * i)
 696    y = int(500 + math.sin(i &#x2F; 5) * i)
 697    ctypes.windll.user32.SetCursorPos(x, y)
 698    time.sleep(0.05)
 699&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 700&lt;p&gt;Ah, it&#x27;s always so pleasant to do random stuff when programming. Sure makes it more fun.&lt;&#x2F;p&gt;
 701&lt;h2 id=&quot;complex-structures&quot;&gt;Complex Structures&lt;&#x2F;h2&gt;
 702&lt;p&gt;&lt;code&gt;SetCursorPos&lt;&#x2F;code&gt; was really simple. It took two parameters and they both were integers. Let&#x27;s go with something harder. Let&#x27;s go with &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;api&#x2F;winuser&#x2F;nf-winuser-sendinput&quot;&gt;&lt;code&gt;SendInput&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;! Emulating input will be a fun exercise:&lt;&#x2F;p&gt;
 703&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;UINT SendInput(
 704    UINT    cInputs,
 705    LPINPUT pInputs,
 706    int     cbSize
 707);
 708&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 709&lt;p&gt;Okay, &lt;code&gt;LPINPUT&lt;&#x2F;code&gt;, what are you? Microsoft likes to prefix types with what they are. In this case, &lt;code&gt;LP&lt;&#x2F;code&gt; stands for &amp;quot;Long Pointer&amp;quot; (I guess?), so &lt;code&gt;LPINPUT&lt;&#x2F;code&gt; is just a Long Pointer to &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;api&#x2F;winuser&#x2F;ns-winuser-taginput&quot;&gt;&lt;code&gt;INPUT&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
 710&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;typedef struct tagINPUT {
 711    DWORD type;
 712    union {
 713        MOUSEINPUT    mi;
 714        KEYBDINPUT    ki;
 715        HARDWAREINPUT hi;
 716    } DUMMYUNIONNAME;
 717} INPUT, *PINPUT, *LPINPUT;
 718&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 719&lt;p&gt;Alright, that&#x27;s new. We have a &lt;code&gt;struct&lt;&#x2F;code&gt; and &lt;code&gt;union&lt;&#x2F;code&gt;, two different concepts. We can define both with &lt;code&gt;ctypes&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
 720&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;INPUT_MOUSE = 0
 721INPUT_KEYBOARD = 1
 722INPUT_HARDWARE = 2
 723
 724class INPUT(ctypes.Structure):
 725    _fields_ = [
 726        (&#x27;type&#x27;, ctypes.c_long),
 727        ...
 728    ]
 729&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 730&lt;p&gt;Structures are classes that subclass &lt;code&gt;ctypes.Structure&lt;&#x2F;code&gt;, and you define their fields in the &lt;code&gt;_fields_&lt;&#x2F;code&gt; class-level variable, which is a list of tuples &lt;code&gt;(field name, field type)&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
 731&lt;p&gt;The C structure had a &lt;code&gt;DWORD type&lt;&#x2F;code&gt;. &lt;code&gt;DWORD&lt;&#x2F;code&gt; is a &lt;code&gt;c_long&lt;&#x2F;code&gt;, and &lt;code&gt;type&lt;&#x2F;code&gt; is a name like any other, which is why we did &lt;code&gt;(&#x27;type&#x27;, ctypes.c_long)&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
 732&lt;p&gt;But what about the union? It&#x27;s anonymous, and we can&#x27;t make anonymous unions (&lt;em&gt;citation needed&lt;&#x2F;em&gt;) with &lt;code&gt;ctypes&lt;&#x2F;code&gt;. We will give it a concrete name and a type.&lt;&#x2F;p&gt;
 733&lt;p&gt;Before defining the union, we need to define its inner structures, &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;api&#x2F;winuser&#x2F;ns-winuser-tagmouseinput&quot;&gt;&lt;code&gt;MOUSEINPUT&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;api&#x2F;winuser&#x2F;ns-winuser-tagkeybdinput&quot;&gt;&lt;code&gt;KEYBDINPUT&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;api&#x2F;winuser&#x2F;ns-winuser-taghardwareinput&quot;&gt;&lt;code&gt;HARDWAREINPUT&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;. We won&#x27;t be using them all, but since they count towards the final struct size (C will choose the largest structure as the final size), we need them, or Windows&#x27; API will get confused and refuse to work (personal experience):&lt;&#x2F;p&gt;
 734&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;class MOUSEINPUT(ctypes.Structure):
 735    _fields_ = [
 736        (&#x27;dx&#x27;, ctypes.c_long),
 737        (&#x27;dy&#x27;, ctypes.c_long),
 738        (&#x27;mouseData&#x27;, ctypes.c_long),
 739        (&#x27;dwFlags&#x27;, ctypes.c_long),
 740        (&#x27;time&#x27;, ctypes.c_long),
 741        (&#x27;dwExtraInfo&#x27;, ctypes.POINTER(ctypes.c_ulong))
 742    ]
 743
 744
 745class KEYBDINPUT(ctypes.Structure):
 746    _fields_ = [
 747        (&#x27;wVk&#x27;, ctypes.c_short),
 748        (&#x27;wScan&#x27;, ctypes.c_short),
 749        (&#x27;dwFlags&#x27;, ctypes.c_long),
 750        (&#x27;time&#x27;, ctypes.c_long),
 751        (&#x27;dwExtraInfo&#x27;, ctypes.POINTER(ctypes.c_ulong))
 752    ]
 753
 754
 755class HARDWAREINPUT(ctypes.Structure):
 756    _fields_ = [
 757        (&#x27;uMsg&#x27;, ctypes.c_long),
 758        (&#x27;wParamL&#x27;, ctypes.c_short),
 759        (&#x27;wParamH&#x27;, ctypes.c_short)
 760    ]
 761
 762
 763class INPUTUNION(ctypes.Union):
 764    _fields_ = [
 765        (&#x27;mi&#x27;, MOUSEINPUT),
 766        (&#x27;ki&#x27;, KEYBDINPUT),
 767        (&#x27;hi&#x27;, HARDWAREINPUT)
 768    ]
 769
 770
 771class INPUT(ctypes.Structure):
 772    _fields_ = [
 773        (&#x27;type&#x27;, ctypes.c_long),
 774        (&#x27;value&#x27;, INPUTUNION)
 775    ]
 776&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 777&lt;p&gt;Some things to note:&lt;&#x2F;p&gt;
 778&lt;ul&gt;
 779&lt;li&gt;Pointers are defined as &lt;code&gt;ctypes.POINTER(inner type)&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
 780&lt;li&gt;The field names can be anything you want. You can make them more &amp;quot;pythonic&amp;quot; if you want (such as changing &lt;code&gt;dwExtraInfo&lt;&#x2F;code&gt; for just &lt;code&gt;extra_info&lt;&#x2F;code&gt;), but I chose to stick with the original naming.&lt;&#x2F;li&gt;
 781&lt;li&gt;The union is very similar, but it uses &lt;code&gt;ctypes.Union&lt;&#x2F;code&gt; instead of &lt;code&gt;ctypes.Structure&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
 782&lt;li&gt;We gave a name to the anonymous union, &lt;code&gt;INPUTUNION&lt;&#x2F;code&gt;, and used it inside &lt;code&gt;INPUT&lt;&#x2F;code&gt; with also a made-up name, &lt;code&gt;(&#x27;value&#x27;, INPUTUNION)&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
 783&lt;&#x2F;ul&gt;
 784&lt;p&gt;Now that we have all the types we need defined, we can use them:&lt;&#x2F;p&gt;
 785&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;KEYEVENTF_KEYUP = 0x0002
 786
 787def press(vk, down):
 788    inputs = INPUT(type=INPUT_KEYBOARD, value=INPUTUNION(ki=KEYBDINPUT(
 789        wVk=vk,
 790        wScan=0,
 791        dwFlags=0 if down else KEYEVENTF_KEYUP,
 792        time=0,
 793        dwExtraInfo=None
 794    )))
 795    ctypes.windll.user32.SendInput(1, ctypes.byref(inputs), ctypes.sizeof(inputs))
 796
 797
 798for char in &#x27;HELLO&#x27;:
 799    press(ord(char), down=True)
 800    press(ord(char), down=False)
 801&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 802&lt;p&gt;Run it! It will press and release the keys &lt;code&gt;hello&lt;&#x2F;code&gt; to type the word &lt;code&gt;&amp;quot;hello&amp;quot;&lt;&#x2F;code&gt;!&lt;&#x2F;p&gt;
 803&lt;p&gt;&lt;code&gt;vk&lt;&#x2F;code&gt; stands for &amp;quot;virtual key&amp;quot;. Letters correspond with their upper-case ASCII value, which is what we did above. You can find all the available keys in the page with all the &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;inputdev&#x2F;virtual-key-codes&quot;&gt;Virtual Key Codes&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
 804&lt;h2 id=&quot;dynamic-inputs-and-pointers&quot;&gt;Dynamic Inputs and Pointers&lt;&#x2F;h2&gt;
 805&lt;p&gt;What happens if a method wants something by reference? That is, a pointer to your thing? For example, &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;api&#x2F;winuser&#x2F;nf-winuser-getcursorpos&quot;&gt;&lt;code&gt;GetCursorPos&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
 806&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;typedef struct tagPOINT {
 807    LONG x;
 808    LONG y;
 809} POINT, *PPOINT, *NPPOINT, *LPPOINT;
 810
 811BOOL GetCursorPos(
 812    LPPOINT lpPoint
 813);
 814&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 815&lt;p&gt;It wants a Long Pointer to &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;desktop&#x2F;api&#x2F;windef&#x2F;ns-windef-point&quot;&gt;&lt;code&gt;POINT&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;. We can do just that with &lt;code&gt;ctypes.byref&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
 816&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;class POINT(ctypes.Structure):
 817    _fields_ = [
 818        (&#x27;x&#x27;, ctypes.c_long),
 819        (&#x27;y&#x27;, ctypes.c_long)
 820    ]
 821
 822
 823def get_mouse():
 824    point = POINT()
 825    ctypes.windll.user32.GetCursorPos(ctypes.byref(point))
 826    #                  pass our point by ref ^^^^^
 827    # this lets GetCursorPos fill its x and y fields
 828
 829    return point.x, point.y
 830
 831
 832while True:
 833    print(get_mouse())
 834    time.sleep(0.05)
 835&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 836&lt;p&gt;Now you can track the mouse position! Make sure to &lt;code&gt;Ctrl+C&lt;&#x2F;code&gt; the program when you&#x27;re tired of it.&lt;&#x2F;p&gt;
 837&lt;p&gt;What happens if a method wants a dynamically-sized input?&lt;&#x2F;p&gt;
 838&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;buffer = ctypes.create_string_buffer(size)
 839&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 840&lt;p&gt;In that case, you can create an in-memory &lt;code&gt;buffer&lt;&#x2F;code&gt; of &lt;code&gt;size&lt;&#x2F;code&gt; with &lt;code&gt;ctypes.create_string_buffer&lt;&#x2F;code&gt;. It will return a character array of that size, which you can pass as a pointer directly (without &lt;code&gt;ctypes.byref&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
 841&lt;p&gt;To access the buffer&#x27;s contents, you can use either &lt;code&gt;.raw&lt;&#x2F;code&gt; or &lt;code&gt;.value&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
 842&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;entire_buffer_as_bytes = buffer.raw
 843up_until_null = buffer.value
 844&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 845&lt;p&gt;When the method fills in the data, you can &lt;code&gt;cast&lt;&#x2F;code&gt; your buffer back into a pointer of a concrete type:&lt;&#x2F;p&gt;
 846&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;result_ptr = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_long))
 847&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 848&lt;p&gt;And you can de-reference pointers with &lt;code&gt;.contents&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
 849&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;first_result = result_ptr.contents
 850&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 851&lt;h2 id=&quot;arrays&quot;&gt;Arrays&lt;&#x2F;h2&gt;
 852&lt;p&gt;Arrays are defined as &lt;code&gt;type * size&lt;&#x2F;code&gt;. Your linter may not like that, and if you don&#x27;t know the size beforehand, consider creating a 0-sized array. For example:&lt;&#x2F;p&gt;
 853&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;# 10 longs
 854ten_longs = (ctypes.c_long * 10)()
 855for i in range(10):
 856    ten_longs[i] = 2 ** i
 857
 858# Unknown size of longs, e.g. inside some Structure
 859longs = (ctypes.c_long * 0)
 860
 861# Now you know how many longs it actually was
 862known_longs = ctypes.cast(
 863    ctypes.byref(longs),
 864    ctypes.POINTER(ctypes.c_long * size)
 865).contents
 866&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 867&lt;p&gt;If there&#x27;s a better way to initialize arrays, please let me know.&lt;&#x2F;p&gt;
 868&lt;h2 id=&quot;wintypes&quot;&gt;wintypes&lt;&#x2F;h2&gt;
 869&lt;p&gt;Under Windows, the &lt;code&gt;ctypes&lt;&#x2F;code&gt; module has a &lt;code&gt;wintypes&lt;&#x2F;code&gt; submodule. This one contains definitions like &lt;code&gt;HWND&lt;&#x2F;code&gt; which may be useful and can be imported as:&lt;&#x2F;p&gt;
 870&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;from ctypes.wintypes import HWND, LPCWSTR, UINT
 871&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 872&lt;h2 id=&quot;callbacks&quot;&gt;Callbacks&lt;&#x2F;h2&gt;
 873&lt;p&gt;Some functions (I&#x27;m looking at you, &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;win32&#x2F;api&#x2F;winuser&#x2F;nf-winuser-enumwindows&quot;&gt;&lt;code&gt;EnumWindows&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;) ask us to pass a callback. In this case, it wants a &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;previous-versions&#x2F;windows&#x2F;desktop&#x2F;legacy&#x2F;ms633498(v=vs.85)&quot;&gt;&lt;code&gt;EnumWindowsProc&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
 874&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;BOOL EnumWindows(
 875    WNDENUMPROC lpEnumFunc,
 876    LPARAM      lParam
 877);
 878
 879BOOL CALLBACK EnumWindowsProc(
 880    _In_ HWND   hwnd,
 881    _In_ LPARAM lParam
 882);
 883&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 884&lt;p&gt;The naive approach won&#x27;t work:&lt;&#x2F;p&gt;
 885&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;def callback(hwnd, lParam):
 886    print(hwnd)
 887    return True
 888
 889ctypes.windll.user32.EnumWindows(callback, 0)
 890# ctypes.ArgumentError: argument 1: &amp;lt;class &#x27;TypeError&#x27;&amp;gt;: Don&#x27;t know how to convert parameter 1
 891# Aww.
 892&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 893&lt;p&gt;Instead, you must wrap your function as a C definition like so:&lt;&#x2F;p&gt;
 894&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;from ctypes.wintypes import BOOL, HWND, LPARAM
 895
 896EnumWindowsProc = ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM)
 897
 898def callback(hwnd, lParam):
 899    print(hwnd)
 900    return True
 901
 902# Wrap the function in the C definition
 903callback = EnumWindowsProc(callback)
 904
 905ctypes.windll.user32.EnumWindows(callback, 0)
 906# Yay, it works.
 907&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 908&lt;p&gt;You may have noticed this is what decorators do, wrap the function. So…&lt;&#x2F;p&gt;
 909&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;from ctypes.wintypes import BOOL, HWND, LPARAM
 910
 911@ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM)
 912def callback(hwnd, lParam):
 913    print(hwnd)
 914    return True
 915
 916ctypes.windll.user32.EnumWindows(callback, 0)
 917&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 918&lt;p&gt;…will also work. And it is a &lt;em&gt;lot&lt;&#x2F;em&gt; fancier.&lt;&#x2F;p&gt;
 919&lt;h2 id=&quot;closing-words&quot;&gt;Closing Words&lt;&#x2F;h2&gt;
 920&lt;p&gt;With the knowledge above and some experimentation, you should be able to call and do (almost) anything you want. That was pretty much all I needed on my project anyway :)&lt;&#x2F;p&gt;
 921&lt;p&gt;We have been letting Python convert Python values into C values, but you can do so explicitly too. For example, you can use &lt;code&gt;ctypes.c_short(17)&lt;&#x2F;code&gt; to make sure to pass that &lt;code&gt;17&lt;&#x2F;code&gt; as a &lt;code&gt;short&lt;&#x2F;code&gt;. And if you have a &lt;code&gt;c_short&lt;&#x2F;code&gt;, you can convert or cast it to its Python &lt;code&gt;.value&lt;&#x2F;code&gt; as &lt;code&gt;some_short.value&lt;&#x2F;code&gt;. The same applies for integers, longs, floats, doubles… pretty much anything, char pointers (strings) included.&lt;&#x2F;p&gt;
 922&lt;p&gt;If you can&#x27;t find something in their online documentation, you can always &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;ripgrep&quot;&gt;&lt;code&gt;rg&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; for it in the &lt;code&gt;C:\Program Files (x86)\Windows Kits\10\Include\*&lt;&#x2F;code&gt; directory.&lt;&#x2F;p&gt;
 923&lt;p&gt;Note that the &lt;code&gt;ctypes.Structure&lt;&#x2F;code&gt;&#x27;s that you define can have more methods of your own. For example, you can write them a &lt;code&gt;__str__&lt;&#x2F;code&gt; to easily view its fields, or define a &lt;code&gt;@property&lt;&#x2F;code&gt; to re-interpret some data in a meaningful way.&lt;&#x2F;p&gt;
 924&lt;p&gt;For enumerations, you can pass just the right integer number, make a constant for it, or if you prefer, use a &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;enum.html#enum.IntEnum&quot;&gt;&lt;code&gt;enum.IntEnum&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;. For example, &lt;a href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows-hardware&#x2F;manufacture&#x2F;desktop&#x2F;dism&#x2F;dismloglevel-enumeration&quot;&gt;&lt;code&gt;DismLogLevel&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; would be:&lt;&#x2F;p&gt;
 925&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;class DismLogLevel(enum.IntEnum):
 926    DismLogErrors = 0
 927    DismLogErrorsWarnings = 1
 928    DismLogErrorsWarningsInfo = 2
 929&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
 930&lt;p&gt;And you &lt;em&gt;should&lt;&#x2F;em&gt; be able to pass &lt;code&gt;DismLogLevel.DismLogErrors&lt;&#x2F;code&gt; as the parameter now.&lt;&#x2F;p&gt;
 931&lt;p&gt;If you see a function definition like &lt;code&gt;Function(void)&lt;&#x2F;code&gt;, that&#x27;s C&#x27;s way of saying it takes no parameters, so just call it as &lt;code&gt;Function()&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
 932&lt;p&gt;Make sure to pass all parameters, even if they seem optional they probably still want a &lt;code&gt;NULL&lt;&#x2F;code&gt; at least, and of course, read the documentation well. Some methods have certain pre-conditions.&lt;&#x2F;p&gt;
 933&lt;p&gt;Have fun hacking!&lt;&#x2F;p&gt;
 934</content>
 935	</entry>
 936	<entry xml:lang="en">
 937		<title>Shattered Pixel Dungeon</title>
 938		<published>2019-06-03T00:00:00+00:00</published>
 939		<updated>2019-06-03T00:00:00+00:00</updated>
 940		<link href="https://lonami.dev/blog/pixel-dungeon/" type="text/html"/>
 941		<id>https://lonami.dev/blog/pixel-dungeon/</id>
 942		<content type="html">&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;shatteredpixel.com&#x2F;shatteredpd&#x2F;&quot;&gt;Shattered Pixel Dungeon&lt;&#x2F;a&gt; is the classic roguelike RPG game with randomly-generated dungeons. As a new player, it was a bit frustrating to be constantly killed on the first levels of the dungeon, but with some practice it&#x27;s easy to reach high levels if you can kill the first boss.&lt;&#x2F;p&gt;
 943&lt;h2 id=&quot;basic-tips&quot;&gt;Basic Tips&lt;&#x2F;h2&gt;
 944&lt;p&gt;The game comes with its own tips, but here&#x27;s a short and straight-forward summary:&lt;&#x2F;p&gt;
 945&lt;ul&gt;
 946&lt;li&gt;&lt;strong&gt;Don&#x27;t rush into enemies&lt;&#x2F;strong&gt;. Abuse doors and small corridors to kill them one by one. You can use the clock on the bottom left to wait a turn without moving.&lt;&#x2F;li&gt;
 947&lt;li&gt;&lt;strong&gt;Explore each level at full&lt;&#x2F;strong&gt;. You will find goodies and gain XP while doing so.&lt;&#x2F;li&gt;
 948&lt;li&gt;&lt;strong&gt;Upon finding a special room&lt;&#x2F;strong&gt; (e.g. has a chest but is protected by piranhas), drink all potions that you found in that level until there&#x27;s one that helps you (e.g. be invisible so piranhas leave you alone). There is guaranteed to be a helpful one per level with special rooms.&lt;&#x2F;li&gt;
 949&lt;li&gt;&lt;strong&gt;Drink potions as early as possible&lt;&#x2F;strong&gt;. Harmful potions do less damage on early levels (and if you die, you lose less). This will keep them identified early for the rest of the game.&lt;&#x2F;li&gt;
 950&lt;li&gt;&lt;strong&gt;Read scrolls as early as possible&lt;&#x2F;strong&gt; as well. This will keep them identified. It may be worth to wait until you have an item which may be cursed and until the level is clear, because some scrolls clean curses and others alert enemies.&lt;&#x2F;li&gt;
 951&lt;li&gt;&lt;strong&gt;Food and health are resources&lt;&#x2F;strong&gt; that you have to &lt;em&gt;manage&lt;&#x2F;em&gt;, not keep them always at full. Even if you are starving and taking damage, you may not need to eat &lt;em&gt;just yet&lt;&#x2F;em&gt;, since food is scarce. Eat when you are low on health or in possible danger.&lt;&#x2F;li&gt;
 952&lt;li&gt;&lt;strong&gt;Piranhas&lt;&#x2F;strong&gt;. Seriously, just leave them alone if you are melee. They&#x27;re free food if you&#x27;re playing ranged, though.&lt;&#x2F;li&gt;
 953&lt;li&gt;&lt;strong&gt;Prefer armor over weapons&lt;&#x2F;strong&gt;. And make sure to identify or clean it from curses before wearing anything!&lt;&#x2F;li&gt;
 954&lt;li&gt;&lt;strong&gt;Find a dew vial early&lt;&#x2F;strong&gt;. It&#x27;s often a better idea to store dew (health) for later than to use it as soon as possible.&lt;&#x2F;li&gt;
 955&lt;&#x2F;ul&gt;
 956&lt;h2 id=&quot;bosses&quot;&gt;Bosses&lt;&#x2F;h2&gt;
 957&lt;p&gt;There is a boss every 5 levels.&lt;&#x2F;p&gt;
 958&lt;ul&gt;
 959&lt;li&gt;&lt;strong&gt;Level 5 boss&lt;&#x2F;strong&gt;. Try to stay on water, but don&#x27;t let &lt;em&gt;it&lt;&#x2F;em&gt; stay on water since it will heal. Be careful when he starts enraging.&lt;&#x2F;li&gt;
 960&lt;li&gt;&lt;strong&gt;Level 10 boss&lt;&#x2F;strong&gt;. Ranged weapons are good against it.&lt;&#x2F;li&gt;
 961&lt;li&gt;&lt;strong&gt;Level 15 boss&lt;&#x2F;strong&gt;. I somehow managed to tank it with a health potion.&lt;&#x2F;li&gt;
 962&lt;li&gt;&lt;strong&gt;Level 20 boss&lt;&#x2F;strong&gt;. I didn&#x27;t get this far just yet. You are advised to use scrolls of magic mapping in the last levels to skip straight to the boss, since there&#x27;s nothing else of value.&lt;&#x2F;li&gt;
 963&lt;li&gt;&lt;strong&gt;Level 25 boss&lt;&#x2F;strong&gt;. The final boss. Good job if you made it this far!&lt;&#x2F;li&gt;
 964&lt;&#x2F;ul&gt;
 965&lt;h2 id=&quot;mage&quot;&gt;Mage&lt;&#x2F;h2&gt;
 966&lt;p&gt;If you followed the basic tips, you will sooner or later make use of two scrolls of upgrade in a single run. This will unlock the mage class, which is ridiculously powerful. He starts with a ranged-weapon, a magic missile wand, which is really helpful to keep enemies at a distance. Normally, you want to use this at first to surprise attack them soon, and if you are low on charges, you may go melee on normal enemies if you are confident.&lt;&#x2F;p&gt;
 967&lt;h2 id=&quot;luck&quot;&gt;Luck&lt;&#x2F;h2&gt;
 968&lt;p&gt;This game is all about luck and patience! Some runs will be better than others, and you should thank and pray the RNG gods for them. If you don&#x27;t, they will only give you cursed items and not a single scroll to clean them. So, good luck and enjoy playing!&lt;&#x2F;p&gt;
 969</content>
 970	</entry>
 971	<entry xml:lang="en">
 972		<title>Installing NixOS, Take 2</title>
 973		<published>2019-02-15T00:00:00+00:00</published>
 974		<updated>2019-02-16T00:00:00+00:00</updated>
 975		<link href="https://lonami.dev/blog/installing-nixos-2/" type="text/html"/>
 976		<id>https://lonami.dev/blog/installing-nixos-2/</id>
 977		<content type="html">&lt;p&gt;This is my second take at installing NixOS, after a while being frustrated with Arch Linux and the fact that a few kernel upgrades ago, the system crashed randomly from time to time. &lt;code&gt;journalctl&lt;&#x2F;code&gt; did not have any helpful hints and I thought reinstalling could be worthwhile anyway.&lt;&#x2F;p&gt;
 978&lt;p&gt;This time, I started with more knowledge! The first step is heading to the &lt;a href=&quot;https:&#x2F;&#x2F;nixos.org&quot;&gt;NixOS website&lt;&#x2F;a&gt; and downloading their minimal installation CD for 64 bits. I didn&#x27;t go with their graphical live CD, because their &lt;a href=&quot;https:&#x2F;&#x2F;nixos.org&#x2F;nixos&#x2F;manual&quot;&gt;installation manual&lt;&#x2F;a&gt; is a wonderful resource that guides you nicely.&lt;&#x2F;p&gt;
 979&lt;p&gt;Once you have downloaded their &lt;code&gt;.iso&lt;&#x2F;code&gt;, you should probably verify it&#x27;s &lt;code&gt;sha256sum&lt;&#x2F;code&gt; and make sure that it matches. The easiest thing to do in my opinion is using an USB to burn the image in it. Plug it in and check its device name with &lt;code&gt;fdisk -l&lt;&#x2F;code&gt;. In my case, it was &lt;code&gt;&#x2F;dev&#x2F;sdb&lt;&#x2F;code&gt;, so I went ahead with it and ran &lt;code&gt;dd if=nixos.iso of=&#x2F;dev&#x2F;sdb status=progress&lt;&#x2F;code&gt;. Make sure to run &lt;code&gt;sync&lt;&#x2F;code&gt; once that&#x27;s done.&lt;&#x2F;p&gt;
 980&lt;p&gt;If either &lt;code&gt;dd&lt;&#x2F;code&gt; or &lt;code&gt;sync&lt;&#x2F;code&gt; seem &amp;quot;stuck&amp;quot; in the end, they are just flushing the changes to disk to make sure all is good. This is normal, and depends on your drives.&lt;&#x2F;p&gt;
 981&lt;p&gt;Now, reboot your computer with the USB plugged in and make sure to boot into it. You should be welcome with a pretty screen. Just select the first option and wait until it logs you in as root. Once you&#x27;re there you probably want to &lt;code&gt;loadkeys es&lt;&#x2F;code&gt; or whatever your keyboard layout is, or you will have a hard time with passwords, since the characters are all over the place.&lt;&#x2F;p&gt;
 982&lt;p&gt;In a clean disk, you would normally create the partitions now. In my case, I already had the partitions made (100MB for the EFI system, where &lt;code&gt;&#x2F;boot&lt;&#x2F;code&gt; lives, 40GB for the root &lt;code&gt;&#x2F;&lt;&#x2F;code&gt; partition with my old Linux installation, and 700G for &lt;code&gt;&#x2F;home&lt;&#x2F;code&gt;), so I didn&#x27;t need to do anything here. The manual showcases &lt;code&gt;parted&lt;&#x2F;code&gt;, but I personally use &lt;code&gt;fdisk&lt;&#x2F;code&gt;, which has very helpful help I check every time I use it.&lt;&#x2F;p&gt;
 983&lt;p&gt;&lt;strong&gt;Important&lt;&#x2F;strong&gt;: The &lt;code&gt;XY&lt;&#x2F;code&gt; in &lt;code&gt;&#x2F;dev&#x2F;sdXY&lt;&#x2F;code&gt; is probably different in your system! Make sure you use &lt;code&gt;fdisk -l&lt;&#x2F;code&gt; to see the correct letters and numbers!&lt;&#x2F;p&gt;
 984&lt;p&gt;With the partitions ready in my UEFI system, I formatted both &lt;code&gt;&#x2F;&lt;&#x2F;code&gt; and &lt;code&gt;&#x2F;boot&lt;&#x2F;code&gt; just to be safe with &lt;code&gt;mkfs.ext4 -L nixos &#x2F;dev&#x2F;sda2&lt;&#x2F;code&gt; and &lt;code&gt;mkfs.fat -F 32 -n boot &#x2F;dev&#x2F;sda1&lt;&#x2F;code&gt; (remember that these are the letters and numbers used in my partition scheme). Don&#x27;t worry about the warning in the second command regarding lowercase letters and Windows. It&#x27;s not really an issue.&lt;&#x2F;p&gt;
 985&lt;p&gt;Now, since we gave each partition a label, we can easily mount them through &lt;code&gt;mount &#x2F;dev&#x2F;disk&#x2F;by-label&#x2F;nixos &#x2F;mnt&lt;&#x2F;code&gt; and, in UEFI systems, be sure to &lt;code&gt;mkdir -p &#x2F;mnt&#x2F;boot&lt;&#x2F;code&gt; and &lt;code&gt;mount &#x2F;dev&#x2F;disk&#x2F;by-label&#x2F;boot &#x2F;mnt&#x2F;boot&lt;&#x2F;code&gt;. I didn&#x27;t bother setting up swap, since I have 8GB of RAM in my laptop and that&#x27;s really enough for my use case.&lt;&#x2F;p&gt;
 986&lt;p&gt;With that done, we will now ask the configuration wizard to do some work for us (in particular, generate a template) with &lt;code&gt;nixos-generate-config --root &#x2F;mnt&lt;&#x2F;code&gt;. This generates a very well documented file that we should edit right now (and this is important!) with whatever editor you prefer. I used &lt;code&gt;vim&lt;&#x2F;code&gt;, but you can change it for &lt;code&gt;nano&lt;&#x2F;code&gt; if you prefer.&lt;&#x2F;p&gt;
 987&lt;p&gt;On to the configuration file, we need to enable a few things, so &lt;code&gt;vim &#x2F;mnt&#x2F;etc&#x2F;nixos&#x2F;configuration.nix&lt;&#x2F;code&gt; and start scrolling down. We want to make sure to uncomment:&lt;&#x2F;p&gt;
 988&lt;pre&gt;&lt;code&gt;# We really want network!
 989networking.wireless.enable = true;
 990
 991# This &amp;quot;fixes&amp;quot; the keyboard layout. Put the one you use.
 992i18n = {
 993consoleKeyMap = &amp;quot;es&amp;quot;;
 994}
 995
 996# Timezones are tricky so let&#x27;s get this right.
 997time.timeZone = &amp;quot;Europe&#x2F;Madrid&amp;quot;;
 998
 999# We *really* want some base packages installed, such as
1000# wpa_supplicant, or we won&#x27;t have a way to connect to the
1001# network once we install...
1002environment.systemPackages = with pkgs; [
1003wpa_supplicant wget curl vim neovim cmus mpv firefox git tdesktop
1004];
1005
1006# Printing is useful, sure, enable CUPS
1007services.printing.enable = true;
1008
1009# We have speakers, let&#x27;s make use of them.
1010sound.enable = true;
1011hardware.pulseaudio.enable = true;
1012
1013# We want the X11 windowing system enabled, in Spanish.
1014services.xserver.enable = true;
1015services.xserver.layout = &amp;quot;es&amp;quot;;
1016
1017# I want a desktop manager in my laptop.
1018# I personally prefer XFCE, but the manual shows plenty
1019# of other options, such as Plasma, i3 WM, or whatever.
1020services.xserver.desktopManager.xfce.enable = true;
1021services.xserver.desktopManager.default = &amp;quot;xfce&amp;quot;;
1022
1023# Touchpad is useful (although sometimes annoying) in a laptop
1024services.xserver.libinput.enable = true;
1025
1026# We don&#x27;t want to do everything as root!
1027users.users.lonami = {
1028isNormalUser = true;
1029uid = 1000;
1030home = &amp;quot;&#x2F;home&#x2F;lonami&amp;quot;;
1031extraGroups = [ &amp;quot;wheel&amp;quot; &amp;quot;networkmanager&amp;quot; &amp;quot;audio&amp;quot; ];
1032};
1033&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1034&lt;p&gt;&lt;em&gt;(Fun fact, I overlooked the configuration file until I wrote this and hadn&#x27;t noticed sound&#x2F;pulseaudio was there. It wasn&#x27;t hard to find online how to enable it though!)&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
1035&lt;p&gt;Now, let&#x27;s modify &lt;code&gt;hardware-configuration.nix&lt;&#x2F;code&gt;. But if you have &lt;code&gt;&#x2F;home&lt;&#x2F;code&gt; in a separate partition like me, you should run &lt;code&gt;blkid&lt;&#x2F;code&gt; to figure out its UUID. To avoid typing it out myself, I just ran &lt;code&gt;blkid &amp;gt;&amp;gt; &#x2F;mnt&#x2F;etc&#x2F;nixos&#x2F;hardware-configuration.nix&lt;&#x2F;code&gt; so that I could easily move it around with &lt;code&gt;vim&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
1036&lt;pre&gt;&lt;code&gt;# (stuff...)
1037
1038fileSystems.&amp;quot;&#x2F;home&amp;quot; =
1039{ device = &amp;quot;&#x2F;dev&#x2F;disk&#x2F;by-uuid&#x2F;d344c686-cae7-4dd3-840e-308eddf86608&amp;quot;;
1040fsType = &amp;quot;ext4&amp;quot;;
1041};
1042
1043# (more stuff...)
1044&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1045&lt;p&gt;Note that, obviously, you should put your own partition&#x27;s UUID there. Modifying the configuration is where I think the current NixOS&#x27; manual should have made more emphasis, at this step of the installation. They do detail it below, but that was already too late in my first attempt. Anyway, you can boot from the USB and run &lt;code&gt;nixos-install&lt;&#x2F;code&gt; as many times as you need until you get it working!&lt;&#x2F;p&gt;
1046&lt;p&gt;But before installing, we need to configure the network since there are plenty of things to download. If you want to work from WiFi, you should first figure out the name of your network card with &lt;code&gt;ip link show&lt;&#x2F;code&gt;. In my case it&#x27;s called &lt;code&gt;wlp3s0&lt;&#x2F;code&gt;. So with that knowledge we can run &lt;code&gt;wpa_supplicant -B -i wlp3s0 -c &amp;lt;(wpa_passphrase SSID key)&lt;&#x2F;code&gt;. Be sure to replace both &lt;code&gt;SSID&lt;&#x2F;code&gt; and &lt;code&gt;key&lt;&#x2F;code&gt; with the name of your network and password key, respectively. If they have spaces, surround them in quotes.&lt;&#x2F;p&gt;
1047&lt;p&gt;Another funny pitfall was typing &lt;code&gt;wpa_supplicant&lt;&#x2F;code&gt; in the command above twice (instead of &lt;code&gt;wpa_passphrase&lt;&#x2F;code&gt;). That sure spit out a few funny errors! Once you have ran that, wait a few seconds and &lt;code&gt;ping 1.1.1.1&lt;&#x2F;code&gt; to make sure that you can reach the internet. If you do, &lt;code&gt;^C&lt;&#x2F;code&gt; and let&#x27;s install NixOS!&lt;&#x2F;p&gt;
1048&lt;pre&gt;&lt;code&gt;nixos-install
1049&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1050&lt;p&gt;Well, that was pretty painless. You can now &lt;code&gt;reboot&lt;&#x2F;code&gt; and enjoy your new, functional system.&lt;&#x2F;p&gt;
1051&lt;h2 id=&quot;afterword&quot;&gt;Afterword&lt;&#x2F;h2&gt;
1052&lt;p&gt;The process of installing NixOS was really painless once you have made sense out of what things mean. I was far more pleased this time than in my previous attempt, despite the four attempts I needed to have it up and running.&lt;&#x2F;p&gt;
1053&lt;p&gt;However not all is so good. I&#x27;m not sure where I went wrong, but the first time I tried with &lt;code&gt;i3&lt;&#x2F;code&gt; instead of &lt;code&gt;xfce&lt;&#x2F;code&gt;, all I was welcome with was a white, small terminal in the top left corner. I even generated a configuration file with &lt;code&gt;i3-config-wizard&lt;&#x2F;code&gt; to make sure it could detect my Mod1&#x2F;Mod4 keys (which, it did), but even after rebooting, my commands weren&#x27;t responding. For example, I couldn&#x27;t manage to open another terminal with &lt;code&gt;Mod1+Enter&lt;&#x2F;code&gt;. I&#x27;m not even sure that I was in &lt;code&gt;i3&lt;&#x2F;code&gt;…&lt;&#x2F;p&gt;
1054&lt;p&gt;In my very first attempt, I pressed &lt;code&gt;Alt+F8&lt;&#x2F;code&gt; as suggested in the welcome message. This took me an offline copy of the manual, which is really nicely done. Funny enough, though, I couldn&#x27;t exit &lt;code&gt;w3m&lt;&#x2F;code&gt;. Both &lt;code&gt;Q&lt;&#x2F;code&gt; and &lt;code&gt;B&lt;&#x2F;code&gt; to quit and take me back wouldn&#x27;t work. Somehow, it kept throwing me back into &lt;code&gt;w3m&lt;&#x2F;code&gt;, so I had to forcibly shutdown.&lt;&#x2F;p&gt;
1055&lt;p&gt;In my second attempt, I also forgot to configure network, so I had no way to download &lt;code&gt;wpa_supplicant&lt;&#x2F;code&gt; without having &lt;code&gt;wpa_supplicant&lt;&#x2F;code&gt; itself to connect my laptop to the network! So, it was important to do that through the USB before installing it (which comes with the program preinstalled), just by making sure to add it in the configuration file.&lt;&#x2F;p&gt;
1056&lt;p&gt;Some other notes, if you can&#x27;t reach the internet, don&#x27;t add any DNS in &lt;code&gt;&#x2F;etc&#x2F;resolv.conf&lt;&#x2F;code&gt;. This should be done declaratively in &lt;code&gt;configuration.nix&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1057&lt;p&gt;In the end, I spent the entire afternoon playing around with it, taking breaks and what-not. I still haven&#x27;t figured out why &lt;code&gt;nvim&lt;&#x2F;code&gt; was printing the literal escape character when going from normal to insert mode in the &lt;code&gt;xfce4-terminal&lt;&#x2F;code&gt; (and other actions also made it print this &amp;quot;garbage&amp;quot; to the console), why sometimes the network can reach the internet (and only some sites!) and sometimes not, and how to setup dualboot.&lt;&#x2F;p&gt;
1058&lt;p&gt;But despite all of this, I think it was a worth installing it again. One sure sees things from a different perspective, and gets the chance to write another blog post!&lt;&#x2F;p&gt;
1059&lt;p&gt;If there&#x27;s something I overlooked or that could be done better, or maybe you can explain it differently, please be sure to &lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;contact&quot;&gt;contact me&lt;&#x2F;a&gt; to let me know!&lt;&#x2F;p&gt;
1060&lt;h2 id=&quot;update&quot;&gt;Update&lt;&#x2F;h2&gt;
1061&lt;p&gt;Well, that was surprisingly fast feedback. Thank you very much &lt;a href=&quot;https:&#x2F;&#x2F;bb010g.keybase.pub&#x2F;&quot;&gt;@bb010g&lt;&#x2F;a&gt; for it! As they rightfully pointed out, one can avoid adding &lt;code&gt;&#x2F;home&lt;&#x2F;code&gt; manually to &lt;code&gt;hardware-configuration.nix&lt;&#x2F;code&gt; if you mount it before generating the configuration files. However, the installation process doesn&#x27;t need &lt;code&gt;&#x2F;home&lt;&#x2F;code&gt; mounted, so I didn&#x27;t do it.&lt;&#x2F;p&gt;
1062&lt;p&gt;The second weird issue with &lt;code&gt;w3m&lt;&#x2F;code&gt; is actually a funny one. &lt;code&gt;Alt+F8&lt;&#x2F;code&gt; &lt;em&gt;switches to another TTY&lt;&#x2F;em&gt;! That&#x27;s why quitting the program wouldn&#x27;t do anything. You&#x27;d still be in a different TTY! Normally, this is &lt;code&gt;Ctrl+Alt+FX&lt;&#x2F;code&gt;, so I hadn&#x27;t even thought that this is what could be happening. Anyway, the solution is not quitting the program, but rather going back to the main TTY with &lt;code&gt;Alt+F1&lt;&#x2F;code&gt;. You can switch back and forth all you need to consult the manual.&lt;&#x2F;p&gt;
1063&lt;p&gt;More suggestions are having &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rycee&#x2F;home-manager&quot;&gt;&lt;code&gt;home-manager&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; manage the graphical sessions, since it should be easier to deal with than the alternatives.&lt;&#x2F;p&gt;
1064&lt;p&gt;Despite having followed the guide and having read it over and over several times, it seems like my thoughts in this blog post may be a bit messy. So I recommend you also reading through the guide to have two versions of all this, just in case.&lt;&#x2F;p&gt;
1065&lt;p&gt;Regarding network issues, they use &lt;code&gt;connman&lt;&#x2F;code&gt; so that may be worth checking out.&lt;&#x2F;p&gt;
1066&lt;p&gt;Regarding terminal issues with &lt;code&gt;nvim&lt;&#x2F;code&gt; printing the literal escape character, I was told off for not having checked what my &lt;code&gt;$TERM&lt;&#x2F;code&gt; was. I hadn&#x27;t really looked into it much myself, just complained about it here, so sorry for being annoying about that. A quick search in the &lt;code&gt;nixpkgs&lt;&#x2F;code&gt; repository lets us find &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;NixOS&#x2F;nixpkgs&#x2F;blob&#x2F;release-18.09&#x2F;pkgs&#x2F;applications&#x2F;editors&#x2F;neovim&#x2F;default.nix&quot;&gt;neovim&#x2F;default.nix&lt;&#x2F;a&gt;, with version 0.3.1. Looking at &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;neovim&#x2F;neovim&quot;&gt;Neovim&#x27;s main repository&lt;&#x2F;a&gt; we can see that this is a bit outdated, but that is fine.&lt;&#x2F;p&gt;
1067&lt;p&gt;If only I had bothered to look at &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;neovim&#x2F;neovim&#x2F;wiki&#x2F;FAQ#nvim-shows-weird-symbols-2-q-when-changing-modes&quot;&gt;Neovim&#x27;s wiki&lt;&#x2F;a&gt;, (which they found through &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;neovim&#x2F;neovim&#x2F;issues&#x2F;7749&quot;&gt;Neovim&#x27;s GitHub issues&lt;&#x2F;a&gt;) I would&#x27;ve seen that some terminals just don&#x27;t support the program properly. The solution is, of course, to use a different terminal emulator with better support or to disable the &lt;code&gt;guicursor&lt;&#x2F;code&gt; in Neovim&#x27;s config.&lt;&#x2F;p&gt;
1068&lt;p&gt;This is a pretty good life lesson. 30 seconds of searching, maybe two minutes and a half for also checking XFCE issues, are often more than enough to troubleshoot your issues. The internet is a big place and more people have surely came across the problem before, so make sure to look online first. In my defense I&#x27;ll say that it didn&#x27;t bother me so much so I didn&#x27;t bother looking for that soon either.&lt;&#x2F;p&gt;
1069</content>
1070	</entry>
1071	<entry xml:lang="en">
1072		<title>Breaking Risk of Rain</title>
1073		<published>2019-01-12T00:00:00+00:00</published>
1074		<updated>2019-01-12T00:00:00+00:00</updated>
1075		<link href="https://lonami.dev/blog/breaking-ror/" type="text/html"/>
1076		<id>https://lonami.dev/blog/breaking-ror/</id>
1077		<content type="html">&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;riskofraingame.com&#x2F;&quot;&gt;Risk of Rain&lt;&#x2F;a&gt; is a fun little game you can spend a lot of hours on. It&#x27;s incredibly challenging for new players, and fun once you have learnt the basics. This blog will go through what I&#x27;ve learnt and how to play the game correctly.&lt;&#x2F;p&gt;
1078&lt;h2 id=&quot;getting-started&quot;&gt;Getting Started&lt;&#x2F;h2&gt;
1079&lt;p&gt;If you&#x27;re new to the game, you may find it frustrating. You must learn very well to dodge.&lt;&#x2F;p&gt;
1080&lt;p&gt;Your first &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Category:Characters&quot;&gt;character&lt;&#x2F;a&gt; will be &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Commando&quot;&gt;Commando&lt;&#x2F;a&gt;. He&#x27;s actually a very nice character. Use your third skill (dodge) to move faster, pass through large groups of enemies, and negate fall damage.&lt;&#x2F;p&gt;
1081&lt;p&gt;If there are a lot of monsters, remember to &lt;strong&gt;leave&lt;&#x2F;strong&gt; from there! It&#x27;s really important for survival. Most enemies &lt;strong&gt;don&#x27;t do body damage&lt;&#x2F;strong&gt;. Not even the body of the &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Magma_Worm&quot;&gt;Magma Worm&lt;&#x2F;a&gt; or the &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Wandering_Vagrant&quot;&gt;Wandering Vagrant&lt;&#x2F;a&gt; (just dodge the head and projectiles respectively).&lt;&#x2F;p&gt;
1082&lt;p&gt;The first thing you must do is always &lt;strong&gt;rush for the teleporter&lt;&#x2F;strong&gt;. Completing the levels quick will make the game easier. But make sure to take note of &lt;strong&gt;where the chests are&lt;&#x2F;strong&gt;! When you have time (even when the countdown finishes), go back for them and buy as many as you can. Generally, prefer &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Chest&quot;&gt;chests&lt;&#x2F;a&gt; over &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Shrine&quot;&gt;shrines&lt;&#x2F;a&gt; since they may eat all your money.&lt;&#x2F;p&gt;
1083&lt;p&gt;Completing the game on &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Difficulty&quot;&gt;Drizzle&lt;&#x2F;a&gt; is really easy if you follow these tips.&lt;&#x2F;p&gt;
1084&lt;h2 id=&quot;requisites&quot;&gt;Requisites&lt;&#x2F;h2&gt;
1085&lt;p&gt;Before breaking the game, you must obtain several &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Item#Artifacts&quot;&gt;artifacts&lt;&#x2F;a&gt;. We are interested in particular in the following:&lt;&#x2F;p&gt;
1086&lt;ul&gt;
1087&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Sacrifice&quot;&gt;Sacrifice&lt;&#x2F;a&gt;. You really need this one, and may be a bit hard to get. With it, you will be able to farm the first level for 30 minutes and kill the final boss in 30 seconds.&lt;&#x2F;li&gt;
1088&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Command&quot;&gt;Command&lt;&#x2F;a&gt;. You need this unless you want to grind for hours to get enough of the items you really need for the rest of the game. Getting this one is easy.&lt;&#x2F;li&gt;
1089&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Glass&quot;&gt;Glass&lt;&#x2F;a&gt;. Your life will be very small (at the beginning…), but you will be able to one-shot everything easily.&lt;&#x2F;li&gt;
1090&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Kin&quot;&gt;Kin&lt;&#x2F;a&gt; (optional). It makes it easier to obtain a lot of boxes if you restart the first level until you get &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Lemurian&quot;&gt;lemurians&lt;&#x2F;a&gt; or &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Jellyfish&quot;&gt;jellyfish&lt;&#x2F;a&gt; as the monster, since they&#x27;re cheap to spawn.&lt;&#x2F;li&gt;
1091&lt;&#x2F;ul&gt;
1092&lt;p&gt;With those, the game becomes trivial. Playing as &lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Huntress&quot;&gt;Huntress&lt;&#x2F;a&gt; is excellent since she can move at high speed while killing everything on screen.&lt;&#x2F;p&gt;
1093&lt;h2 id=&quot;breaking-the-game&quot;&gt;Breaking the Game&lt;&#x2F;h2&gt;
1094&lt;p&gt;The rest is easy! With the command artifact you want the following items.&lt;&#x2F;p&gt;
1095&lt;h3 id=&quot;common-items&quot;&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Category:Common_Items&quot;&gt;Common Items&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
1096&lt;ul&gt;
1097&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Soldier&amp;#x27;s_Syringe&quot;&gt;Soldier&#x27;s Syringe&lt;&#x2F;a&gt;. &lt;strong&gt;Stack 13&lt;&#x2F;strong&gt; of these and you will triple your attack speed. You can get started with 4 or so.&lt;&#x2F;li&gt;
1098&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Paul&amp;#x27;s_Goat_Hoof&quot;&gt;Paul&#x27;s Goat Hoof&lt;&#x2F;a&gt;. &lt;strong&gt;Stack +30&lt;&#x2F;strong&gt; of these and your movement speed will be insane. You can get a very good speed with 8 or so.&lt;&#x2F;li&gt;
1099&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Crowbar&quot;&gt;Crowbar&lt;&#x2F;a&gt;. &lt;strong&gt;Stack +20&lt;&#x2F;strong&gt; to guarantee you can one-shot bosses.&lt;&#x2F;li&gt;
1100&lt;&#x2F;ul&gt;
1101&lt;p&gt;If you want to be safer:&lt;&#x2F;p&gt;
1102&lt;ul&gt;
1103&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Hermit&amp;#x27;s_Scarf&quot;&gt;Hermit&#x27;s Scarf&lt;&#x2F;a&gt;. &lt;strong&gt;Stack 6&lt;&#x2F;strong&gt; of these to dodge 1&#x2F;3 of the attacks.&lt;&#x2F;li&gt;
1104&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Monster_Tooth&quot;&gt;Monster Tooth&lt;&#x2F;a&gt;. &lt;strong&gt;Stack 9&lt;&#x2F;strong&gt; of these to recover 50 life on kill. This is plenty, since you will be killing &lt;em&gt;a lot&lt;&#x2F;em&gt;.&lt;&#x2F;li&gt;
1105&lt;&#x2F;ul&gt;
1106&lt;p&gt;If you don&#x27;t have enough and want more fun, get one of these:&lt;&#x2F;p&gt;
1107&lt;ul&gt;
1108&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Gasoline&quot;&gt;Gasoline&lt;&#x2F;a&gt;. Burn the ground on kill, and more will die!&lt;&#x2F;li&gt;
1109&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Headstompers&quot;&gt;Headstompers&lt;&#x2F;a&gt;. They make a pleasing sound on fall, and hurt.&lt;&#x2F;li&gt;
1110&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Lens-Maker&amp;#x27;s_Glasses&quot;&gt;Lens-Maker&#x27;s Glasses&lt;&#x2F;a&gt;. &lt;strong&gt;Stack 14&lt;&#x2F;strong&gt; and you will always deal a critical strike for double the damage.&lt;&#x2F;li&gt;
1111&lt;&#x2F;ul&gt;
1112&lt;h3 id=&quot;uncommon-items&quot;&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Category:Uncommon_Items&quot;&gt;Uncommon Items&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
1113&lt;ul&gt;
1114&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Infusion&quot;&gt;Infusion&lt;&#x2F;a&gt;. You only really need one of this. Your life will skyrocket after a while, since this gives you 1HP per kill.&lt;&#x2F;li&gt;
1115&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Hopoo_Feather&quot;&gt;Hopoo Feather&lt;&#x2F;a&gt;. &lt;strong&gt;Stack +10&lt;&#x2F;strong&gt; of these. You will pretty much be able to fly with so many jumps.&lt;&#x2F;li&gt;
1116&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Guardian&amp;#x27;s_Heart&quot;&gt;Guardian&#x27;s Heart&lt;&#x2F;a&gt;. Not really necessary, but useful for early and late game, since it will absorb infinite damage the first hit.&lt;&#x2F;li&gt;
1117&lt;&#x2F;ul&gt;
1118&lt;p&gt;If, again, you want more fun, get one of these:&lt;&#x2F;p&gt;
1119&lt;ul&gt;
1120&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Ukulele&quot;&gt;Ukelele&lt;&#x2F;a&gt;. Spazz your enemies!&lt;&#x2F;li&gt;
1121&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Will-o&amp;#x27;-the-wisp&quot;&gt;Will-o&#x27;-the-wisp&lt;&#x2F;a&gt;. Explode your enemies!&lt;&#x2F;li&gt;
1122&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Chargefield_Generator&quot;&gt;Chargefield Generator&lt;&#x2F;a&gt;. It should cover your entire screen after a bit, hurting all enemies without moving a finger.&lt;&#x2F;li&gt;
1123&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Golden_Gun&quot;&gt;Golden Gun&lt;&#x2F;a&gt;. You will be rich, so this gives you +40% damage.&lt;&#x2F;li&gt;
1124&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Predatory_Instincts&quot;&gt;Predatory Instincts&lt;&#x2F;a&gt;. If you got 14 glasses, you will always be doing critical strikes, and this will give even more attack speed.&lt;&#x2F;li&gt;
1125&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;56_Leaf_Clover&quot;&gt;56 Leaf Clover&lt;&#x2F;a&gt;. More drops, in case you didn&#x27;t have enough.&lt;&#x2F;li&gt;
1126&lt;&#x2F;ul&gt;
1127&lt;h3 id=&quot;rare-items&quot;&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Category:Rare_Items&quot;&gt;Rare Items&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
1128&lt;ul&gt;
1129&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Ceremonial_Dagger&quot;&gt;Ceremonial Dagger&lt;&#x2F;a&gt;. &lt;strong&gt;Stack +3&lt;&#x2F;strong&gt;, then killing one thing kills another thing and makes a chain reaction.&lt;&#x2F;li&gt;
1130&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Alien_Head&quot;&gt;Alien Head&lt;&#x2F;a&gt;. &lt;strong&gt;Stack 3&lt;&#x2F;strong&gt;, and you will be able to use your abilities more often.&lt;&#x2F;li&gt;
1131&lt;&#x2F;ul&gt;
1132&lt;p&gt;For more fun:&lt;&#x2F;p&gt;
1133&lt;ul&gt;
1134&lt;li&gt;&lt;a href=&quot;http:&#x2F;&#x2F;riskofrain.wikia.com&#x2F;wiki&#x2F;Brilliant_Behemoth&quot;&gt;Brilliant Behemoth&lt;&#x2F;a&gt;. Boom boom.&lt;&#x2F;li&gt;
1135&lt;&#x2F;ul&gt;
1136&lt;h2 id=&quot;closing-words&quot;&gt;Closing Words&lt;&#x2F;h2&gt;
1137&lt;p&gt;You can now beat the game in Monsoon solo with any character. Have fun! And be careful with the sadly common crashes.&lt;&#x2F;p&gt;
1138</content>
1139	</entry>
1140	<entry xml:lang="en">
1141		<title>WorldEdit Commands</title>
1142		<published>2018-07-11T00:00:00+00:00</published>
1143		<updated>2018-07-11T00:00:00+00:00</updated>
1144		<link href="https://lonami.dev/blog/world-edit/" type="text/html"/>
1145		<id>https://lonami.dev/blog/world-edit/</id>
1146		<content type="html">&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;dev.bukkit.org&#x2F;projects&#x2F;worldedit&quot;&gt;WorldEdit&lt;&#x2F;a&gt; is an extremely powerful tool for modifying entire worlds within &lt;a href=&quot;https:&#x2F;&#x2F;minecraft.net&quot;&gt;Minecraft&lt;&#x2F;a&gt;, which can be used as either a mod for your single-player worlds or as a plugin for your &lt;a href=&quot;https:&#x2F;&#x2F;getbukkit.org&#x2F;&quot;&gt;Bukkit&lt;&#x2F;a&gt; servers.&lt;&#x2F;p&gt;
1147&lt;p&gt;This command guide was written for Minecraft 1.12.1, version &lt;a href=&quot;https:&#x2F;&#x2F;dev.bukkit.org&#x2F;projects&#x2F;worldedit&#x2F;files&#x2F;2460562&quot;&gt;6.1.7.3&lt;&#x2F;a&gt;, but should work for newer versions too. All WorldEdit commands can be used with a double slash (&lt;code&gt;&#x2F;&#x2F;&lt;&#x2F;code&gt;) so they don&#x27;t conlict with built-in commands. This means you can get a list of all commands with &lt;code&gt;&#x2F;&#x2F;help&lt;&#x2F;code&gt;. Let&#x27;s explore different categories!&lt;&#x2F;p&gt;
1148&lt;h2 id=&quot;movement&quot;&gt;Movement&lt;&#x2F;h2&gt;
1149&lt;p&gt;In order to edit a world properly you need to learn how to move in said world properly. There are several straightforward commands that let you move:&lt;&#x2F;p&gt;
1150&lt;ul&gt;
1151&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;ascend&lt;&#x2F;code&gt; goes up one floor.&lt;&#x2F;li&gt;
1152&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;descend&lt;&#x2F;code&gt; goes down one floor.&lt;&#x2F;li&gt;
1153&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;thru&lt;&#x2F;code&gt; let&#x27;s you pass through walls.&lt;&#x2F;li&gt;
1154&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;jumpto&lt;&#x2F;code&gt; to go wherever you are looking.&lt;&#x2F;li&gt;
1155&lt;&#x2F;ul&gt;
1156&lt;h2 id=&quot;information&quot;&gt;Information&lt;&#x2F;h2&gt;
1157&lt;p&gt;Knowing your world properly is as important as knowing how to move within it, and will also let you change the information in said world if you need to.&lt;&#x2F;p&gt;
1158&lt;ul&gt;
1159&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;biomelist&lt;&#x2F;code&gt; shows all known biomes.&lt;&#x2F;li&gt;
1160&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;biomeinfo&lt;&#x2F;code&gt; shows the current biome.&lt;&#x2F;li&gt;
1161&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;setbiome&lt;&#x2F;code&gt; lets you change the biome.&lt;&#x2F;li&gt;
1162&lt;&#x2F;ul&gt;
1163&lt;h2 id=&quot;blocks&quot;&gt;Blocks&lt;&#x2F;h2&gt;
1164&lt;p&gt;You can act over all blocks in a radius around you with quite a few commands. Some won&#x27;t actually act over the entire range you specify, so 100 is often a good number.&lt;&#x2F;p&gt;
1165&lt;h3 id=&quot;filling&quot;&gt;Filling&lt;&#x2F;h3&gt;
1166&lt;p&gt;You can fill pools with &lt;code&gt;&#x2F;&#x2F;fill water 100&lt;&#x2F;code&gt; or caves with &lt;code&gt;&#x2F;&#x2F;fillr water 100&lt;&#x2F;code&gt;, both of which act below your feet.&lt;&#x2F;p&gt;
1167&lt;h3 id=&quot;fixing&quot;&gt;Fixing&lt;&#x2F;h3&gt;
1168&lt;p&gt;If the water or lava is buggy use &lt;code&gt;&#x2F;&#x2F;fixwater 100&lt;&#x2F;code&gt; or &lt;code&gt;&#x2F;&#x2F;fixlava 100&lt;&#x2F;code&gt; respectively.&lt;&#x2F;p&gt;
1169&lt;p&gt;Some creeper removed the snow or the grass? Fear not, you can use &lt;code&gt;&#x2F;&#x2F;snow 10&lt;&#x2F;code&gt; or &lt;code&gt;&#x2F;&#x2F;grass 10&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1170&lt;h3 id=&quot;emptying&quot;&gt;Emptying&lt;&#x2F;h3&gt;
1171&lt;p&gt;You can empty a pool completely with &lt;code&gt;&#x2F;&#x2F;drain 100&lt;&#x2F;code&gt;, remove the snow with &lt;code&gt;&#x2F;&#x2F;thaw 10&lt;&#x2F;code&gt;, and remove fire with &lt;code&gt;&#x2F;&#x2F;ex 10&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1172&lt;h3 id=&quot;removing&quot;&gt;Removing&lt;&#x2F;h3&gt;
1173&lt;p&gt;You can remove blocks above and below you in some area with the &lt;code&gt;&#x2F;&#x2F;removeabove N&lt;&#x2F;code&gt; and &lt;code&gt;&#x2F;&#x2F;removebelow N&lt;&#x2F;code&gt;. You probably want to set a limit though, or you could fall off the world with &lt;code&gt;&#x2F;&#x2F;removebelow 1 10&lt;&#x2F;code&gt; for radius and depth. You can also remove near blocks with &lt;code&gt;&#x2F;&#x2F;removenear block 10&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1174&lt;h3 id=&quot;shapes&quot;&gt;Shapes&lt;&#x2F;h3&gt;
1175&lt;p&gt;Making a cylinder (or circle) can be done with through &lt;code&gt;&#x2F;&#x2F;cyl stone 10&lt;&#x2F;code&gt;, a third argument for the height. The radius can be comma-separated to make a ellipses instead, such as &lt;code&gt;&#x2F;&#x2F;cyl stone 5,10&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1176&lt;p&gt;Spheres are done with &lt;code&gt;&#x2F;&#x2F;sphere stone 5&lt;&#x2F;code&gt;. This will build one right at your center, so you can raise it to be on your feet with &lt;code&gt;&#x2F;&#x2F;sphere stone 5 yes&lt;&#x2F;code&gt;. Similar to cylinders, you can comma separate the radius &lt;code&gt;x,y,z&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1177&lt;p&gt;Pyramids can be done with &lt;code&gt;&#x2F;&#x2F;pyramic stone 5&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1178&lt;p&gt;All these commands can be prefixed with &amp;quot;h&amp;quot; to make them hollow. For instance, &lt;code&gt;&#x2F;&#x2F;hsphere stone 10&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1179&lt;h2 id=&quot;regions&quot;&gt;Regions&lt;&#x2F;h2&gt;
1180&lt;h3 id=&quot;basics&quot;&gt;Basics&lt;&#x2F;h3&gt;
1181&lt;p&gt;Operating over an entire region is really important, and the first thing you need to work comfortably with them is a tool to make selections. The default wooden-axe tool can be obtained with &lt;code&gt;&#x2F;&#x2F;wand&lt;&#x2F;code&gt;, but you must be near the blocks to select. You can use a different tool, like a golden axe, to use as your &amp;quot;far wand&amp;quot; (wand usable over distance). Once you have one in your hand type &lt;code&gt;&#x2F;&#x2F;farwand&lt;&#x2F;code&gt; to use it as your &amp;quot;far wand&amp;quot;. You can select the two corners of your region with left and right click. If you have selected the wrong tool, use &lt;code&gt;&#x2F;&#x2F;none&lt;&#x2F;code&gt; to clear it.&lt;&#x2F;p&gt;
1182&lt;p&gt;If there are no blocks but you want to use your current position as a corner, use &lt;code&gt;&#x2F;&#x2F;pos1&lt;&#x2F;code&gt; or 2.&lt;&#x2F;p&gt;
1183&lt;p&gt;If you made a region too small, you can enlarge it with &lt;code&gt;&#x2F;&#x2F;expand 10 up&lt;&#x2F;code&gt;, or &lt;code&gt;&#x2F;&#x2F;expand vert&lt;&#x2F;code&gt; for the entire vertical range, etc., or make it smaller with &lt;code&gt;&#x2F;&#x2F;contract 10 up&lt;&#x2F;code&gt; etc., or &lt;code&gt;&#x2F;&#x2F;inset&lt;&#x2F;code&gt; it to contract in both directions. You can use short-names for the cardinal directions (NSEW).&lt;&#x2F;p&gt;
1184&lt;p&gt;Finally, if you want to move your selection, you can &lt;code&gt;&#x2F;&#x2F;shift 1 north&lt;&#x2F;code&gt; it to wherever you need.&lt;&#x2F;p&gt;
1185&lt;h3 id=&quot;information-1&quot;&gt;Information&lt;&#x2F;h3&gt;
1186&lt;p&gt;You can get the &lt;code&gt;&#x2F;&#x2F;size&lt;&#x2F;code&gt; of the selection or even &lt;code&gt;&#x2F;&#x2F;count torch&lt;&#x2F;code&gt; in some area. If you want to count all blocks, get their distribution &lt;code&gt;&#x2F;&#x2F;distr&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1187&lt;h3 id=&quot;filling-1&quot;&gt;Filling&lt;&#x2F;h3&gt;
1188&lt;p&gt;With a region selected, you can &lt;code&gt;&#x2F;&#x2F;set&lt;&#x2F;code&gt; it to be any block! For instance, you can use &lt;code&gt;&#x2F;&#x2F;set air&lt;&#x2F;code&gt; to clear it entirely. You can use more than one block evenly by separting them with a comma &lt;code&gt;&#x2F;&#x2F;set stone,dirt&lt;&#x2F;code&gt;, or with a custom chance &lt;code&gt;&#x2F;&#x2F;set 20%stone,80%dirt&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1189&lt;p&gt;You can use &lt;code&gt;&#x2F;&#x2F;replace from to&lt;&#x2F;code&gt; instead if you don&#x27;t want to override all blocks in your selection.&lt;&#x2F;p&gt;
1190&lt;p&gt;You can make an hollow set with &lt;code&gt;&#x2F;&#x2F;faces&lt;&#x2F;code&gt;, and if you just want the walls, use &lt;code&gt;&#x2F;&#x2F;walls&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1191&lt;h3 id=&quot;cleaning&quot;&gt;Cleaning&lt;&#x2F;h3&gt;
1192&lt;p&gt;If someone destroyed your wonderful snow landscape, fear not, you can use &lt;code&gt;&#x2F;&#x2F;overlay snow&lt;&#x2F;code&gt; over it (although for this you actually have &lt;code&gt;&#x2F;&#x2F;snow N&lt;&#x2F;code&gt; and its opposite &lt;code&gt;&#x2F;&#x2F;thaw&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
1193&lt;p&gt;If you set some rough area, you can always &lt;code&gt;&#x2F;&#x2F;smooth&lt;&#x2F;code&gt; it, even more than one time with &lt;code&gt;&#x2F;&#x2F;smooth 3&lt;&#x2F;code&gt;. You can get your dirt and stone back with &lt;code&gt;&#x2F;&#x2F;naturalize&lt;&#x2F;code&gt; and put some plants with &lt;code&gt;&#x2F;&#x2F;flora&lt;&#x2F;code&gt; or &lt;code&gt;&#x2F;&#x2F;forest&lt;&#x2F;code&gt;, both of which support a density or even the type for the trees. If you already have the dirt use &lt;code&gt;&#x2F;&#x2F;green&lt;&#x2F;code&gt; instead. If you want some pumpkins, with &lt;code&gt;&#x2F;&#x2F;pumpkins&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1194&lt;h3 id=&quot;moving&quot;&gt;Moving&lt;&#x2F;h3&gt;
1195&lt;p&gt;You can repeat an entire selection many times by stacking them with &lt;code&gt;&#x2F;&#x2F;stack N DIR&lt;&#x2F;code&gt;. This is extremely useful to make things like corridors or elevators. For instance, you can make a small section of the corridor, select it entirely, and then repeat it 10 times with &lt;code&gt;&#x2F;&#x2F;stack 10 north&lt;&#x2F;code&gt;. Or you can make the elevator and then &lt;code&gt;&#x2F;&#x2F;stack 10 up&lt;&#x2F;code&gt;. If you need to also copy the air use &lt;code&gt;&#x2F;&#x2F;stackair&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1196&lt;p&gt;Finally, if you don&#x27;t need to repeat it and simply move it just a bit towards the right direction, you can use &lt;code&gt;&#x2F;&#x2F;move N&lt;&#x2F;code&gt;. The default direction is &amp;quot;me&amp;quot; (towards where you are facing) but you can set one with &lt;code&gt;&#x2F;&#x2F;move 1 up&lt;&#x2F;code&gt; for example.&lt;&#x2F;p&gt;
1197&lt;h3 id=&quot;selecting&quot;&gt;Selecting&lt;&#x2F;h3&gt;
1198&lt;p&gt;You can not only select cuboids. You can also select different shapes, or even just points:&lt;&#x2F;p&gt;
1199&lt;ul&gt;
1200&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;sel cuboid&lt;&#x2F;code&gt; is the default.&lt;&#x2F;li&gt;
1201&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;sel extend&lt;&#x2F;code&gt; expands the default.&lt;&#x2F;li&gt;
1202&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;sel poly&lt;&#x2F;code&gt; first point with left click and right click to add new points.&lt;&#x2F;li&gt;
1203&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;sel ellipsoid&lt;&#x2F;code&gt; first point to select the center and right click to select the different radius.&lt;&#x2F;li&gt;
1204&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;sel sphere&lt;&#x2F;code&gt; first point to select the center and one more right click for the radius.&lt;&#x2F;li&gt;
1205&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;sel cyl&lt;&#x2F;code&gt; for cylinders, first click being the center.&lt;&#x2F;li&gt;
1206&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;sel convex&lt;&#x2F;code&gt; for convex shapes. This one is extremely useful for &lt;code&gt;&#x2F;&#x2F;curve&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
1207&lt;&#x2F;ul&gt;
1208&lt;h2 id=&quot;brushes&quot;&gt;Brushes&lt;&#x2F;h2&gt;
1209&lt;p&gt;Brushes are a way to paint in 3D without first bothering about making a selection, and there are spherical and cylinder brushes with e.g. &lt;code&gt;&#x2F;&#x2F;brush sphere stone 2&lt;&#x2F;code&gt;, or the shorter form &lt;code&gt;&#x2F;&#x2F;br s stone&lt;&#x2F;code&gt;. For cylinder, one must use &lt;code&gt;cyl&lt;&#x2F;code&gt; instead &lt;code&gt;sphere&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1210&lt;p&gt;There also exists a brush to smooth the terrain which can be enabled on the current item with &lt;code&gt;&#x2F;&#x2F;br smooth&lt;&#x2F;code&gt;, which can be used with right-click like any other brush.&lt;&#x2F;p&gt;
1211&lt;h2 id=&quot;clipboard&quot;&gt;Clipboard&lt;&#x2F;h2&gt;
1212&lt;p&gt;Finally, you can copy and cut things around like you would do with normal text with &lt;code&gt;&#x2F;&#x2F;copy&lt;&#x2F;code&gt; and &lt;code&gt;&#x2F;&#x2F;cut&lt;&#x2F;code&gt;. The copy is issued from wherever you issue the command, so when you use &lt;code&gt;&#x2F;&#x2F;paste&lt;&#x2F;code&gt;, remember that if you were 4 blocks apart when copying, it will be 4 blocks apart when pasting.&lt;&#x2F;p&gt;
1213&lt;p&gt;The contents of the clipboard can be flipped to wherever you are looking via &lt;code&gt;&#x2F;&#x2F;flip&lt;&#x2F;code&gt;, and can be rotated via the &lt;code&gt;&#x2F;&#x2F;rotate 90&lt;&#x2F;code&gt; command (in degrees).&lt;&#x2F;p&gt;
1214&lt;p&gt;To remove the copy use &lt;code&gt;&#x2F;&#x2F;clearclipboard&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1215</content>
1216	</entry>
1217	<entry xml:lang="en">
1218		<title>An Introduction to Asyncio</title>
1219		<published>2018-06-13T00:00:00+00:00</published>
1220		<updated>2020-10-03T00:00:00+00:00</updated>
1221		<link href="https://lonami.dev/blog/asyncio/" type="text/html"/>
1222		<id>https://lonami.dev/blog/asyncio/</id>
1223		<content type="html">&lt;h2 id=&quot;index&quot;&gt;Index&lt;&#x2F;h2&gt;
1224&lt;ul&gt;
1225&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;asyncio&#x2F;#background&quot;&gt;Background&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
1226&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;asyncio&#x2F;#input_output&quot;&gt;Input &#x2F; Output&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
1227&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;asyncio&#x2F;#diving_in&quot;&gt;Diving In&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
1228&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;asyncio&#x2F;#a_toy_example&quot;&gt;A Toy Example&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
1229&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;asyncio&#x2F;#a_real_example&quot;&gt;A Real Example&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
1230&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;asyncio&#x2F;#extra_material&quot;&gt;Extra Material&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
1231&lt;&#x2F;ul&gt;
1232&lt;h2 id=&quot;background&quot;&gt;Background&lt;&#x2F;h2&gt;
1233&lt;p&gt;After seeing some friends struggle with &lt;code&gt;asyncio&lt;&#x2F;code&gt; I decided that it could be a good idea to write a blog post using my own words to explain how I understand the world of asynchronous IO. I will focus on Python&#x27;s &lt;code&gt;asyncio&lt;&#x2F;code&gt; module but this post should apply to any other language easily.&lt;&#x2F;p&gt;
1234&lt;p&gt;So what is &lt;code&gt;asyncio&lt;&#x2F;code&gt; and what makes it good? Why don&#x27;t we just use the old and known threads to run several parts of the code concurrently, at the same time?&lt;&#x2F;p&gt;
1235&lt;p&gt;The first reason is that &lt;code&gt;asyncio&lt;&#x2F;code&gt; makes your code easier to reason about, as opposed to using threads, because the amount of ways in which your code can run grows exponentially. Let&#x27;s see that with an example. Imagine you have this code:&lt;&#x2F;p&gt;
1236&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;def method():
1237	line 1
1238	line 2
1239	line 3
1240	line 4
1241	line 5
1242&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1243&lt;p&gt;And you start two threads to run the method at the same time. What is the order in which the lines of code get executed? The answer is that you can&#x27;t know! The first thread can run the entire method before the second thread even starts. Or it could be the first thread that runs after the second thread. Perhaps both run the &amp;quot;line 1&amp;quot;, and then the line 2. Maybe the first thread runs lines 1 and 2, and then the second thread only runs the line 1 before the first thread finishes.&lt;&#x2F;p&gt;
1244&lt;p&gt;As you can see, any combination of the order in which the lines run is possible. If the lines modify some global shared state, that will get messy quickly.&lt;&#x2F;p&gt;
1245&lt;p&gt;Second, in Python, threads &lt;em&gt;won&#x27;t&lt;&#x2F;em&gt; make your code faster most of the time. It will only increase the concurrency of your program (which is okay if it makes many blocking calls), allowing you to run several things at the same time.&lt;&#x2F;p&gt;
1246&lt;p&gt;If you have a lot of CPU work to do though, threads aren&#x27;t a real advantage. Indeed, your code will probably run slower under the most common Python implementation, CPython, which makes use of a Global Interpreter Lock (GIL) that only lets a thread run at once. The operations won&#x27;t run in parallel!&lt;&#x2F;p&gt;
1247&lt;h2 id=&quot;input-output&quot;&gt;Input &#x2F; Output&lt;&#x2F;h2&gt;
1248&lt;p&gt;Before we go any further, let&#x27;s first stop to talk about input and output, commonly known as &amp;quot;IO&amp;quot;. There are two main ways to perform IO operations, such as reading or writing from a file or a network socket.&lt;&#x2F;p&gt;
1249&lt;p&gt;The first one is known as &amp;quot;blocking IO&amp;quot;. What this means is that, when you try performing IO, the current application thread is going to &lt;em&gt;block&lt;&#x2F;em&gt; until the Operative System can tell you it&#x27;s done. Normally, this is not a problem, since disks are pretty fast anyway, but it can soon become a performance bottleneck. And network IO will be much slower than disk IO!&lt;&#x2F;p&gt;
1250&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;import socket
1251
1252# Setup a network socket and a very simple HTTP request.
1253# By default, sockets are open in blocking mode.
1254sock = socket.socket()
1255request = b&#x27;&#x27;&#x27;HEAD &#x2F; HTTP&#x2F;1.0\r
1256Host: example.com\r
1257\r
1258&#x27;&#x27;&#x27;
1259
1260# &amp;quot;connect&amp;quot; will block until a successful TCP connection
1261# is made to the host &amp;quot;example.com&amp;quot; on port 80.
1262sock.connect((&#x27;example.com&#x27;, 80))
1263
1264# &amp;quot;sendall&amp;quot; will repeatedly call &amp;quot;send&amp;quot; until all the data in &amp;quot;request&amp;quot; is
1265# sent to the host we just connected, which blocks until the data is sent.
1266sock.sendall(request)
1267
1268# &amp;quot;recv&amp;quot; will try to receive up to 1024 bytes from the host, and block until
1269# there is any data to receive (or empty if the host closes the connection).
1270response = sock.recv(1024)
1271
1272# After all those blocking calls, we got out data! These are the headers from
1273# making a HTTP request to example.com.
1274print(response.decode())
1275&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1276&lt;p&gt;Blocking IO offers timeouts, so that you can get control back in your code if the operation doesn&#x27;t finish. Imagine that the remote host doesn&#x27;t want to reply, your code would be stuck for as long as the connection remains alive!&lt;&#x2F;p&gt;
1277&lt;p&gt;But wait, what if we make the timeout small? Very, very small? If we do that, we will never block waiting for an answer. That&#x27;s how asynchronous IO works, and it&#x27;s the opposite of blocking IO (you can also call it non-blocking IO if you want to).&lt;&#x2F;p&gt;
1278&lt;p&gt;How does non-blocking IO work if the IO device needs a while to answer with the data? In that case, the operative system responds with &amp;quot;not ready&amp;quot;, and your application gets control back so it can do other stuff while the IO device completes your request. It works a bit like this:&lt;&#x2F;p&gt;
1279&lt;pre&gt;&lt;code&gt;&amp;lt;app&amp;gt; Hey, I would like to read 16 bytes from this file
1280&amp;lt;OS&amp;gt; Okay, but the disk hasn&#x27;t sent me the data yet
1281&amp;lt;app&amp;gt; Alright, I will do something else then
1282(a lot of computer time passes)
1283&amp;lt;app&amp;gt; Do you have my 16 bytes now?
1284&amp;lt;OS&amp;gt; Yes, here they are! &amp;quot;Hello, world !!\n&amp;quot;
1285&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1286&lt;p&gt;In reality, you can tell the OS to notify you when the data is ready, as opposed to polling (constantly asking the OS whether the data is ready yet or not), which is more efficient.&lt;&#x2F;p&gt;
1287&lt;p&gt;But either way, that&#x27;s the difference between blocking and non-blocking IO, and what matters is that your application gets to run more without ever needing to wait for data to arrive, because the data will be there immediately when you ask, and if it&#x27;s not yet, your app can do more things meanwhile.&lt;&#x2F;p&gt;
1288&lt;h2 id=&quot;diving-in&quot;&gt;Diving In&lt;&#x2F;h2&gt;
1289&lt;p&gt;Now we&#x27;ve seen what blocking and non-blocking IO is, and how threads make your code harder to reason about, but they give concurrency (yet not more speed). Is there any other way to achieve this concurrency that doesn&#x27;t involve threads? Yes! The answer is &lt;code&gt;asyncio&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1290&lt;p&gt;So how does &lt;code&gt;asyncio&lt;&#x2F;code&gt; help? First we need to understand a very crucial concept before we can dive any deeper, and I&#x27;m talking about the &lt;em&gt;event loop&lt;&#x2F;em&gt;. What is it and why do we need it?&lt;&#x2F;p&gt;
1291&lt;p&gt;You can think of the event loop as a &lt;em&gt;loop&lt;&#x2F;em&gt; that will be responsible for calling your &lt;code&gt;async&lt;&#x2F;code&gt; functions:&lt;&#x2F;p&gt;
1292&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;asyncio&#x2F;eventloop.svg&quot; alt=&quot;The Event Loop&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
1293&lt;p&gt;That&#x27;s silly you may think. Now not only we run our code but we also have to run some &amp;quot;event loop&amp;quot;. It doesn&#x27;t sound beneficial at all. What are these events? Well, they are the IO events we talked about before!&lt;&#x2F;p&gt;
1294&lt;p&gt;&lt;code&gt;asyncio&lt;&#x2F;code&gt;&#x27;s event loop is responsible for handling those IO events, such as file is ready, data arrived, flushing is done, and so on. As we saw before, we can make these events non-blocking by setting their timeout to 0.&lt;&#x2F;p&gt;
1295&lt;p&gt;Let&#x27;s say you want to read from 10 files at the same time. You will ask the OS to read data from 10 files, and at first none of the reads will be ready. But the event loop will be constantly asking the OS to know which are done, and when they are done, you will get your data.&lt;&#x2F;p&gt;
1296&lt;p&gt;This has some nice advantages. It means that, instead of waiting for a network request to send you a response or some file, instead of blocking there, the event loop can decide to run other code meanwhile. Whenever the contents are ready, they can be read, and your code can continue. Waiting for the contents to be received is done with the &lt;code&gt;await&lt;&#x2F;code&gt; keyword, and it tells the loop that it can run other code meanwhile:&lt;&#x2F;p&gt;
1297&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;asyncio&#x2F;awaitkwd1.svg&quot; alt=&quot;Step 1, await keyword&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
1298&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;asyncio&#x2F;awaitkwd2.svg&quot; alt=&quot;Step 2, await keyword&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
1299&lt;p&gt;Start reading the code of the event loop and follow the arrows. You can see that, in the beginning, there are no events yet, so the loop calls one of your functions. The code runs until it has to &lt;code&gt;await&lt;&#x2F;code&gt; for some IO operation to complete, such as sending a request over the network. The method is &amp;quot;paused&amp;quot; until an event occurs (for example, an &amp;quot;event&amp;quot; occurs when the request has been sent completely).&lt;&#x2F;p&gt;
1300&lt;p&gt;While the first method is busy, the event loop can enter the second method, and run its code until the first &lt;code&gt;await&lt;&#x2F;code&gt;. But it can happen that the event of the second query occurs before the request on the first method, so the event loop can re-enter the second method because it has already sent the query, but the first method isn&#x27;t done sending the request yet.&lt;&#x2F;p&gt;
1301&lt;p&gt;Then, the second method &lt;code&gt;await&lt;&#x2F;code&gt;&#x27;s for an answer, and an event occurs telling the event loop that the request from the first method was sent. The code can be resumed again, until it has to &lt;code&gt;await&lt;&#x2F;code&gt; for a response, and so on. Here&#x27;s an explanation with pseudo-code for this process if you prefer:&lt;&#x2F;p&gt;
1302&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;async def method(request):
1303    prepare request
1304    await send request
1305
1306    await receive request
1307
1308    process request
1309    return result
1310
1311run in parallel (
1312	method with request 1,
1313	method with request 2,
1314)
1315&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1316&lt;p&gt;This is what the event loop will do on the above pseudo-code:&lt;&#x2F;p&gt;
1317&lt;pre&gt;&lt;code&gt;no events pending, can advance
1318
1319enter method with request 1
1320	prepare request
1321	await sending request
1322pause method with request 1
1323
1324no events ready, can advance
1325
1326enter method with request 2
1327	prepare request
1328	await sending request
1329pause method with request 2
1330
1331both requests are paused, cannot advance
1332wait for events
1333event for request 2 arrives (sending request completed)
1334
1335enter method with request 2
1336	await receiving response
1337pause method with request 2
1338
1339event for request 1 arrives (sending request completed)
1340
1341enter method with request 1
1342	await receiving response
1343pause method with request 1
1344
1345...and so on
1346&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1347&lt;p&gt;You may be wondering &amp;quot;okay, but threads work for me, so why should I change?&amp;quot;. There are some important things to note here. The first is that we only need one thread to be running! The event loop decides when and which methods should run. This results in less pressure for the operating system. The second is that we know when it may run other methods. Those are the &lt;code&gt;await&lt;&#x2F;code&gt; keywords! Whenever there is one of those, we know that the loop is able to run other things until the resource (again, like network) becomes ready (when a event occurs telling us it&#x27;s ready to be used without blocking or it has completed).&lt;&#x2F;p&gt;
1348&lt;p&gt;So far, we already have two advantages. We are only using a single thread so the cost for switching between methods is low, and we can easily reason about where our program may interleave operations.&lt;&#x2F;p&gt;
1349&lt;p&gt;Another advantage is that, with the event loop, you can easily schedule when a piece of code should run, such as using the method &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;asyncio-eventloop.html#asyncio.loop.call_at&quot;&gt;&lt;code&gt;loop.call_at&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, without the need for spawning another thread at all.&lt;&#x2F;p&gt;
1350&lt;p&gt;To tell the &lt;code&gt;asyncio&lt;&#x2F;code&gt; to run the two methods shown above, we can use &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;asyncio-future.html#asyncio.ensure_future&quot;&gt;&lt;code&gt;asyncio.ensure_future&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which is a way of saying &amp;quot;I want the future of my method to be ensured&amp;quot;. That is, you want to run your method in the future, whenever the loop is free to do so. This method returns a &lt;code&gt;Future&lt;&#x2F;code&gt; object, so if your method returns a value, you can &lt;code&gt;await&lt;&#x2F;code&gt; this future to retrieve its result.&lt;&#x2F;p&gt;
1351&lt;p&gt;What is a &lt;code&gt;Future&lt;&#x2F;code&gt;? This object represents the value of something that will be there in the future, but might not be there yet. Just like you can &lt;code&gt;await&lt;&#x2F;code&gt; your own &lt;code&gt;async def&lt;&#x2F;code&gt; functions, you can &lt;code&gt;await&lt;&#x2F;code&gt; these &lt;code&gt;Future&lt;&#x2F;code&gt;&#x27;s.&lt;&#x2F;p&gt;
1352&lt;p&gt;The &lt;code&gt;async def&lt;&#x2F;code&gt; functions are also called &amp;quot;coroutines&amp;quot;, and Python does some magic behind the scenes to turn them into such. The coroutines can be &lt;code&gt;await&lt;&#x2F;code&gt;&#x27;ed, and this is what you normally do.&lt;&#x2F;p&gt;
1353&lt;h2 id=&quot;a-toy-example&quot;&gt;A Toy Example&lt;&#x2F;h2&gt;
1354&lt;p&gt;That&#x27;s all about &lt;code&gt;asyncio&lt;&#x2F;code&gt;! Let&#x27;s wrap up with some example code. We will create a server that replies with the text a client sends, but reversed. First, we will show what you could write with normal synchronous code, and then we will port it.&lt;&#x2F;p&gt;
1355&lt;p&gt;Here is the &lt;strong&gt;synchronous version&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
1356&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;# server.py
1357import socket
1358
1359
1360def server_method():
1361	# create a new server socket to listen for connections
1362	server = socket.socket()
1363
1364	# bind to localhost:6789 for new connections
1365	server.bind((&#x27;localhost&#x27;, 6789))
1366
1367	# we will listen for one client at most
1368	server.listen(1)
1369
1370	# *block* waiting for a new client
1371	client, _ = server.accept()
1372
1373	# *block* waiting for some data
1374	data = client.recv(1024)
1375
1376	# reverse the data
1377	data = data[::-1]
1378
1379	# *block* sending the data
1380	client.sendall(data)
1381
1382	# close client and server
1383	server.close()
1384	client.close()
1385
1386
1387if __name__ == &#x27;__main__&#x27;:
1388	# block running the server
1389	server_method()
1390&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1391&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;# client.py
1392import socket
1393
1394
1395def client_method():
1396	message = b&#x27;Hello Server!\n&#x27;
1397	client = socket.socket()
1398
1399	# *block* trying to stabilish a connection
1400	client.connect((&#x27;localhost&#x27;, 6789))
1401
1402	# *block* trying to send the message
1403	print(&#x27;Sending&#x27;, message)
1404	client.sendall(message)
1405
1406	# *block* until we receive a response
1407	response = client.recv(1024)
1408	print(&#x27;Server replied&#x27;, response)
1409
1410	client.close()
1411
1412
1413if __name__ == &#x27;__main__&#x27;:
1414	client_method()
1415&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1416&lt;p&gt;From what we&#x27;ve seen, this code will block on all the lines with a comment above them saying that they will block. This means that for running more than one client or server, or both in the same file, you will need threads. But we can do better, we can rewrite it into &lt;code&gt;asyncio&lt;&#x2F;code&gt;!&lt;&#x2F;p&gt;
1417&lt;p&gt;The first step is to mark all your &lt;code&gt;def&lt;&#x2F;code&gt;initions that may block with &lt;code&gt;async&lt;&#x2F;code&gt;. This marks them as coroutines, which can be &lt;code&gt;await&lt;&#x2F;code&gt;ed on.&lt;&#x2F;p&gt;
1418&lt;p&gt;Second, since we&#x27;re using low-level sockets, we need to make use of the methods that &lt;code&gt;asyncio&lt;&#x2F;code&gt; provides directly. If this was a third-party library, this would be just like using their &lt;code&gt;async def&lt;&#x2F;code&gt;initions.&lt;&#x2F;p&gt;
1419&lt;p&gt;Here is the &lt;strong&gt;asynchronous version&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
1420&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;# server.py
1421import asyncio
1422import socket
1423
1424# get the default &amp;quot;event loop&amp;quot; that we will run
1425loop = asyncio.get_event_loop()
1426
1427
1428# notice our new &amp;quot;async&amp;quot; before the definition
1429async def server_method():
1430	server = socket.socket()
1431	server.bind((&#x27;localhost&#x27;, 6789))
1432	server.listen(1)
1433
1434	# await for a new client
1435	# the event loop can run other code while we wait here!
1436	client, _ = await loop.sock_accept(server)
1437
1438	# await for some data
1439	data = await loop.sock_recv(client, 1024)
1440	data = data[::-1]
1441
1442	# await for sending the data
1443	await loop.sock_sendall(client, data)
1444
1445	server.close()
1446	client.close()
1447
1448
1449if __name__ == &#x27;__main__&#x27;:
1450	# run the loop until &amp;quot;server method&amp;quot; is complete
1451	loop.run_until_complete(server_method())
1452&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1453&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;# client.py
1454import asyncio
1455import socket
1456
1457loop = asyncio.get_event_loop()
1458
1459
1460async def client_method():
1461	message = b&#x27;Hello Server!\n&#x27;
1462	client = socket.socket()
1463
1464	# await to stabilish a connection
1465	await loop.sock_connect(client, (&#x27;localhost&#x27;, 6789))
1466
1467	# await to send the message
1468	print(&#x27;Sending&#x27;, message)
1469	await loop.sock_sendall(client, message)
1470
1471	# await to receive a response
1472	response = await loop.sock_recv(client, 1024)
1473	print(&#x27;Server replied&#x27;, response)
1474
1475	client.close()
1476
1477
1478if __name__ == &#x27;__main__&#x27;:
1479	loop.run_until_complete(client_method())
1480&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1481&lt;p&gt;That&#x27;s it! You can place these two files separately and run, first the server, then the client. You should see output in the client.&lt;&#x2F;p&gt;
1482&lt;p&gt;The big difference here is that you can easily modify the code to run more than one server or clients at the same time. Whenever you &lt;code&gt;await&lt;&#x2F;code&gt; the event loop will run other of your code. It seems to &amp;quot;block&amp;quot; on the &lt;code&gt;await&lt;&#x2F;code&gt; parts, but remember it&#x27;s actually jumping to run more code, and the event loop will get back to you whenever it can.&lt;&#x2F;p&gt;
1483&lt;p&gt;In short, you need an &lt;code&gt;async def&lt;&#x2F;code&gt; to &lt;code&gt;await&lt;&#x2F;code&gt; things, and you run them with the event loop instead of calling them directly. So this…&lt;&#x2F;p&gt;
1484&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;def main():
1485	...  # some code
1486
1487
1488if __name__ == &#x27;__main__&#x27;:
1489	main()
1490&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1491&lt;p&gt;…becomes this:&lt;&#x2F;p&gt;
1492&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;import asyncio
1493
1494
1495async def main():
1496	...  # some code
1497
1498
1499if __name__ == &#x27;__main__&#x27;:
1500	asyncio.get_event_loop().run_until_complete(main)
1501&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1502&lt;p&gt;This is pretty much how most of your &lt;code&gt;async&lt;&#x2F;code&gt; scripts will start, running the main method until its completion.&lt;&#x2F;p&gt;
1503&lt;h2 id=&quot;a-real-example&quot;&gt;A Real Example&lt;&#x2F;h2&gt;
1504&lt;p&gt;Let&#x27;s have some fun with a real library. We&#x27;ll be using &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;LonamiWebs&#x2F;Telethon&quot;&gt;Telethon&lt;&#x2F;a&gt; to broadcast a message to our three best friends, all at the same time, thanks to the magic of &lt;code&gt;asyncio&lt;&#x2F;code&gt;. We&#x27;ll dive right into the code, and then I&#x27;ll explain our new friend &lt;code&gt;asyncio.wait(...)&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
1505&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;# broadcast.py
1506import asyncio
1507import sys
1508
1509from telethon import TelegramClient
1510
1511# (you need your own values here, check Telethon&#x27;s documentation)
1512api_id = 123
1513api_hash = &#x27;123abc&#x27;
1514friends = [
1515	&#x27;@friend1__username&#x27;,
1516	&#x27;@friend2__username&#x27;,
1517	&#x27;@bestie__username&#x27;
1518]
1519
1520# we will have to await things, so we need an async def
1521async def main(message):
1522	# start is a coroutine, so we need to await it to run it
1523	client = await TelegramClient(&#x27;me&#x27;, api_id, api_hash).start()
1524
1525	# wait for all three client.send_message to complete
1526	await asyncio.wait([
1527		client.send_message(friend, message)
1528		for friend in friends
1529	])
1530
1531	# and close our client
1532	await client.disconnect()
1533
1534
1535if __name__ == &#x27;__main__&#x27;:
1536	if len(sys.argv) != 2:
1537		print(&#x27;You must pass the message to broadcast!&#x27;)
1538		quit()
1539
1540	message = sys.argv[1]
1541	asyncio.get_event_loop().run_until_complete(main(message))
1542&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1543&lt;p&gt;Wait… how did that send a message to all three of
1544my friends? The magic is done here:&lt;&#x2F;p&gt;
1545&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;[
1546	client.send_message(friend, message)
1547	for friend in friends
1548]
1549&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1550&lt;p&gt;This list comprehension creates another list with three
1551coroutines, the three &lt;code&gt;client.send_message(...)&lt;&#x2F;code&gt;.
1552Then we just pass that list to &lt;code&gt;asyncio.wait&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
1553&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;await asyncio.wait([...])
1554&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
1555&lt;p&gt;This method, by default, waits for the list of coroutines to run until they&#x27;ve all finished. You can read more on the Python &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;asyncio-task.html#asyncio.wait&quot;&gt;documentation&lt;&#x2F;a&gt;. Truly a good function to know about!&lt;&#x2F;p&gt;
1556&lt;p&gt;Now whenever you have some important news for your friends, you can simply &lt;code&gt;python3 broadcast.py &#x27;I bought a car!&#x27;&lt;&#x2F;code&gt; to tell all your friends about your new car! All you need to remember is that you need to &lt;code&gt;await&lt;&#x2F;code&gt; on coroutines, and you will be good. &lt;code&gt;asyncio&lt;&#x2F;code&gt; will warn you when you forget to do so.&lt;&#x2F;p&gt;
1557&lt;h2 id=&quot;extra-material&quot;&gt;Extra Material&lt;&#x2F;h2&gt;
1558&lt;p&gt;If you want to understand how &lt;code&gt;asyncio&lt;&#x2F;code&gt; works under the hood, I recommend you to watch this hour-long talk &lt;a href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;M-UcUs7IMIM&quot;&gt;Get to grips with asyncio in Python 3&lt;&#x2F;a&gt; by Robert Smallshire. In the video, they will explain the differences between concurrency and parallelism, along with others concepts, and how to implement your own &lt;code&gt;asyncio&lt;&#x2F;code&gt; &amp;quot;scheduler&amp;quot; from scratch.&lt;&#x2F;p&gt;
1559</content>
1560	</entry>
1561	<entry xml:lang="en">
1562		<title>Atemporal Blog Posts</title>
1563		<published>2018-02-03T00:00:00+00:00</published>
1564		<updated>2018-02-03T00:00:00+00:00</updated>
1565		<link href="https://lonami.dev/blog/posts/" type="text/html"/>
1566		<id>https://lonami.dev/blog/posts/</id>
1567		<content type="html">&lt;p&gt;These are some interesting posts and links I&#x27;ve found around the web. I believe they are quite interesting and nice reads, so if you have the time, I encourage you to check some out.&lt;&#x2F;p&gt;
1568&lt;h2 id=&quot;algorithms&quot;&gt;Algorithms&lt;&#x2F;h2&gt;
1569&lt;ul&gt;
1570&lt;li&gt;http:&#x2F;&#x2F;www.tannerhelland.com&#x2F;4660&#x2F;dithering-eleven-algorithms-source-code&#x2F;. Image Dithering: Eleven Algorithms and Source Code. What does it mean and how to achieve it?&lt;&#x2F;li&gt;
1571&lt;li&gt;https:&#x2F;&#x2F;cristian.io&#x2F;post&#x2F;bloom-filters&#x2F;. Idempotence layer on bloom filters. What are they and how can they help?&lt;&#x2F;li&gt;
1572&lt;li&gt;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Huffman_coding. Huffman coding. This encoding is a simple yet interesting way of compressing information.&lt;&#x2F;li&gt;
1573&lt;li&gt;https:&#x2F;&#x2F;github.com&#x2F;mxgmn&#x2F;WaveFunctionCollapse. Wave Function Collapse. Bitmap &amp;amp; tilemap generation from a single example with the help of ideas from quantum mechanics.&lt;&#x2F;li&gt;
1574&lt;li&gt;https:&#x2F;&#x2F;blog.nelhage.com&#x2F;2015&#x2F;02&#x2F;regular-expression-search-with-suffix-arrays&#x2F;. Regular Expression Search with Suffix Arrays. A way to efficiently search large amounts of text.&lt;&#x2F;li&gt;
1575&lt;&#x2F;ul&gt;
1576&lt;h2 id=&quot;culture&quot;&gt;Culture&lt;&#x2F;h2&gt;
1577&lt;ul&gt;
1578&lt;li&gt;https:&#x2F;&#x2F;www.wired.com&#x2F;story&#x2F;ideas-joi-ito-robot-overlords&#x2F;. Why Westerners Fear Robots and the Japanese Do Not. Explains some possible reasons for this case.&lt;&#x2F;li&gt;
1579&lt;li&gt;http:&#x2F;&#x2F;catb.org&#x2F;~esr&#x2F;faqs&#x2F;smart-questions.html. How To Ask Questions The Smart Way. Some bits of hacker culture and amazing tips on how to ask a question.&lt;&#x2F;li&gt;
1580&lt;li&gt;http:&#x2F;&#x2F;apenwarr.ca&#x2F;log&#x2F;?m=201809#14. XML, blockchains, and the strange shapes of progress. Some of history about XML and blockchain.&lt;&#x2F;li&gt;
1581&lt;li&gt;https:&#x2F;&#x2F;czep.net&#x2F;17&#x2F;legion-of-lobotomized-unices.html. Legion of lobotomized unices. A time where computers are treated a lot more nicely.&lt;&#x2F;li&gt;
1582&lt;li&gt;https:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2016&#x2F;the-expression-problem-and-its-solutions&#x2F;.  The Expression Problem and its solutions. What is it and what can we do to solve it?&lt;&#x2F;li&gt;
1583&lt;li&gt;http:&#x2F;&#x2F;allendowney.blogspot.com&#x2F;2015&#x2F;08&#x2F;the-inspection-paradox-is-everywhere.html. The Inspection Paradox is Everywhere. Interesting and very common phenomena.&lt;&#x2F;li&gt;
1584&lt;li&gt;https:&#x2F;&#x2F;github.com&#x2F;ChrisKnott&#x2F;Algojammer. An experimental code editor for writing algorithms. Contains several links to different tools for reverse debugging.&lt;&#x2F;li&gt;
1585&lt;li&gt;http:&#x2F;&#x2F;habitatchronicles.com&#x2F;2017&#x2F;05&#x2F;what-are-capabilities&#x2F;. What Are Capabilities? Good ideas with great security implications.&lt;&#x2F;li&gt;
1586&lt;li&gt;https:&#x2F;&#x2F;blog.aurynn.com&#x2F;2015&#x2F;12&#x2F;16-contempt-culture. Contempt Culture. Or why you should not speak crap about your non-favourite programming languages.&lt;&#x2F;li&gt;
1587&lt;li&gt;https:&#x2F;&#x2F;www.lesswrong.com&#x2F;posts&#x2F;tscc3e5eujrsEeFN4&#x2F;well-kept-gardens-die-by-pacifism. Well-Kept Gardens Die By Pacifism. Risks any online community can run into.&lt;&#x2F;li&gt;
1588&lt;li&gt;https:&#x2F;&#x2F;ncase.me&#x2F;. It&#x27;s Nicky Case! They make some cool things worth checking out, I really like &amp;quot;we become what we behold&amp;quot;.&lt;&#x2F;li&gt;
1589&lt;&#x2F;ul&gt;
1590&lt;h2 id=&quot;debate&quot;&gt;Debate&lt;&#x2F;h2&gt;
1591&lt;ul&gt;
1592&lt;li&gt;https:&#x2F;&#x2F;steemit.com&#x2F;opensource&#x2F;@crell&#x2F;open-source-is-awful. Open Source is awful. Has some points about why is it bad and how it could improve.&lt;&#x2F;li&gt;
1593&lt;li&gt;http:&#x2F;&#x2F;www.mondo2000.com&#x2F;2018&#x2F;01&#x2F;17&#x2F;pink-lexical-goop-dark-side-autocorrect&#x2F;. Pink Lexical Goop: The Dark Side of Autocorrect. It can shape how you think.&lt;&#x2F;li&gt;
1594&lt;li&gt;http:&#x2F;&#x2F;blog.ploeh.dk&#x2F;2015&#x2F;08&#x2F;03&#x2F;idiomatic-or-idiosyncratic&#x2F;. Idiomatic or idiosyncratic? Can porting code constructs from other languages have a positive effect?&lt;&#x2F;li&gt;
1595&lt;li&gt;https:&#x2F;&#x2F;gamasutra.com&#x2F;view&#x2F;news&#x2F;169296&#x2F;Indepth_Functional_programming_in_C.php. In-depth: Functional programming in C++. Is it useful to bother with functional concepts in a language like C++?&lt;&#x2F;li&gt;
1596&lt;li&gt;https:&#x2F;&#x2F;vorpus.org&#x2F;blog&#x2F;notes-on-structured-concurrency-or-go-statement-considered-harmful&#x2F;. Notes on structured concurrency, or: Go statement considered harmful.&lt;&#x2F;li&gt;
1597&lt;li&gt;https:&#x2F;&#x2F;queue.acm.org&#x2F;detail.cfm?id=3212479. C Is Not a Low-level Language. Could there be alternative programming models designed for more specialized CPUs?&lt;&#x2F;li&gt;
1598&lt;&#x2F;ul&gt;
1599&lt;h2 id=&quot;food-for-thought&quot;&gt;Food for Thought&lt;&#x2F;h2&gt;
1600&lt;ul&gt;
1601&lt;li&gt;https:&#x2F;&#x2F;www.hillelwayne.com&#x2F;post&#x2F;divide-by-zero&#x2F;. 1&#x2F;0 = 0. Explores why it makes sense to redefine mathemathics under some circumstances, and why it is possible to do so.&lt;&#x2F;li&gt;
1602&lt;li&gt;https:&#x2F;&#x2F;jeremykun.com&#x2F;2018&#x2F;04&#x2F;13&#x2F;for-mathematicians-does-not-mean-equality&#x2F;. For mathematicians, = does not mean equality. What other definitions does the equal sign have?&lt;&#x2F;li&gt;
1603&lt;li&gt;https:&#x2F;&#x2F;www.lesswrong.com&#x2F;posts&#x2F;2MD3NMLBPCqPfnfre&#x2F;cached-thoughts. Cached Thoughts. How is it possible that our brains work at all?&lt;&#x2F;li&gt;
1604&lt;li&gt;http:&#x2F;&#x2F;tonsky.me&#x2F;blog&#x2F;disenchantment&#x2F;. Software disenchantment. Faster hardware and slower software is a trend.
1605&lt;ul&gt;
1606&lt;li&gt;https:&#x2F;&#x2F;blackhole12.com&#x2F;blog&#x2F;software-engineering-is-bad-but-it-s-not-that-bad&#x2F;. Software Engineering Is Bad, But That&#x27;s Not Why. This post has some good counterpoints to Software disenchantment.&lt;&#x2F;li&gt;
1607&lt;&#x2F;ul&gt;
1608&lt;&#x2F;li&gt;
1609&lt;li&gt;http:&#x2F;&#x2F;journal.stuffwithstuff.com&#x2F;2015&#x2F;02&#x2F;01&#x2F;what-color-is-your-function&#x2F;. What Color is Your Function? Spoiler: can we approach asynchronous IO better?&lt;&#x2F;li&gt;
1610&lt;li&gt;https:&#x2F;&#x2F;hackernoon.com&#x2F;im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8cb347c5b5. I&#x27;m harvesting credit card numbers and passwords from your site. A word of warning when mindlessly adding dependencies.&lt;&#x2F;li&gt;
1611&lt;li&gt;https:&#x2F;&#x2F;medium.com&#x2F;message&#x2F;everything-is-broken-81e5f33a24e1. Everything Is Broken. Some of the (probable) truths about our world.&lt;&#x2F;li&gt;
1612&lt;&#x2F;ul&gt;
1613&lt;h2 id=&quot;funny&quot;&gt;Funny&lt;&#x2F;h2&gt;
1614&lt;ul&gt;
1615&lt;li&gt;http:&#x2F;&#x2F;thedailywtf.com&#x2F;articles&#x2F;We-Use-BobX. We Use BobX. BobX.&lt;&#x2F;li&gt;
1616&lt;li&gt;http:&#x2F;&#x2F;thedailywtf.com&#x2F;articles&#x2F;the-inner-json-effect. The Inner JSON Effect. For some reason, custom languages are in.&lt;&#x2F;li&gt;
1617&lt;li&gt;https:&#x2F;&#x2F;thedailywtf.com&#x2F;articles&#x2F;exponential-backup. Exponential Backup. Far better than git.&lt;&#x2F;li&gt;
1618&lt;li&gt;https:&#x2F;&#x2F;thedailywtf.com&#x2F;articles&#x2F;ITAPPMONROBOT. ITAPPMONROBOT. Solving software problems with hardware.&lt;&#x2F;li&gt;
1619&lt;li&gt;https:&#x2F;&#x2F;thedailywtf.com&#x2F;articles&#x2F;a-tapestry-of-threads. A Tapestry of Threads.More threads must mean faster code, right?&lt;&#x2F;li&gt;
1620&lt;li&gt;https:&#x2F;&#x2F;medium.com&#x2F;commitlog&#x2F;a-brief-totally-accurate-history-of-programming-languages-cd93ec806124. A Brief Totally Accurate History Of Programming Languages. Don&#x27;t take offense for it!&lt;&#x2F;li&gt;
1621&lt;&#x2F;ul&gt;
1622&lt;h2 id=&quot;graphics&quot;&gt;Graphics&lt;&#x2F;h2&gt;
1623&lt;ul&gt;
1624&lt;li&gt;http:&#x2F;&#x2F;shaunlebron.github.io&#x2F;visualizing-projections&#x2F;. Visualizing Projections. Small post about different projection methods.&lt;&#x2F;li&gt;
1625&lt;li&gt;http:&#x2F;&#x2F;www.iquilezles.org&#x2F;www&#x2F;index.htm. A &lt;em&gt;lot&lt;&#x2F;em&gt; of useful and quality articles regarding computer graphics.&lt;&#x2F;li&gt;
1626&lt;&#x2F;ul&gt;
1627&lt;h2 id=&quot;history&quot;&gt;History&lt;&#x2F;h2&gt;
1628&lt;ul&gt;
1629&lt;li&gt;https:&#x2F;&#x2F;twobithistory.org&#x2F;2018&#x2F;08&#x2F;18&#x2F;ada-lovelace-note-g.html. What Did Ada Lovelace&#x27;s Program Actually Do?. And other characters that took part in the beginning&#x27;s of programming.&lt;&#x2F;li&gt;
1630&lt;li&gt;https:&#x2F;&#x2F;chrisdown.name&#x2F;2018&#x2F;01&#x2F;02&#x2F;in-defence-of-swap.html. In defence of swap: common misconceptions. Swap is still an useful concept.&lt;&#x2F;li&gt;
1631&lt;li&gt;https:&#x2F;&#x2F;www.pacifict.com&#x2F;Story&#x2F;. The Graphing Calculator Story. A great classic Apple tale.&lt;&#x2F;li&gt;
1632&lt;li&gt;https:&#x2F;&#x2F;twobithistory.org&#x2F;2018&#x2F;10&#x2F;14&#x2F;lisp.html. How Lisp Became God&#x27;s Own Programming Language. Lisp as a foundational programming language.&lt;&#x2F;li&gt;
1633&lt;&#x2F;ul&gt;
1634&lt;h2 id=&quot;motivational&quot;&gt;Motivational&lt;&#x2F;h2&gt;
1635&lt;ul&gt;
1636&lt;li&gt;https:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;2002&#x2F;01&#x2F;06&#x2F;fire-and-motion&#x2F;. Fire And Motion. What does actually take to get things done?&lt;&#x2F;li&gt;
1637&lt;li&gt;https:&#x2F;&#x2F;realmensch.org&#x2F;2017&#x2F;08&#x2F;25&#x2F;the-parable-of-the-two-programmers&#x2F;. The Parable of the Two Programmers. This tale is about two different types of programmer and their respective endings in a company, illustrating how the one you wouldn&#x27;t expect to actually ends in a better situation.&lt;&#x2F;li&gt;
1638&lt;li&gt;https:&#x2F;&#x2F;byorgey.wordpress.com&#x2F;2018&#x2F;05&#x2F;06&#x2F;conversations-with-a-six-year-old-on-functional-programming&#x2F;. Conversations with a six-year-old on functional programming. Little kids today can be really interested in technological topics.&lt;&#x2F;li&gt;
1639&lt;li&gt;https:&#x2F;&#x2F;bulletproofmusician.com&#x2F;how-many-hours-a-day-should-you-practice&#x2F;. How Many Hours a Day Should You Practice?. While the article is about music, it applies to any other areas.&lt;&#x2F;li&gt;
1640&lt;li&gt;http:&#x2F;&#x2F;nathanmarz.com&#x2F;blog&#x2F;suffering-oriented-programming.html. Suffering-oriented programming. A possibly new approach on how you could tackle your new projects.&lt;&#x2F;li&gt;
1641&lt;li&gt;https:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;2000&#x2F;04&#x2F;06&#x2F;things-you-should-never-do-part-i&#x2F;. Things You Should Never Do, Part I. There is no need to rewrite your code.&lt;&#x2F;li&gt;
1642&lt;&#x2F;ul&gt;
1643&lt;h2 id=&quot;optimization&quot;&gt;Optimization&lt;&#x2F;h2&gt;
1644&lt;ul&gt;
1645&lt;li&gt;http:&#x2F;&#x2F;blog.llvm.org&#x2F;2011&#x2F;05&#x2F;what-every-c-programmer-should-know.html. What Every C Programmer Should Know About Undefined Behavior #1&#x2F;3. Explains what undefined behaviour is and why it makes sense.&lt;&#x2F;li&gt;
1646&lt;li&gt;http:&#x2F;&#x2F;ridiculousfish.com&#x2F;blog&#x2F;posts&#x2F;labor-of-division-episode-i.html. Labor of Division (Episode I). Some tricks to divide without division.&lt;&#x2F;li&gt;
1647&lt;li&gt;http:&#x2F;&#x2F;blog.moertel.com&#x2F;posts&#x2F;2013-12-14-great-old-timey-game-programming-hack.html. A Great Old-Timey Game-Programming Hack. Abusing instructions to make games playable even on the slowest hardware.&lt;&#x2F;li&gt;
1648&lt;li&gt;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20191213224640&#x2F;https:&#x2F;&#x2F;people.eecs.berkeley.edu&#x2F;~sangjin&#x2F;2012&#x2F;12&#x2F;21&#x2F;epoll-vs-kqueue.html. Scalable Event Multiplexing: epoll vs kqueue. How good OS primitives can really help performance and scability.&lt;&#x2F;li&gt;
1649&lt;li&gt;https:&#x2F;&#x2F;adamdrake.com&#x2F;command-line-tools-can-be-235x-faster-than-your-hadoop-cluster.html. Command-line Tools can be 235x Faster than your Hadoop Cluster. Or how to use the right tool for the right job.&lt;&#x2F;li&gt;
1650&lt;li&gt;https:&#x2F;&#x2F;nullprogram.com&#x2F;blog&#x2F;2018&#x2F;05&#x2F;27&#x2F;. When FFI Function Calls Beat Native C. How lua beat C at it and the explanation behind it.&lt;&#x2F;li&gt;
1651&lt;li&gt;http:&#x2F;&#x2F;igoro.com&#x2F;archive&#x2F;gallery-of-processor-cache-effects&#x2F;. Gallery of Processor Cache Effects. Knowing a few things about the cache can make a big difference.&lt;&#x2F;li&gt;
1652&lt;&#x2F;ul&gt;
1653</content>
1654	</entry>
1655	<entry xml:lang="en">
1656		<title>Graphs</title>
1657		<published>2017-06-02T00:00:00+00:00</published>
1658		<updated>2017-06-02T00:00:00+00:00</updated>
1659		<link href="https://lonami.dev/blog/graphs/" type="text/html"/>
1660		<id>https://lonami.dev/blog/graphs/</id>
1661		<content type="html">&lt;p&gt;&lt;noscript&gt;There are a few things which won&#x27;t render unless you enable
1662JavaScript. No tracking, I promise!&lt;&#x2F;noscript&gt;&lt;&#x2F;p&gt;
1663&lt;blockquote&gt;
1664&lt;p&gt;Don&#x27;t know English? &lt;a href=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;graphs&#x2F;spanish.html&quot;&gt;Read the Spanish version instead&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
1665&lt;&#x2F;blockquote&gt;
1666&lt;p&gt;Let&#x27;s imagine we have 5 bus stations, which we&#x27;ll denote by ((s_i)):&lt;&#x2F;p&gt;
1667&lt;div class=&quot;matrix&quot;&gt;
1668      &#x27; s_1 &#x27; s_2 &#x27; s_3 &#x27; s_4 &#x27; s_5 \\
1669s_1   &#x27;     &#x27;  V  &#x27;     &#x27;     &#x27;     \\
1670s_2   &#x27;  V  &#x27;     &#x27;     &#x27;     &#x27;  V  \\
1671s_3   &#x27;     &#x27;     &#x27;     &#x27;  V  &#x27;     \\
1672s_4   &#x27;     &#x27;  V  &#x27;  V  &#x27;     &#x27;     \\
1673s_5   &#x27;  V  &#x27;     &#x27;     &#x27;  V  &#x27;
1674&lt;&#x2F;div&gt;
1675&lt;p&gt;This is known as a &amp;quot;table of direct interconnections&amp;quot;.
1676The ((V)) represent connected paths. For instance, on the first
1677row starting at ((s_1)), reaching the ((V)),
1678allows us to turn up to get to ((s_2)).&lt;&#x2F;p&gt;
1679&lt;p&gt;We can see the above table represented in a more graphical way:&lt;&#x2F;p&gt;
1680&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;lonami.dev&#x2F;blog&#x2F;graphs&#x2F;example1.svg&quot; alt=&quot;Table 1 as a Graph&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
1681&lt;p&gt;This type of graph is called, well, a graph, and it&#x27;s a directed
1682graph (or digraph), since the direction on which the arrows go does
1683matter. It&#x27;s made up of vertices, joined together by edges (also known as
1684lines or directed arcs).&lt;&#x2F;p&gt;
1685&lt;p&gt;One can walk from a node to another through different paths. For
1686example, ((s_4 $rightarrow s_2 $rightarrow s_5)) is an indirect path of order
1687two, because we must use two edges to go from ((s_4)) to
1688((s_5)).&lt;&#x2F;p&gt;
1689&lt;p&gt;Let&#x27;s now represent its adjacency matrix called A which represents the
1690same table, but uses 1 instead V to represent
1691a connection:&lt;&#x2F;p&gt;
1692&lt;div class=&quot;matrix&quot;&gt;
1693  0 &#x27; 1 &#x27; 0 &#x27; 0 &#x27; 0 \\
1694  1 &#x27; 0 &#x27; 0 &#x27; 0 &#x27; 1 \\
1695  0 &#x27; 0 &#x27; 0 &#x27; 1 &#x27; 0 \\
1696  0 &#x27; 1 &#x27; 1 &#x27; 0 &#x27; 0 \\
1697  1 &#x27; 0 &#x27; 0 &#x27; 1 &#x27; 0
1698&lt;&#x2F;div&gt;
1699&lt;p&gt;This way we can see how the ((a_{2,1})) element represents the
1700connection ((s_2 $rightarrow s_1)), and the ((a_{5,1})) element the
1701((s_5 $rightarrow s_1)) connection, etc.&lt;&#x2F;p&gt;
1702&lt;p&gt;In general, ((a_{i,j})) represents a connection from
1703((s_i $rightarrow s_j))as long as ((a_{i,j}$geq 1)).&lt;&#x2F;p&gt;
1704&lt;p&gt;Working with matrices allows us to have a computable representation of
1705any graph, which is very useful.&lt;&#x2F;p&gt;
1706&lt;hr &#x2F;&gt;
1707&lt;p&gt;Graphs have a lot of interesting properties besides being representable
1708by a computer. What would happen if, for instance, we calculated
1709((A^2))? We obtain the following matrix:&lt;&#x2F;p&gt;
1710&lt;div class=&quot;matrix&quot;&gt;
17111 &#x27; 0 &#x27; 0 &#x27; 0 &#x27; 1 \\
17121 &#x27; 1 &#x27; 0 &#x27; 1 &#x27; 0 \\
17130 &#x27; 1 &#x27; 1 &#x27; 0 &#x27; 0 \\
17141 &#x27; 0 &#x27; 0 &#x27; 1 &#x27; 1 \\
17150 &#x27; 2 &#x27; 1 &#x27; 0 &#x27; 0
1716&lt;&#x2F;div&gt;
1717&lt;p&gt;We can interpret this as the paths of order two.
1718But what does the element ((a_{5,2}=2)) represent? It indicates
1719the amount of possible ways to go from  ((s_5 $rightarrow s_i $rightarrow s_2)).&lt;&#x2F;p&gt;
1720&lt;p&gt;One can manually multiply the involved row and column to determine which
1721element is the one we need to pass through, this way we have the row
1722(([1 0 0 1 0])) and the column (([1 0 0 1 0])) (on
1723vertical). The elements ((s_i$geq 1)) are ((s_1)) and
1724((s_4)). This is, we can go from ((s_5)) to
1725((s_2)) via ((s_5 $rightarrow s_1 $rightarrow s_2)) or via
1726((s_5 $rightarrow s_4 $rightarrow s_2)):
1727&lt;img src=&quot;example2.svg&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
1728&lt;p&gt;It&#x27;s important to note that graphs to not consider self-connections, this
1729is, ((s_i $rightarrow s_i)) is not allowed; neither we work with multigraphs
1730here (those which allow multiple connections, for instance, an arbitrary
1731number ((n)) of times).&lt;&#x2F;p&gt;
1732&lt;div class=&quot;matrix&quot;&gt;
17331 &#x27; 1 &#x27; 0          &#x27; 1 &#x27; 0 \\
17341 &#x27; 2 &#x27; \textbf{1} &#x27; 0 &#x27; 1 \\
17351 &#x27; 0 &#x27; 0          &#x27; 1 &#x27; 1 \\
17361 &#x27; 2 &#x27; 1          &#x27; 1 &#x27; 0 \\
17372 &#x27; 0 &#x27; 0          &#x27; 1 &#x27; 2
1738&lt;&#x2F;div&gt;
1739&lt;p&gt;We can see how the first ((1)) just appeared on the element
1740((a_{2,3})), which means that the shortest path to it is at least
1741of order three.&lt;&#x2F;p&gt;
1742&lt;hr &#x2F;&gt;
1743&lt;p&gt;A graph is said to be strongly connected as long as there is a
1744way to reach all its elements.&lt;&#x2F;p&gt;
1745&lt;p&gt;We can see all the available paths until now by simply adding up all the
1746direct and indirect ways to reach a node, so for now, we can add
1747((A+A^2+A^3)) in such a way that:&lt;&#x2F;p&gt;
1748&lt;div class=&quot;matrix&quot;&gt;
17492 &#x27; 2 &#x27; 0 &#x27; 1 &#x27; 1 \\
17503 &#x27; 3 &#x27; 1 &#x27; 1 &#x27; 3 \\
17511 &#x27; 1 &#x27; 1 &#x27; 2 &#x27; 1 \\
17522 &#x27; 3 &#x27; 2 &#x27; 2 &#x27; 1 \\
17533 &#x27; 2 &#x27; 1 &#x27; 2 &#x27; 2
1754&lt;&#x2F;div&gt;
1755&lt;p&gt;There isn&#x27;t a connection between ((s_1)) and ((s_3)) yet.
1756If we were to calculate ((A^4)):&lt;&#x2F;p&gt;
1757&lt;div class=&quot;matrix&quot;&gt;
17581 &#x27; 2 &#x27; 1 &#x27;   &#x27;   \\
1759  &#x27;   &#x27;   &#x27;   &#x27;   \\
1760  &#x27;   &#x27;   &#x27;   &#x27;   \\
1761  &#x27;   &#x27;   &#x27;   &#x27;   \\
1762  &#x27;   &#x27;   &#x27;   &#x27;
1763&lt;&#x2F;div&gt;
1764&lt;p&gt;We don&#x27;t need to calculate anymore. We now know that the graph is
1765strongly connected!&lt;&#x2F;p&gt;
1766&lt;hr &#x2F;&gt;
1767&lt;p&gt;Congratulations! You&#x27;ve completed this tiny introduction to graphs.
1768Now you can play around with them and design your own connections.&lt;&#x2F;p&gt;
1769&lt;p&gt;Hold the left mouse button on the above area and drag it down to create
1770a new node, or drag a node to this area to delete it.&lt;&#x2F;p&gt;
1771&lt;p&gt;To create new connections, hold the right mouse button on the node you
1772want to start with, and drag it to the node you want it to be connected to.&lt;&#x2F;p&gt;
1773&lt;p&gt;To delete the connections coming from a specific node, middle click it.&lt;&#x2F;p&gt;
1774&lt;table&gt;&lt;tr&gt;&lt;td style=&quot;width:100%;&quot;&gt;
1775  &lt;button onclick=&quot;resetConnections()&quot;&gt;Reset connections&lt;&#x2F;button&gt;
1776  &lt;button onclick=&quot;clearNodes()&quot;&gt;Clear all the nodes&lt;&#x2F;button&gt;
1777  &lt;br &#x2F;&gt;
1778  &lt;br &#x2F;&gt;
1779  &lt;label for=&quot;matrixOrder&quot;&gt;Show matrix of order:&lt;&#x2F;label&gt;
1780  &lt;input id=&quot;matrixOrder&quot; type=&quot;number&quot; min=&quot;1&quot; max=&quot;5&quot;
1781                          value=&quot;1&quot; oninput=&quot;updateOrder()&quot;&gt;
1782  &lt;br &#x2F;&gt;
1783  &lt;label for=&quot;matrixAccum&quot;&gt;Show accumulated matrix&lt;&#x2F;label&gt;
1784  &lt;input id=&quot;matrixAccum&quot; type=&quot;checkbox&quot; onchange=&quot;updateOrder()&quot;&gt;
1785  &lt;br &#x2F;&gt;
1786  &lt;br &#x2F;&gt;
1787  &lt;div&gt;
1788    &lt;table id=&quot;matrixTable&quot;&gt;&lt;&#x2F;table&gt;
1789  &lt;&#x2F;div&gt;
1790&lt;&#x2F;td&gt;&lt;td&gt;
1791  &lt;canvas id=&quot;canvas&quot; width=&quot;400&quot; height=&quot;400&quot; oncontextmenu=&quot;return false;&quot;&gt;
1792  Looks like your browser won&#x27;t let you see this fancy example :(
1793  &lt;&#x2F;canvas&gt;
1794  &lt;br &#x2F;&gt;
1795&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;table&gt;
1796&lt;script src=&quot;tinyparser.js&quot;&gt;&lt;&#x2F;script&gt;
1797&lt;script src=&quot;enhancements.js&quot;&gt;&lt;&#x2F;script&gt;
1798&lt;script src=&quot;graphs.js&quot;&gt;&lt;&#x2F;script&gt;
1799</content>
1800	</entry>
1801	<entry xml:lang="en">
1802		<title>Installing NixOS</title>
1803		<published>2017-05-13T00:00:00+00:00</published>
1804		<updated>2019-02-16T00:00:00+00:00</updated>
1805		<link href="https://lonami.dev/blog/installing-nixos/" type="text/html"/>
1806		<id>https://lonami.dev/blog/installing-nixos/</id>
1807		<content type="html">&lt;h2 id=&quot;update&quot;&gt;Update&lt;&#x2F;h2&gt;
1808&lt;p&gt;&lt;em&gt;Please see &lt;a href=&quot;..&#x2F;installing_nixos_2&#x2F;index.html&quot;&gt;my followup post with NixOS&lt;&#x2F;a&gt; for a far better experience with it&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
1809&lt;hr &#x2F;&gt;
1810&lt;p&gt;Today I decided to install &lt;a href=&quot;http:&#x2F;&#x2F;nixos.org&#x2F;&quot;&gt;NixOS&lt;&#x2F;a&gt; as a recommendation, a purely functional Linux distribution, since &lt;a href=&quot;https:&#x2F;&#x2F;xubuntu.org&#x2F;&quot;&gt;Xubuntu&lt;&#x2F;a&gt; kept crashing. Here&#x27;s my journey, and how I managed to install it from a terminal for the first time in my life. Steps aren&#x27;t hard, but they may not seem obvious at first.&lt;&#x2F;p&gt;
1811&lt;ul&gt;
1812&lt;li&gt;
1813&lt;p&gt;Grab the Live CD, burn it on a USB stick and boot. I recommend using &lt;a href=&quot;https:&#x2F;&#x2F;etcher.io&#x2F;&quot;&gt;Etcher&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
1814&lt;&#x2F;li&gt;
1815&lt;li&gt;
1816&lt;p&gt;Type &lt;code&gt;systemctl start display-manager&lt;&#x2F;code&gt; and wait.&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
1817&lt;&#x2F;li&gt;
1818&lt;li&gt;
1819&lt;p&gt;Open both the manual and the &lt;code&gt;konsole&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1820&lt;&#x2F;li&gt;
1821&lt;li&gt;
1822&lt;p&gt;Connect to the network using the GUI.&lt;&#x2F;p&gt;
1823&lt;&#x2F;li&gt;
1824&lt;li&gt;
1825&lt;p&gt;Create the disk partitions by using &lt;code&gt;fdisk&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1826&lt;p&gt;You can list them with &lt;code&gt;fdisk -l&lt;&#x2F;code&gt;, modify a certain drive with &lt;code&gt;fdisk &#x2F;dev&#x2F;sdX&lt;&#x2F;code&gt; (for instance, &lt;code&gt;&#x2F;dev&#x2F;sda&lt;&#x2F;code&gt;) and follow the instructions.&lt;&#x2F;p&gt;
1827&lt;p&gt;To create the file system, use &lt;code&gt;mkfs.ext4 -L &amp;lt;label&amp;gt; &#x2F;dev&#x2F;sdXY&lt;&#x2F;code&gt; and swap with &lt;code&gt;mkswap -L &amp;lt;label&amp;gt; &#x2F;dev&#x2F;sdXY&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1828&lt;p&gt;The EFI partition should be done with &lt;code&gt;mkfs.vfat&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1829&lt;&#x2F;li&gt;
1830&lt;li&gt;
1831&lt;p&gt;Mount the target to &lt;code&gt;&#x2F;mnt&lt;&#x2F;code&gt; e.g. if the label was &lt;code&gt;nixos&lt;&#x2F;code&gt;, &lt;code&gt;mount &#x2F;dev&#x2F;disk&#x2F;by-label&#x2F;nixos &#x2F;mnt&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
1832&lt;&#x2F;li&gt;
1833&lt;li&gt;
1834&lt;p&gt;&lt;code&gt;mkdir &#x2F;mnt&#x2F;boot&lt;&#x2F;code&gt; and then mount your EFI partition to it.&lt;&#x2F;p&gt;
1835&lt;&#x2F;li&gt;
1836&lt;li&gt;
1837&lt;p&gt;Generate a configuration template with &lt;code&gt;nixos-generate-config --root &#x2F;mnt&lt;&#x2F;code&gt;, and modify it with &lt;code&gt;nano &#x2F;etc&#x2F;nixos&#x2F;configuration.nix&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1838&lt;&#x2F;li&gt;
1839&lt;li&gt;
1840&lt;p&gt;While modifying the configuration, make sure to add &lt;code&gt;boot.loader.grub.device = &amp;quot;&#x2F;dev&#x2F;sda&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
1841&lt;&#x2F;li&gt;
1842&lt;li&gt;
1843&lt;p&gt;More useful configuration things are:&lt;&#x2F;p&gt;
1844&lt;ul&gt;
1845&lt;li&gt;Uncomment the whole &lt;code&gt;i18n&lt;&#x2F;code&gt; block.&lt;&#x2F;li&gt;
1846&lt;li&gt;Add some essential packages like &lt;code&gt;environment.systemPackages = with pkgs; [wget git firefox pulseaudio networkmanagerapplet];&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
1847&lt;li&gt;If you want to use XFCE, add &lt;code&gt;services.xserver.desktopManager.xfce.enable = true;&lt;&#x2F;code&gt;, otherwise, you don&#x27;t need &lt;code&gt;networkmanagerapplet&lt;&#x2F;code&gt; either. Make sure to add &lt;code&gt;networking.networkmanager.enable = true;&lt;&#x2F;code&gt; too.&lt;&#x2F;li&gt;
1848&lt;li&gt;Define some user for yourself (modify &lt;code&gt;guest&lt;&#x2F;code&gt; name) and use a UID greater than 1000. Also, add yourself to &lt;code&gt;extraGroups = [&amp;quot;wheel&amp;quot; &amp;quot;networkmanager&amp;quot;];&lt;&#x2F;code&gt; (the first to be able to &lt;code&gt;sudo&lt;&#x2F;code&gt;, the second to use network related things).&lt;&#x2F;li&gt;
1849&lt;&#x2F;ul&gt;
1850&lt;&#x2F;li&gt;
1851&lt;li&gt;
1852&lt;p&gt;Run &lt;code&gt;nixos-install&lt;&#x2F;code&gt;. If you ever modify that file again, to add more packages for instance (this is how they&#x27;re installed), run &lt;code&gt;nixos-rebuild switch&lt;&#x2F;code&gt; (or use &lt;code&gt;test&lt;&#x2F;code&gt; to test but don&#x27;t boot to it, or &lt;code&gt;boot&lt;&#x2F;code&gt; not to switch but to use on next boot.&lt;&#x2F;p&gt;
1853&lt;&#x2F;li&gt;
1854&lt;li&gt;
1855&lt;p&gt;&lt;code&gt;reboot&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
1856&lt;&#x2F;li&gt;
1857&lt;li&gt;
1858&lt;p&gt;Login as &lt;code&gt;root&lt;&#x2F;code&gt;, and set a password for your user with &lt;code&gt;passwd &amp;lt;user&amp;gt;&lt;&#x2F;code&gt;. Done!&lt;&#x2F;p&gt;
1859&lt;&#x2F;li&gt;
1860&lt;&#x2F;ul&gt;
1861&lt;p&gt;I enjoyed the process of installing it, and it&#x27;s really cool that it has versioning and is so clean to keep track of which packages you install. But not being able to run arbitrary binaries by default is something very limitting in my opinion, though they&#x27;ve done a good job.&lt;&#x2F;p&gt;
1862&lt;p&gt;I&#x27;m now back to Xubuntu, with a fresh install.&lt;&#x2F;p&gt;
1863&lt;h2 id=&quot;update-1&quot;&gt;Update&lt;&#x2F;h2&gt;
1864&lt;p&gt;It is not true that &amp;quot;they don&#x27;t allow running arbitrary binaries by default&amp;quot;, as pointed out in their &lt;a href=&quot;https:&#x2F;&#x2F;nixos.org&#x2F;nixpkgs&#x2F;manual&#x2F;#sec-fhs-environments&quot;&gt;manual, buildFHSUserEnv&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
1865&lt;blockquote&gt;
1866&lt;p&gt;&lt;code&gt;buildFHSUserEnv&lt;&#x2F;code&gt; provides a way to build and run FHS-compatible lightweight sandboxes. It creates an isolated root with bound &lt;code&gt;&#x2F;nix&#x2F;store&lt;&#x2F;code&gt;, so its footprint in terms of disk space needed is quite small. This allows one to run software which is hard or unfeasible to patch for NixOS -- 3rd-party source trees with FHS assumptions, games distributed as tarballs, software with integrity checking and&#x2F;or external self-updated binaries. It uses Linux namespaces feature to create temporary lightweight environments which are destroyed after all child processes exit, without root user rights requirement.&lt;&#x2F;p&gt;
1867&lt;&#x2F;blockquote&gt;
1868&lt;p&gt;Thanks to &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;bb010g&quot;&gt;@bb010g&lt;&#x2F;a&gt; for pointing this out.&lt;&#x2F;p&gt;
1869&lt;h2 id=&quot;notes&quot;&gt;Notes&lt;&#x2F;h2&gt;
1870&lt;div class=&quot;footnote-definition&quot; id=&quot;1&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;1&lt;&#x2F;sup&gt;
1871&lt;p&gt;The keyboard mapping is a bit strange. On my Spanish keyboard, the keys were as follows:&lt;&#x2F;p&gt;
1872&lt;&#x2F;div&gt;
1873&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Keyboard&lt;&#x2F;th&gt;&lt;th&gt;Maps to&lt;&#x2F;th&gt;&lt;th&gt;Shift&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
1874&lt;tr&gt;&lt;td&gt;&#x27;&lt;&#x2F;td&gt;&lt;td&gt;-&lt;&#x2F;td&gt;&lt;td&gt;_&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
1875&lt;tr&gt;&lt;td&gt;´&lt;&#x2F;td&gt;&lt;td&gt;&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&amp;quot;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
1876&lt;tr&gt;&lt;td&gt;`&lt;&#x2F;td&gt;&lt;td&gt;[&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
1877&lt;tr&gt;&lt;td&gt;+&lt;&#x2F;td&gt;&lt;td&gt;]&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
1878&lt;tr&gt;&lt;td&gt;¡&lt;&#x2F;td&gt;&lt;td&gt;=&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
1879&lt;tr&gt;&lt;td&gt;-&lt;&#x2F;td&gt;&lt;td&gt;&#x2F;&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
1880&lt;tr&gt;&lt;td&gt;ñ&lt;&#x2F;td&gt;&lt;td&gt;;&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
1881&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
1882</content>
1883	</entry>
1884</feed>