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.
These last couple of months I've been learning a bit of Assembler and C programming, as these days I have the time available. I've always found Python and other high-level languages fast enough for what I needed to do, but I've always wondered a bit about C and Assembler.
What I've learned so far is that the computer is in fact a very large calculator, and pretty much everything that happens is that instructions are called (for example adding two numbers), and that numbers are moved around in memory, disk, peripherals etc. I've found it useful to learn about Assembler and C because it gives me a more detailed and correct view of how things work in computing.
With my programming and system administration background, I found it easy to dive into C and Assembler, and I also appreciate a lot more what for example Python does as a high-level programming language.
I've been looking for some gig or project to create a C and Assembler project for, and what I've landed on so far is that I want to create an XML parser. An XML parser that validates the Unicode used, as well as insures that the document is "well formed". I haven't gotten that far yet, but I've pretty much decided that the parser should (for now at least) be restricted to an UTF-32-LE encoding, and that whenever I work with pointers the rule is to initialize to null when they are created as well as after free() has been called.
I think this is good fun and I do it whenever I have the time and energy, here's the code so far:
#include <stdlib.h> #include <stdio.h> int main() { char *buffer = NULL; int read = 0; buffer = malloc(1024*sizeof(char)); FILE *file = NULL; file = fopen("test.xml.2", "rb+"); read = fread(buffer, sizeof(char), 1024, file); if ((char)buffer[0] == (char)0xFF && (char)buffer[1] == (char)0xFE && (char)buffer[2] == (char)0x00 && (char)buffer[3] == (char)0x00) { // We have a UTF-32-LE Byte Order Mark printf("BOM found\n"); } else { printf("BOM not found, %x\n", buffer[0]); exit(1); } printf("%i\n", read); fwrite(buffer, read, 1, stdout); printf("\n"); free(buffer); buffer = NULL; return 0; }
# The following code is available under the GPL, version 3, available here: http://www.gnu.org/copyleft/gpl.html import soundcloud, urllib2, urllib from soundcloud.request import make_request import os CLIENT_ID = 'REGISTER ON SOUNDCLOUD AS APP' CLIENT_SECRET = 'REGISTER ON SOUNDCLOUD AS APP' USERNAME='YOUR SOUNDCLOUD EMAIL' PASSWORD='YOUR SOUNDCLOUD PASSWORD' LIMIT = 1000 # Maximum number of tracks to download # a limit in case something goes wrong # so we don't hammer the system. def download_tracks(output_directory): client = soundcloud.Client( client_id=CLIENT_ID, client_secret=CLIENT_SECRET, username=USERNAME, password=PASSWORD, ) for track in client.get('/me/tracks', limit=LIMIT): path = track.download_url[len('https://api.soundcloud.com/')-1:] filename, data = client.get(track.download_url) output = open(os.path.join(output_directory, filename), 'w') output.write(data) output.close() print 'Downloaded file: ', filename if __name__ == '__main__': import sys if len(sys.argv) != 2: raise SystemExit, 'output directory required' import os output_directory = sys.argv[1] try: os.mkdir(output_directory) except OSError: pass download_tracks(output_directory)
Some months I suddenly felt the urge to buy a new smartphone, and got myself a HTC One X smartphone. I've been using it over months now and am satisified with how it works. If I use it a lot, the phone needs to get charged during the day, but I'm not sure what the reason for that is, might be many apps running polling and pushing over the network.
I've been looking for a TV-adapter for the phone, but couldn't find any. Looked around many places, and no-one had an adapter. So I was pleasantly surprised when one salesman said they had a wireless HD adapter (Media Link HD) that pairs with the HTC One X. So, OK, I bought it.
Setting it up (pairing the phone with the adapter) was as easy as plugging into the power adapter, connecting HDMI and swiping some fingers on the phone and they autoconfigured and were ready to go.
I've played around with the phone and adapter for a couple of days now, having struggled a bit with for example choppy playback of video, and sound lagging a bit.
Here's the phone streaming to the TV yesterday.
So I took a look at the processes that were running (task manager) and stopped a lot of them, Facebook, Maps etc. - all non-essential processes.
And that made a big difference, now playback is almost perfect, some minor hiccups once in a while, but nothing that can't be pragmatically overlooked.
Well, that's that. But I'd like to see an app that can instantly kill all non-essential processes, or a setup where some programs like those who display video and are a bit "heavy" can get maximum CPU priority so that other apps running don't disturb the playback.
Oh, and I would probably be good with an app that can diagnose things relevant to streaming over Wi-Fi, such as network bandwidth, network latency, CPU used by background processes and so on.