One Man's Trash is Another Man's Blog
type: channel
date: 2021-05-25T22:25:16Z
update period: hourly
update frequency: 1
update base: 2000-01-01T12:00+00:00
generator agent: https://wordpress.org/
items: A Better Spaced Repetition Learning Algorithm: SM2+
items: Using Vector3.Lerp() correctly in Unity
items: How fast are computers in everyday terms?
items: A Heap-Based C# Priority Queue Optimized for A* Pathfinding
items: Branchless Conditionals (Compiler Optimization Technique)
items: Making Use of Spare Hard-Drives
items: 1+2+3+… = -1/12
items: (Un)Common Questions about Electricity
items: How to Give Someone Elf Ears and Vampire Fangs in Photoshop
items: How to Double the Length of Any Essay (Without Writing a Word!)

A Better Spaced Repetition Learning Algorithm: SM2+
type: item
creator: BlueRaja
date: 2016-08-03T02:34:10Z
subject: Uncategorized
description: By far the most popular algorithm for Spaced Repetition is SM2. Sites like Anki, Duolingo, Memrise, and Wanikani all chose SM2 over later SM-iterations (eg. SM15) because it is extremely simple, yet effective. Despite that, it still has a number of glaring issues. In this article I explain those issues, and provide a simple way […]
encoded: By far the most popular algorithm for Spaced Repetition is SM2. Sites like Anki, Duolingo, Memrise, and Wanikani all chose SM2 over later SM-iterations (eg. SM15) because it is extremely simple, yet effective. Despite that, it still has a number of glaring issues. In this article I explain those issues, and provide a simple way to resolve them. Original SM2 Algorithm The algorithm determines which items the user must review every day. To do that, it attaches the following data to every review-item: easiness:float – A number ≥ 1.3 representing how easy the item is, with 1.3 being the hardest. Defaults to 2.5 consecutiveCorrectAnswers:int – How many times in a row the user has correctly answered this item nextDueDate:datetime – The next time this item needs to be reviewed When the user wants to review, every item past its nextDueDate is queued. After the user reviews an item, they (or the software) give themselves a performanceRating on a scale from 0-5 (0=worst, 5=best). Set a cutoff for an answer being “correct” (defaults to 3). Then make the following changes to that item: easiness += consecutiveCorrectAnswers = nextDueDate = <img decoding="async" src="https://www.blueraja.com/blog/wp-content/ql-cache/quicklatex.com-cd970a9579b79d8e1f48c5c7ed23c311_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="\begin{cases} \text{now + $(6*easiness^{consecutiveCorrectAnswers-1})$ days}, \text{ if correct} \\ \text{now + 1 day}, \text{ if incorrect} \end{cases}" title="Rendered by QuickLaTeX.com" height="54" width="491" style="vertical-align: -23px;"/> Problems with SM2 SM2 has a number of issues that limit its usefulness/effectiveness: Problem: Non-generic variable ranges The variable ranges are very specific to the original software, Supermemo. easiness is a number ≥ 1.3, while performanceRating is an integer from [0,5] Solution Normalize easiness and performanceRating to [0,1]. This requires setting a max value for easiness , which I set to 3.0. I also replace…

