Morphex's blogologue (Life, technology, music, politics, business, mental health and more)

This is the blog of Morten W. Petersen, aka. morphex in various places. I blog about my life, and what I find interesting and/or important. This is a personal blog without any editor or a lot of oversight so treat it as such. :)

My email is morphex@gmail.com.

An OGG/Vorbis player, implemented in Javascript.

My Kiva bragging page
My shared (open source) code on GitHub

Morphex's Blogodex

News
Slashdot

Zope hosting by Nidelven IT

Morten Petersen on Linkedin

Morten Petersen on Facebook

Morten Petersen on SoundCloud

Morten Petersen on MixCloud

Blogologue on Twitter



Older entries



Atom - Subscribe - Categories


Graceful degredation of redirect using meta http-equiv and Javascript in XHTML, for caching

So, I saw that SSL was becoming more or less mandatory these days, so I got SSL setup for the domain blogologue.com.

However, since I also wanted to keep serving the site over HTTP as well as HTTPS (for graceful degradation and a fallback), and I have a cache sitting between the SSL-server and the weblog system, which pretty much caches everything, all the time, for a long time, I had to do a bit of extra work.

The cache in this setup isn't able to tell the difference between requests coming via HTTP or HTTPS, so an extra '&protocol=http[s]' is added at the end of URLs.

So with this code

  <meta http-equiv="refresh" id="meta_refresh" content="1;
        http://blogologue.com/?protocol=http" />
  <script type="text/javascript">
    refresh = document.getElementById('meta_refresh');
    refresh.parentNode.removeChild(refresh);
  </script>

it is possible to have the page redirect with the protocol key without Javascript, while this piece of Javascript

    <script type="text/javascript">
    // <![CDATA[
    function myOnLoad() {
      if (window.parent.document.location.toString().indexOf('http://blogologue.com/frames') != 0) {
        if (window.parent.document.location.toString().indexOf('https:') != 0) {
          window.parent.document.location='http://blogologue.com/frames?url=http://blogologue.com/&protocol=http';
        }
      }
      if (window.parent.document.location.toString().indexOf('https://blogologue.com/frames') != 0) {
        if (window.parent.document.location.toString().indexOf('http:') != 0) {
          window.parent.document.location='https://blogologue.com/frames?url=https://blogologue.com/&protocol=https';
        }
      }
    }
    document.getElementById('iFrameLoadTest').myOnLoad = myOnLoad;
    document.getElementById('iFrameLoadTest').myOnLoad();
    // ]]>
    </script>

does redirect to setup frames *and* add the protocol key. I setup this site so that it would be possible to access the site without a browser that supports [i]frames, and I guess it is reasonable to expect that a browser that doesn't support Javascript, also doesn't support frames.

Although for example the NoScript extension for Firefox does enable blocking Javascript per-site etc. for security.

So the cache is able to cache http and https pages differently, which again is tidy and neat, as URLs generated on the blog are often absolute starting with http: or https: - and not relative, for example /morphex.

If you're wondering how the meta tag is generated, that's by a script on the server side, which decides to redirect with an &protocol= suffix on URLs, based on an environment variable HTTP_X_FORWARDED_PROTO, which the cache sitting in the middle, is unable to take into account.

It did add "Vary: HTTP_X_FORWARDED_PROTO" to the pages generated in the weblog, but that did not affect the cache.

Now, I was wondering how long a timeout the http-equiv refresh should have, and found 0 was too short, and 2 was too long. If the timeout is 0, it is reasonable to expect that the browser will execute the refresh immediately. It is also reasonable to expect that within 1 second, the following <script> tag is read and executed, and when that Javascript is run, it deletes the meta tag, and from what I can tell, deleting the meta tag, also stops any actions contained within that tag.

You might think that adding <meta> tag within a <noscript> tag in the header would be much easier, and it would be, however, that is not valid XHTML according to the W3C validator, so this "hack" is what will work and be accepted as valid XHTML.



[Permalink] [By morphex] [Web (Atom feed)] [23 Jun 15:18 Europe/Oslo]

An OGG/Vorbis player, implemented in Javascript

So, I've had a productive week(end), and after some fiddling over the last couple of months, I've managed to create a Javascript demuxer/decoder of OGG/Vorbis files. :)

It's located here:

http://blogologue.com/player/

Long story short, it runs in some browsers, as mentioned on the page. I think this is very cool, and it is nice to see that I've managed to make some practical use of the C programming I've been dabbling with the last couple of years.

[Permalink] [By morphex] [Web (Atom feed)] [16 Oct 08:40 Europe/Oslo]

Taking a look at SASS, Compass & Zen Grid

OK, so a couple of days ago I got the idea that I should create a new personal website, which syndicates information from various sources into one channel, or page. That is, all my Youtube stuff, Tweets, stuff posted on SoundCloud, Instagram and so on.

