Jump to content

requinix

Administrators
  • Posts

    15,053
  • Joined

  • Last visited

  • Days Won

    413

Everything posted by requinix

  1. Whatever XML you're transforming, or maybe the XSLT you're using, has some duplicate ids in it. That is not allowed. Each ID must be unique in the entire XML document.
  2. So being able to handle white makes things awkward: it's not a hue range but both a saturation (how much color bleeds in) and lightness (grayscale) range. Playing around, it looks like good ranges are - White is S=[0.0,0.1] L=[0.9,1.0] - Gray is S=[0.0,0.1] L=[0.1,0.9] - Black is S=[0.0,0.1] L=[0.0,0.1] I figure* the best approach would be deciding what HSL ranges constitute each color, then doing some quick math to convert each component between the current color's ranges and the desired color's ranges. For example, you might say that red is H=[330,15] (meaning both [330,360] and [0,15]) S=[0.1,1.0] (so not to overlap with the grayscale) L=[0.1,1.0]; mapping a value which you've determined to qualify as "red" onto "white" could be h[white] = h[red] // hue unchanged s[white] = (s[red] - S[red,min]) / (S[red,max] - S[red,min]) * (S[white,max] - S[white,min]) + S[white,min] // convert 0.1<s[red]<1.0 to 0.0<s[white]<0.1 l[white] = (l[red] - L[red,min]) / (L[red,max] - L[red,min]) * (L[white,max] - L[white,min]) + L[white,min] // convert 0.1<l[red]<1.0 to 0.9<l[white]<1.0 That's a linear transformation - something polynomial (eg, bell curve, sigmoid) would get different results but it would take more planning and math. * I know math and the RGB and HSL colorspaces, but beyond that it's just educated guesswork.
  3. Well, the class name is "row" + number, right? So "row" + numberThen use jQuery to do the search. Remember to put a period before the class name, otherwise you'll be telling it to look for a element.
  4. That technique works well (for images that aren't too large, at least) but only works because it recolors by shifting the hue of each relevant pixel (it being much easier to do this using HSL than with RGB). It's not so much a mapping of blue to green but a mapping of a range of green colors of some size to a range of blue colors of the same size. So you have to figure out two ranges: what you want to recolor from and what you want to recolor to. If all you have to work with is "blue" or "green" then you can guess by picking the midpoint of the hue range for that color and adding/subtracting roughly 60° *. Those will affect the if condition and the colorshift value, so it's probably best to make those all parameters. function recolorPants(hueStart, hueEnd, colorshift) { // correct hueStart and hueEnd for out-of-range values, both <0 and >=360 hueStart = (360 + (hueStart % 360)) % 360; hueEnd = (360 + (hueEnd % 360)) % 360; if (hueStart < hueEnd && hue > hueStart && hue < hueEnd || hueStart > hueEnd && (hue > hueStart || hue < hueEnd)) {- If the color you're starting with is RGB, convert it to HSL and use the hue value.- I suggest "bold" colors for the color choices; you can convert hue=0..360°, saturation=100%, lightness=50% to get them. * Hue ranges from 0 to 360°, and with 6 basic colors that's 60° per color and ±30°. But there's also overlap - consider how teal is greenish and blueish. So you bump that limit out to, say, 50-60° instead.
  5. Cool. Are you storing them as strings or numbers? Or to be more clear, is the data type for the column in the table a string type or a number type?
  6. Are you storing the phone number in your database as a string or as a number? Hint: it should be a string.
  7. id="alunos[]"That's wrong. The ID should just be "alunos". The [] is only for the name.
  8. How you display results is your decision. So how do you want to display it? For the checkboxes, name them all clients[] and then you'll get an array of values instead of just a single value. Then use a loop to execute the command on every machine.
  9. A bit. So you have a parent method which does a thing, but it doesn't have the full picture (you made it protected so somebody else in the class hierarchy has to call it) while the child classes have the rest (the usethis1 and usethis2 values, which comes from within the class and doesn't need to be passed in)? Two approaches: a) The parent's method becomes a helper method with a different name, and the child classes call it with the right value. b) The parent's method is the real method, defines an abstract method (which the children implement) to get whatever value, and calls it within the method to get the value. Requires your parent be abstract. And you can use traits for a variation on either of those. That adds onto the "if something then call method" option, which is a lot like the (b) approach in that the parent's method calls other methods to get data and to perform additional actions. Anonymous functions are appealing, it's true, but there's an object-oriented design solution here that would be more appropriate.
  10. 1. Making $extra optional with a default value needs to be handled below the parent class. If you use "dummy" a lot, that hints at those child classes having something more in common than simply that one argument, which then suggests you create another class between the parent and child which redefines those methods. 2. If the "if something then call method" pattern is very common, and kinda even if it isn't, then move that logic into the parent class. Parent has "something; $this->bla();", defines an empty bla(), and each child overrides it with their own code (ie, renaming bla_a and bla_b to bla).
  11. You're asking for information about why stuff is working, but you're only talking about half of the work you've done. "Altering [the images] with str_replace or preg_replace" can work fine if done correctly. That getimage.php could work fine if everything else is in line with it. So I'm not sure what to say. If you're simply migrating data and not looking too much into the future (where the images may change yet again) then I'd recommend just running a one-time script that updates all the tags in all the pages with whatever you want. Like that getimage.php stuff, which also necessitates storing the replaced image data somewhere else at the same time.
  12. So, this isn't really OOP... It's still procedural code like before, except you're using functions instead of having to copy/paste code around. An OOP version would be like class Flag { private $FlagName = ""; private $pdo = null; public function __construct($pdo, $FlagName) { $this->FlagName = $FlagName; $this->pdo = $pdo; } public function CheckValue($FlagValue) { $sql = "SELECT 1 FROM flags WHERE flagname = ? AND flagvalue = ? LIMIT 1"; $stmt = $this->pdo->prepare($sql); $stmt->execute([$this->FlagName, $FlagValue]); return $stmt->fetchColumn(); } public function GetDescription($FlagValue) { $sql = "SELECT flagdescription FROM flags WHERE flagname = ? AND flagvalue = ? LIMIT 1"; $stmt = $this->pdo->prepare($sql); $stmt->execute([$this->FlagName, $FlagValue]); return $stmt->fetchColumn(); } } $pdo = new PDO($dsn, $username, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $intent = new Flag($pdo, 'intent'); if ($intent->CheckValue(2)) { echo "valid"; } else { echo "invalid"; }1. It could be that "a flag" is not just a name but a name/value pair, in which case you'd set up the name and value with the Flag class and then not have to pass the value into the CheckValue and GetDescription methods.2. If you did that name/value pair thing, better than querying the database in each method would be to simply load up all data when the class gets constructed - then CheckValue and GetDescription could just return values already available.
  13. If you don't want it overwriting then what do you mean by having the image "changed"?
  14. By making a new thread detailing whatever it is you're asking about.
  15. ...no. You will have to actually write code. Weird, huh?
  16. The word you're looking for is pagination. Your SQL queries will look like SELECT * FROM $tbl_name ORDER BY id DESC LIMIT $offset, 20and $offset = ($page - 1) * 20 (assuming the first page is $page=1).
  17. You want to use empty cells? Normally this kind of edge stuff is dealt with by keeping the map at the edges and moving the character's sprite around (as opposed to the normal way of moving the map around and keeping the character in place). Consider moving left twice, from (2,2) to (0,2): 1. Move left: moves the map from (1,1)-(3,3) to (0,1)-(2,3) 2. The map is now at the left edge and cannot move anymore 3. Move left: moves the character over one square 1 2 3 0 1 2 0 1 2 +---+---+---+ +---+---+---+ +---+---+---+ 1 | | 1 | | 1 | | + + + + + + 2 | C | 2 | C | 2 | C | + + + + + + 3 | | 3 | | 3 | | +---+---+---+ +---+---+---+ +---+---+---+Movement is always either (a) the map if there is still space to show, or (b) the character if not. What you're saying is 1 2 3 0 1 2 -1 0 1 +---+---+---+ +---+---+---+ +---+---+---+ 1 | | 1 | | 1 |XXX | + + + + +XXX + 2 | C | 2 | C | 2 |XXX C | + + + + +XXX + 3 | | 3 | | 3 |XXX | +---+---+---+ +---+---+---+ +---+---+---+to always move the map, and fill empty spaces with the empty cell icon. It's not necessarily bad, just less common. (Makes it easier to work with non-rectangular maps though.) For that, 1. Do your query like normal 2. Tally each cell in a grid, to keep track of which squares you have cells for 3. Run through the grid, look for empty squares, and add in "empty" cells with calculated data (eg, icon URL, title, alt text) 4. Send the final result to the client Or alternatively, handle the emptiness on the client: 1. AJAX returns each cell and where it gets positioned 2. Javascript positions each returned cell 3. The map, or some parent element, has a background image, which will be visible in the areas where there wasn't a cell positioned The first approach will probably work better for your current system.
  18. So there's two elements to this: the map in the background and the position of the player. Those two are out of sync, like the character thinks it has to move towards the trees due to the map boundary yet the map can continue to move. Not knowing what you have now, this is the way I would implement it: The AJAX call to move would return something like "the map should now show the area (x1,y1)-(x2,y2) and the character is at position (cx,cy)" and the Javascript determines where to place the character. The Javascript previously retrieved map information (like boundaries and image URLs) so it can handle the entire process of rendering without the AJAX needing to return CSS values or HTML markup. Say the map is 20x20 and has boundaries (0,0)-(19,19). After movement the AJAX returns an area (0,2)-(12,14) and the character at location (4, . That location is 5 squares from the left and 9 squares from the top - not the middle of the map. The Javascript sets the map to show its background using offset (0px,64px) and positions the character at (128px,256px). After moving right a few times the AJAX may return (1,2)-(13,14) and the character at (7, ; the map is displayed with offset (32px,64px) and the character at (224px,256px). [edit] PS: I'm not 100% sure I got the numbers exactly right.
  19. No, you cannot return from the function. Just like you cannot use return in your original code. Unfortunately I can't find anything good that explains how AJAX works and what you can and cannot do with it. Unfortunate because I wanted to give you something to read (preferably something that would take more than a couple minutes) before you touched any more code. The callback function has to do a thing. It cannot return a thing. Use it to perform an action. Put the code performing an action inside the callback. 1. Why are you even using AJAX for this? Do you expect the list of users to change while the page is still open? What was wrong with the json_encode() from earlier? 2. The "callback function has to do a thing" approach will not work for that code. It's already within an event handler. Probably the most appropriate approach would be to set a variable (like but not quite how the other variables around lines 62+ are set) containing the list of users, and put that variable on line 197. But to do this best requires an answer to my first question.
  20. You cannot return the list from the uList function. AJAX is asynchronous (it's the first 'A') which means it's not executing like a normal function call but will execute eventually and somewhere else. Instead of calling uList() and then doing something with the return value, give uList() a function to call when it's ready. function uList(callback) { $.ajax({ type: "POST", url: "techs.php", success: callback }); } uList(function(users) { // do something with users console.log(users); });
  21. I'm going to copy/paste from the source: /********************************************************************** Cumulative Distribution Function POIsson distribution Function Calculates any one parameter of the Poisson distribution given values for the others. Arguments WHICH --> Integer indicating which argument value is to be calculated from the others. Legal range: 1..3 iwhich = 1 : Calculate P and Q from S and XLAM iwhich = 2 : Calculate A from P,Q and XLAM iwhich = 3 : Calculate XLAM from P,Q and S P <--> The cumulation from 0 to S of the poisson density. Input range: [0,1]. Q <--> 1-P. Input range: (0, 1]. P + Q = 1.0. S <--> Upper limit of cumulation of the Poisson. Input range: [0, +infinity). Search range: [0,1E100] XLAM <--> Mean of the Poisson distribution. Input range: [0, +infinity). Search range: [0,1E100] STATUS <-- 0 if calculation completed correctly -I if input parameter number I is out of range 1 if answer appears to be lower than lowest search bound 2 if answer appears to be higher than greatest search bound 3 if P + Q .ne. 1 BOUND <-- Undefined if STATUS is 0 Bound exceeded by parameter number I if STATUS is negative. Lower search bound if STATUS is 1. Upper search bound if STATUS is 2. Method Formula 26.4.21 of Abramowitz and Stegun, Handbook of Mathematical Functions (1966) is used to reduce the computation of the cumulative distribution function to that of computing a chi-square, hence an incomplete gamma function. Cumulative distribution function (P) is calculated directly. Computation of other parameters involve a seach for a value that produces the desired value of P. The search relies on the monotinicity of P with the other parameter. **********************************************************************/If $which == 1,- $par1 is the S value - $par2 is the XLAM value If $which == 2, - $par1 is the P value (and Q is 1-P) - $par2 is the XLAM value If $which == 3, - $par1 is the S value - $par2 is the P value (and Q is 1-P)
  22. Obviously it does exist. What is the exact error message? You've made sure that with those exact table structures and that exact trigger you're getting the same error, right? I think so but it's not clear. It sounds like you are turning a "insert a record into d_records" operation into a "create a record thing by inserting rows into d_records and h_records" operation. Or it could be that h_records is some sort of history or auditing table and you want inserts to be sort of mirrored? Or I don't know. Either way I think (not knowing your situation) I would go with a stored procedure; triggers that cause side effects in other tables and not because of something like foreign key relations feel icky to me. Too automagical. It's entirely non-obvious that inserting into d_records will also insert into h_records, but that's also due to what triggers are so... Eh, opinion.
  23. Behavior like this with a trigger? Ew. How about a stored procedure instead?
  24. ...Yes? It wouldn't be very nice if you checked out a local copy of a remote branch and it wasn't up to date.
  25. allow_url_include is about trying to do stuff like include("http://..."), which is never acceptable. It doesn't matter here. What if you try equivalent code using cURL instead?
×
×
  • 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.