Jump to content

requinix

Administrators
  • Posts

    15,274
  • Joined

  • Last visited

  • Days Won

    432

Everything posted by requinix

  1. Doesn't look like ReactPHP has something to make use of generators... Those would have been pretty much the ideal answer to this. Can't you split doWork's work up? If it needs to send a group of emails, don't try to do them all at once: have it do whatever emails it can fit within one second or something, then stop and let the event loop take over. That's the basic approach to how some sorts of cronjob-type tasks run. It's not about getting everything done at once but about doing a chunk of them every time you get "processor" time.
  2. Start writing code and see how it goes. If you have specific questions like how to get the IP address, then feel free to ask, but for your code you can just put in something temporary so that you can keep going. $need = [3, 7, 4, 8, 2, 9]; // todo: get from the coordinates $ip = "75.36.25.58"; // todo: get real address (and note actual addresses are not padded) /* you'll need some code in here to break apart $ip... */ $digits = [ "A" => // first (0) "B" => // second (7) "C" => // third (5) // etc ]; // returns a single letter or null if nothing function choose_single_letter($needed, $digits) { // look for $needed in $digits if (/* $needed in $digits */) { return // the digit - if there's multiple matches then pick one (randomly?) } else { // nothing return null; } } // returns an array of [single letter, "+" or "-", single letter] or null if nothing function choose_paired_letters($needed, $digits) { // addition loop for ($i = 1; $i <= $needed - 1; $i++) { if (/* $i in $digits and ($needed - $i) in digits */) { return [/* the digit for $i */, "+", /* the digit for $needed - $i */]; } } // subtraction loop for ($i = 9; $i >= $needed + 1; $i--) { if (/* $i in $digits and ($needed + $i) in digits */) { return [/* the digit for $i */, "-", /* the digit for $needed + $i */]; } } // nothing return null; } // returns an array of [single letter or number, "+" or "-", number or single letter] function choose_any($needed, $digits) { // pick random digit in $digits if (/* $needed - digit >= 1 */) { return [/* digit */, "+", /* $needed - digit */]; } else { // needed + digit <= 9 return [/* $needed + digit */, "-", /* digit */]; } } $exprs = []; foreach ($need as $needed) { // call choose_single_letter, of that fails choose_paired_letters, or if that fails choose_any $exprs[] = // result } // now $exprs is an array where each entry is a thing that represents an expression: // (a) a single letter to draw // (b/c) an array in the form [operand, operator, operand] to draw To get the result into the picture, that totally varies based on how you want to do that, but the best approach will very likely be to get the whole coordinates+expressions thing into a single string, kinda like $string = "N 35° 54. (?) (?) (?) W 84° 01. (?) (?) (?)"; (substituting each question mark for the string representation of each expression that goes in there)
  3. I can't tell: are you still trying to solve the undefined index problem? When you use fetchAll, $row (that being the variable you chose to assign the results to) will be an array of arrays. You need to loop over that just like you did with ->query. If you write that code out you'll get foreach ($row as $row) { Now, doesn't that look a little weird?
  4. That was a bit hard to understand, so I'll rephrase it: The user is supposed to figure out N 35° 54.374' W 84° 01.829'. They are given most of it: N 35° 54.???' W 84° 01.???'. (Note that 1' is a little more than a mile, so you're giving them a lot of information here.) Each of the six question marks is a single digit, and uses a simple expression based on the 12 digits in their IP address, which we'll say is ABC.DEF.GHI.JKL. Each expression is (a) a single letter if possible (digits be reused?), otherwise (b) two letters added or subtracted if possible, otherwise (c) one letter added or subtracted with a number. If the user's IP address is 075.036.025.058 and the six missing digits are 3 7 4 8 2 9 then we can apply (a) to get 3=E, 7=B, 8=L, 2=H easily, but the 4 and 9 aren't available. Next is to combine two digits using (b): 4 can't be formed through addition but it can through subtraction with 6-2=F-H or 7-3=B-E. 9 can be formed with 7+2=B+H or 6+3=F+E (as well as 2+7 and 3+6). Don't need to invoke (c). Obviously, you need to start by grabbing the IP address and splitting it into the digits you can work with, as well as figuring out the six digits of the coordinates you need to fill in. Then you try to determine the formula for each of those six digits: Using the (a) process is easy: if there's a digit in the IP address then pick it. The (b) process is a couple loops: 1. Try addition. Loop from 1 to the digit-1 (or digit-1 to 1) - we can skip 0 because that would be digit+0 which (a) couldn't satisfy, and skip the digit itself for the same reason. If the number and (digit-number) is in the IP address then use them. 2. Try subtraction. Loop from 9 to the digit+1 (or digit+1 to 9). Again, if the number and (digit+number) exist in the IP address then use them. (There's actually a little more optimization you can do here.) The (c) process is easy: pick a digit from the IP address, decide on either addition or subtraction (keeping in mind that one of those might put you out of the 0-9 bounds), and get the other number.
  5. You already have a thread for this.
  6. Not sure what that is supposed to mean, but if you're saying that it's still redirecting then either you didn't remove the redirect or there's another one somewhere in there that you'll need to remove as well.
  7. I suspect date_added has a time component.
  8. Where's the code to enter the information into the database?
  9. Posting a giant blob of code (and without formatting, which I've added for you this time) and a super vague statement about what you want is really not a good way to get help. What is the problem you are trying to solve? What is your difficulty in solving it? What have you tried so far? What specific part of the code is relevant?
  10. There's code in there that says to do a redirect to whatever the response.url was. Tried removing that?
  11. If the problem is that a message appears in signup.php then have you considered removing the message?
  12. Okay. So what's the problem?
  13. Consider that __ is for translating text, not HTML.
  14. If you want those subdomains to behave a certain way then you have to write the configuration to do it.
  15. Not that I know of. The value is a date. Feed it to Date and be done with it.
  16. Let's take a closer look at the first two lines. var etaDate = new Date(); etaDate = document.getElementById("etaDate").value; On the first line, you set etaDate to be a new Date instance. On the second line you throw away that Date and instead get a value from some input. Does that seem weird? Also, the .value from a form field is always a string. Always.
  17. Try answering my question.
  18. There's nothing unusual in there so I have to assume there's something more going on here than just the alert.
  19. What is "etaDate"? According to the code.
  20. Put the spinner in the place where the content is going to go, initially hidden, then unhide it when the button is clicked.
  21. That is the correct answer. Why do you not want to do it?
  22. Pretty sure nobody has an email address 65,535 characters long. Nor 150 either, for that matter. The technical limit is 320, but if you find someone complaining that their 151-character long email address isn't working in your system, you can deal with it then.
  23. I don't think I understand. Are you suggesting there's at least one other equally-valid solution besides increasing the length of the column? Why is it even limited to 32 in the first place?
  24. Not if you don't show the controls.
×
×
  • 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.