More from The Web Witch's Blog
And here we are three years after I wrote about the Google Pixel Fold being announced, followed now with the announcement of the iPhone Duo...(I have questions about the naming by the way). Four years ago I was talking about web primitives in the platform for the Surface Duo. My how time flies. There are CSS media features, a Viewport Segments API, a Device Posture API but Chromium based browsers are the only ones currently supporting these things. I haven't been able to find any signal yet on whether Safari will support these things in the web platform as the developer docs focus on application development. If you're interested in trying out the platform features, you can emulate the Surface Duo and Galaxy Z Fold in the developer tools. And if you're thinking, do I really have to have my website adapt to two screens? The answer is no. Adding a design to an application or dual screen makes sense if you have an experience that has two simulataneous contexts that are useful e.g. a list of email messages/inbox on one screen, an open message, email thread or email composer on the other. Here's one of my talks from 2022 if you're interested in learning more about what's available in the browser for dual screen/foldable devices. Happy building :)
The year flies by when you're postpartum, sleep-deprived and your little bubba is suddenly on the move and making developmental leaps. Time is this sort of weird compressed experience, not dissimilar to the way I felt about COVID and 2020 (wasn't that just yestersday? No indeed it was not, it was 6 years ago). And I'm a bit discombobulated as September is upon us. Budget planning at work? Didn't I just do budget planning for 2026? I went back to work in June, which has been an adjustment and prompted many an identity crisis, but at the same time I am happy to be back and doing lots of soul-searching. I'm in a better place than the start of the summer. Part of the soul-searching has been prompted by AI and the state of tech that I re-entered into. I still hate how it is being shoved down our throats and the prioritization of data centers, especially in places experieincing drought. Everyone should have access to water and humans should be prioritized over a data center. Full stop. For my current role, it has been extremely helpful in speeding up mundane tasks like compiling reports, and giving me more time to spend on things like design and social media content, which I historically had barely enough time for. But I continue to be baffled by AI and its bubble. The IPO valuations seem wildly ridiculous, and I've seen the salaries offered to people and I wonder how it is even remotely sustainable. I also hate the fearmongering and the polarizing content ("AI is going to replace [your industry of choice here]") to create engagement bait that has come with the commercialization of this technology. It is a horrible and interesting time in tech. I have seen many qualified people laid off because of "cost-cutting", and it's not right. Summer Bits # We survived multiple heatwaves in South East England, and while I'm told there were four, it really felt continous up until a week or two ago. I've kept the windows open and the house chilly in the morning because it is a relief. The first heatwave in May was stressful as hell, with Chloe about to be 5 months and trying to keep her cool while our upstairs rose to 28 C. The number of parents lamenting online about the lack of knowledge sharing in prenatal classes about how to keep a baby cool in hot weather was more than zero. We all knew the safe sleep guidelines said 17-21 C but wtf are you supposed to do when you can't get any part of your house that cool? It was stressful and horrible, but it's over for now. I think. My dog Vogue has had health issues since last October and we have finally got to a point where I have not had to take her to the vet in about a month or so. She's on heart meds and has mitral valve heart disease. Her heart is quite enlarged but we're managing. She rides in the bottom of Chloe's pram for walks so she still gets to go out and about. I love her to bits, I can't believe she's 14 and I cherish the time I have remaining with her. The Patio # While it became increasingly apparent that we will need more space when Chloe is older, I decided to make the most of what we have and asked our landscapers to put a patio in off the back of the house, and they finished it in early July. It has become a daily sanctuary, and I'm sad the nights are getting shorter. There was a good 3-4 weeks when we were outside eating dinner. Yorkshire Coast # We didn't leave the country this year for my birthday. I can't remember why it didn't quite work out, but we took our first overnight trip with Chloe up to the Yorkshire Coast and Whitby. It was beautiful and by the time we eventually found our groove with Chloe and naps and going out to do things, it was already time to leave. I love the sea, and it was lovely to be along the coast for a few nights. Will hopefully make a more permanent move along a coastline at some point. Family coming to visit # My mother came to visit for 3 weeks and help with Chloe which was so lovely for her to get that time bonding with her granddaughter. She also got to see Chloe make some big development leaps even in the short time she was here. Then my sister came and stayed with us for a week. We went to Wrest Park, London and Warwick Castle and Chloe loved it all. I only wish both my mom and sister could have stayed longer. What I've been... # Watching # A lot of reality TV. I've just been hella into Bravo shows more than usual. Ladies of London: The New Reign - It was the best Bravo show I've watched in a long time. Interesting characters who felt more authentic than Real Houswives. I am gutted it was not renewed. I want more of Mark and Martha! The Valley - More reality TV. Oddly comforting as the new season started when I was 3-4 months postpartum and two of the women on the series were also at that stage of postpartum so it made me feel a bit normal and seen. House of the Dragon - Season 3 was way better than 2. Rooster - Love a Steve Carrell show. It was different. I enjoyed it. Dutton Ranch - Ridiculous and outlandish like Yellowstone but entertaining. And it's Premier League season again babyyyy. Though I am extremely sad Arsenal sold Trossard. Boooo. But I'm thrilled there has been so much football on. Reading # Ha - it is taking me months to finish books at this particular moment in time. Glad I read so many last year. I did finish Crescent City #3 House of Flame and Shadow back in April. I started Brimstone (Fae & Alchemy #2) but could not stay engaged, so I DNF. I know book one was ripped apart because of the writing, but I was entertained. I couldn't look past the writing this time. I am currently making my way through the first book of Dungeon Crawler Carl. Other Bits # In this process of soul-searching and finding my identity as a mother, I am back to the state of mind prompting me to ask "why not?" when something comes up. So I bought a Pioneer DDJ-FLX4 to learn how to DJ and have been rediscovering the music I so love at festivals and feeling re-energized about something new. I'm loving mixing and am excited to see where this takes me. I've also decided to go back to school. Not your normal school though. I have become deeply interested in astrology and am going to pursue that for fun. Looking forward to being in a classroom setting again. Because why the hell not?
I started work back up again yesterday, June 1, as a remote tech worker for an open source consultancy. My husband started his paternity leave today. I'm only going back part-time for the moment so my rough plan is to work 3 days a week with the exception of this week, as I wanted to open my laptop, clear out my inbox, setup my Notion pages for 2026, change my away message and just try to get a vague sense of what's happened while I've been away. I'll work Monday-Thursday but Monday and Tuesday will be half days. My goal for the day was to get up with Chloe at 6:00 AM like normal. Put her down for her nap at 7:30. Have Jhey take over while I take the dog to the vet for heart scan and then log on for a little bit this afternoon. The universe said, a plan with an almost 5 month old? Nice try. Chloe woke up at 3:00 AM which is unusual for her. I rocked her back to sleep. Put her down. Tried to crawl back into bed. She woke up, rolled onto her tummy, and cried because she can't get onto her back because she's seemingly forgotten how to do so. She started rolling tummy to back weeks ago, but now that she can go back to tummy...that's all she does. Rinse and repeat until 6 AM. So I'm at that shattered level of tired. So much so that when I take my dog Vogue to the vet and they're telling me the results of her heart scan, it's not processing how poorly her heart actually is until I get home and talk to Jhey. She'll be on medication for the rest of her life. She's 14. We'll do another scan in a month to see if the meds help slow the progression of her heart enlargement and then I'll ask for a potential timeline...how much time they think she has left. Jhey goes to the gym and then someone shows up to pick up his special edition Mustang that he's sold. I get Chloe down for her nap and log on at 2:00 PM. I had briefly logged on for a half hour in the morning to just do a quick check and update. My inbox is a disaster as it seems my out of office reply, replied to spam messages that would normally not be in my inbox and I have 100s to delete. I try to be ruthless and delete as much as possible but leave the more company-wide discussions for follow up. I try and skim the chat. But there's too much. By the time it's 5:00 PM I have barely managed to get my Notion pages set back up. I'll try again tomorrow. I remind myself that today was particularly difficult with scheduling and is not indicative of my days going forward. Tomorrow I'll try for more routine. I go over to Jhey's parents' house and chat, we bring Chloe back for her nap, then bath and bedtime routine. I make a quick dinner of shrimp stir fry with a nice veggie stir fry pack from Waitrose. I almost make it to the end of the Euphoria finale but pass out briefly and then go up to bed. Exhausted but accomplished. Day one of this new life and routine and figuring it out is complete.
Today is my last day of maternity leave. Chloe is down for her morning nap and I'm trying to process the last 5 months and where it has all gone and all these complicated feelings. I want to go back to work and I don't. I am only going back part-time for a few months but it still feels like a massive shift is about to happen. Chloe is on a pretty good routine at the moment and just learned to roll over from her back to front. She is more aware, getting stronger and so damn cute. Her little gummy smile when I get her out of her cot in the morning and after naps fills my heart with such joy. I'm not sleeping particularly well at the moment and it's not necessarily because she wakes up at night. I have a lot of anxiety around sleep at the moment because of how hot it's been in the UK. Somehow despite the broken sleep, I get through the day and have a burst of energy after she goes to bed. I started anti-depressants for postpartum depression around the 3.5 month mark. This can also cause sleep issues and insomnia but I feel a lot better and have no problem saying without medication I'd be struggling to survive. I've even rediscovered my joy for a few hobbies and am excited to start gardening again and have decided our outdoor space needs an upgrade. I'm finding a rhythm again, ever so slowly. When it comes to the web and my career, I feel like I'm coming back at a weird time. AI is wrecking havoc and I continue to be skeptical of how hard it is being pushed. I believe it can be useful and is a tool, but the places where it could have the most impact and be incredibly transformational are not being funded adequately. I also don't believe it can adequately replace entire roles, and I don't believe we should be expecting 10x the output from workers because AI may be automating some tasks for them. We should not be pushing AI generated code to PRs without reviewing it or having some understanding of what has been generated. I fear there's going to be a lot of slop to clean up. I've been approached to create a proposal for a new side project. Details TBD but I'm considering moving ahead with it as it ties into Design for Developers. There's a lot on my mind, but I'm expecting Chloe to wake up any moment so I will eventually share those things on the blog but I will be back from maternity leave tomorrow (June 1) and dipping my toes back into adult life again. I've enjoyed the level of disconnection from online. My screen time is way down as I try to avoid being on my phone when Chloe is in front of me. Priorities have shifted. I've shifted. I feel like a completely different person, but I think it'd be strange if I didn't. How can you not grow after the experience of giving birth and motherhood?
And suddenly it happens one day in March. The sun beams down in a rare cloudless sky. It might be cold as the wind gently blows but The Sun. The Sun beams down and it promises Long nights on the horizon. It promises miserable humid days And lovely warm days. Harsh mid-day light. Dreamy golden evenings. It comes out to announce Winter's end before It once again disappears behind England's cloudy skies. And Suddenly Spring is here and my soul is warmed once again.
More in programming
A clip of me singing a funny song from Gilbert and Sullivan’s Ruddigore back in 2013
In this video, we look at why fork() needs copy-on-write, how it works inside the kernel, and a memory usage problem that Instagram encountered with Python.
Comments require commitment, but they’re worth it.
An aggregation is some kind of summary of a set of data. This can be the sum, length, minimum, etc. It is quite common to want to calculate such a summary repeatedly, e.g. “the maximum noise level in dB for the past 30 seconds” for a nuisance detector. In such a case we say there is a sliding window over our data, and we want to aggregate over our window. If our aggregation is a binary operator with an inverse, like integer sums, there is a very easy solution using a double-ended queue: from collections import deque class SlidingWindowSum: def __init__(self): self.sum = 0 self.elems = deque() def push(self, x): self.sum += x self.elems.append(x) def pop(self): self.sum -= self.elems.popleft() def eval(self): return self.sum But what if our operator has no inverse? This is actually the case for most interesting summaries such as minimum, quantile, approximate unique count (for example using HyperLogLog), etc. In fact, even something as simple as a floating-point sum suffers from the fact that floating-point addition is not invertible. For example, if you ever have a NaN in your input data with the above naive algorithm your sum will forever remain NaN, even long after the bad value has left your window. Six years ago I came up with an algorithm for maintaining just the minimum/maximum in a sliding window and posted it to cs.stackexchange. I now consider this algorithm pointless, because it turns out there is a simple and efficient algorithm that solves this problem for a very wide class of aggregations. I’m writing this blog post to spread the word, because I feel it should be more widely known. Folklore I came across this algorithm while reading a far more advanced paper, Low-Latency Sliding-Window Aggregation in Worst-Case Constant Time by Tangwongsan et al. Why is this paper titled low-latency? Because it does the same as what I’m about to describe, but in O(1) time for each step. However, in it they also described a “two-stack” algorithm, which does it in amortized O(1), and is far, far simpler. Amortized O(1) means that across many operations the total amount of work per element is constant, but an individual operation can take much longer. This is almost always fine, unless you absolutely need a low upper bound on latency. Funnily enough that paper attributes this algorithm to “adamax” from a 2011 Stack Overflow post. They in turn credit a 2001 lecture note by D. Sleator for the inspiration. However, this lecture note does not describe a sliding window aggregate, it describes the classical two-stack algorithm for implementing a FIFO queue and does amortized analysis on it. Ultimately I would not be surprised to find that this algorithm was already described in an obscure paper from the 1970s, seeing how simple and brilliant it is. Two stacks Like the authors of the paper, I will generalize the two-stack algorithm to arbitrary associative aggregation functions. By abstracting the aggregation as a set of functions, empty(), unit(x), combine(x, y) and finalize(x), you can describe many possible aggregations, for example a mean: empty = lambda: (0, 0) unit = lambda x: (x, 1) combine = lambda x, y: (x[0] + y[0], x[1] + y[1]) finalize = lambda x: x[0] / x[1] if x[1] else None I’d like to note here that these functions have the following signatures: fn empty() -> Agg; fn unit(x: Value) -> Agg; fn combine(x: Agg, y: Agg) -> Agg; fn finalize(x: Agg) -> Out; I’m making a distinction here between Value, Agg and Out because while they seem superficially similar for something like an integer sum, for an approximate unique count on strings you would have (Value, Agg, Out) = (String, HyperLogLogSketch, u64), three wildly different types. Without further ado, the algorithm: class TwoStackAgg: def __init__(self): self.values = [] self.values_agg = empty() self.cum_aggs = [] def push(self, x): self.values.append(x) self.values_agg = combine(self.values_agg, unit(x)) def pop(self): if not self.cum_aggs: cum_agg = empty() while self.values: cum_agg = combine(unit(self.values.pop()), cum_agg) self.cum_aggs.append(cum_agg) self.values_agg = empty() self.cum_aggs.pop() def eval(self): return finalize( combine(self.cum_aggs[-1], self.values_agg) if self.cum_aggs else self.values_agg ) That’s it, the entire algorithm. There’s two stacks (values and cum_aggs) and one more aggregate, values_agg. At any point in time values_agg holds the aggregate of values, and cum_aggs contains the cumulative aggregates of all values in our window that aren’t in values, in reverse order. From this we can get the aggregate over our entire window in constant time by by combining the last value of cum_aggs with values_agg. The neat part is that (assuming w is our window size) every wth operation we drain all of values and maintain a running aggregate while pushing the partial cumulative aggregates onto cum_aggs. This is what makes it amortized O(1), doing O(w) internal operations every wth pop bounds the total amount of work per element to O(1), even though a singular operation might not be constant time. I think this is best visualized. Suppose we sum [1, 2, ..., 10] with a fixed-size sliding window of four elements, then the state on each eval() call would look like this (values_agg not shown as it is simply the aggregate of the values): cum_aggs values out [] [] = 0 [] [1] = 1 [] [1, 2] = 1 + 2 [] [1, 2, 3] = 1 + 2 + 3 [] [1, 2, 3, 4] = 1 + 2 + 3 + 4 [4, 3 + 4, 2 + 3 + 4] [5] = 2 + 3 + 4 + 5 [4, 3 + 4] [5, 6] = 3 + 4 + 5 + 6 [4] [5, 6, 7] = 4 + 5 + 6 + 7 [] [5, 6, 7, 8] = 5 + 6 + 7 + 8 [8, 7 + 8, 6 + 7 + 8] [9] = 6 + 7 + 8 + 9 [8, 7 + 8] [9, 10] = 7 + 8 + 9 + 10 [8] [9, 10] = 8 + 9 + 10 [] [9, 10] = 9 + 10 [10] [] = 10 [] [] = 0 In total the memory usage is O(w), where w is your maximum window size. Note that for simplicity of analysis and the example I assumed a fixed-size window w, but there is nothing about the two-stack algorithm that requires this. You can call push(x) and pop() as many times as you’d like between each eval(), growing and shrinking the window size as needed. Floating-point non-associativity Note that we required above that our aggregate combine is associative, meaning: combine(combine(x, y), z) = combine(x, combine(y, z)) Technically speaking, floating-point addition doesn’t respect this. Nevertheless, the above algorithm is still very useful because the results closely match the expected outcome, even more so if you use a compensated summation algorithm like Kahan summation. Another neat thing about the two-stack algorithm is that it doesn’t require commutativity, if you follow the above implementation precisely. The order of operands is maintained, which can matter for things like string concatenation. However, there is a second very useful property of the above algorithm. Each aggregate is strictly a combination of the elements in the window, and none outside the window. This means if your window contains a NaN or infinity (or some other outlier), that value only poisons the windows that contain it rather than the rest of your computation. But even without NaN or infinity it is useful, due to not propagating errors endlessly. E.g. if your sliding window starts with [1e20, 1], this is what would happen with a naive rolling sum: >>> 1e20 + 1 - 1e20 - 1 -1.0 Compensated summation will reduce these effects, but not making your result depend on values outside of the window will eliminate long-term error accumulation entirely.