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 Kiva bragging page
My shared (open source) code on PyPi
My shared (open source) code on GitHub

Morphex's Blogodex

Misc
Zope/Plone
News

Zope hosting by Nidelven IT

No description available

No description available

Get firefox

Morten Petersen on Linkedin

Morten Petersen on Facebook

Morten Petersen on SoundCloud

Morten Petersen on MixCloud

Blogologue on Twitter






Older entries



Atom - Subscribe - Categories

Developing my XML project in C

So, these last couple of months I've been dabbling with C and XML, to get to know C better. Out of all of this there might also come a nice XML parser and writer that will be freely available for anyone to use.

I wish I learned more C earlier, as a lot of things related to IT have fallen into place now that I've been forced to work on low-level stuff.

There have been quite a number of posts to comp.lang.c, and lots of useful information has been exchanged back and forth.

Anyway, the project is here:

https://github.com/morphex/smash_xml

I guess the bulk of the main code and tests are now around 25KB, which is quite a bit of code. One of the next steps is to create the main parsing loop, which will break down the XML file into its internal C representation. There will also have to be some data types created so that things work well.

One of the more interesting points that have come up is whether to use iteration or recursion when working with the internal representation.

In C, when you do a function call, things are pushed onto something called the stack. And with recursion, more and more things get pushed onto the stack, and if the recursion is deep enough, the stack is exhausted with unpredictable results.

So I think I'm opting for an iterative design in the C code, and using little if any recursion. I'm sure that's going to tick some people off, but having predictable and intelligible results when running the code is important for this project, because one can work with malicious input data.

Right now it feels like I'm past the most "painful" parts of learning C, and look forward to learning and writing more in the time to come.


[Permalink] [By morphex] [C & XML (Atom feed)] [Comments] [13 Jul 00:51 Europe/Oslo]

C & XML

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;
}


[Permalink] [By morphex] [Technology (Atom feed)] [Comments] [09 May 11:44 Europe/Oslo]

A small victory

So, it's been a while since I blogged about my mental health, and I thought I'd do that today. Some years ago I had a major crash (psychosis), and after some months I was put on Seroquel, and over a period upped the dose to a top of 800 mg.

Together with the psychologists and psychiatrists and lately my doctor I've been reducing the amount of medicine, and today I'm on 450 mg a day and it feels OK.

I've seen some advocating for medicine-free treatment, but from my experience, the medicine has helped. That and going to therapy has helped me a lot, and today I feel better, smarter and stronger than what I did before the crash.

Now the medication isn't perfect, it has side effects as most medicines do, but I can say today that I'm glad medications were an option.

Psychosis can happen to anyone. There's a lot of stress and pressure in society, there is a lot of (heavy) things to think about, life is a mystery, and my impression is that mental health issues is rather something that counts towards the patients' intelligence than against it.

Some can become psychotic from physical trauma, some can develop it over time for various reasons, some can be slipped a pill - many different things can happen that causes psychosis and severe mental illness has been documented for a long time in history.

So it's good that there is a way to deal with these issues, the treatment isn't perfect but it is a lot better than the alternative, maybe going through a kind of hell for an entire life.

[Permalink] [By morphex] [Health (Atom feed)] [Comments] [29 Apr 17:18 Europe/Oslo]

An alternative to SoundCloud, MixCloud and similar services

I'm a software developer, that has pretty much loved music my entire life, and I've at times listened to music almost all my waking hours.

I'm now in the middle of my thirties, and these last couple of years I've also been playing the guitar, singing and doing some piano and drumming as well.

Now, to me it seems natural that one learns to play instruments, by playing songs one has grown up with and know, it's a natural place to start. So for some time I created simple cover versions of songs, and uploaded them to SoundCloud.

Around this last Christmas (...) I got a notice from SoundCloud that my account had "two strikes" with a dire warning of my account being "terminated", where they had taken down my track "Summer (original by Calvin Harris) Simple Mic". Now it is funny that I get a notice like that on the 1st day of Christmas (25th of December). Another funny thing is that I asked to get a copy of my track, but they denied that request and said that

"This was reported to us by an anti-piracy agency on behalf of Sony. We won't be able to reinstate this, not even privately, unless you have permission from Sony to have it on SoundCloud."

Now, luckily I had a copy of the track on my computer, but it would have been a bit more sticky situtation if I didn't. Now this track is 01:19 long, that is just under 80 seconds and recorded on a simple microphone, but they still saw it necessary to take it down. If it was because I made a remark somewhere that you could just put that snippet on repeat and there you had pretty much the entire song I don't know.

