Tuesday, 23 October 2012

EXTRACT-ing results from Pear DB into separate variables


I was used to writing this sort of code when using php_mysql

$result = $db->getRow($sql);
list($surname,$initials,$login,$email,$tutor,$prog)=$result;
//now got separate variables $surname, $initials, etc

Now that I am using PEAR DB, list(...) does not work, so I have found another 'trick' using the PHP function extract

extract($result,EXTR_PREFIX_ALL, "student");
//student is used as a prefix
//now got variables like $student_surname, $student_initials, etc

Note:
I am using 
$db->setFetchMode(DB_FETCHMODE_ASSOC);
so the alternative is to access the names as
$result['surname'], $result['initials']

Friday, 12 October 2012

Parsing the Search String/Query String (revised)

This version avoids using the eval() function and so is neater and safer.
[Compared with the version given in an earlier note in this blog]

var GLOBAL={}

location.search.replace(
  new RegExp("([^?=&]+)(=([^&]*))?", "g"),
  function($0, $1, $2, $3) {
    GLOBAL[$1]=$3;
  }
);

Monday, 9 July 2012

Using jQuery datepicker with html5 contenteditable


You are supposed to use jQuery datepicker with an input element.
Trying to attach it to a div gives a stay open calendar.
The trick here is to attach the datepicker to a hidden input element.

Use the "trigger by button" feature (hence little 'calendar' graphic)

When the datepicker closes (onClose) the new value can be planted (.html() )  in the visible contenteditable element.

If you are watching "on focus" & "on blur" of the contenteditable (to catch user editing) then these events can be simulated as the value is entered (.focus() - .blur() ) so that the change in date is dealt with as if the user entered it themselves.

HTML code:

<div>
<span class='date' contenteditable='false'>9/7/2012</span>
<input type='hidden' class='datepicker' />
</div>
Javascript code:

$(".datepicker").datepicker({
  dateFormat: 'dd/mm/yy',
  showOn: "button",
  buttonImage: "images/calendar.gif",
  buttonImageOnly: true,
  onClose: function(dateText, inst) {
  $(this).parent().find("[contenteditable=true]").focus().html(dateText).blur();
  }
});

Wednesday, 6 June 2012

Deleting HTML5 database tables in Safari

If you are developing using HTML5 databases in Safari (SQLite) you may need to delete tables. In OSX Safari you can use Develop|"Show Web Inspector", then Resources, Databases. There you will have a type in window where you can enter SQL statements like "DROP TABLE ".

In iOS you have to rely on Settings, Safari, "Clear Cookies & Data"

Thursday, 12 January 2012

Appleworks drawings after Lion

Appleworks drawings after Lion

Appleworks does not (& will not) run under Lion

There are many solutions to many of the document types but...
There are many postings saying that the only real solution for Appleworks drawings is to buy EazyDraw

I want to offer a possible workaround - using Keynote
(N.B. this relies on doing something BEFORE) you migrate to Lion

1) Using Appleworks, make a new presentation and paste some of your Appleworks drawings in, one drawing to a slide
2) Now save the presentation and then open it in Keynote

Hey Presto, your diagrams are all there and you can ungroup them and edit them (if you know how to use Keynote, that is)

Problems?

I found that Keynote undersizes the text boxes so they need stretching to the right to stop the word wrap

I found that my arcs (quarter circles for the most part) had gained "radii" making them look like segments of a circle. (Hence the previous post on how to draw arcs in Keynote)


How to draw a perfect arc in Keynote

To draw a perfect quarter circle in Keynote (the OSX presentation package)

1) Work at 400% (or whatever for greater accuracy) 
2) Draw square first
3) Choose Insert|Shape|Draw with pen (to start drawing a Bezier curve)
4) Click on first point (e.g. bottom left corner of square)
5) With mouse still down, drag the tangent upwards to next corner of square (e.g. top left)
6) Release mouse
[That's the first point done]
7) Click mouse at end point of arc (e.g. top, right corner of square), release. 
8) Press escape key

Hey presto, you should have a perfect quarter circle.

You can now delete your square
Then you can go on to treat your arc as a 'line' and adjust the thickness, colour, etc

Tuesday, 3 January 2012

Repeating Labels - Printing multiple copies of 1 label in OSX AddressBook

Repeating Labels
Printing multiple copies of 1 label in OSX AddressBook


OSX AddressBook is great for printing Christmas Card labels etc (i.e. proper address labels) but it is not clear how to use it to print multiple copies of a single label as you would do for labels on Homemade jam or on "sent by" stickers for the back of an envelope.


I have found one way to do it as follows...


Create a text file with a header line and then n repeats of an address data line where n is the number of labels on your label stationery (I used tab delimiter)




Last                            Home Street Home Street 2   Home City     Home State    Home zip
(sent by) J Bloggs    My No/Street     My Town             My City      My County      My Postcode
(sent by) J Bloggs    My No/Street     My Town             My City      My County      My Postcode
etc.

In AddressBook make a new group and File|Import... your text file of address - you will have n identical addresses

Use the AddressBook Label to print the group in the normal way (either selecting the Avery labels that you are using or creating a custom template).

Hint: If you are using Photocopier labels with no margins, then make your own template - I was using 8x3 photocopy labels and my template was...
top:0
bottom:0
left 4.670
right 4.670
rows:8
columns:3
horizontal gutter: 2.54
vertical gutter: 0