Results matching “javascript”

I already blogged about RFID readers but now I really need to replace antique 3M software with something better. So, basically, I started with specification:

User should put RFID tag on reader and get output from Koha
Nice and simple. However, readers are connected to Windows machine. And we need some way for reader to push data about new tag to browser. Hmmm... push? Sound like Comet, doesn't it?

Let's see what we need:

  1. Comet server to display page in web browser and push updates
  2. RFID reader program installable on Windows to communicate with serial port and push messages to Comet server
  3. User with a browser
Again, seems somewhat reasonable. Can perl do it? It seems it can:
  1. Meteor server provides perl comet server which required one additional file to provide integration with Koha.
    I needed comet server to deliver Koha data because of single origin security in browsers which doesn't allow me to make AJAX requests to Koha directly. On the other hand, this gave me excuse to try out HTML::Query to extract part of page which I needed on server.
    I liked this split between Koha and Comet server (even on different boxes and/or network segments), but it came with a price: every page generated in Koha took more than 2 seconds, which was just too slow for nice interactive demo. So, I implemented on-disk caching which is also really nice for debugging. In production version, requests for Koha data might be implemented as forkers (since browser uses AJAX request for it, it makes sense) or I will issue queries directly over Koha's database.
  2. Next step was to add push from my perl RFID reader to Meteor.
    This also turned out to be simple: one socket connection to Meteor, and few revisions later I had more or less following protocol which reader could push to comet server as pipe | encoded string:
    meteor( 'info', "Found reader hardware $hw_ver" );
    meteor( 'info-none-in-range' );
    meteor( 'info-in-range', join(' ',@tags));
    meteor( 'in-range', $tag );
    meteor( 'read', $tag ); 
    meteor( 'removed', $tag ); 
    
  3. I also needed web interface in browser.
    When I need to do something quickly I often turn to jQuery as long time readers of my blog already know. One additional javascript file in Meteor's public_html directory and we have a working interface.
    At first, I created JavaScript object (like hash in perl :-) to keep track of visible tags on screen. But, since each tag is div which has id set to SID of tag, it was easier (and shorter) to just use jQuery to ask DOM if there is element on page. KISS wins again...

So how does it look, you might ask? (You might want to turn volume down, because AudioSwap feature of YouTube should be really considered harmful :-)

This might help solve question is perl dead. Only if it means dead easy. it's 4k of perl code, 4k of JavaScript and 4k of CSS.

I'm preparing walk-through screencasts for workshop about virtualization so I needed easy way to produce console screencasts.

First, I found TTYShare which displays ttyrec files using flash, but I really wanted to copy/paste parts of commands and disliked flash plugin requirement.

It seems that I wasn't only one who wanted JavaScript client for ttyrec. jsttplay can produce screencasts like this one about OpenVZ using plain copy/paste friendly JavaScript within browser.

But, for some parts (like Debian installation under VirtualBox) I really needed movie capture. x11grab option from ffmpeg seemed easy enough to use:

ffmpeg -f x11grab -s 640x480 -r 10 -i :0.0 /tmp/screencast.avi
but getting right window size isn't something I want to do by hand. So, I wrote small perl script record-screencast.pl which extract window position and size using xwininfo and pass it to ffmpeg so I don't have to.

You wanted to take a quick look at last firefox tab state on browser which isn't stared any more? You want to restore session state from some other profile (from other computer perhaps?).

Firefox stores session data (including back history!) in .mozilla/firefox/po0qgwdl.default/sessionstore.js and you can use html page generation javascript from ZeePrime@mozillaZine forums.

For easy access I re-idented it here. Thanks, ZeePrime, very useful.

Publish your data with Exhibit

As you might remember, back in 2007 I wrote about Exhibit which in meantime released version 2.0 and moved to google code.

This time, I made few more converters which enable you to:

simile-svn.png

This is probably best test of JavaScript speed in your browser. Exhibit seems to work best with around 500 items in older browsers, but Firefox 3.1b2 works with 3000 objects, even on EeePC :-)

First of all, we had first ever Croatian perl workshop. Thanks to all the people who showed up, we had attendance of about ten.

Organizing a workshop event turned out to be much more work then I anticipated, and various other tasks stopped me from preparing for it as good as I should. Also, small number of people force me to re-consider my lectures about perl. On one hand, I really, really, tried to spread perl (and had good fortune of being at right place at right time to get Zagreb.pm off the ground), but with such low attendance, I must conclude that perl is used only by about 20 people in Zagreb. This seems somehow disturbing. Comparing size of Zagreb with Moscow turned out to show about same proportion, so I was just overly optimistic.

