Jump to content
Pardon our ads (a necessary update) ×

requinix

Administrators
  • Posts

    15,308
  • Joined

  • Last visited

  • Days Won

    439

Posts posted by requinix

  1. 55 minutes ago, Psycho said:

    I'm sure there is a more elegant way to deal with possible multiple decimal points (possibly with a single regex), but I've not worked with Regex for quite a while.

    It's a little painful, but not too complicated if you treat the input as being one of two things: a number starting with a ".", or a number starting with a digit and optionally containing a fractional portion.

    ^(\.\d+|\d+(\.\d*)?)

    The separation because there has to be at least one digit in there somewhere, but it could be before the decimal or after.

    If you run that through preg_match, $1 (and $0 for that matter) is the leading numeric portion of the string it matched. Then you can also do a quick strlen check to see if anything got lost.

    However, floatval/cast to float will implicitly drop any trailing non-numeric portion as it is, so there's no need to try to remove it manually. Minor downside that exponential numbers, like "1.23e45" are acceptable, but IMO it doesn't matter enough to prohibit it in the backend if someone the frontend allowed it.

  2. If the input is supposed to be numbers then help yourself by using an input with type=number so the user can't accidentally type non-digits.

    Also, it would help to give a visual indication of the currency being implied - typically this looks like a little £ symbol to the left of the input area.

    image.png

     

     

    The actual problem you're having is 99% likely to be character encoding. There are multiple possible byte encodings of the character "£", and PHP only cares about bytes. So if the £ coming from the form is encoded one way and the £ written in your code is encoded another way, the substitution doesn't happen.
    Make sure you're using UTF-8 encoding (or some other specific encoding) for absolutely everything - your webpages, your database, your code files, everything. Then you won't have problems with bytes not matching up.

    • Like 1
  3. Honestly, the comments give a good overview of the whole thing. Did you have any specific questions about what they said?

     

    7 hours ago, polaryeti said:

    My concern is not the logic of the program, but the structure of the program.

    There's a big class containing all the code, an inner class that handles just the animation portion, and a static main.
    The big class's start() initializes things and then tells JavaFX to start executing the animation.
    The animation happens by executing handle() at ~60 calls/second (aka Hz).

    7 hours ago, polaryeti said:

    And the javafx way of displaying stuffs on screen. It just does not come to me instantly or lately

    The code for handle, which is the only method in that class, calculates a couple X,Y coordinates and draws then a line on the canvas...

  4. Kinda curious why you're studying relational algebra... Do you like low-level math like that? It's a very niche field of study.

    Looking around I found this. It's basically just a page aggregating other sources, but it includes a description of divide-by that seems straightforward:

    Quote

    The final relational operation we consider is relational division. Division of table A by table B is only meaningful if A has more columns than B. Let's assume that table A has two sets of columns, X and Y, and table B has a set of columns Y. In other words, X is the set of columns in A that are not present in B. We'll assume an ordered relation between the Y columns in A and B so that we know which column in B corresponds to which column in A.

    The result of A ÷ B is formed by restricting the result to those rows of A where the Y column values in A all the rows of B and then deleting the Y columns from A. The expression A ÷ B may also be written as A divide-by B. Figure 12.26 shows a trivial example, where the attribute domains are denoted by X1, X2, Y1.

    3-s2.0-B9780123735683500163-f12-26-9780123735683.jpg

    That's the unique values of A.a1, A.a2 (columns of A that are not shared with B) where every row in B has a matching row in A (according to their shared A.a3/B.b column).

    1. (1, 2) has a match on both 50 and 80.
    2. (3, 4) has a match on 50 but not on 80.

    The second example is more intuitive:

    Quote

    3-s2.0-B9780123735683500163-f12-27-9780123735683.jpg

    1. Australia has a match on English but not on French.
    2. Belgium has a match on French but not on English.
    3. Canada has both languages. (Naturally, as the example is specifically about Canada.)
    4. Cuba does not have any match at all.
    5. Dominica has both languages.

     

    The SQL equivalent is actually pretty complicated, but that page I linked explains how. The way to get that SQL is, honestly, to understand what division does ("keeps columns X but not Y", "unique values from A", "matching every row in B") and then translate that literally into SQL.

     

    30 minutes ago, polaryeti said:

    It is probably the best book to learn this as others are very surface level on relational algebra.

    Well yeah, it's not really something anybody ever needs to know. It's much easier (and practical) to understand SQL itself than to delve into the "pure math" foundations behind it.

  5. What is the question supposed to do?

    Is the question supposed to test if the interviewee knows about the 110 pods/host limit? Then you ask a question like "How many pods can k3s run on a host?"
    Is the question supposed to test if they know about Kubernetes networking and about pod and cluster IP addresses? Then you ask a detailed question like "If a k3s network is configured to use the entire 192.168 subnet for pod networking, how many pods will be able to run?"

    Is the question supposed to be a trick question, meaning it is supposed to confuse and disorient the interviewee? Then don't ask it. Because asking trick questions in interviews is an indicator of abusive management and poor leadership.

  6. k3s is a simplified version of k8s, not a trial version. You can have as many pods as you have resources for, and "resources" includes IP addressing space. But IP addresses depends on your networking setup, which can be anything from a tiny 192.168 IPv4 space to a massive IPv6 range, to even multiple CIDRs.

    Were they trying to get a specific number? Because my answer would have been "as many as you want".

  7. The explanation there isn't... well, it's not an explanation. It's a description of what happens when the program runs. I guess you're supposed to reverse-engineer the algorithm from that?

    What you have there doesn't actually match the algorithm they're trying to get you to use. For example, you have the "output" argument - which isn't even actually necessary for this. You're also doing that "Nothing found" error message when the description is happy to stick with just empty strings.

    If you're looking for a more prescriptive version of what it is you're supposed to do, I'll rewrite it using your (better) sample input:

    Call find_caps with "nePaL" to get a value to print...
    	The input string is not empty.
    	The first letter "n" is not a capital letter, so return:
    	Call find_caps with the rest of the input argument ("ePaL")...
    		The input string is not empty.
    		The first letter "e" is not a capital letter, so return:
    		Call find_caps with the rest of the input argument ("PaL")...
    			The input string is not empty.
    			The first letter "P" is a capital letter, so return:
    			A string consisting of that letter followed by:
    			Call find_caps with the rest of the input argument ("aL")...
    				The input string is not empty.
    				The first letter "a" is not a capital letter, so return:
    				Call find_caps with the rest of the input argument ("L")...
    					The input string is not empty.
    					The first letter "L" is a capital letter, so return:
    					A string consisting of that letter followed by:
    					Call find_caps with the rest of the input argument (""):
    						The input string is empty so return "".
    					Thus the return value will be "L" followed by "".
    				Thus the return value will be "L".
    			Thus the return value will be "P" followed by "L".
    		Thus the return value will be "PL".
    	Thus the return value will be "PL".
    Thus the value to print is "PL".

     

    • Like 2
  8. Did I miss where a question was asked? What was the source .py being copied here, in case that's necessary information?

    Input arguments are rather awkward, like gizmola said something like $_POST or even $_GET will probably be more appropriate. Obviously the exact nature of the $on/$off stuff is irrelevant to operating the board so it can be rewritten into any style.

    For the board, seems odd that you're actually supposed to include a "0x" in the buffer? Otherwise since this is a device, a mere file_put_contents is likely sufficient - w vs. r+ shouldn't matter.

  9. Paul-D: I've redacted a few things in your post as a courtesy but you can safely assume it's already out there on the internet. Be more careful in the future.

     

    2 hours ago, Random8 said:

    I'd suggest changing your MySQL password now that you've posted it in a forum

    Shame about the email addresses too.

  10. You're right, it is a frequent requirement. It's so frequent that people don't implement these things themselves.

    If you want to monitor for "bad" activity and ban clients, that's literally what tools like fail2ban are made for.

  11. I'm betting that Tea was developed through vibe coding...

    1 hour ago, phppup said:

    The page was built with a pop-up modal that contains a short list of items which AI decided to create in hardcoded HTML with inline CSS.

    98% of inline CSS is bad and shouldn't be inline CSS, but IMO there are reasonable and not uncommon situations where inline CSS is the "correct" solution:

    Namely, when an amount of required styling for some element is just so damned specific and unique that it doesn't make sense to hoist it into CSS that exists Somewhere In The Project, and instead tightly coupling it to the element (ie. inline) actually makes understanding and maintaining it easier.
    Which isn't to say that it could/should never be promoted into a stylesheet, just that there's no apparent call to do so (yet).

    Off topic, just saying.

    (Even more off-topic is that Bootstrap is the worst thing to ever happen to the world of front-end development; I could write a VERY lengthy rant about how screwed up standard CSS practices are because of that nonsense.)

    1 hour ago, phppup said:

    When I asked/told (I'm not quite sure who was 'in charge'...  LOL) AI to make a second modal that resembled the first it took a lot of tweaking to reach my goal.

    That's the thing pro-vibe coding people leave out when they evangelize the idea: yeah, sure, the AI spit out a bunch of code much faster than a professional developer could have, but the amount of time spent screwing around with it afterwards because the output sucked offsets those gains by so, so much.

    1 hour ago, phppup said:

    The question: Is one more efficient? Beneficial? Effective?

    As an old-school programmer, I avoid using Javascript for anything that regular HTML/non-Javascript practices can handle. Which means I hate React and its frenemies.

    But even setting that aside, there really is no good reason in remotely modern web development to be using Javascript to simulate CSS functionality. Back in the 2000s that was necessary because CSS was still young and web designers wanted to do much more than it was capable of (we didn't even have :hover back then), but nowadays CSS is capable of far more than many people give it credit for.

    Naturally there are still concepts that CSS can't do and that Javascript is required to "polyfill" - UIs will always want to be one step ahead of technology - but if CSS can do a thing then CSS should do the thing. Reasons vary: graceful degradation, requirements for technical know-how, browser performance, single-responsibility principle...

  12. "Revolution"? lol. It's another Whatever from the tech world. It's not the first fad used to pump up stock prices, and it won't be the last.

    The current state of glorified autocomplete systems AI contributes just about as much value to the world as The Blockchain does. You remember that whole thing? Wasn't that long ago when The Blockchain was being called a "revolution" too...

    The next Whatever will happen in a few weeks, or months, or years, and every publicly-traded company will jump on that as fast as they can too. (Make sure you're not still holding onto all of your NVDA when that happens.)
    And I'm sure that'll bring its own "revolution" too.

    • Like 1
  13. E_DEPRECATED and E_USER_DEPRECATED are the same thing, with the one difference that the former is used by the engine and the latter is used by trigger_error.

    So the question is in what environments do you care/not care about getting messages about using deprecated features and functionality?

    • Great Answer 1
  14. 2 hours ago, rick645 said:

    Granular level?

    Yes, granular, as in "highly detailed; having many small and distinct parts".

    2 hours ago, rick645 said:

    Why the php tick3.php command does not produce output?

    Because you missed the part in my reply where I said "write a bunch of code". You wrote a very small amount and you're not going to see how ticks work unless you write a lot more.

  15. A tick happens every time the engine does something at a fairly granular level. Like executes a statement, but even lower-level than that.

    The easiest way to understand it is going to be to play with code: set up a ticket handler every 1/2/3/whatever ticks, have it output something, and then write a bunch of code to execute and see what happens.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.