Anyway, because of this, I got somewhat stressed and decided to move my cover songs to MixCloud, because there you can tag the artist and the song in uploaded tracks, and the artists (and MixCloud) get some revenue, and that seemed like the best thing I could do.

However, I recently reviewed the terms on the MixCloud site, and it basically says that they can do whatever they want with what I upload, forever. This wasn't what I expected; what I expected was that I could put things up there as a temporary solution, and take things down if necessary, or take things down if something I create has potential to make money. Now, I guess I could leave everything I have up there as the recordings aren't high quality, but it would be nice to have a reasonable amount of control of what I've created.

So my expectations of MixCloud and what is in their terms of service didn't match up, and I sent an email to MixCloud asking about this, but the reply I got was

"For licensing reasons we don't host individual tracks (even if it's your own track), so unfortunately we've had to disable your single track upload."

Which wasn't close to what I emailed them about

"
Expected Behaviour
------------------------
My impression of the site was that one could upload things, and take them down and that was pretty much it, you and the original content owners got a cut through radio-style fees.


Actual Behaviour
------------------------
However, I've read the terms you have, and found that for example having others create derivates, that I'm liable for being in the middle, that you can use my content perpetually etc. is not something I expected.
"

So now I'm in a situation where I have created content which I'm unsure about who has the rights to do what with, and I also can't continue doing podcasts and cover songs because I don't have a place to share these things.

Does anyone know of alternatives to these services that work like I want them to? Comments or emails to morphex@gmail.com are much appreciated.

[Permalink] [By morphex] [Music (Atom feed)] [Comments] [12 Apr 10:08 Europe/Oslo]

An updated version of the Issue Dealer, building Zope 2.13.22

It's been a while since I did anything on Zope 2, and these last couple of months some bugs on the weblog publisher on blogologue.com have been bugging me.

So I decided I should get that fixed, and also get the IssueDealer updated to work with the latest stable version of Zope 2.

It has been some days of fixing things back and forth to get things working, but now I have an updated version of the IssueDealer, as well as a procedure for building the latest and greatest Zope 2.

I've been quite out of touch with what has been going on in the Zope, Plone and Python world lately, and it took me quite some effort to get things working, from getting Zope from GitHub, getting the right dependencies in etc. One thing I've noticed is that pypi.python.org is using a common name of www.python.org - which forced me to make a shell script to aid in the process of setting up Zope. This is sloppy at best, as it forces users to skip SSL verification.

But, enough of that, here's the hands on procedure for getting Zope 2 installed on a Debian Linux box. Beforehand, I think it's necessary to install the build-essential package as well as git, in other words:

sudo apt-get install build-essential git

I'm not sure what the procedure is for Fedora/Red Hat, SuSe etc. is but it should be easy enough to figure out.

OK. We'll install Python and Zope in a directory called

/home/morphex/zope_blogologue.com

First thing we do is get Python 2.7.9 installed, which is done with

mkdir zope_blogologue.com
chmod o-rwx zope_blogologue.com # So other users can't read the database etc.
cd zope_blogologue.com
mkdir tmp
cd tmp
wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
tar xfz Python-2.7.9.tgz
cd Python-2.7.9/
./configure --prefix=/home/morphex/zope_blogologue.com
make install
cd /home/morphex/zope_blogologue.com/
git clone https://github.com/zopefoundation/Zope zope
cd zope
git checkout 2.13.22
wget --no-check-certificate https://raw.githubusercontent.com/morphex/IssueDealer/master...
chmod +x bootstrap.sh
./bootstrap.sh ~/zope_blogologue.com/bin/

Now, edit the buildout.cfg file, so that the [zopepy] and [wsgi] sections contains the line

    Products.IssueDealer==0.9.140

like so, maybe using the command "nano buildout.cfg":

[...]
[zopepy]
recipe = zc.recipe.egg
eggs = Zope2
    Products.IssueDealer==0.9.140
interpreter = zopepy
scripts = zopepy
[...]
[wsgi]
recipe = zc.recipe.egg
eggs =
    Zope2
    repoze.who
    repoze.tm2
    repoze.retry
    Paste
    PasteDeploy
    PasteScript  
    Products.IssueDealer==0.9.140

Now, when that's done, we're ready to run buildout. Run the command

./bin/buildout

