Archive

Archive for February, 2013

Installing a HTTP Proxy on Debian 4 (ETCH)

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.

Categories: Uncategorized

Use Google Docs as a basic CMS

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

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

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

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

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

Categories: Uncategorized

Upload a photo from iPhone camera with PhoneGap

Getting a photo from an iPhone camera to the internet is the first step in any photo-sharing app. Here is a snippet of code using PhoneGap that uploads a photo from an iPhone to a webserver.

function onBodyLoad()

{

document.addEventListener(“deviceready”,onDeviceReady,false);

}

function onDeviceReady()

{

try{

navigator.camera.getPicture(onCaptureSuccess, onCaptureFail);

}

catch(ex)

{

alert(ex);

}

}

function onCaptureSuccess(imageURI)

{

try

{

$.ajax({

type: “POST”,

url: “http://distance.freetextuk.com/upload.aspx&#8221;,

data: { image: imageURI}

}).done(function( msg ) {

$(“#imgLoad”).attr(“src”,”http://yourserver.com/uploads/&#8221; + msg);

}).fail(function(a,b){

alert( “Failed to save:” + b);

});

}

catch(ex)

{

alert(ex);

}

}

function onCaptureFail()

{

alert(“Failed to capture!”);

}

 As you can see, it takes a picture using the navigator.camera.getPicture function, which returns (asynchronously) a base 64 encoded string of the image in Jpeg format. This base64 data is posted via Ajax to a .NET script running at yourserver.com – Which stores the image in a folder, and returns a string containing the filename, which is auto-generated.
The image is downloaded by simply setting the src attribute of an img tag on the page.
The .NET server side code is as follows:

protected void Page_Load(object sender, EventArgs e)
{
string strImage = Request.Form[“Image”];
if (string.IsNullOrEmpty(strImage))
{
Response.Write(“Image field not provided”);
return;
}
byte[] b = System.Convert.FromBase64String(strImage);
var strRealPath = Server.MapPath(“~/uploads/”);
var strRandomFile = System.IO.Path.GetRandomFileName() + “.jpg”;
FileStream fs = new FileStream(strRealPath + strRandomFile, FileMode.CreateNew);
fs.Write(b, 0, b.Length);
fs.Close();
Response.Write(strRandomFile);
}

Note, that you will need to create an “uploads” folder, and give this folder write permissions.

Categories: Uncategorized

Rotating worlds, using CSS only

Just playing with some CSS3 animation with the rotating planet mars:

http://dananos.brinkster.net/rotatingworlds/

The CSS being:

#mars {
width: 100px;
height: 100px;
background: url(images/mars.jpg);
border-radius: 50%;
background-size: 210px;
box-shadow: inset 16px 0 40px 6px rgb(0, 0, 0),
inset -3px 0 6px 2px rgba(255, 255, 255, 0.2);
-webkit-animation-name: rotate;
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
position:absolute;
left:100px;
top:250px;
}

@-webkit-keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 210px; }
}

 

Categories: Uncategorized

Fixing the spotlight on a Mac

I had a problem today, when I used the spotlight on my mac, that is, the little magnifying glass in the top right hand corner, that it wouldn’t find any applications. Sure, you can work around it, but jeez, was it annoying.

Anyway, after a few searches on the internet, I read this solution, – which worked for me.

Open Terminal, and type

mdimport /Applications

It chugged for a few minutes, and outputted stuff like

2013-02-08 19:18:53.666 mdimport[1072:903] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.
2013-02-08 19:18:55.068 mdimport[1072:903] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.
2013-02-08 19:18:55.070 mdimport[1072:903] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.
2013-02-08 19:18:55.076 mdimport[1072:903] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.
2013-02-08 19:18:55.078 mdimport[1072:903] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.
2013-02-08 19:18:55.083 mdimport[1072:903] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.
Incorrect start/end range ordering; fixing.
Incorrect start/end range ordering; fixing.
Incorrect start/end range ordering; fixing.
Incorrect start/end range ordering; fixing.
2013-02-08 19:27:03.781 mdimport[1072:903] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.

And once it was finished, my spotlight was working again!

Categories: Uncategorized
%d bloggers like this: