Archive

Archive for February, 2013

Installing a HTTP Proxy on Debian 4 (ETCH)

February 22, 2013 Leave a comment

I’m very much a Linux newbie, however, I just managed to install a HTTP proxy on my Linux box, with a view to install it on my Raspberry pi. Which will provide me with a proxy server with a dynamic IP address.

The abridged version is quite simple:

1. Run apt-get update

2. Run apt-get install tinyproxy

3. Edit /etc/tinyproxy/tinyproxyy.conf and  add a “#” before the Allow lines to make the proxy public

4. Run  /etc/init.d/tinyproxy restart to apply the configuration changes.

I initially thought there was a problem when I went to the proxy url directly

Cache Error!
The following error has occured: Unknown URL type


Generated by tinyproxy (1.6.3)

But this is perfectly normal, you’re not supposed to request it directly.

Advertisements
Categories: Uncategorized

Use Google Docs as a basic CMS

February 21, 2013 Leave a comment

If you want to provide a really quick CMS back end to a website or app, then you can use Google Doc’s spreadsheet CSV export, and a CSV-to-JSON proxy.

If you just create a spreadsheet in Google Docs, then press “Publish the web”, get the link and note the “KEY” parameter – then you can use the key in the following url:

http://dananos.brinkster.net/gdoc2json.php?KEY=0AtUK1jTDzCmodEtEYUE4alVjdUVvdFVHcWZlTlNub1E

where “KEY” is taken from the Google Doc.

You can then call this URL from your app.

 

Categories: Uncategorized

Take a picture and upload it using Webworks on Playbook

February 20, 2013 Leave a comment

When I tried to port a BlackBerry Phonegap project (v 2.0.4) to Playbook (QNX), I noticed that the camera did not return data as Base64 data, rather a FILE_URI, despite the Camera destination type being set to DATA_URL – So going back to first principles, I tried to re-implement the camera capture using BlackBerry WebWorks only.

After 14 tests and failures, this is the final version that worked:

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” >
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<meta name=”viewport” id=”viewport” content=”height=device-height,width=device-width,user-scalable=no” />
<script src=”jquery.js”></script>
<script language=”javascript” type=”text/JavaScript” >
function takePicture()
{
blackberry.media.camera.takePicture(successCB, closedCB, errorCB);
}

function successCB(filePath)
{
var can = document.getElementById(‘canvas’);
var ctx = can.getContext(‘2d’);
var img = new Image();
img.onload = function(){
can.width = img.width/10;
can.height = img.height/10;
ctx.drawImage(img, 0, 0, img.width/10, img.height/10);
var b64Text = can.toDataURL();
b64Text = b64Text.replace(“data:image/png;base64,”,””);
upload(b64Text)
}
img.src = filePath;
}
function upload(imageURI)
{
try
{
$.ajax({
type: “POST”,
url: “http://xxx.yourwebsite.com/upload.aspx&#8221;,
data: { image: imageURI}
}).done(function( msg ) {
alert(msg);
}).fail(function(a,b){
alert( “Failed to save:” + b);
});
}
catch(ex)
{
alert(ex);
}
}
function closedCB() {}
function errorCB(e) {}
</script>
</head>
<body >
<p>(V14) Test the Camera by pressing the button below</p>
<b><a href=”#” onclick=”takePicture();”>Take a Picture</a></b><br>
<canvas id=”canvas”></canvas>
</body>
</html>

Again, I’ve omitted the URL of the uploading script, but the source code for this can be found earlier in this blog.

I did notice that Webworks’ BlobToString BASE64 didn’t seem to work, so I instead, drew the image onto a canvas, (resized to a 10th of the normal size, since the PlayBook’s photos are massive). And called toDataURL on the canvas to get the Base64 image, then stripped off the data:image/png;base64,

Now, to replace the non-working Phonegap code with this working code…

Categories: Uncategorized

Invalid config.xml – the value of id attribute is not valid

February 19, 2013 4 comments

I decided eventually to upgrade from Phonegap-0.9.4 to Phonegap 2.4.0 for my BlackBerry development work after having trouble getting the camera to work, the old phonegap was ignoring my targetWidth / targetHeight parameters, couldn’t close the camera (key injection), and failed to save any image over 1.5 Meg.

Anyway, the new phonegap got round most of the problems with the camera, but when it came to packaging for the Playbook, I hit this error “Invalid config.xml – the value of id attribute is not valid

load-device:

[exec] [INFO] Parsing command line options
[exec] [INFO] Parsing bbwp.properties
[exec] [INFO] Validating WebWorks archive
[exec] [INFO] Parsing config.xml
[exec] [ERROR] Invalid config.xml – the value of id attribute is not valid

The issue was simple to fix, but didn’t seem to be explained online, so here’s the solution:

<widget xmlns=”http://www.w3.org/ns/widgets&#8221;
xmlns:rim=”http://www.blackberry.com/ns/widgets&#8221;
version=”1.0.0.0″ id=”org.apache.cordova.example”>

Just Remove the id attribute from the <widget> tag, and it works!

Remove

Categories: Uncategorized

Debugging live device on Blackberry

February 17, 2013 Leave a comment

com.phonegap.camera

A Bit of an “easter egg” when it comes to debugging BlackBerry phones, is the key combination ALT + lglg, which, if you type in on the home screen of a blackberry phone shows the system error log. If you clear this, then run your app, errors and alerts will be written here.

When trying to port an iPhone Phonegap app to BlackBerry Webworks, the camera wasn’t working right. I could see it opening the camera, but it didn’t close the camera app automatically, and no data seemed to be uploaded.

I used this code example straight from the demo code:

navigator.camera.getPicture(onCaptureSuccess, onCaptureFail,
{ destinationType: Camera.DestinationType.DATA_URL, quality: 50 });

But it appears that at Quality 50, the image data is still too big – I’m going to try reducing this, and I’ll update this post if it works.

*Update*

Using the camera on Phonegap 0.9.4 is a non-starter. There is a size limit of 1.5 MB per photo, and the quality parameter, along with targetWidth and targetHeight are ignored. Also, the native camera app will not close unless you ask the user to manually turn on key injection. (Options > Application Management > Select App > Edit Permissions > Interactions >  Input Simulation > Allow).

Simple solution was to upgrade to Phongap 2.4.0 and then set the targetWidth and targetHeight to something more manageable.

 

Categories: Uncategorized

Get External IP address in Python

February 16, 2013 Leave a comment

Getting your External IP address requires a remote server to reply with your client ip. I used a one-liner PHP script with simply <?php echo $_SERVER[‘REMOTE_ADDR’]; ?>  hosted at dananos.brinkster.net/ip.php

Then I used the following python script to request the IP from this URL, and then save the output to file.

import httplib
conn = httplib.HTTPConnection(“dananos.brinkster.net”)
conn.request(“GET”, “/ip.php”)
r1 = conn.getresponse()
data1 = r1.read()
f = open(‘tempfile.txt’, ‘w’)
f.write(data1)
f.close()

Bit of trial-and-error, but it works.

Categories: Uncategorized

servedwithpi.com – a tiny webserver

February 15, 2013 7 comments

Categories: Uncategorized