Posts

This profile is from a federated server and may be incomplete. Browse more on the original instance.

jeff, to php
@jeff@phpc.social avatar

I'm surprised more projects aren't having this MySQL scaling issue in .

MYSQLI_OPT_CONNECT_TIMEOUT only affects the TCP init, not the time to first byte.

MYSQLI_OPT_READ_TIMEOUT is then also needed to time out quickly if a socket connects but sends no data in a reasonable time (DoS otherwise).

However, that also aborts queries that run longer than the limit (reports, schema upgrades).

You have to set the timeouts before a connection and can't use @@session.

https://bugs.php.net/bug.php?id=76703

ramsey,
@ramsey@phpc.social avatar

@jeff Maybe because more folks use PDO_MYSQL instead of mysqli?

jeff,
@jeff@phpc.social avatar

@ramsey Sure, that's possible. I'll check if PDO avoids the issue, but a glance at the docs seems like ATTR_TIMEOUT doesn't make a connection / read distinction for MySQL either.

The bug report proposes a reasonable change of including the max-time-to-first-byte in the connection timeout so connect/read are properly decoupled. RDS has had this issue a few times (probably load balancer related).

Cerb is likely older than PDO, so that's not an easy change. I'd break more than I fix. 😅

jeff, to python
@jeff@phpc.social avatar
jeff,
@jeff@phpc.social avatar
jeff, to php
@jeff@phpc.social avatar

I've completed "Never Tell Me The Odds" - Day 24 - Advent of Code 2023

I'd already finished this one with Python+Z3, but that felt like cheating. I had some free time today to understand the math and do a pure PHP solution for Part 2.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/24-hailstones/solution.php?ts=4

jeff, to random
@jeff@phpc.social avatar

I just completed all 25 days of Advent of Code 2023! https://adventofcode.com/

dave,
@dave@1password.social avatar

@jeff Congratulations! I always run out of gas before finishing. What language did you try this year?

jeff,
@jeff@phpc.social avatar

@dave Thanks, Dave! 😀 Yeah, the last week can become a slog w/ ramped up complexity and less time during holidays.

I used PHP again, since it's a good excuse to get experience w/ newer features (>8.2) that are currently above my project minimum versions.

I've also been able to add a few of the nicer solutions to my library. e.g. Graph traversal + combinations.

I did use Python+Z3 for a final one, and Graphviz for another; but I'm revisiting those after reviewing smarter solutions. 🤓

jeff, to php
@jeff@phpc.social avatar

I've completed "A Long Walk" - Day 23 - Advent of Code 2023

I'm still catching up after the Christmas break.

I lost a bit of time trying to optimize this one more than I really needed to.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/23-long-walk/solution.php?ts=4

jeff, to php
@jeff@phpc.social avatar

I've completed "Sand Slabs" - Day 22 - Advent of Code 2023

This was a fun 3d problem. I had a decent approach for both parts right off the bat, but a silly bug only solved the example and not my input.

Part 2 was easy with the same approach but not very efficient.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/22-sand-slabs/solution.php?ts=4

18+ jeff,
@jeff@phpc.social avatar

The input was short enough to put all the blocks in a hash table for intersections.

I wrote quick functions to get blocks from bricks, and to register/unregister those blocks from an interchangeable state. A brick could move down if its projected block locations didn't intersect any other blocks.

I used a generator to get blocks, but used 'return' rather than 'yield' when the ends were the same; which took too long to find.

Swapping/resetting state made Part 2 easy.

jeff, to Roblox
@jeff@phpc.social avatar

We didn't have many puzzles this year that felt suitable for rendering. Finally, on Day 22 (Sand Slabs) we have a 3D construct.

Here's my "Jenga tower" input data rendered in before processing.

A 3D rendering of a tower of bricks for the Advent of Code 2023 Day 22 (Sand Slabs) puzzle. The sandy bricks are a mix of vertical and adjacent beams that are precariously stacked toward the sky.

jeff, to php
@jeff@phpc.social avatar

I just completed "Step Counter" - Day 21 - Advent of Code 2023

Catching up. Part 1 was straightforward. I took my first hint of AoC 2023 for Part 2 after a few hours spent dicing up the infinite grid.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/21-step-counter/solution.php?ts=4

18+ jeff,
@jeff@phpc.social avatar

Part 1 was just BFS outward from the start point. After visualizing ASCII output in the first few mins I spotted the chessboard pattern and used modulo.

Part 2 started out simple. It only took ~4 lines to convert my Grid2d class into InfiniteGrid2d w/ modulo magic.

I got bogged down trying to generalize the solution w/o catching the grid cycles radiating around the starting grid.

I took my first Reddit hint on Lagrange polynomial interpolation and learned something 🤓

jeff, to php
@jeff@phpc.social avatar

I just completed "Pulse Propagation" - Day 20 - Advent of Code 2023

My code is a little longer than usual since OOP + inheritance made the network and module logic much easier to follow.

Spoilers in comments.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/20-pulse-propagation/solution.php?ts=4

18+ jeff,
@jeff@phpc.social avatar

Part 1 was simple enough. I implemented the modules w/ OOP and used a queue to dispatch signals in order.

Part 1 was a handy sanity check on handling undefined modules (output example & rx input).

In Part 2, I used graphviz/dot on the input data since it was already describing a directed graph network.

That immediately showed the conjunction hubs, which I assumed correctly had cycles. LCM again to solve.

I ignored all the other logic and just watched those.

18+ velkuns,
@velkuns@phpc.social avatar