I also gave half an hour presentation about Jifty, based on Building a Jifty app in a jiffy by Kevin Falcone and showed some examples of my jifty apps (I actually didn't talk about last one, just mentioned it as integration of external javascript -- CodePress in this example).

I also have to thank to Andrew Shitov from Moscow.pm who have managed to prepare several very interesting topics which, in my opinion, made this event worthwhile. If it wasn't free I would ask my money back :-\

What did I do last two days or so? I have been looking for solution to convert pdf magazine archive from simple pdf downloads into something more Web 2.0 like. As a first instinct, I hoped that I will find JavaScript solution, and do simple rendering into bitmaps.

But, then I remembered that almost everybody has Flash plugin by now (at least more people than pdf reader or plugin) and Flash also can do smooth scaling. How ward would be to find Flash picture viewer with nice page-flipping transitions.

Half way in that journey I stumbled upon Open Library which has very nice interface (and is pure JavaScript!) which was supposed to be available under GPL, but source is not available. It would be cool to re-use this reader, but if there is no source compressed version available on site isn't much help. I sent e-mail to developer, and now I'm hoping for some pointers.

Than I found several commercial flash page flipping offers (strange how flash community is strictly separated to Open Source and commercial part without much cross-over). If there is so much solution to turn pdf into flash, one of them must be Open Source, right?

And there is! SWFTOOLS is great suite of programs (available in Debian) which has automatic generation of swf files from pdf and even ability to add navigation elements over it. To cut it short, here is little snippet for example usage:

rm tmp/*
pdf2swf -p 1-20 -s insertstop magazine.pdf -o tmp/pages.swf
swfcombine -o tmp/pages+nav.swf SimpleViewer.swf viewport=tmp/pages.swf
jpeg2swf loader.jpg -o tmp/loader.swf
swfcombine -o tmp/magazine.swf PreLoader.swf loader=tmp/loader.swf movie=tmp/pages+nav.swf
cd tmp && swfdump --html magazine.swf > magazine.html
cd -

It's sweet and simple, but navigation which SimpleViewer is giving me is... Somewhat too simple. I would like to have buttons for zoom in/out (or slider) and page number for example. However, other than accidental exposure to haxe I don't know a first thing about Flash. There are at least two CPAN modules with swf support, and I have seen flv media player in one of them, but they look incredibly complicated to me, almost like the source which produce SimpleViewer itself.

I would love to design something in Inkscape and than convert that to bits of logic (if possible externally controlled by JavaScript), but I don't even know where to start looking for information. I'm only interested in solutions which are scriptable and runnable without human intervention under Linux.

There are quote a few pages to convert, and it seems that pdf2swf has limit of 65535 objects which translate to about 20 pages out of 100+ pages magazine, so splitting it into single pages seems like much better approach (and users will have less content to download). If this is plain JavaScript, I would preload one page for quick response, but is that concept even supported in Flash?

To make things worse, there is great tutorial over at SitePoint how to make page flipping using jQuery which I know and like.

Am I wasting time trying to find free (as in speech) Flash development environment which would feel good to me? Should I go with my instincts and stick with JavaScript? Time will tell... For a start I will try to convert presentations on my homepage to flash as a initial try...

Update: To make thing clear, I converted pdf files from my presentations to flash using method described above. Now I would like to replace arrows on top-left with more complex navigation, something like PdfMeNot has done.

Update^2: This was easier than I thought it will be. Following examples on swftools site I found two great viewers, and if that is not enough, I found original author of viewer used at PdfMeNot (scroll down to find download link).

Fun with jQuery

During last week of my holiday, I had a few days to spare, so I tried jQuery. It's a really cool JavaScript library.

To prove my words, I present to you following:

No pager is actually a small project consisting of novel idea to share one hash between perl CGI (or stand-alone server, but it doesn't exist yet) and JavaScript. It does so by implementing small subset of HTML::Mason (well, only single-line <% something %> markup), just to look familiar (or syntax-highlight correctly :-)

Proper explanation of that would have to wait for some serious documentation writing...

Update: new upstream version of jQuery (1.0.1) fixed problems in Safari on Mac. Isn't that cool?

This was so simple, that I'm not sure it deserves a whole blog entry. But, anyway. Up until now, I used LiveHTTPHeaders to view cookies, but latest version of Firefox (1.0 RC1) changed version of plugins and LiveHTTPHeaders doesn't work any more.

So, I wrote little bookmarklet to view cookies:

javascript:void(document.write('<html><pre>Cookie: '+unescape(document.cookie+'</pre></html>')));
Or just drag and drop this link to your browser. It displays cookies in format which is suitable for feeding into wget using --cookies=off --header="Cookie: ...." options.

Who said that combobox can't be done with html? As a result of another little project and with help from Matko Andjelinic, here is something: real combobox! Have patience while it loads (just index with 10000 words have 260k), but it works! And it works fast. Design sucks (especially icon for drop down), but you will forgive me that.

My blog also got spammed. I hate that. But, I'm still not disabling comments, so feel free to comment...