“the j stands for Jeweling”
about me | wordpress plugins | jQuery plugins

29 July, 2011

jQuery Clear-on-Focus Plugin

Filed under: jQuery Plugins,Web Development — Tags: , , , , — John @ 10:29 am

A small jQuery plugin I wrote which I thought I would make public. Instead of using <label> elements for each of your form’s fields, use the input’s value attribute to set the label. Clear-on-focus will then take care of clearing the value when a user clicks or focuses the field. If they leave the field blank, the original message is reset back. Also works correctly for password fields. Example usage:

<input type="text" name="username" value="Enter username" class="clear-on-focus" />
<input type="text" name="password" value="Enter password" class="clear-on-focus password" />

Link: github repository

27 July, 2011

Gedit syntax highlighting for Grammatical Framework source code

There is now an official page on the Grammatical Framework website about GF Editor Modes.

For correct syntax highlighting in Ubuntu’s default text editor (gedit) for anyone editing Grammatical Framework source code, put the code below into the file ~/.local/share/gtksourceview-2.0/language-specs/gf.lang (under Ubuntu).

Some helpful notes/links:

  • The code is based heavily on the haskell.lang file which I found in /usr/share/gtksourceview-2.0/language-specs/haskell.lang.
  • Ruslan Osmanov recommends registering your file extension as its own MIME type (see also here), however on my system the .gf extension was already registered as a generic font (application/x-tex-gf) and I didn’t want to risk messing any of that up.
  • This is a quick 5-minute job and might require some tweaking. The GtkSourceView language definition tutorial is the place to start looking.
  • Contributions are welcome!

25 July, 2011

How I revived my disappearing Seagate GoFlex Home DLNA/UPnP server

Filed under: Home Entertainment,Random Tech — Tags: , , , , , — John @ 12:00 pm

My family bought a Seagate GoFlex Home 2TB network-attached drive for streaming videos directly to our Samsung TV via DLNA/UPnP. Everything worked fine for a while, until suddenly one day it just refused to show up on the TV anymore. After eliminating all the home networking factors (cables, IPs, DHCP etc.), I noticed that when restarting the device it actually showed up briefly on the TV, but with no files on it – only to disappear after a few seconds.
Note that the device still behaved normally as a network device, i.e. when browsing using Windows Networking/SAMBA we could still access all our files normally. It was only the DLNA service that did not seem to be functioning.

Combing through the Seagate forums (and the web in general) I found that others have had similar issues but no real solutions seem to have emerged. So a little more investigation had to be done. The GoFlex Home web interface did not report anything untoward, and fiddling with all the settings in the preferences did not seem to have any effect.

So, like all good hackers I got my hands dirty and gained SSH access to the device.

Getting SSH access to the device

As described here and here, to gain access to your GoFlex Home via SSH you will need:

  1. An SSH client (obviously)
  2. The IP address of your GoFlex Home
  3. The administrator username & password
  4. Your device’s product key, which you can find by clicking About GoFlex Home in the bottom left of the web interface
  5. Confidence using the Linux command line

So, you open an SSH connection to your device with this specially-formed username:

USERNAME_hipserv2_seagateplug_XXXX-XXXX-XXXX-XXXX

Where USERNAME is your username and XXXX-XXXX-XXXX-XXXX is your product key.

Once you’re in, go straight into root — as you will need to do so anyway before long — with:

sudo -s

Of course poking around as root is dangerous and could irreversibly mess up your device, but if you’re still reading then you probably already knew that.

Restarting the DLNA service

At this point I tried poking around, trying to find some logs or anything which could give me an idea what the problem was. The name of the service which actually provides the DLNA server is minidlna, for which a totally invaluable reference can be found here. I tried to access the MiniDLNA log with

tail /tmp/minidlna/minidlna.log

but was told that the log was unavailable. Curiously, running ls -l in the directory reported that the file had no size, permissions, or modification date; so that wasn’t much help. I then tried to find the status of the MiniDLNA service with

/etc/init.d/minidlna.init status

which told me that the PID in /mnt/tmpfs/var/run/minidlna.pid did not match that of any running process, implying that the daemon had crashed. Made sense so far, but when I tried to restart the service with

/etc/init.d/minidlna.init restart

the service would attempt to restart, but instantly crash again as described above. Same thing with manually stopping and starting the service. Some trial and error later, I discovered that what needs to be done is is that MiniDLNA’s temporary folder needs to be forcibly unmounted, like so:

umount /tmp/minidlna

Restarting the service again after doing this finally did the trick; Checking the service’s status again as above now reports that MiniDLNA is running, and everything shows up normally on my TV etc.

Rebuilding the database

If the steps above still don’t fix your problem, you likely need to get MiniDLNA to rebuild its media database, with the command

/usr/sbin/minidlna -f /etc/miniupnpd/minidlna.conf -R -d

This time, I was given an error message about being unable to open sqlite database file, /tmp/minidlna/files.db. Attempts to force-delete the file manually also failed, and I finally had to resort to manually unmounting the minidlna directory with

umount /tmp/minidlna

