Jump to content

skaterdav85

Members
  • Content Count

    874
  • Joined

  • Last visited

Posts posted by skaterdav85


  1. In Javascript, when you evaluate a logical OR expression the value of that expression will be the first "truthy" value. So if args does not evaluate to false, then args || arguments will evaluate to args, or else it will evaluate to arguments. It's the same as doing this: if (args) callArgs = args;else callArgs = arguments;
    you explained it much better JSG

  2. Well first off, why are you declaring a function called window? window is already a reserved object in the browser. Second, you will probably want to create all your instance properties/variables on the object. Right now you arent setting all those properties on your InitBuffer object. Move the following into InitBuffer and invoke it with new.

     this.xmlsource=objectsSource;  this.indexbuffer = null;  this.texelbuffer = null;  this.initbuffer = InitBuffer;


  3. super interesting, thanks everyone for helping with this! EDIT: Just noticed, even though I can pass in $this using the 'use' statement, I can no longer call protected and private members. I have to make them public. I'm guessing it is because the context of the callback function is no longer in the class.


  4. In the code sample below, how do I access the value of $this inside the callback function in the hello() method? I also attached the class to this post if you want to execute it. I am getting the error: Fatal error: Using $this when not in object context I want $this to point to the current instance.

    class Person {public function hello() {  $list = array(1, 2, 3, 4, 5);  $this->iterate($list, function($num) {   echo $this->multiply_by_100($num) . 'hello <br>';  });}public function iterate($list, $callback) {  foreach ($list as $num) {   call_user_func($callback, $num);  }}public function multiply_by_100($num) {  return $num * 100;}} $d = new Person();$d->hello();

    php_closure.php


  5. Ya I saw that about PHP 5.4. This was one tricky bug to find out. Luckily there was an extra query string parameter that I could pass to Facebook to encode large ints as strings, which is what I wanted. All the other solutions I saw used tricky regular expressions which looked nasty.


  6. On my local MAMP stack (PHP V 5.3.6), json_decode is taking my JSON and converting long ints to strings. On my production server (PHP V 5.3.2), json_decode is converting long ints to floats. My long ints are Facebook page ID's that looks something like: 755509932534027 I found a workaround that tells Facebook to send me long ints encoded as strings, but how can json_decode behave differently on production? Is it possible to alter the default behavior of this function? Is this common? Thanks!


  7. I did a print_r on a simplexml object and I get the following:

    SimpleXMLElement Object(	[@attributes] => Array		(			[term] => Standards			[scheme] => Responsible Organization		) )

    How do I access @attributes? I want to get the array element [scheme]. $root->@attributes throws a syntax error because of the @ symbol.


  8. I just checked the Firefox extension CacheViewer and the url shows up in the cache. You can also view some of the request and response headers. This is what I see:

    Key: http://localhost/map2/index.php?action=Home&method=search&d=3_14_2012&searchTerm=batteryData Size: 8261 bytesFetch Count: 6Last Modified: Wednesday, March 14, 2012 5:26:22 PMLast Fetched: Wednesday, March 14, 2012 5:26:35 PMExpiration Time: Wednesday, December 31, 1969 4:00:00 PMFile on disk: none request-method: GETrequest-Accept-Encoding: gzip, deflateresponse-head: HTTP/1.1 200 OKDate: Thu, 15 Mar 2012 00:26:22 GMTServer: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9X-Powered-By: PHP/5.2.9Vary: Accept-EncodingContent-Encoding: gzipContent-Length: 8261Content-Type: text/html

    My guess is that the problem lies with the Expiration time since it is 1969. I think I just need to set this to 1 day ahead and hopefully it works. Edit:Turns out just setting the Expires header works. However, you don't see a request made in the Web Console in Firefox. I'm not quite sure what Expiration-Time is, since nothing really comes up on Google about a header called 'Expiration-Time'. Also, is there an easy way to set the Expires header to the next day without parsing the date and setting it?


  9. I want to cache my AJAX responses for my site's search box since the data in the appilcation only changes once a day. I added the jQuery cache property and set it to true

    var date = new Date(), fulldate = [date.getMonth() + 1, date.getDate(), date.getFullYear()].join('_'); 		 $.ajax({			 url: 'index.php?action=Home&method=search&d='+fulldate,			 type: 'GET',			 data: data,			 cache: true,			 success: function(msg) {				 data.msg = msg;				 PS.publish('search-complete', data);			 },			 error: function(jqXHR, textStatus, errorThrown) {				 console.log('Error retrieving results.')			 }		 });

    The URL is unique each day by the d query string parameter and by the searchTerm query string parameter. So if I'm understanding this correctly, the result for this URL should be cached for each day for the searchTerm 'battery'. However, when I make multiple searches on the same day for the same keyword, the web console returns a 2xx status code instead of 304 (which would mean the response was read from cache). http://localhost/map...&method=searchd=3_14_2012&searchTerm=battery[HTTP/1.1 200 OK 359ms] Maybe I am missing something. Anyone understand how to use the cache property in jQuery's ajax method? Thanks!


  10. I just started working with the Zend Framework. I've used CodeIgniter before so I'm familiar with MVC. My question is, how do I work with configuration data in a layout? I've created a layout and it works fine. I've also created a custom config.xml file in the configs folder, which holds data that will be used on the layout. Now on my layout, I have the following code which works.

    $news = new Zend_Config_Xml('../application/configs/config.xml', 'news'); foreach($news->feed as $key => $feed) {	echo '<li class="feed" id="news_'.$key.'">'.$feed->name.'</li>';}

    Creating this Zend_Config object probably shouldn't be in a view type of file. There is probably a more appropriate place to put it like a bootstrap, but I am not sure where. Any suggestions? Thanks!


  11. So I tested it out, and I dont think it works. I created a simple demo on JSBin: http://jsbin.com/idodol/edit#javascript,html The demo references a script on another server and the JS script has an ajax function that tries to make a request to a php file on that other server. However, I get an error that says: XMLHttpRequest cannot load http://www-scf.usc.edu/~dtang/ajax/example1.php?name=Mike. Origin http://jsbin.com is not allowed by Access-Control-Allow-Origin.


  12. Take this with a grain of salt, as I'm not sure of the exact API you're referring to, and how you're using it (I'm just guessing...).
    Im not referring to any specific API. I am just curious about the general process. Maybe later I will try using a JS file hosted on another server I maintain and see if it can access the server-side scripts on the same server. If not, I agree, the only way I can see data being passed back and forth is through creating script elements and passing small amounts of data as a query string through the src attribute of the script element.

  13. If you include a JS file hosted on another server, the Google Maps script for example, how does your site using that JS communicate with server side scripts hosted on other servers when cross domain AJAX isn't allowed? For example, say you include the JS file for Google Maps hosted on Google's servers onto your page which is hosted on mysite.com. When you pan the map, the script is somehow communicating with stuff on Google's servers from your your domain (mysite.com) to retrieve more map images and other relevant data. The only way I can see this being achieved is through dynamic script element creation and using JSONP. Any thoughts? Thanks!


  14. Does anyone know the difference between DOM and SAX is? I've used DOM API methods in JS before to work with XML and HTML elements. Someone recently asked me what the difference between DOM and SAX was. I haven't used SAX before (which I think is more of a Java thing). Can someone clarify? Thanks!

×
×
  • Create New...