Archives

Categories

Bookmarklet to search Google Books from an HTML element

Install the bookmarklet by dragging the link to your bookmarks toolbar:

Or, create a bookmark manually, and change the Location property to the following:

javascript:(function(){window.location="https://www.google.com/search?tbm=bks&q=isbn:"+document.getElementById("isbn");})()

To use it, go to a page which has an element with an id of “isbn” then click on the bookmark.

You can edit the bookmark if the id is called something else (change the bit in brackets and quotes from isbn to something else) or you want to search on another index (change q=isbn to q=somethingelse).

Minimising images in a Twitter feed on Firefox

Recent changes to the standard Twitter timeline have resulted in all images in posts being expanded, thereby interrupting the compressed textual display. Here is a simple way to minimise embedded images in posts on a Twitter feed on Firefox. It uses Firefox’s ability to set up a custom stylesheet so that styles can be applied on top of or instead of those supplied by the website’s creator.

  1. Find your Firefox profile folder[*] and look for a folder called chrome. If it’s not there, create it.
  2. In the chrome folder, create a file called userContent.css and open it in a text editor.
  3. Add the following line to the file: a.twitter-timeline-link img {width:15% !important;}
  4. Save userContent.css.
  5. Restart Firefox
  6. Hurrah, hopefully. It works for me.

It should reduce the large images down to a little blob. It’s not the most elegant looking blob, but it’s small and clickable.

[*] The profile folder will normally live somewhere in a path like Appdata\Mozilla\Firefox, at least on Windows.

MARC Viewer Codecademy Project

I have created a Codecademy project (with a lot of help in corrections and improvements from Esther Arens!) that builds a short script to read a raw MARC record and display it in a more readable format. Try it here: http://www.codecademy.com/courses/marc-viewer/.

This is not by no means the last word in reading a MARC file and is basically a walk through of one way to do it. There are other ways and better ways that use more advanced coding, or allow more sophisticated re-use of the bits and pieces that are pulled out of the MARC record. There are also entire programmes and programming utilities designed to do this kind of thing and to manipulate MARC records, not least library management systems and things like MARCEdit. Moreover, there are limitations in formatting on the Codecademy platform that can easily be overcome by adapting the script to be run directly in an HTML file (I have done a direct simple adaptation without any further elaboration (view the HTML source to see the code and the alterations)).

I hope, if nothing else, that it gives cataloguing coders an idea of what a MARC21 record looks like under the hood and helps clarify the cataloguer’s opinions as to whether MARC must or mustn’t die. (HINT: it must).

Please see the following notes below before proceeding:

1. This project was designed for someone who has done the first few weeks of the Code Year course. By necessity it introduces some new things and an attempt has been made to explain them and encourage the cataloguer to enter the actual lines of Javascript that make up the programme. In any case, the Hints always contain the correct code needed to proceed.

2. Output will often consist of many lines, so sometimes you will have to scroll up in the console to see what has happened.

3. Some lines (including line 1!) will always produce errors, although the script will still run. This will is because MARC uses BAD and DANGEROUS characters. BAD and DANGEROUS characters are of course common in the world of cataloguing (mentioning no names…).

There are many ways this could be improved or extended if you wanted the challenge, e.g.:

  • Take the HTML version and use more HTML and CSS to make it clearer and prettier (e.g. more spacing, colour, bolding of codes). Try making it look like a specific LMS editing screen.
  • Make it capture the elements in more detail and in a more re-usable way. For instance, try making each field an object with tags, indicators, subfields, etc. as properties. This would enable more interesting things, such as…
  • A simple OPAC or even a card index display.
  • Adapt it to read MARC files with more than one record. This isn’t as hard as it sounds, in that each record ends with a specific terminator (see the guide to record structure below).

For full technical details of how a MARC21 bibliographic record is put together, see the MARC 21 Specifications for Record Structure, Character Sets, and Exchange Media Record Structure. For details of the contents and use of MARC21 fields, see LC’s MARC Standards page. For a HTML version of the completed MARC Viewer script, see my adaptation.

The Code Year programme is part of Codecademy, an online set of programming lessons. Cataloguers interested in learning to programme will find the independent CatCode Wiki useful for extra information, advice, and support. See also the #catcode hashtag on Twitter.

Do let me know if you come across any problems with it or have any comments on the project.

Thank you again to Esther for her help.

https://twitter.com/#!/EstherArensEstter

Flexi hours calculator (online and for Excel)

I have tidied up and moved my ancient flexi hours calculator which now lives at http://www.aurochs.org/flexi/flexi.html. Several people have emailed me out of the blue recently about setting up an Excel version, which I have done and which now lives at http://www.aurochs.org/flexi/flexi.xlsx.

This is a version of one of the oldest useful programmes I ever wrote. My dad used to manage an office where everyone filled in paper flexi-time forms. My dad then had to add them all up at the end of every week, which he did manually. I wrote something in AmigaBasic to make it easier for him. The main point of it was that it had to be easy and quick to enter the times in, which is why it uses the simple four figure times and no drop downs (although I’m not sure how or if you can do drop down lists in AmigaBasic (nor do I intend to find out now)). Eventually my dad got the IT people at work to replace their version of a flexi calculator with something based instead on mine, which is silly considering how simple this was. Sometime after starting at my current employer (1997), I thought it would be a useful exercise to convert the programme to work on the web as I was learning Javascript at the time. It still exists and hasn’t changed a lot since then, barring a bit of explanation and some atrocious styling: the last time that file was touched was in 2003.