Now, this script may fail, if there are network issues for example that make downloading of packages break. If that's the case, just re-run the command until it completes with lines something like this:

"""
Generated script '/home/morphex/zope_blogologue.com/zope/bin/runzope'.
Generated script '/home/morphex/zope_blogologue.com/zope/bin/zopectl'.
Generated script '/home/morphex/zope_blogologue.com/zope/bin/zpasswd'.
Generated script '/home/morphex/zope_blogologue.com/zope/bin/addzope2user'.
Generated script '/home/morphex/zope_blogologue.com/zope/bin/mkzopeinstance'.
Generated script '/home/morphex/zope_blogologue.com/zope/bin/paster'.
"""

After a lengthy process with lots of output, we can create the Zope instance, like so:

./bin/mkzopeinstance -d ~/zope_blogologue.com/zope/instance

I'll leave it up to you to choose a username and password.

Now the instance has been setup, and we can run it for the first time. Type in the command

./instance/bin/zopectl fg

And you should see something like this:

/home/morphex/zope_blogologue.com/zope/instance/bin/runzope -X debug-mode=on
2015-02-13 04:31:04 INFO ZServer HTTP server started at Fri Feb 13 04:31:04 2015
        Hostname: 0.0.0.0
        Port: 8080
2015-02-13 04:31:05 INFO Zope Ready to handle requests

Now I login to my server on the URL http://blogologue.com:8080/manage_main - and select "Issue Dealer" from the drop-down list, click on add and give it the ID issues, and the title "My issues". Now that Issue Dealer instance is available on

http://blogologue.com:8080/issues

Voila. If you're setting up a plain Zope 2 or Zope 2 with some product, just remove the Products.IssueDealer parts from the buildout.cfg and it should work.

Hope you found this useful, and comments etc. are much appreciated. My email is morphex AT gmail.

[Permalink] [By morphex] [Zope (Atom feed)] [Comments] [13 Feb 04:05 Europe/Oslo]

A man walks into a bar..

So this week I've been visiting the kids, and the visit went relatively well, it was nice to see the kids again.

I don't have a relationship with the kids mom or her family anymore, and took the train from Mo i Rana to Trondheim yesterday evening.

Some of her relatives were on the train as well, but they didn't stop to say hi and it was fine by me.

Had a good time towards the end of the train journey, ate well and had some wine and beer. Headed towards a regular place when I got to Trondheim to have some beers and maybe meet some friendlies there.

After a while I was ordering a second beer when this chick I might have met before started suggesting what I should have. So OK, I went with her suggestion.

After drinking some of that beer I figured I could go talk to her, since she struck up a conversation with me.

But I think she was (the only girl) sitting at a table with maybe 5 other guys, and as I started talking to her, a guy at the table asked me to stop talking to her, I kept talking a bit with her and she said she studied law, then she said she studies psychology.. I glanced around the table and persisted a bit, but the guy still kept asking me to stop talking to her.

Well, I got a bad feeling right then and there and instinctively agreed with the guy asking me to stop talking to her. Next time I'll look at the company someone's with before I start talking to someone who started talking to me first..

[Permalink] [By morphex] [Living (Atom feed)] [Comments] [06 Feb 21:14 Europe/Oslo]

A Rasbperry Pi router

So, I've been playing around with different technologies the last couple of weeks. The one I've talked the most about is the Raspberry Pi, a small computing unit that's available for cheap.

Where I'm staying doesn't have wired internet, and the Wi-Fi that is available isn't any good. So I decided I should create a router based on the Raspberry Pi that makes some "smart" decisions about network traffic.

I've got two providers of mobile internet, one on my phone and one pure mobile broadband subscription. The former has a good latency but limited capacity, while the latter is the opposite.

So when I'm playing online games like Battlefield, where latency (ping) is very important, I'd like to have the router choose what the best thing to do is, based on my instructions. I also flip between Windows and Linux on the desktop, and having things just work without per-OS configurations would be nice.