Now, I've been using Python, Zope and Plone for many years, in work projects as well as personal projects. This time, I was thinking of creating something very simple, maybe even static HTML, Javascript and CSS files. Well, as for the static part, I think it is a good idea. The process for creating those static files could be done in any way though.

So I started looking at responsive design, and having a framework that delivers a lot seemed like a good idea. I ended up choosing Zen Grid because it felt right, a Ruby- and Compass-based framework for creating grid-based layouts. Ruby is a programming language, and Compass is a framework for creating CSS. I got Ruby installed, and got SASS, Compass and Zen-Grid installed using gem, an easy enough process, typing 'gem install sass', 'gem install compass', 'gem install zen-grid'.

OK, everything installed - fine. Now I had to create a SASS/Compass project, and the 'compass create <projectname>' command handled that. Creating a project creates some files, using the find command shows which files are present in my project right now:

morphex@infernal-love:~/apache/stats/tester$ find .

./config.rb
./index.html
./sass
./sass/ie.scss
./sass/print.scss
./sass/screen.scss
./stylesheets
./stylesheets/ie.css
./stylesheets/print.css
./stylesheets/screen.css

The sass directory contains the SASS files which will be compiled into the CSS files in the stylesheets directory. Now, first thing is first, and that's the web page. It is available here:

http://blogologue.com/stats/tester/index.html

If you look at the source of that file, you can see it's an example copied from the Zen Grid reference, with the E field commented out. This is because I saw the E field being moved down as content was being added in rows to the B field. I couldn't see any need to go beyond the D so it was just easy to remove it and don't have any headaches trying to figure things out.

The CSS file that gives this page its layout and colours is here:

http://blogologue.com/stats/tester/stylesheets/screen.css

And the SASS file that generated that CSS is here:

http://blogologue.com/stats/tester/sass/screen.scss

It's all fairly straightforward, and it is a nice simple way to create a layout on a web page.

A final note on these files, config.rb should contain

  require 'zen-grids'

to make all of this work, like my one does: http://blogologue.com/stats/tester/config.rb

For my part, I'm thinking it could be fun to create some tools in Python that pulls everything together, at least something that can generate HTML with information from all the different sites I post content to. It's easy to start over-engineering on projects like this, but maybe I'll also wrap Ruby, SASS, Compass etc. in a Python package to make these features easily available for Python. As well as look at including Zope's page template package to easily create templates.

Oh well, I'll get back to progress on all of this later. Tata. :)

[Permalink] [By morphex] [Web (Atom feed)] [04 Dec 17:29 Europe/Oslo]

I'd like to see that as well

http://tech.slashdot.org/comments.pl?sid=599793&amp;cid=2400...

I'm sure a lot of people have had that thought before.

[Permalink] [By morphex] [Web (Atom feed)] [30 Jun 22:22 Europe/Oslo]

Don't drink (and get very drunk) and do websites

I'm sitting here sipping some Baileys and thinking to myself - "this is good stuff." So I thought I'd visit the Baileys website (http://www.baileys.com) and have a look.

First I get asked where I am and what my birth date. Fair enough, I guess they have to do this stuff for legal reasons. I enter Norway, 10th of May 1980 click on "remember" and enter. Then I get a page which says "You're not authorized to bla bla." That's what the fuck #1.

So I enter www.baileys.com and voilà, the website shows up. I see some flash icons (I have flash blocker installed, thank god) and select to view the flash things since obviously the site depends on it. I click on a "link" and once more, the flash symbols appear. That's what the fuck #2.

What is it with these brand/media sites and having flash? Can they not create a website that makes *subtle* use of flash? I mean, what the fuck? ;)

[Later..] Aha. Just got an idea. Maybe the flash blocker should have an "enable flash for this website" thing? It does have a whitelist, but it is kinda hard to get at. Hmm.

[Permalink] [By morphex] [Web (Atom feed)] [08 Feb 01:41 Europe/Oslo]

x-visitor

I'm sitting here tailing my logfile, just idling waiting for something to happen.

It would be cool to see who's visiting the site, just have some sort of feed updating with visitor URLs or somesuch - with a link to the visitors webpage. You can have people reading your blog and linking to it, but not everyone is a blogger.

An X-visitor header could be something...

[Permalink] [By morphex] [Web (Atom feed)] [17 Jan 08:30 Europe/Oslo]

How about that, Flash 9 for Linux

Nice to see that version 9 of Flash is available for Linux. It sounds like it even supports esd so sound is working nicely too, even if I've got other things playing.

http://www.adobe.com/shockwave/download/download.cgi?P1_Prod...

How cool.

[Permalink] [By morphex] [Web (Atom feed)] [17 Jan 06:09 Europe/Oslo]