While working on a recent project, I needed to implement a CMS for an image gallery. In this gallery, multiple images may belong to the same item on display. I wireframed a handful of ideas, ultimately deciding that a compact layout, styled after the gallery itself, would be best. To achieve this, I turned to mathematics to create dynamic, fractal image grids within constant-sized containers.
While working on a recent project, I needed to implement an image gallery with a navigable lightbox. I wanted the navigation to include swiping animations and opacity fades, and I wanted the previous and next images to pre-load for an optimal user experience. Initial brainstorms involved various bits of state management, Effect hooks and/or react-transition-group. I eschewed those paths in favor of number theory. The result is a single map function that handles all behavior declaratively via modular arithmetic.
To begin with, I created a lightbox to hold my images. A dissection of the lightbox itself is beyond the scope of this article, but a functional, simplified component follows. …
As part of my studies at https://flatironschool.com/, I have been exploring various LeetCode problems in both Ruby and JavaScript. As a number theory enthusiast, I actively strive to find the most elegant and computationally efficient solutions.
Whenever an opportunity for bit manipulation arises, I get particularly excited. https://en.wikipedia.org/wiki/Bit_manipulation
In a sense, bit manipulation is the meeting space between number theory and a computer’s bare metal. Within the context of an algorithm, it allows you to leverage the properties of binary arithmetic to do the heavy lifting for you.
LeetCode problem #1342 is extraordinarily simple, but it serves as a great launching point into bit shifts. https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/ …
As part of my studies at https://flatironschool.com/, I encountered several caveats when attempting to utilize multipart FormData with a Rails API backend. My use case involved images with accompanying descriptions and tags.
When using strong params in Rails, we permit.require(:controller_name), with :controller_name being the singular name of the controller that we are in.
When POSTing to a Rails API endpoint, a hash of :controller_name is automagically added to the root of the request by Rails’ router.
For example, consider the following route in routes.rb, as well as a corresponding fetch:
post '/users', to: 'users#create'
If we log params from within the users#create action, we find the body of our fetch automagically nested inside of a :user…
As part of my studies at https://flatironschool.com/, I have been exploring various LeetCode problems in both Ruby and JavaScript. As a number theory enthusiast, I actively strive to find the most elegant and computationally efficient solutions.
That said, when left-field solutions bubble out of a brainstorm, I give chase.
The problem, as stated:
Given a string
s
containing just the characters'('
,')'
,'{'
,'}'
,'['
and']'
, determine if the input string is valid.An input string is valid if:
1. Open brackets must be closed by the same type of brackets.
2. Open brackets must be closed in the correct order. …
As part of my studies at https://flatironschool.com/, I was asked to solve Project Euler’s first problem, https://projecteuler.net/problem=1, using Ruby.
While simple at first glance, employing a bit of number theory opens up a solution that is drastically more efficient and extensible.
Adam Drake did a fantastic writeup of this problem using Go, from which I borrowed the namesake: https://adamdrake.com/an-unreasonably-deep-dive-into-project-euler-problem-1.html
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000. …
About