Although it is really hard to find (I can never remember where I left it and it seems impossible to Google), people do seem to come across it quite often and find it useful. I’ve been emailed a couple of times about getting bespoke versions done in Excel which led me to create a version initially to record multiple users, and another with additional days and more complicated working patterns. I’ve put a more standard version up with seven days and two sessions per day. It can easily be altered if you’re into Excel or, if you have something particular in mind, do let me know and I might be able to do something with it.

The original online version is written in Javascript. If you’re learning Javascript, please don’t look at it as it is a most outdated and inefficient way of adding Javascript to a webpage. However, it works, and the effort of making it all elegant would I think be counterproductive. It works on the idea that the first two digits of a four digit time (HHMM) are hours, the second two digits minutes. It converts these both to minutes (HH * 60 + MM) and does all the necessary maths. The slightly more tricky bit is converting a total of minutes back into hours and minutes. This is one rare (for me) real life use of the modulo (%) operation (although looking at the code source I seem to have invented my own weird convoluted version of the same thing). If you have x number of minutes, the number of hours will be x divided by 60 with any remainder taken off, i.e. Math.floor(x / 60); the number of minutes will be that remainder, i.e. x % 60. These can be put together into a pretty string.

I’m always interested to know if people find this useful, come across problems with it, or would find a slightly different version useful.

Tom's Excellent Website Snow (using Greasemonkey)

Behold: a version of Tom’s Excellent Javascript Snow (unobtrusive and customisable javascript snow for web pages using no images) that works on all websites you open on your browser (provided your browser is Firefox or something else that can run Greasemonkey scripts)!

To install it:

  1. Install Greasemonkey add-on for Firefox: https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
  2. Make sure the monkey (probably at the top-right) is happy and colourful. Click on it if not.
  3. Install the tomsnow script by going to http://www.aurochs.org/zlib/js/userjs/tomsnow.user.js then
  4. Click on the Install button.
  5. Go and look at a new web page or reload one.

If you want to turn Greasemonkey off altogether, click on the monkey so he’s grey. If you want to stop individual scripts, click on the monkey, click on Manage User Scripts, and click on Disable next to the script.

These instructions were tested on Firefox 3.6.24 on Linux although I imagine they would be fine on any recent version of Firefox. I would be interested to hear anything confirming or undermining that assertion.

If you’re happy to play around, the snow is very customisable: you can easily alter the amount, speed, and style of snow, and so forth:

  1. Click on the monkey
  2. Click on Manage User Scripts
  3. Select tomsnow from the list
  4. Click on Options
  5. Click on Edit this user script (you will probably have to select a text editor at this point)
  6. Look for the section under the line of asterisks where more instructions can be found on how to make customisations.
  7. Save the file and reload any pages to see changes.

The Greasemonkey version of the script uses slightly different default settings to the previous version, in particular using a lower density of flakes as a huge blizzard of snow is not likely to be welcome if used on all sites one browses.

I haven’t found any particular problems and it doesn’t seem to stop any sites working although sites that are already very script heavy are obviously less happy about running more, e.g. Twitter which is fine but can get sticky, although Gmail seems curiously OK. My cPanel was the only one which was really not happy. When you manage a Greasemonkey script, you will see a box where you can specify websites that you don’t want it to work on. For example, put https://twitter.com/* and it will stop tomsnow working on that URL with anything after it.

*

Tom's Excellent Javascript Snow

Behold: Tom’s Excellent Javascript Snow: unobtrusive and customisable javascript snow for web pages using no images! If you’re looking at this directly, rather than through an RSS aggregator, you should see it falling now. Unless, that is, you’re watching this on Dave, in which case it will be some time past Christmas and I might have taken the snow away again. However, it always snowing at Tom’s Excellent Javascript Snow page!

I’ve been meaning to write this since last year when my attempts were full of fail. The idea was to create simple unobstrusive javascript snow that could be added to any page and that didn’t require any images. I think Tom’s Excellent Javascript Snow fulfills these criteria and is therefore full of win. Furthermore, it is very customisable, so you can easily alter the amount, speed, and style of snow, and so forth. Incidentally, it uses the asterisk character (*) by default. There is in fact a Unicode Tight Trifoliate Snowflake character, but it is only available in a few fonts by the looks of it and I haven’t tried it. The script depends on the DOM and kind of uses CSS, but it is all defined through the Javascript: so many of the properties are different for individual snowflakes or change while the script is running, that it is not worth having a general style. It also means you only need one file to do everything.

To use it, copy tomsnow_v1.js to a directory on your web-server, and add the following code to the head of any pages on which you would like snow:

<script type=”text/javascript” src=”http://www.yourdomain.com/path/tomsnow_v1.js”></script>
<script type=”text/javascript”>
function init () {
snow();
}
window.onload=init;
</script>

I’m sure Stuart will tell me there’s a better way of doing it…

I know this works on Firefox 2 and Internet Explorer 6 on Windows as well as Firefox 3 on Linux.

In the unlikely event you do use this, do let me know for the sake of my own vanity. Any comments generally are welcome. I do have some ideas for version 2, maybe for next year, mostly around wind effects such as better horizontal drifting, prevailing winds, and gusts. Ideally, I would like to make the snow lay in some way, as in the snow at St Pancras (you might have to wait for it to kick in), but that is quite unlikely given the trouble I had with page heights as it was.