Earlier this week I wrote up my first Chrome extension - the AdMob Earnings Checker. It's really easy to build extensions for Chrome - basically just stick a bunch of HTML and Javascript in a zipped folder, upload it and you're done. It took me less than an hour to build this guy (taking reference from a similar extension for AdSense).
The hardest part was actually decoding the AdMob page with the JQuery parser - take a look at the source of your AdMob sites page and you'll see what I mean. Not valid HTML by any means. I had to manually strip some tags in order to get JQuery to accept it as pseudo-html. Once I got over that difficulty though, it was pretty straight forward.
So if you develop Android apps, or operate any kind of mobile website using Google's advertising services, you might like to check out the extension. Any feedback would be appreciated!
Life, the universe and everything. The state of the world, from the perspective of one in it.
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Thursday, 7 April 2011
Monday, 30 August 2010
Symfony 'String could not be parsed as XML'
I was receiving this error on my symfony project (using the sfWhoIsOnline plugin):
Turns out, SimpleXMLElement can't handle empty strings or badly encoded documents well. As a patch of sorts, I replaced the code at line 38 in the sfWhoIsOnlineUserFacade class with the following lines (original lines in bold):
References:
http://drupal.org/node/541892
http://weierophinney.net/matthew/archives/111-mbstring-comes-to-the-rescue.html
http://www.google.com/search?hl=en&q=String+could+not+be+parsed+as+XML&aq=f&aqi=&aql=&oq=&gs_rfai=
http://ketarin.canneverbe.com/forum/viewtopic.php?id=384
[28-Aug-2010 21:50:54] PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/xxxxxxx/plugins/sfWhoIsOnlinePlugin/lib/sfWhoIsOnlineUserFacade.class.php:38
Stack trace:
#0 /home/xxxxxxx/plugins/sfWhoIsOnlinePlugin/lib/sfWhoIsOnlineUserFacade.class.php(38): SimpleXMLElement->__construct('')
#1 /home/xxxxxxx/plugins/sfWhoIsOnlinePlugin/lib/filter/sfWhoIsOnlineFilter.class.php(14): sfWhoIsOnlineUserFacade::registerUser(Object(myUser))
#2 /home/xxxxxxx/cache/frontend/prod/config/config_core_compile.yml.php(1026): sfWhoIsOnlineFilter->execute(Object(sfFilterChain))
#3 /home/xxxxxxx/plugins/sfDoctrineGuardPlugin/lib/sfGuardRememberMeFilter.class.php(56): sfFilterChain->execute()
#4 /home/xxxxxxx/cache/frontend/prod/config/config_core_compile.yml.php(1026): sfGuardRememberMeFilter->execute(Object(sfFilterChain))
#5 /home/xxxxxxx/cache/frontend/prod/config/config_core_compile.yml.php(990): sfFilterChain->execute()
#6 /home/xxxxxxx/cache/frontend/prod/config/config_core_compile.yml.php(1026): sfRenderingFilt in /home/xxxxxxx/plugins/sfWhoIsOnlinePlugin/lib/sfWhoIsOnlineUserFacade.class.php on line 38
[29-Aug-2010 00:06:48] String could not be parsed as XML
[29-Aug-2010 02:14:47] String could not be parsed as XMLTurns out, SimpleXMLElement can't handle empty strings or badly encoded documents well. As a patch of sorts, I replaced the code at line 38 in the sfWhoIsOnlineUserFacade class with the following lines (original lines in bold):
/* Begin Hack to fix error 'String could not be parsed as XML' */
try {
$xml = new SimpleXMLElement($xmlString); // <-- Original line 38 $instance->fromXml($xml); // <-- Original line 39
} catch (Exception $e) {
sfContext::getInstance()->getLogger()->crit('sfWhoIsOnline failed to create SimpleXMLElement');
sfContext::getInstance()->getLogger()->crit('xmlString: '.$xmlString);
}
/* End Hack */References:
http://drupal.org/node/541892
http://weierophinney.net/matthew/archives/111-mbstring-comes-to-the-rescue.html
http://www.google.com/search?hl=en&q=String+could+not+be+parsed+as+XML&aq=f&aqi=&aql=&oq=&gs_rfai=
http://ketarin.canneverbe.com/forum/viewtopic.php?id=384
Thursday, 19 August 2010
Install phploc on openSuSE 11.3 [HOWTO]
Once you've got PEAR installed, run these commands (as root):
At first I was getting errors:
But running:
fixed all the errors.
pear channel-discover pear.phpunit.de pear channel-discover components.ez.nopear install phpunit/phploc
At first I was getting errors:
phpunit/File_Iterator requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/phploc requires package "phpunit/File_Iterator" (version >= 1.2.0)
No valid packages found
install failed
But running:
pear upgrade-all
fixed all the errors.
Friday, 25 December 2009
Android: How to scale an image in ImageView
To scale an image in the provided ImageView control, use this basic code:
This will increase the image size by scalefactorX and scalefactorY, and move the image so that the top left corner is at the location specified by offsetX and offsetY.
Matrix mtrx = new Matrix;
mtrx.postScale(scalefactorX, scalefactorY);
mtrx.postTranslate(offsetX, offsetY);
pic.setImageMatrix(mtrx);
pic.setScaleType(ScaleType.MATRIX);
pic.invalidate();
This will increase the image size by scalefactorX and scalefactorY, and move the image so that the top left corner is at the location specified by offsetX and offsetY.
Friday, 18 December 2009
Installing Android Devloper Tools on Eclipse fails - Ubuntu Karmic 9.10
I followed these instructions to install the Eclipse Android Developer Plugins using Eclipse 3.5.1 and the default Ubuntu Karmic install. However I was presented with the following error message when clicking "Next":
For some reason ubuntu doesn't include the standard update repository for Eclipse by default. To fix this:
Cannot complete the install because one or more required items could not be found.
Software being installed: Android Development Tools 0.9.5.v200911191123-20404 (com.android.ide.eclipse.adt.feature.group 0.9.5.v200911191123-20404)
Missing requirement: Android Development Tools 0.9.5.v200911191123-20404 (com.android.ide.eclipse.adt.feature.group 0.9.5.v200911191123-20404) requires 'org.eclipse.wst.xml.ui 0.0.0' but it could not be foundFor some reason ubuntu doesn't include the standard update repository for Eclipse by default. To fix this:
- Go to "Help/Install New Software..."
- Add http://download.eclipse.org/releases/galileo/ to the update sites list (strange it's not installed by default on ubuntu)
- From there, install WST (use the filter box to find the package)
- Restart eclipse
- Go back to "Help/Install New Software..." and install the Android ADT as explained on the android website.
Wednesday, 16 December 2009
PHP: How to (Code) to check if a Windows file / folder name is valid.
Two PHP functions to check a string to see if it is a valid windows filename. The first simply checks the string, the second function will replace all occurrences of the invalid characters with a blank.
/**
* Checks to see if a filename is valid for Windows
* Invalid characters are: < > : " / \ | ? *
* Returns false if invalid characters found, else true
*/
function isValidFilename($filename)
{
if(preg_match('/[<>:"\/\\\|?*]/i', $filename))
{
//Invalid characters found
setDebug("Filename '$filename' contained invalid characters.");
return false;
} else {
//No invalid characters, must be valid filename
setDebug("Filename '$filename' contained no invalid characters.");
return true;
}
}
/**
* Removes all invalid characters from a Windows filename.
* Invalid characters are: < > : " / \ | ? *
* Returns the (possibly) modified string
*/
function fixFilename($filename)
{
setDebug("Filename to fix: {$filename}");
$newFilename = preg_replace('/[<>:"\/\\\|?*]/i', "", $filename);
setDebug("Fixed filename: {$newFilename}");
return $newFilename;
}
Sunday, 15 November 2009
How to Setup Android SDK / ADB / Fastboot Under Ubuntu 9.10
These instructions work for Ubuntu 9.10, which I am running, as well as most other linux distributions. Basically how to setup Android for debugging. I have found this works with my HTC Magic 32A.
./adb kill-server
sudo ./adb start-server
./adb devices
Setting up UDEV to recognize HTC Device -
./adb kill-server
sudo ./adb start-server
./adb devices
Setting up UDEV to recognize HTC Device -
- Type the following into a terminal (Applications > Accessories > Terminal):
Code:
gksudo gedit /etc/udev/rules.d/51-android.rules
- Now add the following line to the blank file:
Code:
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
- Click save and close.
- To restart udev, open up a terminal and enter:
Code:
sudo /etc/init.d/udev restart
Sunday, 2 August 2009
"All Squash" in Samba FIle Server
NFS has the ability to "root squash" or "all squash" - map authenticated users to alternate user ids, for purposes of security. This makes it easy to setup an NFS public folder where all users share the same permissions.
Samba on the other hand, does not have such capabilities. However, you can achieve similar functionality by configuring a "guest" user, which maps to a specific local user id on the server.
Simply open /etc/samba/smb.conf and enable the following line:
guest account = [mapped user id]
That's all there is to it! Now any anonymous client can access the shared folders, and they will automatically have the same access rights as if they were logged into the server locally, with the username specified in the smb.conf file.
Samba on the other hand, does not have such capabilities. However, you can achieve similar functionality by configuring a "guest" user, which maps to a specific local user id on the server.
Simply open /etc/samba/smb.conf and enable the following line:
guest account = [mapped user id]
That's all there is to it! Now any anonymous client can access the shared folders, and they will automatically have the same access rights as if they were logged into the server locally, with the username specified in the smb.conf file.
Wednesday, 18 June 2008
Latest project: curl-based login
I've often wanted to check for status updates behind login-protected pages, which doesn't work properly with RSS based solutions. Many programs, like Page2RSS would work for standard pages, but not for login based ones. For this purpose, I'm currently working on a curl-based solution that should login, and check for updates to a page. I'm not sure if I'll actually be able to make RSS feeds out of that, but regardless I should be able to do a unix script to make a desktop alert. Here's hoping it all workes out allright.....
Monday, 2 June 2008
How to Solve the Third Question - Google Treasure Hunt 2008
This third question had me slightly confused. As I had no knowledge of network theory, it seemed at first too big a problem. But then, when I Googled the solution, I found that others felt the same way. And really, you don't need great network knowledge to solve this problem. All you need to solve the third problem in the Google Treasure Hunt 2008 is common sense and the ability to follow instructions.
Firstly, a bit about how network routing works. Imkira has a good pseudo-algorithm for finding the path between nodes S and D:
Third Question:
This doesn't even need a program to calculate it. I performed these operations by hand, and it only took about 10 minutes. I'm still waiting on the answer, but I'm fairly confident that it's correct. If you want a spoiler for the default question, click here. The next question's coming out June 3rd (tomorrow) so you'd better hurry if you want to answer this!
By the way, if you're puzzling over those "/24"s, check out Route summarization on Wikipedia.
The Treasure hunt has been a great opportunity so far for the geeks of the world to get creative with some problem solving. I've enjoyed it, as I'm sure many others have. Hopefully Google will continue to promote these "fun" activites, as they get the developer community active and give Google a good image in so far as community involvement goes. Thanks Google!
Update: My answer was correct! :D
Firstly, a bit about how network routing works. Imkira has a good pseudo-algorithm for finding the path between nodes S and D:
Third Question:
- 1- Start at node S
- 2- First, add the current network node to the path. If D is the current network node the algorithm outputs the path and ends since the packet was just delivered to D. Otherwise advance to the next step.
- 3- Iterate each routing table entry:
- 4- D matches the Nth entry's network? Set the current node as the Nth entry's target gateway and Jump to step 2
- 5- D does *not* match any of the routing table entries? Set the current node as the current default gateway and Jump to step 2
This doesn't even need a program to calculate it. I performed these operations by hand, and it only took about 10 minutes. I'm still waiting on the answer, but I'm fairly confident that it's correct. If you want a spoiler for the default question, click here. The next question's coming out June 3rd (tomorrow) so you'd better hurry if you want to answer this!
By the way, if you're puzzling over those "/24"s, check out Route summarization on Wikipedia.
The Treasure hunt has been a great opportunity so far for the geeks of the world to get creative with some problem solving. I've enjoyed it, as I'm sure many others have. Hopefully Google will continue to promote these "fun" activites, as they get the developer community active and give Google a good image in so far as community involvement goes. Thanks Google!
Update: My answer was correct! :D
Thursday, 29 May 2008
Google Earth - coming to a browser near you....
Google Earth just met the browser. In one of Google's most exciting new API releases, the Google Maps API is now extended to include support for 3D maps - Sky, 3D Buildings and all. Once you've downloaded and installed the plugin, you're ready to go, with a whole host of Javascript API calls available to tile, pan and manipulate the earth. Check out the samples to give it a test.
Wednesday, 21 May 2008
Google Treasure Hunt - How to solve the second problem
Warning: spoilers contained within!
How to Solve the Second question in the Google Treasure Hunt 2008
(question: 2 sums from 10202160872969032313.zip: line 4 in *BCD*.xml, line 2 in *def*.js)
Unlike the previous question (the robot on grid), I was able to solve the second question without too much difficulty. After about 20 minutes spent looking up bash manuals online, I came up with the following script:
This script basically uses the linux utility "find" coupled with "grep" to locate all files matching the pattern specified. Then, for each file, I piped the contents through "tail" and "head" to obtain the desired line, which is printed to the standard output.
The sharp-eyed among you might have noticed that this script doesn't actually calculate the sum of all the lines, or multiply these sums together. This is because I actually used the lazy-man's calculator, Google, to complete this part of the problem. Simply copy and paste the command line output from this script into Google, insert "+" symbols between each number, and multiply the two outputs using the same method.
I know this code is "spaghetti" code, but I'm too lazy to fix it up. Please post a comment if you're enough of a nerd to format this in intelligible code.
Now, to wait for the next one...... :)
How to Solve the Second question in the Google Treasure Hunt 2008
(question: 2 sums from 10202160872969032313.zip: line 4 in *BCD*.xml, line 2 in *def*.js)
Unlike the previous question (the robot on grid), I was able to solve the second question without too much difficulty. After about 20 minutes spent looking up bash manuals online, I came up with the following script:
#!/bin/bash
for file in $(find . -maxdepth 999 -path '*BCD*' -or -name '*BCD*' | grep ".xml")
do
tail +4 $file | head -1
done
echo "----"
for file in $(find . -maxdepth 999 -path '*def*' -or -name '*def*' | grep ".js")
do
tail +2 $file | head -1
done
This script basically uses the linux utility "find" coupled with "grep" to locate all files matching the pattern specified. Then, for each file, I piped the contents through "tail" and "head" to obtain the desired line, which is printed to the standard output.
The sharp-eyed among you might have noticed that this script doesn't actually calculate the sum of all the lines, or multiply these sums together. This is because I actually used the lazy-man's calculator, Google, to complete this part of the problem. Simply copy and paste the command line output from this script into Google, insert "+" symbols between each number, and multiply the two outputs using the same method.
I know this code is "spaghetti" code, but I'm too lazy to fix it up. Please post a comment if you're enough of a nerd to format this in intelligible code.
Now, to wait for the next one...... :)
Wednesday, 30 April 2008
New Project
I'm currently working on a big project, which has the potential to grow into a very profitable free service if given enought time. I'm working in conjunction with affiliatejunction to offer...... well, I won't spoil the surprise by telling you now! You'll have to wait and see. :) Hopefully the "beta" will be ready by next week, so keep posted for updates soon.
Sunday, 27 April 2008
AppEngine Apps
I've made my first AppEngine apps now. I plan to do a few more, but for now, here are the URLs:
pi.appspot.com
http-get.appspot.com
pi.appspot.com
http-get.appspot.com
Subscribe to:
Posts (Atom)