This router should be flexible so I can connect to it using Ethernet or Wi-Fi, and the Ethernet USB-dongle I got for it kept crashing the Pi. I reported this bug to the kernel developers but it is an old (not updated in years) driver that's causing the crashes so I don't have my hopes up. I found a patch which fixes the crashing ( https://github.com/kmtaylor/rpi_patches/blob/master/dm9601-b... ), but I'm not sure that patch does the right thing, it's probably the network chip driver is the one that should be patched.

Anyway, today I was able to patch the Raspbian kernel, cross-compile it on my X64 Octo-core 3.4 Ghz (significantly faster than compiling it on the Raspberry itself), install it on an SD-card, modify the config.txt file and boot the Raspberry with usbnet.c patched. And that worked well, copying a large file using scp went painlessly.

I ordered a new Ethernet dongle today, one that supports 1 Gbp/s in addition to 10/100 mbit, as offering that option as well seems like the right thing to do.

The Raspberry has support up to high speed USB 2.0, which has a max bandwidth of 480 Mbit/s (in practice the bandwidth one can use will be significantly lower) and there is also some CPU overhead, so it will never fast enough to give full 1 Gbps access. But it will offer the option of 1 Gbps connectivity, which probably means the upper limit is a couple of hundred Mbps.

I think this was a fun and smart thing to start with, I've also got some other Raspberry Pi ideas lurking, but limitied time and energy to play around with things.


[Permalink] [By morphex] [Technology (Atom feed)] [Comments] [02 Feb 23:05 Europe/Oslo]

Finding a way to share cover songs

OK, so a little while ago I had problems with SoundCloud ( http://blogologue.com/blog_entry?id=1420246529X05 ), they took down a simple remix I made and gave me a dire warning that they would "terminate" my account.

Now I've got got a notice from MixCloud that they've taken down a song, even though it's my understanding that they pay licensing fees to the original creators so even though I make my own cover variant song of their song and all the income for that song goes to MixCloud and the content creators, they still take it down.

I think it's natural that people interpret popular culture and make works with popular culture. Popular music is also where a lot of people start, so there must be many, many people out there who want to share whatever they're working on, if just for fun (but also for feedback, a chance at getting noticed, making it big and so on). For me this music thing is a hobby so I'm not giving much thought to making money off it and all that entails, and to me it seems just wrong that it isn't possible to participate in a cultural exchange without getting hammered down like this.

[Permalink] [By morphex] [Music (Atom feed)] [Comments] [22 Jan 19:33 Europe/Oslo]

Some Hydrogen, EDM-like beats

So, this weekend I was feeling restless and nothing really fancied me, so I decided to play around with Hydrogen.

Hydrogen is an open source drum machine that runs on Linux, I've previously posted ( http://blogologue.com/blog_entry?id=1406401445X72 ) about a VirtualBox image that contains Linux and Hydrogen - which means you can run it on Windows and Macs as well.

Anyway, one of the things I've noticed with some (most?) EDM music is that it contains a "drumstick peak" where the beat gets more intensive in a song.

So I decided to create a drum track in Hydrogen that gives this peak in the song and I was able to do so just using the standard samples in Hydrogen.

The hydrogen file as well as an ogg file is available here:

http://blogologue.com/music/

Just thought I'd share this, if anything it can show how one creates a track in Hydrogen. I like Hydrogen for its simplicity, but now I yearn for something where I can edit the drum track as well as the synth/ambient sounds at the same time. So I'm looking at different apps that run on Linux that could do that.

[Permalink] [By morphex] [Music (Atom feed)] [Comments] [12 Jan 08:04 Europe/Oslo]

Repurposing old devices (NOKIA Lumia and Samsung Galaxy tab) for mobile internet access

So, where I'm staying right now doesn't offer a wired connection, so I've setup a mobile internet solution instead.

The companies that offer wireless mobile internet also offer routers etc. that can be used to setup WiFi access to the internet, but I didn't opt for any of those as I had a couple of old devices that could be setup as WiFi hotspots instead.

Up until a couple of days ago, I was using a Nokia Lumia as a WiFi hotspot and used the computer as a power source via USB, but I found that it started giving a very poor speed (20-30 KB/s) when I was on Linux. So I dug up my old Samsung Galaxy Tab P1000 instead, and placed my mobile internet provider SIM card in there.

It didn't work though, it just gave a couple of bars on the network indicating that there was some sort of connection, but no internet access.

After googling a bit, I found the setup procedure on Netcom (the provider of mobile broadband) for one of the devices they sold if internet didn't work. After some adjusting of the APN settings, I found that setting the Server to internet.netcom.no and the APN-Type of connection to internet, the Galaxy Tab started working as an access point to the internet.

So there you go, if you've got old phones etc. don't throw them away, they can be put to good use later.

[Permalink] [By morphex] [Mobile (Atom feed)] [Comments] [07 Jan 05:11 Europe/Oslo]