Jump to content

Michdd

Members
  • Posts

    510
  • Joined

  • Last visited

    Never

Everything posted by Michdd

  1. Maybe I explained it in a bad fashion. I meant something like: class Base { /* Might have some methods to load different classes, packages, etc.. */ } class Controller extends Base { public function __construct() { parent::__construct(); } /* ... */ } class PageName extends Controller { public function __construct() { parent::__construct(); } /* ... */ } So in this simple MVC pattern there's only 1 instance of the lower level "PageName" class that needs to be invoked, but in a more involved (non-MVC, nor web-based) application there's not such a clear way to do this. It's pretty hard to explain what I mean, maybe I just need to do more research into design patterns.
  2. I've been using OOP for a long time, and I feel like I have a decent grasp on it, but when it comes to designing certain applications in OOP I'm unable to determine the correct route I should take. Building a PHP application that utilizes MVC is easy for me. I have a base class, the controller class extends the base class and then I have classes that extend the controller class to represent each individual page. In this way I get all the functionality of the base class. I want to be able to get this same kind of functionality in other programs (not web based, nor PHP, but that doesn't really matter). In my MVC applications an instance of a class extending the controller class is created when a page is accessed and that in turn gives me the functionality of all the other classes through hierarchy. I can't seem to figure out how I would do this in another type of application (or even if I should). At the moment I end up creating a base class that will hold other objects and I pass a reference of that base class to other objects held by that base object so I can access anything anywhere through that base object. However, I feel this isn't the right way to be using OOP. I've been doing a lot of searching to find examples of entire programs written in OOP that are involved, but I can't seem to find much. Everything I find is extremely basic applications that while do a good job in teaching you what OOP is about, they don't really show you real-world applications. Any suggestions or links would be greatly appreciated.
  3. Doh, that should have been pretty obvious. Thanks. @salathe: That's great, and I'll probably use that for the PHP part of this project. Unfortunately, something so convenient isn't available in the other programming language I'll also be using. I'll just write some procedures that do the same thing as pack() on that platform using the help I got int his topic.
  4. But that's also the binary representation for 253, how can you tell the difference?
  5. I knew about that function. But I was just being stupid. After sleeping I was able to come up with a solution. This is what I came up with (though, I'm pretty sure the first function can be simplified) function getBytes($number) { $binary = decbin($number); for($i = 0, $l = strlen($binary);$i < $l;$i += { $lim = ($extra = strlen($binary) % == 0 ? 8 : $extra; $arr[] = substr($binary, 0, $lim); $binary = substr($binary, $lim); } return array_map('chr', array_map('bindec', $arr)); } function getNumber($bytes) { $bytes = array_map( create_function('$x', 'return str_pad(decbin(ord($x)), 8, "0", STR_PAD_LEFT);' ), $bytes ); return bindec(implode($bytes)); } Say you pass the number 257. The number 257 in binary is 00000001 00000001. So it puts each of them into a separate byte. Coming up with the bytes: 1 & 1. Then when transforming that back into the numerical value the other function takes the binary represented by each byte, combines it and turns it back into a decimal. Does anyone have any suggestions or a reason why I shouldn't do it like this? One other question, this obviously won't work for negative values. Now, should I implement a way to convert negative values correctly? Or is this not really required? If you haven't guessed yet this is for sending data over a socket. And I can't think of any specific case myself where a well-designed program would actually require this.
  6. I need a way to get the bytes that represent a numerical data-type's value (int, short, char, whatever). And vise versa. For example: 265 in binary would be: 00000001 00001001 so the bytes would be 1 and 8, then I'd need to be able to convert 1, 8 back to 265. I'm sure I could do this myself, but I'm just looking for the easiest way to do this. I feel like I should know this, and it's really simple. But I'm extremely exhausted so please forgive me if this is a stupid question.
  7. Michdd

    basic regex

    I need to match something like this: ..namename namename ~ Where namename can be anything alpha numeric and .. is something that doesn't need to be matched.. I thought something like /[\d\D]+ [\d\D]+ ~$/ would work.. but it doesn't.. Any help?
  8. Michdd

    Ajax?

    I guess I have another question about systems like these, it's probably pretty obvious but I'm just not sure. Would systems like these pass information through an AJAX request then the script that it queries relays information to a socket server? Is it something like that?
  9. Michdd

    Ajax?

    I find it shocking that meebo / facebook use blind http requests.. Especially with the amount of processing that needs to be done in certain instances, having this called every 1-2 seconds by every client seems overwhelmingly inefficient..
  10. Michdd

    Ajax?

    Hm.. I was always under the impression that AJAX was pretty slow. Even if it's faster how is it possible to create something 'live' without being extremely inefficient? Isn't AJAX just low-level http requests? Wouldn't you have to run an Ajax request every few seconds to query the server to see if there are any updates? Or is there another way that I'm just completely oblivious to?
  11. Michdd

    Ajax?

    Is it true that http://meebo.com runs on AJAX? How is that possible? Isn't AJAX far too slow to maintain a real-time application like this?
  12. I have a div that will have images appended to it, and everytime something is added I make sure that it's scrolled to the bottom of the div using scrollTop = scrolHeight. The issue is that if I append Images to this div it doesn't scroll completely to the bottom. I figured this was because the images weren't loaded yet so it didn't know the height of the images, and this seemed to be proven true by the fact that if after the image loaded I added just text it would work fine. My idea of a solution was to load the Image in an Image() object and set a function to the onload event to only append it after the image is completely loaded, however I still get this effect of the div not being completely scrolled down. Here's an example of what I tried: function ...(...) { var something = new Image(); something.onload = appendImage('someimage.jpg'); something.src = 'someimage.jpg'; } function appendImage(image) { .... }
  13. That worked perfectly, thanks. I was gonna use preg_replace_callback() also, but I was going to do it in a different fashion.
  14. That won't work because the format isn't always non-number, number, non-number. Even in the example I posted it isn't.
  15. I need to replace (using preg_replace()) all numbers inside of ( ) with <sub>number here</sub> where "number here" is the number matched.
  16. Not exactly like that, but you can do this: $variable = $_POST['renderIntent']; $func = "render_" . $variable . "_info"; $func();
  17. preg_match_all("/\([0-9]+\)/", '(S2O3)-2', $matches); print_r($matches); Output: Array ( [0] => Array ( ) )
  18. I know I can match numbers by just [0-9]+, so I thought matching numbers inside ( ) would be something like /\([0-9]+\)/ , but that doesn't work Can someone correct me please?
  19. I'm trying to figure out a simple way to input numbers not varying much but have the output be highly variating. So even though the numbers being input might be close to each other I want the output to highly different, but still in the rank of 0, 255. I've tried a few things but the only things I can think of return something directly related to the input.
  20. <?php //Store the value of the form element that has the name of "input" in a variable named $input $input = $_POST['input']; //Check to see if the string contains only letters (spaces are also allowed) if(ctype_alpha(str_replace(' ', NULL, $input))) { //Split the string into an array of the different words //Then reverse the order of the words in the array //Finally reform the string separating each word with a space and echoing it echo implode(' ', array_reverse(explode(' ', $input))); } else { //They entered non-alpha characters echo 'You entered Invalid characters'; } ?> Note: That doesn't check to make sure exactly 5 words were entered. But that would be easy to check for.
  21. Michdd

    Timer

    I think you're understanding wrong. I can't use sleep(), because that would halt execution of the shell script.. I need the script to constant run to handle incoming packets and such. I just also want to run something every say... 5 minutes. I know I could do something like this: while(true) { if($last_update + 60*5 <= time()) { //It has been 5 minutes, } //Everything else.. } Is there a better way?
  22. Michdd

    Timer

    Of course, but I don't think that would be best for my situation. This shell script is acting as a server, and the operation that I want it to preform periodically has something to do with the data on the server. I suppose I could use a CRON and connect to my server through the php file run and have my server return the information back to the php file being called by CRON. But that seems unnecessary.
  23. Michdd

    Timer

    I have a shell script using PHP. I would like to do something every X amount of seconds. The only solution that I can think of is putting something within my main (inf) loop to check and see if it has been the amount of time, if so do whatever. This doesn't seem like it would be the best method, but I can't think of anything else. Would this be okay to do? Or is there a better way?
  24. Wow, maybe I shouldn't be trying to do math at 3am. I swear I tried that x.x. Thanks.
×
×
  • 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.