This happily worked, and I was then finally allowed to rebuild the database with the command given above. This will scan your media folders and rebuild the database for you in MiniDLNA’s debug mode, which means it will spit out lots and lots
of output message to the console. After maybe 5 minutes or so, it finally told me the media library scanning was complete, and lo and behold I could once again access my GoFlex Home via my DLNA-enabled TV.

Now, I am still unclear as to what happens when I restart my device. The first time I tried this (after rebuilding the media database) my device went into the exact same problem as before! This time I logged in via SSH again, and run the MiniDLNA daemon in debug mode but without rebuilding the library:

/usr/sbin/minidlna -f /etc/miniupnpd/minidlna.conf -d

This successfully started the service again, allowed me to cleanly exit my SSH connection and access the DLNA server via my TV again. However it did take many minutes until my files all showed up, so I am assuming that MiniDLNA was in fact rebuilding the media database itself.

Conclusion

Despite finally managing to get things working as described above, it turns out that every time my GoFlex Home is restarted the MiniDLNA daemon crashes in the same way, and I am forced to fire up an SSH connection to sort things out. I have as yet found no way of permanently fixing the issue, but since our device is basically online 24/7 it’s not too much of an issue.

Of course I realise the steps here are not for the computer faint hearted, but after exhausting all the “user-friendly” ways of restoring the device, this is only sure-fire way I have found.

14 July, 2011

Geany syntax highlighting for Grammatical Framework source code

There is now an official page on the Grammatical Framework website about GF Editor Modes.

I wrote a custom filetype config file for the Geany text editor, providing correct syntax highlighting for anyone editing Grammatical Framework source code. Put the code below into the file /usr/share/geany/filetypes.GF.conf (under Ubuntu). You will need to manually create the file:

Light Version

Dark Version

You will also need to edit the filetype_extensions.conf file and add the following line somewhere:

GF=*.gf;

Hope that helps someone who doesn’t feel like reading through the Geany documentation! (which btw can be found here).

16 December, 2010

jQuery Tiler Plugin

Filed under: jQuery Plugins,Web Development — Tags: , , , , , — John @ 10:41 am

A new plugin I’m in the process of creating, for neatly tiling boxes of different dimensions into a grid.

If you have ever created tiled a layout by floating a bunch of boxes together, you may have noticed that when these boxes have different dimensions ( heights/widths) you end up with a lot of space and an altogther un-neat layout (Figure A):

Figure A: Floating of different-sized blocks leaves a lot of white space.

Figure B: By using the jquery-tiler plugin our boxes are now neatly stacked

The tiler plugin fixes this by greedily inserting each box into the column which is “shortest”, resulting in something like that in Figure B.

Note how the order of the boxes has changed. To me this is acceptable, but more importantly it is somewhat unavoidable (as someone wise used to tell me, “you have to break eggs if you want to make an omelette”).

Note that in this scenario all boxes are forced into fixed column widths. There is also some support for varying widths (i.e. preserving the width of each box) however it is far from complete. Will implement this when I have some more time (and a few more brain waves).

Anyway if you want to try it out, the git repository is here: http://github.com/johnjcamilleri/jquery-tiler

6 November, 2010

Fuzzy string matching in MySQL using Levenshtein Distance stored function

Filed under: Web Development — Tags: , , , — John @ 12:23 pm

Searching for fuzzy string matching methods will return various algorithms and various implementations of them.

I found this MySQL implementation of Levenshtein Distance to be adequate for my needs, and using this handy MySQL stored function makes it super as to use in queries without having to create temporary search-optimised tables or performing post-processing in another language (eg PHP).

Just install the functions in your database, and use like so:

SELECT * FROM users ORDER BY levenshtein_distance(users.name, 'john')

20 October, 2010

Symphony CMS Extension — Backend Language Switcher

Filed under: Symphony CMS,Web Development — Tags: , , , , — John @ 10:14 am

Just published my first extension for Symphony CMS: Backend Language Switcher

It’s basically a small backend utility to allow users to switch the language in which they view the backend. This is especially useful when used together with the Multilingual Field extension.

Check out the official extension thread and the GitHub repository.

28 September, 2010

jQuery Autoscale Plugin

Filed under: jQuery Plugins,Web Development — Tags: , , , , — John @ 8:50 am

This simple plugin basically takes a source and a target element (could be the same element) and shrinks the font-size in the target when the length of the content in the source increases.

Demo

Download

jQuery Spincrement Plugin

Filed under: jQuery Plugins,Web Development — Tags: , , , — John @ 8:47 am

This is my first jQuery plugin!

It basically takes an element (divtd etc) containing a number and increments up or down to that value.

Demo

Download

A new project – Old Antonians Network

Filed under: Web Development — Tags: , , , — John @ 8:34 am

A project I’ve been working on the past few months is finally online, although there are plenty more features to come in the near future. It’s a niche social network for alumni of my old secondary school San Anton (in Malta) — or Old Antonians — hence the Old Antonians Network. It’s based loosely on LinkedIn, ie promoting professional networking rather than sharing photos and harvesing virtual crops, and it’s the first project of mine using the CakePHP framework. It’s a closed network so you won’t really be able to see any of it, but I wanted to link to it to perhaps bump it up on Google!

Newer Posts »