@jeff ha yes, better to find the cycle inside. I hoped I could leave my code run, but after I saw your answer value, I need to update my code for a better solution. But to late for now.

For the rest, again, we have the same logic (apart queue outside the modules) , but we have almost the same namings 😁

jeff, to php
@jeff@phpc.social avatar

I just completed "Aplenty" - Day 19 - Advent of Code 2023

Part 1 was basically what I do at work every day w/ cascading workflow rules and automation.

I had a good idea of what to do on Part 2 from the start, so it was a lot more enjoyable. I got the runtime for both parts down to ~3ms.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/19-aplenty/solution.php?ts=4

18+ jeff,
@jeff@phpc.social avatar

Once I read Part 2 and saw the example sum of combinations, I knew we'd be dealing with ranges again for hypothetical parts.

I created a HypotheticalPart class with the four (x,m,a,s) ranges of (1-4000) within it.

As I processed workflow rules, I partitioned range remainders into disjoint hypothetical parts.

Otherwise it was pretty standard recursion. Parsing was about half the code today.

jeff, (edited ) to php
@jeff@phpc.social avatar

I've completed "Lavaduct Lagoon" - Day 18 - Advent of Code 2023

I spent a few hours tinkering with an approach on this one, but it was fun. I managed to get the PHP runtime for both parts under 20ms.

One of my shortest solutions once I added some AoC library functions.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/18-lavaduct-lagoon/solution.php?ts=4

18+ jeff,
@jeff@phpc.social avatar

With Part 1 I had started building a 2D grid map, but figured Part 2 would blow that up (and was right).

The directions were like old pen/turtle tutorials. I converted into polygon points (676 vertices). I ran the path through the middle of the cells to include borders (0.5, 0.5 origin).

I added a function to calculate the area of irregular polygons. I expanded the path at the end to include the borders within area.

Lots of testing, but super clean + fast.

jeff, to random
@jeff@phpc.social avatar

I've completed "Clumsy Crucible" - Day 17 - Advent of Code 2023

I'm catching up after the weekend. I went for readability over speed on this one.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/17-clumsy-crucible/solution.php?ts=4

18+ jeff,
@jeff@phpc.social avatar

I lost some time on this one trying to figure out why I was getting a shorter path than the example. It turned out I missed the constraint that the crucible can't U-turn.

A* was happy to backtrack one tile at a cost of 3 to reset the step counter, rather than taking a multiple turn detour.

Adding the min/max steps in Part 2 was easy after the hassle of debugging Part 1.

It still takes about 10 sec to run both parts and needs some optimization.

jeff, to php
@jeff@phpc.social avatar

I've completed "The Floor Will Be Lava" - Day 16 - Advent of Code 2023

GridMap2d and Entity2d continue to come in handy.

This one had a big edge case that wasn't immediately obvious from the instructions.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/16-floor-lava/solution.php?ts=2

18+ jeff,
@jeff@phpc.social avatar

@velkuns So all of my 2d library's features feel equally loved. 😁

Yeah, I feel like I start with DFS on everything by default now.

I like your const map approach. 👍

18+ velkuns,
@velkuns@phpc.social avatar

@jeff Make sense for love 😁

SI started with if { if {} } then switch to map array for readability.

jeff, (edited ) to php
@jeff@phpc.social avatar

I just completed "Lens Library" - Day 15 - Advent of Code 2023

This was really close to three one-liners. A nice break from the past few days.

This one really benefitted from being an array-based language w/ ordered hash tables by default.

I used array_keys(filter) to treat keys as associative and indexed at the same time.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/15-lens-library/solution.php?ts=4

velkuns,
@velkuns@phpc.social avatar

@jeff ok, just need to read five times to really understand that I need to hash only the label 😅

jeff,
@jeff@phpc.social avatar

@velkuns hah! Yeah, the instructions were rather confusing today for what ended up being one of the easier challenges. 😁

jeff, to php
@jeff@phpc.social avatar

I've completed "Parabolic Reflector Dish" - Day 14 - Advent of Code 2023

My GridMap2d class made this much easier. The same premise was used in at least two puzzles last year, so I had a good idea of what I needed to do going into it.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/14-parabolic-dish/part2.php?ts=4

18+ jeff,
@jeff@phpc.social avatar

With my GridMap2d class, part 1 was barely 10 commands. Find 'O' tiles starting from the northmost. Slide them up until they hit an obstacle. Calc load.

In Part 2 I had fun on the 4-way tilt code. Useful for later.

Rather than running 1B cycles, I assumed we'd find a (prime-length) cycle in the load values after a short stabilization period.

I saved load every 10 sims, and checked for cycles every 100. Found in <1500.

Reminded me of Rock Tower + Blizzard last year.

18+ velkuns,
@velkuns@phpc.social avatar

@jeff that was thinking yesterday: just rotate the matrix to always move the rocks in only one direction to have the same code.

But I'm not sure is more efficient, because I need to get each time the rounded rocks list and cubes rocks.

Simpler code vs a little bit optimised 🙂

  • All
  • Subscribed
  • Moderated
  • Favorites
  • anitta
  • thenastyranch
  • magazineikmin
  • everett
  • InstantRegret
  • rosin
  • Youngstown
  • slotface
  • love
  • khanakhh
  • kavyap
  • tacticalgear
  • GTA5RPClips
  • DreamBathrooms
  • megavids
  • modclub
  • mdbf
  • tester
  • Durango
  • ethstaker
  • osvaldo12
  • cubers
  • ngwrru68w68
  • provamag3
  • normalnudes
  • Leos
  • cisconetworking
  • JUstTest
  • All magazines