13eck
Explore posts from serversKPCKevin Powell - Community
•Created by R a ][ n on 12/17/2024 in #front-end
How to make the anchor tag take up the full space of the list item it's present inside.
That's because anchor elements are inline by default, so only take up as much room as they need. You can change it to
inline-block
and give it some padding to achieve the effect you want.3 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
OH! One good reason to not use incremental IDs: distributed databases. If your DB is on multiple servers then you can't use incremental IDs as it's very difficult (or impossible?) to sync IDs. Discord snowflakes, as an example, have a 5-bit worker ID used to identify what server the item was created on
60 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
That's…scary
60 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
Yeah, using (semi-)random IDs is just one way to mitigate any possible security issues with incremental IDs, so it's up to you to decide what/if/how you care about everything and code accordingly.
60 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
Being OK or not is a preference thing, not an absolute. You need to decide if it's ok to expose the number or not. But yes, for most small-scale apps auto-incrementing ID is fine
60 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
Also of note is that auto-incrementing IDs doesn't always mean "I get one number I now know the next." Many keep a table of deleted IDs that can be re-used. So even if the end user gets an ID of 38 there's not guarentee that the next item is 39
60 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
For example, Twitter and Discord use a uint64 snowflake where the first 40-something bits is a timestamp. So it's not auto-incrementing but still easily sorted (as the number assigned is based on when it was assigned). UUIDs, on the other hand, are strings and much more difficult to sort—and strings take up more memory in the DB, which might or might not be an issue
60 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
For example, having a product ID of
4
in a storefront doesn't matter, as knowing how many products you have for sale isn't a big deal.
But if exposing the number of users can be "harmful" (again, what that means is up to you) then you'll want to use something else for primary ID60 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
The only real "unsafe" ness of incremental IDs is that if they're exposed to the end user then they know a bit about how many of
resource X
you have in your DB. If they create an account and their account ID is 38
, for instance, it's a good bet that you don't have a lot of users.
The real question is this: can exposing that information be harmful to your product?60 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
Define "better"
60 replies
KPCKevin Powell - Community
•Created by NIMA on 11/28/2024 in #back-end
how safe is AUTO INCREMENT id ?
Define "safe"
60 replies
KPCKevin Powell - Community
•Created by snxxwyy on 11/24/2024 in #front-end
nodes in js
HTML elements are
Element
s. So if you want an HTML element like a div
, p
, strong
, etc you want to get the element31 replies
KPCKevin Powell - Community
•Created by snxxwyy on 11/24/2024 in #front-end
nodes in js
No, there are so many more nodes. For example,
attr
is a node. You get it using the Element.getAttribute()
method31 replies
KPCKevin Powell - Community
•Created by snxxwyy on 11/24/2024 in #front-end
nodes in js
All elements are nodes, but not all nodes are elements
31 replies
KPCKevin Powell - Community
•Created by snxxwyy on 11/24/2024 in #front-end
nodes in js
This question is better suited to #discussions since it's not about specific code.
But in brief, everything in the DOM as far as JS is concerned is a node.
main
element? Yep, that's a node. The text of a p
element? That's a text node.
Just like in HTML all block-level elements are fancy div
s, in JS everything in the DOM is a fancy node.
https://developer.mozilla.org/en-US/docs/Web/API/Node31 replies
KPCKevin Powell - Community
•Created by Faker on 11/12/2024 in #front-end
When to use rem and em
-# of course the reality is more complex than that, but for beginners who want hard-and-fast rules it's a good starting point. The ultimate answer is, as always, it depends
15 replies
KPCKevin Powell - Community
•Created by Faker on 11/12/2024 in #front-end
When to use rem and em
To answer your question, my rule of thumb for new people is this:
*
rem
is for font size. Use it so you don't run into problems with compounding em
s
* em
should be used for margin, padding, and other things that should change based on the current font size (bigger text needs more room to breathe)
* ch
should be used for text width (ch
is the width of the 0
character in the current font size so it's as close as we have to "one character width")
* px
should only be used for visual flourishes and not for anything textual or visually necessary. Like image sizes, boarders, boarder radius, outline, etc15 replies
KPCKevin Powell - Community
•Created by Faker on 11/12/2024 in #front-end
When to use rem and em
This little snippet will get you "responsive" font sizes so that the font size will start at 1rem (whatever the user's base font size is, default to 16px) and grow to 2rem based on the smaller of the viewport's width or height.
Of course you'll want to do a bit more than just that so it'll work with more than just the base font size.
15 replies
KPCKevin Powell - Community
•Created by Faker on 11/12/2024 in #front-end
When to use rem and em
If you use
px
for font size it overrides even the user's preference, which is super-duper bad for accessibility.15 replies
KPCKevin Powell - Community
•Created by Faker on 11/12/2024 in #front-end
When to use rem and em
rem
/em
are responsive insofar that they change with the user's preference, as snxxwyy said. But there's nothing inherently "responsive" about them in the sense that they don't automatically change. You need to code that yourself.15 replies