Random Ramblings
This website is going mobile
February 27, 2012 at 09:15 AM | categories: website, hacking aroundOver the last few days I've spent a couple of hours working on making this website work better on mobile devices. I've found 4 sites to test with, and all are showing the same problem: My navigation bar is squished down the side so its unreadable, and takes up valuable navigation space.
Page validity
My first stop was the w3 mobile website validator. The tools the W3C provide are great (You'll notice I try to keep this site CSS and XHTML valid too).
The interesting thing about the mobile validator compared to the other two, is that it provides a percentage bar to show how close you are to validity (Fixing two critical issues bumped me from 49% to 93%... whatever that means). It also includes a list of informational points for things you might wish to fix (eg, too much whitespace/comments) - a feature I plan to take advantage of down the line. Unfortunately, the validator doesn't help with my specific problem, as the nav bar is a layout issue not a code issue.
The only glaring omission that I can find, is that it doesn't check for 'jump to content' and 'jump to navigation' links. While these are primarily for accessibility, I feel they are also useful on a mobile screen.
Another validity check is ready.mobi, which gives all sorts of information, including page size, estimated load times and a collection of additional tests. These show a different set of possibilities to the W3 checker, so provide a bit of extra depth to the testing.
But how does it look?
Thats where the other sites come in handy. To test the structure I was aiming for, I found that mowser gave a good layout test. I just need to work out the CSS they use so I can copy it ;) To get the layout I'm after, I'll need to move the website title back over the navigation bar, which means moving it into a different div. (And that means more possible display issues). Despite my using it in this way, mowser isn't a website tester. Its a website minimiser, so you can view any website mobile.
The last page shows how the site looks in a variety of smartphones by loading an image of the phone, then poking the website into it. This is a great way to see how well you fit on various devices... and a great way to discover that this website fits badly!
Mako doesn't like what I'm doing
February 06, 2012 at 10:00 AM | categories: website, hacking aroundI'm working on my website again, and to try and fix categories being listed several times in the navigation bar instead of once, I seem to have introduced another.
I'd managed to have each category from each post printed out (See code below), but there was a problem: categories with multiple posts were being listed multiple times.
% for post in bf.config.blog.posts[:]:
% for category in post.categories:
<li><a href="category/${category}">${category}</a></li>
% endfor
% endfor
What I needed was a way to have python/mako check for duplicates and only print out values once. I asked andrew for some help, and he suggested I use this:
buffer = [ '<li><a href="category/%s">%s</a></li>' % (category, category) for post in bf.config.blog.posts for category in post.categories ]
And it looks pretty cool. I stuck a % in front of it (like the for loops had), and it exploded:
16:36:10 kgoetz@epicfail: ~/srccache/website-blogofile $ SKIPRST='x' ./_make.sh
+ blogofile build
WARNING:blogofile.post:2011102301-running_crg_derbyscoreboard_behind_apache.rst: Post has no YAML section : Skipping this post.
ERROR:blogofile.writer:Error rendering template
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.6/blogofile/writer.py", line 155, in template_render
return template.render(**attrs)
File "/usr/lib/pymodules/python2.6/mako/template.py", line 189, in render
return runtime._render(self, self.callable_, args, data)
[...cut lots of mako calls...]
File "/usr/lib/pymodules/python2.6/mako/parsetree.py", line 69, in __init__
code = ast.PythonFragment(text, **self.exception_kwargs)
File "/usr/lib/pymodules/python2.6/mako/ast.py", line 74, in __init__
code, **exception_kwargs)
CompileException: Fragment 'buffer = [ '<li><a href="category/%s">%s</a></li>' % (category, category) for post in bf.config.blog.posts for category in post.categories ]' is not a partial control statement in file '_templates/navigation.mako' at line: 12 char: 1
After reading the docs it turns out that % is used for things like if/else/for/while etc. What I needed for my python line (buffer= []) was %%.
The code snippet is now:
<%
buffer = [ '<li><a href="category/%s">%s</a></li>' % (category, category) for post in bf.config.blog.posts for category in post.categories ]
%>
Thanks to Andrew for the buffer line, its much fancier then what I had.
Removing duplicate categories.
The problem with the code above is that it collects duplicates into buffer. This means printing it directly through mako lists the tags several times in the side bar - not a feature.
An easy solution is available thanks to Nathan Hamiel of neohaxor.org, in one line of python. (See the next section for the line, albeit combined with the initial code).
The result
The final template file looks like this:
<%
# Build an array with all the categories in it.
# Lowercase so we don't have (eg) Debian and debian listed.
all_categories = [ '<li><a href="/category/%s">%s</a></li>' % \
(repr(category).lower(), repr(category).lower()) \
for post in bf.config.blog.posts for category in post.categories ]
# Dedupe the array before adding it to the nav bar.
nodupes_categories = set(all_categories)
%>
<ul>
% for category in nodupes_categories:
${category}
% endfor
</ul>
Mystery fail2ban failures
January 19, 2012 at 10:00 AM | categories: hacking aroundWhile trying to set up fail2ban to watch the gNewSense MoinMoin instance (It powers the main website and the wiki) I hit an error which didn't seem to make any sense
My filter called 'moinmoin-page-with-spaces' was inexplicably causing fail2ban to return error 200. Annoyingly, my moinmoin-captcha filter appeared to loading perfectly, and both were syntactically identical.
2012-01-19 05:21:09,093 fail2ban.jail : INFO Jail 'moinmoin-page-with-spaces' started 2012-01-19 05:21:09,141 fail2ban.jail : INFO Jail 'moinmoin-captcha' started 2012-01-19 05:21:09,215 fail2ban.jail : INFO Jail 'ssh' started 2012-01-19 05:21:09,213 fail2ban.actions.action: ERROR iptables -N fail2ban-moinmoin-page-with-spaces iptables -A fail2ban-moinmoin-page-with-spaces -j RETURN iptables -I INPUT -p tcp -m multiport --dports www -j fail2ban-moinmoin-page-with-spaces returned 200 2012-01-19 05:28:20,779 fail2ban.jail : INFO Jail 'moinmoin-captcha' stopped 2012-01-19 05:28:21,077 fail2ban.jail : INFO Jail 'ssh' stopped 2012-01-19 05:28:21,364 fail2ban.actions.action: ERROR iptables -D INPUT -p tcp -m multiport --dports www -j fail2ban-moinmoin-page-with-spaces iptables -F fail2ban-moinmoin-page-with-spaces iptables -X fail2ban-moinmoin-page-with-spaces returned 200 2012-01-19 05:28:21,904 fail2ban.jail : INFO Jail 'moinmoin-page-with-spaces' stopped 2012-01-19 05:28:21,910 fail2ban.server : INFO Exiting Fail2ban
Upon running the iptables commands individually it turned out that it was iptables returning 200 (not fail2ban).
Seems that iptables has a maximum string size of 30 chars for its labels. Because fail2ban adds 'fail2ban-' and your filter name together it was pushing the total string length ('fail2ban-moinmoin-page-with-spaces') to 35 chars long. Resolving the issue meant renaming the filter down until it was under 20 chars, so fail2ban could add its 9 chars onto the front and still be ok.
Getting i2p into git from monotone
November 22, 2011 at 10:00 AM | categories: hacking around, howtos and guidesBranching i2p.
i2p is an interesting bit of software, aiming to create an annonymised network that anyone can use. Sadly, its source is kept in mtn.
Checking it out
To be honest, even this is too much of a pain in the arse (compared to what it should be)
mkdir i2p-mtn cd i2p-mtn mtn -d i2p.mtn db init mtn -d i2p.mtn pull mtn.i2p2.de i2p.i2p
To keep it up to date, simply re-run the last line at times and get the updates.
A plea!
Anyone, someone, please! Save me from monotone!
How to escape? bzr has no reliable way of doing it yet (that I can see), but mtn does have a git_export function we might be able to exploit to help us here. (If someone can tell me how to get i2p into bzr too, please let me know! Its still my preferred DVCS).
How to escape
The magic invocation can almost be found at the monotone site , and all it takes is mtn ( > .48) and git installed.
- ::
- mkdir i2p-git cd i2p-git git init mtn --db ../i2p-mtn/ git_export | git fast-import
Note that the linked page talks about 'git fast import' (two spaces), which is invalid - it should be 'fast-import'
This took a while, as it has 6,967 revisions at the time of writing. After that, you'll need to checkout the branch with actual code it in. git co i2p.i2p
And you are ready to view the source! yay!
Look at the 'unknown' branch, you'll see a tree with a debian/ directory too - enjoy.
Future work
I'm yet to really see how well this works (for example, if I can keep it up to date somehow), but not needing to use mtn for day to day poking around is a good start. A good thing to find out would be if git_export can resume where the last export left off, or if each update to the mtn repository means a new start from scratch for git?
PS
Its probably just easier to learn mtn - If you know a good guide to the basics let me know. (If you know a way to stop it being so annoying thats even better)
Disassembling a Belkin wireless MIMO router
November 09, 2011 at 10:00 AM | categories: hacking around, disassembly, howtos and guidesAs I was hoping to install Openwrt on yet another device (The first being a proper Linksys WRT54g), I began to research the hardware on which it will be installed. Seems successful installs on this device are few and far between - found less then a dozen results with Google, one of which will be the base of my installing efforts, and two of which reference the useful link.
As you've probably guessed by now, the device is a Belkin wireless G plus MIMO router, a F5D9230-4R v3001 (The version is important, as the different major versions use different chipsets).
Seeing references to accessing the device via ftp or serial, I tried to find a guide to taking it apart ... and came up dry. Searches like 'serial access to f5d9230-4r' and 'how to disassemble f5d9230-4r' (with various permutations) came up dry, leaving me to try it for myself.
Disassembly
So here you go, a quick photographic guide to taking it apart.
Tools required: a philips head screwdriver and a flat head screwdriver (flatheads of different sizes might be handy, esp if they have a longer handle then the one I have in the photo).
Undo the bottom screws
Prise out the back panel. You should be careful doing this, as the cable into the wireless antenna (next to the power plug) is quite short, and doesn't have a lot of room. Its also worth noting that the back panel is not attached to the ports, but is to the antennas. This means it can be prised out the back, but you might have to poke and push at it a bit.
Carefully insert a flathead down the side, and using the plastic 'towers' (for screwing the two halves together) for leverage undo each hook one at a time.
Once the sides are loose, the top should only need a little wiggle to get the front loose.
And thats pretty much it! From here you can take out the PCB, but there is nothing attached to the underside
But where is that serial port? I'm not sure, but I suspect its CON1 (JP1 is the only other possibility). If I find a link to resolve the question, I'll link it here :)
Reassembly
This is easiest if you take the PCB out. From there you can sit the rear plate against the power/connection ports, and slot it all back into the bottom casing.
Thats about it really, let me know if I forgot to mention something (I might still remember...)
Next Page ยป