Dec 29, 2010

PHP:: Facebook getLoginUrl iframe next parameter redirect issue

DUE TO FREQUENT FACEBOOK API CHANGES THIS ARTICLE IS OUTDATED.

The php-sdk from Facebook has some bugs in it.

http://stackoverflow.com/questions/3380876/how-to-authorize-facebook-app-using-redirect-in-canvas http://forum.developers.facebook.net/viewtopic.php?id=70575

These solutions didn't work for me, so I had to change the function getLoginUrl in class Facebook

  public function getLoginUrl($params=array()) {
 $currentUrl = $this->getCurrentUrl();
 $args = array(
        'api_key'         => $this->getAppId(),
        'cancel_url'      => 'http://www.facebook.com/',
        'display'         => 'page',
        'fbconnect'       => 0,
        'next'            => $currentUrl,
        'return_session'  => 1,
        'session_version' => 3,
  'canvas'          => 1,
        'v'               => '1.0',
      );
 foreach($params as $key=>$val) {
  $args[$key] = $val;
 }
 return $this->getUrl(
  'www',
  'login.php',
  $args
 );
  }
Example:
if($me) {
 $logoutUrl = $facebook->getLogoutUrl();
} else {
 $loginUrl = $facebook->getLoginUrl(array('next'=>'http://apps.facebook.com/xxxxxxx/'));
 ?>
 <script type="text/javascript">
 top.location.href = '<?=$loginUrl?>';
 </script>
 <?php 
 exit;
}

Dec 6, 2010

PHP:: relative paths in include() or require()

While this might seem fairly obvious, I'd still like to point out that PHP's functions include(), include_once(), require() and require_once() have problems including files in different directories where paths of the filenames are relative. The absolute path of the included files is generated from the filename of the first included file, so any relative path in the second nested include will not have relative paths starting from it's directory, but the directory of the first file. To avoid confusion I find it's best to use absolute paths with the magic constant __FILE__, which is always the current script's filename.

Example:
require_once(dirname(__FILE__).'/../../include_all.php');

Nov 21, 2010

Flash wmode (transparent/opaque/window) z-index

In flash player 9 and below there was a problem with the object's z-index if the wmode was set to window.

When this option is set to transparent, it fixes the z-index issue, but messes up the keyboard layout and mouse wheel events in flash object. Flash player 10.1 fixes the keyboard layout issue.

Workaround
Setting wmode to opaque keeps the mouse wheel functionality and z-index of absolute elements on the page, but only if you set the background color for the element!

Having a transparent background (or setting the opacity attribute in CSS) (still) does not solve the issue.

Nov 13, 2010

flashlog.txt NS_ERROR_FAILURE

If flash player (debugger) locks the flashlog.txt file (can't be deleted or truncated), try deleting the mm.cfg file and restarting the browser and/or flash player. After that, try using a different plugin/software for reading flash traces.

Aug 22, 2010

Installing BackTrack Linux on a USB key with VMWare, the easy way

  1. Create a new virtual machine in VMWare. You do not need to add a hard disk. Just delete it, just in case. For the CD Rom add the iso image of BackTrack Linux.
  2. Start the virtual machine. You might need to edit boot in the BIOS, so press F2 to enter BIOS setup and set CD rom as the primary boot.
  3. Enable Removable Device in vmware so that it will show up as a USB disk on Backtrack
  4. When BackTrack loads open install.sh on the desktop.
  5. The installer should now automatically use your USB key as the primary disk for the install.
  6. Use default partitioning and install. Just Click OK.
  7. After a successfull installation, your USB key is ready to boot.
  8. Boot into Backtrack and login with root/toor - the default username and password

Jul 31, 2010

Enabling Lightbox on Google's Blogger


It's fairly simple. Just add a simple JavaScript to the template next to the Lightbox import.
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('#Blog1 a img[class!=icon-action]').parent().attr('rel','lightbox[imgs]');
jQuery('#Blog1 a img[class!=icon-action]').parent().attr('title','© Žan Kafol');
});
</script>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen">

Jul 16, 2010

JavaScript: escape()