Using Vector3.Lerp() correctly in Unity
type: item
creator: BlueRaja
date: 2014-02-08T20:09:52Z
subject: Uncategorized
description: A lot of Unity 3D tutorials online use Unity’s linear interpolation incorrectly, including the official video tutorials(!). However, it’s actually very easy to use, once you understand how it works. The prototype for Vector3.Lerp looks like this [crayon-6a2ea7c083423463438024-i/] What it does is simple: it returns a point between start and finish, based on the value […]
encoded: A lot of Unity 3D tutorials online use Unity’s linear interpolation incorrectly, including the official video tutorials(!). However, it’s actually very easy to use, once you understand how it works. The prototype for Vector3.Lerp looks like this static Vector3 Lerp(Vector3 start, Vector3 finish, float percentage) What it does is simple: it returns a point between start and finish, based on the value of percentage: At percentage = 0.0, Lerp() returns start At percentage = 1.0, Lerp() returns finish At 0.0 < percentage < 1.0, Lerp() returns a point between start and finish. So at percentage = 0.5, it returns the point exactly halfway between start and finish. And at percentage = 0.10, it returns a point very near to start etc. This explains why it’s called linear interpolation: It moves smoothly (interpolates) at a constant speed (linearly) between two points! How to use Lerp correctly To use Lerp() correctly, you simply have to make sure that you pass the same start and finish values every frame while moving percentage up from 0.0 to 1.0 each frame. Here’s an example. When the spacebar is pressed, we’ll lerp our object 10 spaces forward over a period of 1 second. using UnityEngine; using System.Collections; public class LerpOnSpacebarScript : MonoBehaviour { /// /// The time taken to move from the start to finish positions /// public float timeTakenDuringLerp = 1f; /// /// How far the object should move when 'space' is pressed /// public float distanceToMove = 10; //Whether we are currently interpolating or not private bool _isLerping; //The start and finish positions for the interpolation private Vector3 _startPosition; private Vector3 _endPosition; //The Time.time value when we started the interpolation private float _timeStartedLerping; /// /// Called to begin the linear interpolation /// void StartLerping() { _isLerping = true; _timeStartedLerping = Time.time; //We set the start position to the current position, and the finish to 10 spaces in the 'forward' direct…

How fast are computers in everyday terms?
type: item
creator: BlueRaja
date: 2013-07-25T04:50:04Z
subject: Uncategorized
description: It’s hard for humans to understand just how freakishly fast modern computers are. Here’s an analogy that has helped me: Imagine that it takes you 1 second to do a simple computation, like adding two numbers. If you were to sit at your desk and add numbers all day non-stop, with no sleep, every day […]
encoded: It’s hard for humans to understand just how freakishly fast modern computers are. Here’s an analogy that has helped me: Imagine that it takes you 1 second to do a simple computation, like adding two numbers. If you were to sit at your desk and add numbers all day non-stop, with no sleep, every day of every month of every year, it would take you 95 years straight to do what a computer can do in one second.† 95 years. That’s probably longer than your entire life. Stop to think about how many seconds have passed in your life, and how many more will need to pass before you hit 95 years old. A computer does that much work every second. Now that we have a relatable timescale, here are some approximate computer-times for some programming tasks (and other things). Keep in mind that 95 years of computer-time is one second of real-life time. The following are all in computer-time (Based on Intel i7 x86 timings): Time for light to travel 1 cm (in vacuum) 0.1 seconds Addition/subtraction 1 second If statement 2 seconds Integer multiplication 5 seconds Cache miss (L1 to L2) 10 seconds Function call†† 8-12 seconds Virtual function call†† 12-14 seconds If statement (branch prediction failure) 20 seconds Integer division 17-28 seconds Cache miss (L2 to L3) 40 seconds Cache miss (L3 to DRAM) 2 minutes SHA1 hash of 64-byte message 15 minutes Call to malloc() (rough estimate) 30 minutes Time for a speeding bullet to travel one inch 3 days Fastest Windows Timer Resolution (0.5ms) 2 weeks Read 1MB file with high-end SSD drive (1.9ms) 2 months Fastest blip the human eye can see (2ms) 2.25 months Executing a large-ish SQL statement (3ms) 3.5 months Time between frames in a 60fps video game (16.6ms) 1.5 years Time it takes an incandescent lightbulb to turn on (90ms) 8.5 years Average human reaction time (220ms) 21 years † That’s assuming a 3 GHz x86 CPU with one core and no throttling or instruction level parallelism. If we took into account the multiple cores and ILP that modern CPUs have…

A Heap-Based C# Priority Queue Optimized for A* Pathfinding
type: item
creator: BlueRaja
date: 2013-07-03T06:44:11Z
subject: Uncategorized
description: In fine-tuning my Pathery application, I found the need for a faster priority queue. Since this could be useful to others (pathfinding is often a bottleneck for video games), I finally got around to publishing it. You can find it here; or read the documentation here. Enjoy! Note: If you found this page hoping to […]
encoded: In fine-tuning my Pathery application, I found the need for a faster priority queue. Since this could be useful to others (pathfinding is often a bottleneck for video games), I finally got around to publishing it. You can find it here; or read the documentation here. Enjoy! Note: If you found this page hoping to optimize your pathfinder, you may want to check out this post first, which has a few tips on optimizing pathfinders for games. Additional Reading: Really Simple, Stupid How to Double the Length of Any Essay (Without Writing a Word!) How fast are computers in everyday terms? RSA Encryption, Part 2 1+2+3+… = -1/12

Branchless Conditionals (Compiler Optimization Technique)
type: item
creator: BlueRaja
date: 2011-05-10T07:51:08Z
subject: Uncategorized
description: One of the neater and lesser-known optimizations a compiler can perform is a “branchless conditional” – a conditional statement that contains no branches. To understand what this means, take a look at the following C-snippet: [crayon-6a2ea7c085407283508694/] When compiled with no optimizations in Visual Studio, this is the output [crayon-6a2ea7c08540f135085981/] Nothing surprising here – almost a […]
encoded: One of the neater and lesser-known optimizations a compiler can perform is a “branchless conditional” – a conditional statement that contains no branches. To understand what this means, take a look at the following C-snippet: if(SomeFunc() == 4) return 54; else return 2; When compiled with no optimizations in Visual Studio, this is the output if(SomeFunc() == 4) 00A0140E call SomeFunc 00A01413 cmp eax, 4 00A01416 jne 00A01421 return 54; 00A01418 mov eax, 54 00A0141D jmp 00A01426 else return 2; 00A01421 mov eax, 2 00A01426 ret Nothing surprising here – almost a literal translation from C to assembly. Small, fast, efficient – what could we possibly improve upon? One possible improvement could be removing the conditional branch – the jne instruction. Branch instructions are not in-and-of themselves particularly slow; all a jmp instruction does is write a value to the Program Counter (PC) register, and on a simple CPU which reads and executes one instruction at a time, jne wouldn’t be slower than any other instruction which writes to a register. However, modern CPUs are anything but simple. On modern CPUs, instructions are not read then immediately executed, one-by-one. Rather, the process is split into multiple stages, called the Instruction Pipeline. This allows, for example, the instruction two instructions in the future to be fetched (read) while the next instruction is being decoded and the current instruction is being executed, and the previous instruction is writing its results to memory! This speeds up execution time enormously, but now that the CPU is essentially executing multiple instructions at once, the CPU designers must take extreme precautions to make sure that the results of the execution are still correct! And herein lies the problem with conditional jumps like jne: How does the processor know what the “next” instruction will be before it actually executes the conditional? The answer is: it doesn’t. It can guess (real-world programs are highly predicta…

Making Use of Spare Hard-Drives
type: item
creator: BlueRaja
date: 2009-08-21T06:20:23Z
subject: Uncategorized
description: Additional Reading: Why do we use Alternating Current (AC) instead of Direct Current (DC) in power lines?
encoded: Additional Reading: Why do we use Alternating Current (AC) instead of Direct Current (DC) in power lines?

1+2+3+… = -1/12
type: item
creator: BlueRaja
date: 2009-08-13T06:19:24Z
subject: Uncategorized
description: The following is from an essay on Ramanujan I wrote a few years back. Enjoy. …they recognized Ramanujan’s enormous talent for mathematics, and together they convinced Ramanujan to write to English mathematicians about his discoveries. […] The third letter he wrote, to M. J. M. Hill, received a reply, but was not very encouraging. […]
encoded: The following is from an essay on Ramanujan I wrote a few years back. Enjoy. …they recognized Ramanujan’s enormous talent for mathematics, and together they convinced Ramanujan to write to English mathematicians about his discoveries. […] The third letter he wrote, to M. J. M. Hill, received a reply, but was not very encouraging. In his reply, Hill stated, “Mr. Ramanujan is evidently a man with a taste for Mathematics, and with some ability, but he has got on two wrong lines. He does not understand the precautions which have to be taken in dealing with divergent series, otherwise he could not have obtained the erroneous results you send me, viz:– However, the problem was not with Ramanujan’s result itself, but rather with his lack of explanation of the result – or perhaps with Hill’s lack of knowledge on divergent series. Before Ramanujan’s result can be explained, though, we have to first take a step back over 150 years in history. In 1749, the mathematics giant Leonhard Euler wrote a paper in which he derived the paradoxical result that 1 – 2 + 3 – 4 + … = 1/4. Theorem (Euler) 1 – 2 + 3 – 4 + … = 1/4 Proof. Notice that the power series for 1/(x+1)2 is If we assume this to be true for all x, we can plug in the value x=1 to obtain the desired result! ◊ In order for his result to make sense, Euler proposed (several times throughout his life) that an extended definition of the word “sum” be made. In his own words, “Let us say, therefore, that the sum of any infinite series is the finite expression, by the expansion of which the series is generated. In this sense the sum of the infinite series 1 − x + x2 − x3 + … will be 1⁄1+x, because the series arises from the expansion of the fraction, whatever number is put in place of x. If this is agreed, the new definition of the word sum coincides with the ordinary meaning when a series converges; and since divergent series have no sum in the proper sense of the word, no inconvenience can arise from this new terminology. Finall…

(Un)Common Questions about Electricity
type: item
creator: BlueRaja
date: 2009-07-27T06:18:04Z
subject: Uncategorized
description: When I first began learning about electronics and electricity, there were a number of seemingly obvious questions that never seemed to be answered by my professors, books, or articles on electricity; I had to scrape together answers gradually, gathering knowledge from every source I could find. I’m collecting these questions and answers here in the […]
encoded: When I first began learning about electronics and electricity, there were a number of seemingly obvious questions that never seemed to be answered by my professors, books, or articles on electricity; I had to scrape together answers gradually, gathering knowledge from every source I could find. I’m collecting these questions and answers here in the hopes that they will someday save some poor internet-goer like yourself from all the trouble I had to go through. Contents Why do we use Alternating Current (AC) instead of Direct Current (DC) in power lines? Does electricity flow from positive (+) to negative (-) or from negative to positive? What’s the difference between "voltage at a point" and "voltage between two points?" Also, what is ‘ground?’ How fast do electrons move in a circuit? Why can the resistor go at the beginning of the circuit or at the end? What’s the difference between neutral and ground? How is it possible that there’s not a complete circuit to the power plant? How does jump starting a car work if current only flows when there’s a difference in voltage? Do transformers obey Ohm’s Law? Additional Reading: How is it possible that there’s not a complete circuit to the power plant? What’s the difference between “voltage at a point” and “voltage between two points?” Also, what is ‘ground?’ Why can the resistor go at the beginning of the circuit OR at the end? Do transformers obey Ohm’s Law? Does electricity flow from positive (+) to negative (-) or from negative to positive?

How to Give Someone Elf Ears and Vampire Fangs in Photoshop
type: item
creator: BlueRaja
date: 2009-06-21T06:16:41Z
subject: Uncategorized
description: As if the Internet doesn’t have enough weird fetishes floating around, here’s a quick tutorial for beginners on how to give someone elf ears and vampire fangs in photoshop. For this tutorial, I’ve used a stock photograph of the beautiful American model, Valerie Hatfield. Those interested in her work can contact her here. Open your […]
encoded: As if the Internet doesn’t have enough weird fetishes floating around, here’s a quick tutorial for beginners on how to give someone elf ears and vampire fangs in photoshop. For this tutorial, I’ve used a stock photograph of the beautiful American model, Valerie Hatfield. Those interested in her work can contact her here. Open your image in Photoshop As always, duplicate the background layer before anything else. Highlight the ear. This can be done rather easily using the quick-select tool (alt+click to remove from selection). Now warp the ear (edit->transform->warp) to your liking. (Note that you may have to remove part of the ear from the background. See any tutorial on removing objects from images – you could, for example, simply copy and paste a piece of hair over the old ear) That takes care of the elf ears – now let’s give her vampire teeth as well. We could use the same technique we used for the ears, but that leaves the tooth looking flat and two-dimensional; I prefer a technique which causes the tooth to affect the lips as well. Select the tooth in the same way you selected the ear. Now, using the lasso tool, add to the selection (by holding shift) a small portion of the lip and chin just below and around the tooth, as so: Open the liquify window (Filter->liquify). Using the forward-warp tool and a brush about the size of the tooth, drag the tooth downwards. Try to do it one one swift motion, using undo (ctrl+alt+z) to go back as many times as necessary. Select the Reconstuct Tool on the left, and use it to give your tooth a point. You may want to lower your brush density and experiment with different reconstruct modes (under ‘Tool Options’) to get it just right. That’s it! Here’s what the finished tooth looks like: And, after a few more tweaks, the final image: Additional Reading: The Greatest Romance Stories of All Time Polka, Burgers, and Sound Financial Advice How to Double the Length of Any Essay (Without Writing a Word!) RSA Encryption, Part 2 Java Big…

How to Double the Length of Any Essay (Without Writing a Word!)
type: item
creator: BlueRaja
date: 2009-06-15T06:11:05Z
subject: Uncategorized
description: As promised, here are a few tips to help double the length of any essay. All of these statistics/instructions are for Microsoft Word 2007, but they apply equally well to older versions of Word or OpenOffice. Replace All the Periods Increase in size: 42.9% How to do it: Go to edit->replace and place a period […]
encoded: As promised, here are a few tips to help double the length of any essay. All of these statistics/instructions are for Microsoft Word 2007, but they apply equally well to older versions of Word or OpenOffice. Replace All the Periods Increase in size: 42.9% How to do it: Go to edit->replace and place a period (.) in both boxes. Highlight the period in the "replace with" box, and click on "more" in the lower-right hand corner. Then click format->font. Under "size," increase the font-size significantly – I used 16 in this example. Click OK, then hit "replace all." Increase the Paragraph Spacing Increase in size: 21.6% How to do it: Higlight everything (edit->select all), right-click->Paragraph. Set "Line Spacing" to multiple, and set it to something between 2 and 3 (or between 1 and 2 if it’s a single-spaced essay). I set it to 2.5 for this example. Change the Font Size Increase in size: 9.1% How to do it: The font size is right next to the font face, at the top. After highlighting everything, increase it by up to a whole point – I set it a half-point larger (11.5) for this example. Use a Different Font Increase in size: 9.1% How to do it: Highlight everything, and just change the font from something other than the default, Calibri. I changed it to the old default, Times New Roman (12 pt font), for the 9.1% increase, but there are probably other similiar-looking fonts that will increase that even more. Change the Margins Increase in size: 7.2% How to do it: Go to Page Layout->Margins->Custom and increase the margins. They default to 1" all around – I changed it to 1.15" all around. Change the Character Spacing Increase in size: 7.1% How to do it: Select everything (ctrl+a), then right-click->Font->Character Spacing. Change the spacing to something small (Half a point or less). I use 0.3pt All effects put together: Increase in size: 114.5% (over double!) Additional Reading: How to Give Someone Elf Ears and Vampire Fangs in Photoshop How to Save Thousands on Textbooks Gol…