01.05.13
Tumblr Blog
I’ve moved my occassional writing efforts to Tumblr http://www.tumblr.com/blog/imollusc
Musings of a Clever Clam
I’ve moved my occassional writing efforts to Tumblr http://www.tumblr.com/blog/imollusc
I asked a question on Stackoverflow.com today.
I was looking around for this example, so once I figured it out I thought I’d post it here for others.
It took me a while to figure out how to create a full contact for the IPhone using phonegap, as all the existing examples are very basic and give examples showing how to create a contact with a name and
Basically I found out that the input format is the same as the output format. Simply dump a contact to the console as a JSON string. Make sure it has all the fields you are interested in.
function find() {
// find all contacts with 'Mollusc' in any name field
var options = new ContactFindOptions();
options.filter="Mollusc";
options.multiple = false;
var fields = ["*"];
navigator.contacts.find(fields, onSuccess, onError, options);
}
function onSuccess(contacts) {
console.log(JSON.stringify(contacts));
}
To create a contact you do the following.
function createContact(){
var myContact = navigator.contacts.create({"displayName":null,"name":{"givenName":"Intellectual","formatted":"Intellectual Mollusc","middleName":null,"familyName":"Mollusc","honorificPrefix":null,"honorificSuffix":null},"nickname":null,"phoneNumbers":[{"type":"other","value":"00353 2345235","id":0,"pref":false},{"type":"mobile","value":" ","id":1,"pref":false}],"emails":[{"type":"home","value":"work@intellectualmollusc.net","id":0,"pref":false}],"addresses":[{"postalCode":"","type":"work","id":0,"locality":"cork","pref":"false","streetAddress":" ","region":" ","country":"Ireland"}],"ims":null,"organizations":[{"name":"School","title":"Student","type":null,"pref":"false","department":"Kitchen"}],"birthday":null,"note":"YourRefUniqueID:47831","categories":null,"urls":[{"type":"other","value":"intellectualmollusc.net","id":0,"pref":false}]});
myContact.save();
console.log("The contact, " + myContact.name.givenName + ", has been created");
}
Reasonably Straightforward.
I use stackexchange / stackoverflow a whole lot, and recently found a cool site that someone had built with their API, called Stackgeography.com It shows you where in the world people are asking questions on stackoverflow.com
I have a number of legacy sites I look after that are old enough to have not been created with any CMS system like Drupal, Joomla or CodeIgnitor, just good old fashioned code.
I like source code control software, I’ve used
However despite having experience with almost 10 differnt source code control systems, I still end up using the wonderful Editpadpro to simply connect via ftp to these sites and make a quick little change live on the server. If I need to do anything major I do it with Source Control, but for 2 line changes or to fix a bug I often do it online/on-production , despite breaking the cardinal rule of software. The obvious problem here is when I introduce a problem, if I don’t catch it immediately its sometimes a bit tricky to figure out what I broke.
Now I have a solution.
My host (Dreamhost.com) has git installed on some of its servers. I have written a simple php script called gitmysite that allows basic sc interaction on the server. This is read only externally, and is not designed to be pushed to. It is basically a simple change repository. Now when I make a change via ftp or editpadpro, I can simply go to http://www.mysite.com/gitmysite.php and after logging in write a quick commit message – click a button and I have a record of what I changed. It will add all files I changed across the entire site. This is still in development so it is a bit rough at the moment, but take a look at it on github and send me any feedback you might have.
https://github.com/tobya/gitmysite
With the script you can
Recently I was looking for a really simple ToDo program that worked online, that I could share between a few people to work more as a reminder than a real todo system. Lots of these programs are far too complex.
I found myTinyTodo . It perfect for what I want, you can create new tabs for type of todo, there is a text box where you type your todo – hit return and it appears in your list, then click the checkbox and it dissappears.
If you need a simple Todo Manager, this one’s great.
Links to pages I’d like to check out some other time.
Clone of facebook link to page code
http://youhack.me/2011/06/25/create-a-facebook-wall-system-using-php-and-jquery-part-1/
I had an idea the other day, I thought ‘Why do we have to type all these 192.168.1.x addresses, it seems like a waste of time and a bit archaic. Why can I name my machines and have a domain name for them. Actually why cant everybody’. Now they can.
Introducing ‘Anynework.net’
I have updated the DNS on anynetwork.net to have lots and lots of fully quaified domains pointing to IP addresses within the 192.168.1.x address space.
Simple
server1.anynetwork.net – 192.168.1.1
server2.anynetwork.net- 192.168.1.2
…
server254.anynetwork.net- 192.168.1.254
Fruity
apple.anynetwork.net – 192.168.1.1
banana.anynetwork.net- 192.168.1.2
I’m in the process of writing an API so that you can get your app to request a subdomain to use for a specific ip address.
See Anynetwork.net for more details.
The only gotcha is if you’re disconnected from the net the names may not work.
I have recently discovered QRCode (stands for Quick Response Codes but thats not really relevant). These are two dimensional barcodes that can store a reasonable amount of data – up to several thousand characters, enough for a URL, Contact Info, a bit of text etc. Recognition with a smartphone camera is trivial (taking a fraction of a second) and with Iphones and Android apps all sorts of cool things can be done. I have now discovered that the quickest way by far to get contact details of a client onto my phone from our computer system is to scan a QRCode. I now declare that I am going to use QRCodes for everything.
Here are two really good ways to generate QRCodes.
Zebra Crossing Barcode Generator (Using Googles Charts API)
PHP QRCode Generator (Pure PHP)
Both are really good, although for volume use the zxing / google one is probably better. I chose to use the php library as I am using client data to generate contact cards in an internal app and wasnt completely happy about sending that info to Google over the web, even though they do say they only store it in Logs for a couple of weeks. For non-sensitive data the google chart api is a brilliant way to generate qrcodes. Just embed the details you need into the src attribute of an img tag on your page.
There are some very good QRCode Scanners for phones, the best I’ve found for the Iphone is Barcodes from the zxing people.