When you're sending a string through a GET request with javascript, you should obviously URL encode the string to ensure all characters get transmitted. The escape() function in javascript works fairly well, even when you're sending UTF-8 characters. But the + character is interpreted as a space in the GET request, so you need to handle it manually. Here's how I do it:
 msg = msg.replace(/\+/g,'%2B'); 
 geturl('ajax.get.php?msg='+escape(msg));
First, you do a global regex match for the plus character, replace it with it's url encoded equivalent, and then you url encode the string with escape().

Jul 12, 2010

Example usage of Facebook.streamPublish()

DUE TO FREQUENT FACEBOOK API CHANGES THIS ARTICLE IS OUTDATED.

You can force streamPublish dialog from within the href bar in the browser. Also note the application ID prefix in the functions. More detailed code description is superfluous. javascript:c=9999999;h='Click Challenge';l='http://apps.facebook.com/click-challenge-en/?ref_6w=f_clicks';a126752370697733_Facebook.streamPublish('',{'name':h,'href':l,'caption':'{*actor*} made '+(c/1)+' clicks in 10 seconds.','properties':{'Speed':{'text':(c/10)+' clicks/sec','href':l}},'media':[{'type':'image','src':'http://w6.6waves.com/my-app/data/126752370697733/logo.gif','href':l}]},[{'text':h,'href':l}]);

Mar 26, 2010

Solution for problem code FCTRL on SPOJ

#include <stdio.h>

int main() {
int s;
scanf("%d",&s);
while(s--) {
int r,c,x=0,p=1;
scanf("%d",&c);
do x += (r = c/(p*=5)); while(r);
printf("%d\n",x);
}
return 0;
}

Jan 18, 2010

PHP: calculate distance between two points

Each point is an one-dimensional array, each value in the array is a coordinate, so dimension of coordinates in this function is arbitriary.
 /*
 * Calculates Euclidian distance between two points in p-norm
 * Points $p1 and $p2 are Nx1 matrices
 */
 function euclidian_distance($p1,$p2) {
  if(count($p1) != count($p2)) return false;
  $distances = 0;
  
  $p1 = array_values($p1);
  $p2 = array_values($p2);
  
  $norm = count($p2);
  
  for($i=0;$i<$norm;$i++) $distances += pow(abs($p1[$i]-$p2[$i]),2);
  
  return pow($distances,1/2);
 }

Jan 8, 2010

Windows 7/Vista & ArcGIS & ESRI License Manager

It seems that ESRI License Manager has difficulties running in Windows 7 or Vista – the License server fails to start at boot or on demand in License Manager Tools.
Consequently, ArcGIS didn’t start because there was no license server running. Obviously this problem doesn’t occur if the license server is running on another machine in the network.
At first I tried the quick and dirty solution – to manually start the server daemon and see where it fails.
I ran Command Prompt as an administrator:
Untitled
Now, the server is called lmgrd.exe, so if you navigate to C:\Program Files\ESRI\License\arcgis9x and start lmgrd, it says that there is no license specified.
So I typed the location of the license (it was in the same folder), ran the program in the foreground:
lmgrd –c license.lic -z
I kept the command prompt open, and ArcGIS started succesfully.
But this isn’t really a long term solution, since this method would require manual server start in the command prompt everytime I would want to start ArcGIS.
So I thought, maybe the problem is that the server can’t find the license file. After some googling, I found out that the environment variable LM_LICENSE_FILE wasn’t set. It says on the support page that you’d need to enter port@machine-name for the variable value, but since we’re running the server on the local machine, you just need to enter your C:\Path\to\your\license.lic.
sd
When all goes well with License Manager Tools, you might still need to enter "localhost" in the ArcGIS desktop manager in the license server.
If anyone has a better solution or information, please post in the comments.
UPDATE:
After further experimentation I found out that you also need the Sentinel driver to successfuly run License Manager on Windows 7. Don't know why, but it works. You should install Sentinel driver first, then the license manager, so that everything for the license works before you install ArcGIS. That way you won't have to manually configure ArcGIS for license after it has been installed. You have less work that way.