Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Thursday, November 25, 2010

Exporting OpenOffice Base query results

It seems the only way to do this is

1. Select the query name in the list of queries, and Copy
2. Paste into a new Calc spreadsheet

You cannot paste into Excel this way, and you cannot copy from the query results grid like you'd expect. Even if you select all on the results grid by clicking at top left, and Copy, only one cell gets copied to the clipboard.

NB that if you have put a filter on the query, although it will show in data table view, it will not be applied to the export.

I don't know why 'free' has to mean 'bizarre'. I'd expect copying the query name to copy the SQL source, not the output.

Tuesday, November 23, 2010

Greasemonkey sandbox

You do need to pay attention to all that 'sandbox' stuff as it means some actions which you might expect to be able to do are not allowed:

You can't change/delete global variables
without using the 'location hack'.

Friday, November 19, 2010

IFRAME

An event listener in the parent document, or the parent window, is not triggered by events in a child iframe.

Thursday, November 18, 2010

C# String

If you index into a string

s[i]

what you get is a char, not a 1-character string.

Wednesday, November 17, 2010

getElementsBy...

Element only has the getElementsByTagName[NS]() methods, not the other getElementsBy... ones.

Javascript array/object

You can't use .length to get the property count of an Object. It only works for genuine arrays.

JScript

Most of the time with JScript you are working with Windows objects and concepts rather than Javascript ones. Particularly note that you have to use the VB 'Collection' syntax, eg

WScript.Arguments.Item(0)

not

WScript.Arguments.Item[0]


(the latter will silently fail).

Yes, you can say

WScript.Arguments(0)

but that's just too unJavascriptish for me, I prefer to spell it out at length.

Monday, November 15, 2010

iframe

iframe elements have a .contentWindow - but this property doesn't have a value until the iframe has been placed in the document. Once it has, you refer to

ifr.contentWindow.document.body

to get stuff done.

Getting elements

getElementsByTagName returns a NodeList, which has .length and can be indexed into with [], or item() if you prefer.

XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE returns (an object) which has .snapshotLength and has to be indexed with snapshotItem(). The types of the objects returned by snapshotItem() depend on what tags they represent, eg HTMLLIElement, HTMLBodyElement; but these objects are all descendants of HTMLElement, Element and Node, so they can be supplied as the context node to another invocation of document.evaluate.

Insofar as JS has a type hierarchy, then a specific HTML element type, eg HTMLDivElement, 'is' a HTMLElement and a HTMLElement is an Element, and an Element is a Node.

NB that getElementById is so spelt (singular) and returns an Element, not a NodeList with 1 item. It genuinely expects there to be only one element with a given 'id'.

Friday, November 12, 2010

IFRAME

If you have an iframe element its document is accessible via the contentDocument property.

textContent

textContent appears to be a perfectly pukka, DOM-specified way of getting the text of all the text nodes under an element (ie including text from child elements).

It's node.textContent btw.

It can be set as well as read - but will destroy all child nodes in the process of replacing them with one big text node.

bookmarklets

The reason bookmarklet links in web pages have void() round them is that void is a JS keyword which evaluates its argument and doesn't return anything (or returns undefined according to who you believe). If this is not used, the browser will replace the document in which the javascript: link was evaluated, with the result of the evaluation, which is generally not what you want.

NB that while javascript: URLs can contain whole chunks of code, void expects an expression, not a block or series of statements. So code of any complexity inside void needs to be inside an anonymous function evaluation.

While I'm on, the anonymous function syntax is thus

(function () { code; more code; })()

From the inside out, you have a block of code in {}, which is being used to construct a function with no arguments - function () - and that function definition has ( ) round it, and then it is being evaluated with no arguments, hence the trailing ().

Btw Firefox will take quite a lot of text in a javascript: URL. You can paste it in from a file with line breaks etc and FF doesn't care.

However, using a drop-line comment // seems to give it a headache. It probably thinks you're trying to say javascript://blah .

C-style block comments seem fine though.

Wednesday, November 10, 2010

Document

The Document class is designed to model HTML and XML documents. Stuff specific to HTML ones is modelled in the HTMLDocument interface.

(Interface is in the usual modern sense of a set of methods, properties etc which a class can implement, without having to be a subclass of anything).

Friday, November 5, 2010

Eyepieces

F = focal length of main (objective) lens/mirror
D = aperture thereof
f = focal length of eyepiece

magnification M = F/f

focal ratio = F/D (this is the quantity photographers quote as f/10 etc))

exit pupil = f / (F/D) = fD / f

actual field of view = (apparent field of view) / M

(eg if eyepiece has an apparent field of 55 deg, and its focal length gives it a magnification of 40x with your telescope, actual field of view - ie the size of the bit of sky you can see - is 55/40 = 1.38 deg, or well over 2 Moon-widths)

Monday, November 1, 2010

Text nodes

The text in a text node is in its data property.

(data is actually CharacterData.data. You can also use nodeValue, which is Node.nodeValue).

Element.textContent is the amalgamated text of all the text nodes under an element, at all levels.

Node.TEXT_NODE will show up as 3 in Firefox from javascript: , but appears to be undefined in Greasemonkey context.

Followers

Blog Archive