my article<\/a> about creating a script to help process my family finances, I mentioned a spreadsheet function called SUMPRODUCT. Let me explain a little more clearly how it works.<\/p>\n\nThe SUMPRODUCT function is available in LibreOffice Calc and Microsoft Excel, as well as other programs like Google Sheets. As the name suggests, it returns the sum of the products between the arrays in the arguments.<\/p>\n
Examples of SUMPRODUCT in Action<\/h2>\n
Here's an example. Take the following table of values:<\/p>\n
<\/p>\n
and the following formula:<\/p>\n
=SUMPRODUCT( B1:B4, C1:C4 )<\/code><\/p>\nThis is the equivalent of:<\/p>\n
\\(B1 \\times C1 + B2 \\times C2 + B3 \\times C3 + B4 \\times C4\\)<\/span><\/p>\nor<\/p>\n
\\(1 \\times 2 + 3 \\times 4 + 5 \\times 6 + 7 \\times 8\\)<\/span><\/p>\nwhich is 100.<\/p>\n
This also works for arrays of more than a single column (or row):<\/p>\n
<\/p>\n
=SUMPRODUCT( A1:B4, D1:E4 )<\/code><\/p>\nis<\/p>\n
\\(1 \\times 3 + 2 \\times 4 +5 \\times 7 + 6 \\times 8 +9 \\times 11 + 10 \\times 12 +13 \\times 15 + 14 \\times 16\\)<\/span><\/p>\nwhich is 732.<\/p>\n
And this works for multiple arrays as well, holding that each array has the same dimensions as all the others.<\/p>\n
<\/p>\n
=SUMPRODUCT( A1:A4, B1:B4, C1:C4 )<\/code><\/p>\nGives<\/p>\n
\\(1 \\times 2 \\times 3 + 4 \\times 5 \\times 6 + 7 \\times 8 \\times 9 + 10 \\times 11 \\times 12\\)<\/span><\/p>\nwhich is 1950.<\/p>\n
All this can be done with simpler formulae and intermediate data fields; but then again, all this can be done by hand on paper, or by a dozen carefully trained monkeys with sticks and stones. A cost-benefit analysis may be in order.<\/p>\n
What's interesting about SUMPRODUCT, and what makes it useful for my situation, is the ability to apply conditions on the arrays. Suppose we have the following table, and we want to filter the results:<\/p>\n
<\/p>\n
If you only want the sum of the products for all the apples, you can use this formula:<\/p>\n
=SUMPRODUCT( A1:A4 = E2, B1:B4, C1:C4 )<\/code><\/p>\nWhat that first argument, A1:A4 = E2<\/code>, does is inspect each value in the array A1:A4<\/code> and checks if it's equal to the value in E2<\/code> (it also works if you put in \"apple\"<\/code> directly into the formula). This turns it into a boolean array, containing only true<\/code> or false<\/code>. In some spreadsheet programs, you have to convert the true<\/code>s and false<\/code>s into numbers, but in LibreOffice, it will automatically coerce true<\/code> into 1 and false<\/code> into 0 whenever the situation requires it.<\/p>\nThe formula is then equivalent to:<\/p>\n
\\(1 \\times 1 \\times 2 + 1 \\times 3 \\times 4 + 0 \\times 5 \\times 6 + 1 \\times 7 \\times 8\\)<\/span><\/p>\nwhich is 70.<\/p>\n
The false<\/code>s become zeroes, which when multiplied by any value becomes zero, and cancels out that term. This also works with other mathematical checks, like <<\/code> or ><\/code>.<\/p>\nHow I Used It<\/h2>\n
So here's how I used it. I have a table that looks like this (somewhat simplified):<\/p>\n
<\/p>\n
Suppose I...<\/p>","tags":["tech choice","finances","automation","spreadsheets"],"image":"\/blog\/user\/pages\/01.blog\/how-i-used-the-sumproduct-function\/sumproduct-0.png"},{"title":"Family Finances Script","date_published":"2018-09-05T16:32:00-04:00","id":"https:\/\/www.brwong.net\/blog\/family-finances-script","url":"https:\/\/www.brwong.net\/blog\/family-finances-script","content_html":"
I've been looking for a better way to keep track of my family finances, but - being the picky person I am - I've been having trouble finding one that meets all my needs. Obviously, my software developer mindset keeps telling me to make my own solution, but also, when it comes to my money and spending habits, I am even more privacy-obsessed than usual.<\/p>\n\n
What We've Been Doing<\/h2>\n
Usually, my wife and I look over our finances at least monthly. The idea is just to be able to track where and when my money is coming into my possession, where and when it is leaving, and then using that information to plan for the future (ie: budget). What we had been doing up until now was using a Google Sheet to track categories of spending. On the second Monday of every month, the two of us would sit down, and review our incomes and expenditures of the past month. We would categorize each transaction, and type in the amount in the appropriate cell. So, for example, if I ate out for lunch, we would type in \"personal - brandon: $10.27\". Because most categories would have more than one transaction in it, instead of a simple value, we would type in a calculation in the formula bar - \"= 10.27 + 5.77 + 12.99\" - and the spreadsheet gives the total.<\/p>\n
<\/p>\n
Yes, all the numbers in the images are made up.<\/em><\/p>\nThis process worked, in that it gave us a bird's-eye view of where our money was coming from, and where it was going, as well as whether we ended the month in the red or in the black. It being a spreadsheet, I could also customize it as we wanted. I could add or remove categories, add derived values (like sums or averages), and highlight certain data that I felt was important. There were some problems, however.<\/p>\n
The biggest one was that, with this spreadsheet, we did not track individual transactions, only categories. This gave us a general view, but no detailed information. This also meant that we had to wait until a month was over (and at least a few days after that) before considering the expenditures for that month. This is because it's difficult to add to a dozen or so cells, each with their own little summation formula, days later. It was also near impossible to find errors (like typos), let alone fix them, without redoing the whole month.<\/p>\n
There were also a lot of recurring transactions, such as rent and utilities, that we had to type in with all the rest. They have the same payee, and often, the same amount, every month. It was annoying to type it in over and over again. This is a prime candidate for automation.<\/p>\n
Finally, although this system dealt with subtotals, and not details, I was still wary of feeding personal financial information into the Google machine (my love for them notwithstanding).<\/p>\n
A New Solution<\/h2>\n
This is what...<\/p>","tags":["personal","tech choice","self-hosted","workflow","finances","automation"],"image":"\/blog\/user\/pages\/01.blog\/family-finances-script\/csv-file.png"},{"title":"Keyboard-Centric Operation","date_published":"2017-12-23T16:11:00-05:00","id":"https:\/\/www.brwong.net\/blog\/keyboard-centric-operation","url":"https:\/\/www.brwong.net\/blog\/keyboard-centric-operation","content_html":"
Back around the time that I was learning vim, my friend Simon from university introduced me to the concept of a \"power user\".<\/p>\n
In general, a power user is someone that can get his or her way around a computer with great familiarity and ease. As someone who uses a computer very often - let's say... more than the average person - that part about \"great familiarity and ease\" appealed to me quite a bit. In order to get to that point, part of it requires getting used to certain workflows that seem weird at first, but are really efficient once you're more used to it. Part of it requires the right hardware and software. In the end, it mostly requires experimentation and practice.<\/p>\n
Back to vim. vim is a text editing program. I use it mostly for writing code. It's a command-line program, meaning that it's completely text-based: no toolbars, no icons, no buttons. You can't even use the mouse with it. What really sets it apart, though, is the fact that it's a modal editor; meaning it has \"modes\". So when you open vim for the first time, you'll see that you can't immediately start typing your text. That's because by default, vim is in \"command mode\". Certain letters that you type are issuing commands to the editor. This could be as simple as deleting a character or a line, or switching to another mode. You need to switch to the \"insert mode\" before you can actually type your content. Incidentally, vim is also notoriously and hilariously difficult for beginners to exit<\/a>.<\/p>\nModes? No buttons? No mouse? Why go through all the hassle? Because, despite the steep learning curve, vim is really efficient to use. I can get far more done in the same amount of time in vim than I could using, for example, my previous default editor, notepad++. And one of the greatest parts of it is, I don't have to use the mouse.<\/p>\n
Keyboard-Heavy Workflow<\/h2>\n
That's right. As it turns out, the mouse is a remarkably inefficient computer input device for many situations. Take as a sample use case: moving the cursor of a text editor. With a mouse, you would first have to take your hand off the keyboard, and lay it on the mouse. Next, you would usually have to move the mouse a bit in order to find the pointer on the screen. If you have a nice editor, the pointer was probably hidden so that it is out of the way. Once it has reappeared and you see it dancing in a corner, you need to scroll the page, so that you can find the place where you want the cursor. This is done either with the scroll wheel (it's rare to find a mouse without one), or by clicking and dragging the scroll bar. The first option requires several repetitive motions of your finger on the wheel. The second option requires locating the scroll bar, moving the pointer there,...<\/p>","tags":["tech choice","keynav","vim","xmonad","workflow"],"image":"\/blog\/user\/pages\/01.blog\/keyboard-centric-operation\/no-mouse-photo.jpg"},{"title":"How Asymmetric Encryption Works Under the Hood","date_published":"2017-09-20T16:34:00-04:00","id":"https:\/\/www.brwong.net\/blog\/how-asymmetric-encryption-works-under-the-hood","url":"https:\/\/www.brwong.net\/blog\/how-asymmetric-encryption-works-under-the-hood","content_html":"
This is a simplified overview of how public-key cryptography works. It is meant to be a supplement to my other article, Asymmetric Encryption<\/a>, which you might want to read first. What you are about to read involves some high-school-level math<\/strong>. If that's not your thing, feel free to skip this one!<\/p>\n\nAlso note, I'm going to cover specifically how RSA encryption works. This system is slowly being replaced by others, like elliptic curve cryptography, but it's the oldest and still the most popular.<\/em><\/p>\nThe principle reference for this explanation are my notes from my university discrete mathematics class. I have simplified it a bit, but not by much - turns out this is already pretty easy to get!<\/em><\/p>\nConcepts<\/h2>\n
There are three mathematical concepts that you need in order to understand how and why this system works: exponentiation, modular arithmetic, and prime numbers.<\/p>\n
Exponentiation<\/h3>\n
Exponentiation is simple; it's just the number of times you multiply a number by itself. For example, 23<\/sup> = 2 * 2 * 2 = 8.<\/p>\nModular Arithmetic<\/h3>\n
Modular arithmetic is even simpler. It is when you take a number and count up to that number, but reset as you hit another number called the modulus<\/em>. Loosely, it is the integer remainder after a division.<\/p>\nThis is sometimes known as \"clock counting\", since clocks are a great example of this. In the case of a clock, our modulus is 12. If someone tells you that it's 14 o'clock (or 1400 hours), you know that they mean 2 o'clock, since you counted up to 12, then another 2 hours after that. If, for some strange reason, someone told you it was 26 o'clock, that would also mean 2 o'clock, since you counted up to 12 twice before finally counting another 2 hours.<\/p>\n
In many programming languages, the modulo operation is written with a percent sign: 14 % 12 = 2. Mathematicians would say \"14 is congruent with 2 mod 12\", and write: 14 ≡ 2 (mod 12). Other examples include: 55 ≡ 11 (mod 22), 31 % 4 = 3, and 6 % 91 = 6.<\/p>\n
Prime Numbers<\/h3>\n
Prime numbers are whole numbers that can only be evenly divided by one or itself. In other words, it has no other factors<\/em>. Seven is a great prime number - seven is only evenly divisible by 1 and 7. You cannot divide it by 2, 3, 4, 5, or 6 without getting some remainder.<\/p>\nThere are an infinite number of prime numbers. Because computers can calculate so quickly, the prime numbers that they use for encryption are very long (hundreds of digits).<\/p>\n
The other important thing to know is that every integer has a unique prime factorization. This means that if I take two prime numbers and multiply them together, no other pair (or any combination) of prime numbers will multiply together to get that same product. Multiplying two prime numbers together - even very big ones - is easy and fast. Finding out...<\/p>","image":"\/blog\/user\/pages\/01.blog\/how-asymmetric-encryption-works-under-the-hood\/rsa-notes-2.jpg"}]}