Learning Haskell, wrote startsWith a bunch of times
So I started learning Haskell a day or so ago. I dived right into http://learnyouahaskell.com and read through the first few chapters. As soon as I learned how to write an if statement and got familiar with some basic list functions (head, tail and such) I started experimenting with my own code. I don’t know why, but I decided to implement a simple startsWith function, here is the first version:
startsWith' l s =
if null s then
True
else
if null l then
False
else
if head l == head s then
startsWith' (tail l) (tail s)
else
False
Now I know what you are thinking. This looks horrible and I know I shouldn’t write code that looks like this. I agree completely, but at the time of writing I only knew really basic Haskell syntax. After reading another chapter I quickly improved my code:
startsWith' _ [] = True
startsWith' [] _ = False
startsWith' l s =
if head l == head s then
startsWith' (tail l) (tail s)
else
False
Writing code like this is familiar to me as I have done some Prolog programming for a class. It seems ‘academic’ programming languages tend to borrow each others ideas almost as much as other languages do! I was also delighted to see that, similarly to Prolog, Haskell provides a shortcut for retrieving the head and the tail of the list:
startsWith' _ [] = True
startsWith' [] _ = False
startsWith' (hl:tl) (hs:ts) =
if hl == hs then
startsWith' tl ts
else
False
But unfortunately this is where similarities between these two languages end. If this was Prolog I could get rid of the last if statement like this:
startsWith' _ [] = True
startsWith' [] _ = False
startsWith' (h:tl) (h:ts) = startsWith' tl ts
startsWith' _ _ = False
Notice that the h variable has been ‘defined’ twice. Prolog magically understands this as the head of the first list needs to be the same as the head of the second list. Awesome, right? Thankfully Haskell didn’t leave me hanging. It has something called ‘guards’ and with their help I got rid of the last if statement:
startsWith' _ [] = True
startsWith' [] _ = False
startsWith' (hl:tl) (hs:ts)
| hl == hs = startsWith' tl ts
| otherwise = False
I would not be embarrassed to introduce this last code snippet to my mother. It’s a great improvement over the hideous first version. I have not yet reached the end of the tutorial and there are probably ways of improving it even further. Any ideas?
I like Haskell so far. The reason I started learning it in the first place was because I wanted to improve my coding in general. Learning a purely functional language seemed like a good idea as it teaches you all about side effects and makes your brain think differently. This something an engineers brain should know how to do…
Disqus redesigned
A couple of days ago I noticed Disqus started experimenting with a new design. Because I am always eager to try out new things I requested an invite immediatly. One day later I received an email informing me I can activate the new design on my sites.
Lo and behold
The “Disqus 2012”, as they are calling the new design, is now enabled for this site and you can try it out right now (just scroll to the bottom of this page). The most prominent change from my point of view is the community tab. It allows you to see which the top discussions and commenters are on the blog. Useful bits of information to get the feel for the community. For instance, if you check out the community on this blog, you will learn that it is a sad thing indeed.
They also seem to be grasping the social aspect much more fiercely than before. Clicking on a commentor now shows you a bunch of his last posts and some basic information. You can even follow people whose comments you like. I don’t remember if this was in the old design as well, but I haven’t noticed it until now, so I guess they did something right! I might even give this feature a try.
But what about commenting?
The community tab and the added social aspects are great, but what did they do to improve the whole commenting process? Well from what I can tell, not a single thing! And I believe this is a good thing. Writing comments worked well, and it would make little sense to change it. They did seem to add upvotes and downvotes instead of a “like” button, but I have no idea how this little change might impact larger communities.
All in all I like the facelift, but will it convince more people to share their comments? Lets wait and see.
Navbar in Django Admin
I wanted to add navigation to the Django top bar. The idea was that all of the installed apps should show up in the navbar beside the brand name. This is a screenshot of the working solution in action:
A solution
I hacked together a solution using a custom context processor in order to feed the installed applications to every template in the django admin site. I borrowed most of the code from the admin index view. context_processors.py:
from django.utils.text import capfirst
from django.db.models import get_models
from django.utils.safestring import mark_safe
from django.contrib.admin import ModelAdmin
from django.contrib.admin.validation import validate
# get_models returns all the models, but there are
# some which we would like to ignore
IGNORE_MODELS = (
"sites",
"sessions",
"admin",
"contenttypes",
)
def app_list(request):
'''
Get all models and add them to the context apps variable.
'''
user = request.user
app_dict = {}
admin_class = ModelAdmin
for model in get_models():
validate(admin_class, model)
model_admin = admin_class(model, None)
app_label = model._meta.app_label
if app_label in IGNORE_MODELS:
continue
has_module_perms = user.has_module_perms(app_label)
if has_module_perms:
perms = model_admin.get_model_perms(request)
# Check whether user has any perm for this module.
# If so, add the module to the model_list.
if True in perms.values():
model_dict = {
'name': capfirst(model._meta.verbose_name_plural),
'admin_url': mark_safe('%s/%s/' % (app_label, model.__name__.lower())),
}
if app_label in app_dict:
app_dict[app_label]['models'].append(model_dict)
else:
app_dict[app_label] = {
'name': app_label.title(),
'app_url': app_label + '/',
'has_module_perms': has_module_perms,
'models': [model_dict],
}
app_list = app_dict.values()
app_list.sort(key=lambda x: x['name'])
for app in app_list:
app['models'].sort(key=lambda x: x['name'])
return {'apps': app_list}
We add the custom context processor to the settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
"context_processors.app_list"
)
With the context processor in place we should have an ‘apps’ variable available in our admin templates. The only thing left to do is to add the code that renders the installed applications. I am using twitter bootstrap for the navbar. Here is my templates/admin/base.html:
<ul class="nav">
{ % for app in apps % }
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{ % trans app.name % }<b class="caret"></b>
</a>
<ul class="dropdown-menu">
{ % for model in app.models % }
<li><a href="/{ { model.admin_url } }">{ { model.name } }</a></li>
{ % endfor % }
</ul>
</li>
{ % endfor % }
</ul>
Note: I had to add spaces to the { % and { { tags as jekyll/markdown doesn’t seem to be able to handle them in code segments.
This is pretty much it. Suggestions for improvements are welcome!
Gnome Shell and Unity
Ubuntu 12.04 LTS is just a few weeks away and it is going to bring a new version of the Unity desktop. The recently released Gnome Shell 3.4 will also be only one apt-get install command away. I am therefore left with a tough decision: which desktop shell should I primarily use when the new Ubuntu lands.
Unity
Unity has really come a long way since it’s first release back in 11.04. I have already blogged about the most exciting new features a month back. My main issue in the old blog was multi monitor support. The launcher in the middle had a sticky behavior making the mouse stick when transitioning from screen to screen. The sticky behavior is now an option and one can even set which monitor will be used for displaying the launcher! They even made it easy to customize the launcher itself. The appearance dialog now lets you set the launcher background, icon size and such. We finally have some accessible options to customize the look and feel of the Unity desktop, this was one of the chief complaints with Unity in 11.04 and I hope we will get even more options in future releases.
Gnome Shell
Similarly to Unity, there was a lot of hate going round the interntes about Gnome Shell. Gnome Shell introduced a new way of doing things. It removed the bottom bar and changed the way people switch between applications. I understand that the workflow can be confusing at first but after a few hours it gets super smooth. I love it. So much so that I even wrote a Gnome Shell extension to make it even faster and easier to use.
The latest 3.4 version brings many changes. Most importantly for me, the stability on AMD propriety drivers has gone way up and I am no longer getting segfaults every 10 minutes or so. Maximized windows now hide the titlebar (sort of like Ubuntu does) to save precious screen estate, and the application menus are now exposed through a special menu.
The verdict
This really is a tough call. Both of the new desktops seem really awesome to me, and I will probably have them both installed on my new system. But for me the breaking point in favor of Unity is HUD. If it turns out to be as useful as I hope it will be, I might find myself using Unity more often than Gnome Shell.
How about you? Gnome Shell, Unity or something else?
My plans for Raspberry Pi
A week or so ago, I was able to preorder a little piece of hardware named Raspberry Pi. On the day the thing got released I and quite a few other people, managed to take down websites from Farnell and RS Components. The first 10.000 units sold out in 7 minutes or so.
What is it
Unless you have been living under a rock, you probably already know what a Raspberry Pi is. It’s a tiny computer with an ARM processor, hdmi, audio, ethernet and 2 usb ports. It is somewhat comparable by performance to an iPhone, but a Raspberry Pi costs less than a HDMI connector for the said phone. It was made to help children across the world to learn programming, but the first few batches will probably be all bought up by geeks like me.
Why do I want one
I already own a similar device - an ARMv5 board with a 196MHz processor and some RAM. I use it to run an annoying IRC bot, that logs our chats and tells us when a link is a repost (some of it’s code is on Github, but it’s not the prettiest thing I’ve writen). This little ARM board is great, but I have ran into a few problems with it. I haven’t managed to get git working, as all of my crosscompiling attempts have failed and compiling on the actual board takes forever before it throws up a random error. To be fair, I had this problem with everything that isn’t in the default buildroot environment, which only contains a handful of applications I would like to use.
Raspberry Pi is, on the other hand, backed up by actual Linux distributions (Arch, Debian and Fedora) and I am very confident, that installing software will not be such a pain. This will of course make the Pi useful for many things. Here are a few that come to mind:
- Host for private git repositories,
- simple webserver for testing out things like nodejs,
- SSH “entrance” for my home network,
- my IRC chat bot.
The Raspberry Pi is ideal for this as it has a processor that can tackle all of these things and is completely silent, as it doesn’t need a fan. To top off, it uses only a small amount of energy.
And much more
The stuff I mentioned so far is just the geeky stuff that I will be doing as soon as I get my new board. There are many uses for it for less techy users as well. It can be used as a movie player (it even plays full hd videos), and it can probably transform ones USB hard drive into a network disk. As it can run a desktop environment it could even be used for some simple office work or web browsing.
What about you
Do you have any ideas? What are you going to do with your Raspberry 3.14?
Coding and keyboard layouts
Keyboard layouts are important, especially for us programmers, as we spend most of the day cranking out code. But some layouts seem to be better for coding than others. I have recently switched from Slovenian layout to the English one and I am really happy with my decision. Let me tell you why.
Slovenian keyboard is a mess
The Slovenian keyboard layout has 31 letters. This is 6 letters more than they are in our alphabet and 5 more than on a ‘normal’ keyboard. We even have two letters left over from Yugoslavia which we aren’t a part of for more than 20 years. Madness! There has been some talk about a new, refined standard a few years back, but I have yet to see an actual physical model. This means that we are stuck with the extra unneeded letters for the foreseeable future.
What does all this got to do with coding
The number of keys on a keyboard is more or less fixed for all the countries round the world. This of course means that those extra letters need to replace other characters. To access those one must do some weird finger acrobatics. Let me give you an example. Writing square brackets ([]) is really easy on a English keyboard, but on a Slovenian one it requires you to press two keys alt gr and f for [ and alt gr and g for ]. It is similar with curly brackets, the ‘at’ symbol, backslash and so on. These are all characters that programmers use very often and having to excess them by weird keyboard combinations is annoying to say the least.
Reasons why I now code on an English layout
It took me quite some time to decide to move to a different layout, even though @zidarsk8, @swizec and @majcnm were convincing me that the English layout is way better for coding. I was not keen on switching because I would still need to use the Slovenian layout from time to time, and switching between them causes confusion and errors. But once I tried to write a few lines of code with the English layout there was no turning back. Here are my reasons for finally switching:
- While writing code I do not need Slovenian letters at all. Writing code and comments should be done in English without an exception. And besides, have you ever tried putting a UTF character in a Python comment? Try it!
- Removing all those unneeded characters frees up space for the characters that you actually do need. Having easier access to brackets, front/back slashe and is a big performance boost.
- Most programming languages were made by people using the English layout. Naturally they chose characters that are quick and easy to type on a English layout.
- English layout is more universal than Slovenian, which means that I won’t be lost if I will have to do some coding on a foreign keyboard someday.
Now I am not saying that every developer should switch. I am just saying that worked for me. Also before somebody suggests Dvorak I am going to say that I’ve tried it but just couldn’t get it to stick. I am not convinced this is a good layout for programming and it sure makes using VIM confusing.
What about you
Do you use a different layout for coding? Which layout do you think is best?
Ubuntu 12.04 Beta 1
A few days ago Ubuntu 12.04 hit the web and I tried it out immediately. I installed it on my USB stick and loaded it up.
I am impressed
A lot has been done since the last Alpha release, where many of the new features were only available from a special testing PPA, but now most of these new features are available by default. The system also seems really stable, and I only saw a small amount of “App crashed, please send feedback” dialogs.
The HUD
One new feature is the HUD and I think it’s amazing. It enables you to search through application menus using your keyboard, making it really easy to access those hard to reach options of the application. This is not a feature regular Joes will be using a lot, but it will allow more advanced users to find those pesky menu items faster. They will aslo reach for the mouse less often, thus saving valuable time. I know some other desktop shells had this feature before (I hear Awesome has it for quite some time now) but I really don’t understand why this isn’t more common.
I had some issues where the HUD displayed the wrong application menus and it was a bit slow at times, but that could all be due to me running the system on an USB stick. All in all this is a feature I am looking forward to most. It might even make me start using Unity instead of Gnome Shell.
Multiple monitor support
There was a lot of talk this release cycle on how 12.04 will improve the multimonitor experience. What they have done so far is to display the Unity launcher on all of the monitors and not just on the primary display like it was before. This change makes you loose some screen space on both of your monitors, but it does make your application shortcuts more available. I can see how this could annoy some people but I don’t really mind seeing a duplicate launcher (you can even make both of them autohide which solves the screen space issue). What I do mind is that currently, the mouse gets stuck while transitioning from one monitor to the other as it “collides” with the launcher in the middle of the screen. This gets a little annoying after some time and I really hope they will fix this before the final release.
Notifications oddly enough still appear only on the secondary monitor, making them easy to miss when you are focusing on something on the primary monitor.
I was surprised that I had no troubles at all with the AMD Catalyst drivers, as multimonitor support worked out of the box even on the propriety drivers. I even copied the xorg.conf file from the beta back to my 11.10 installation to fix an issue I was having.
All in all
I was really tempted to upgrade to the Beta already, but I am sticking with the 11.10 release as I need a stable machine for (school) work. I can’t wait until the final version gets released on April 26th and it seems like I won’t be switching to Arch any time soon…
Three CS students and a tablet
A few weeks ago ComTrade - a local tech company decided to sponsor a challenge event in association with our faculty. The idea was that three teams, each with three students, would work on a fun little project - building an android application that visualizes data received from a remote controlled car. Because the application was meant to run on a Samsung Galaxy Tab 10.1 me and a few of my friends got excited and we signed up for the challenge immediately.
The rules of the game
Each team received a tablet to develop their solution. We were told that the winning team would get to keep all three tablets so we were really motivated to create the best possible application. We did not have a lot of time to do this though. The time constraint was about three weeks and we were in the middle of the exam period when the challenge started.
The application would be receiving data via bluetooth. The remote controlled car was sending data from its G-force sensor, its wheel turn value and its revs count. It was up to us to come up with cool and interesting ways to visualize this data.
Our solution
We quickly decided that drawing graphs is all well and good but it would not be enough. So we came up with an idea to draw the actual car in 3D space. The car would move on a virtual road that it plotted as it went. Our final solution actually worked rather well although we would have to do some more calibration with the actual car, if we wanted the path in our simulation to match the path that the car actually made. One can’t believe what a difference turning radius can have on the path.
We ended up doing a lot of different graphs as well as many dials and counters, for the more techy people out there. We were drawing all of these in canvas which turned out to be a bad decision as it created quite a few performance issues. We managed to find workarounds but decided that our next app would be OpenGl only. OpenGl ES2.0 if we get a say in it!
The most difficult part of the whole thing was creating a design that looked good. Up until a few hours to the deadline our application looked horrible, but then thankfully @zidarsk8 opened up gimp and made the application look awesome.
There were a lot of things that we could still improve, but the final application somehow managed to impress the judges and we ended up winning the challenge!
The development process
We had one tablet but there were three of us. This of course meant that at any given time, two team mates would be forced to use the emulator. Now the thing with the android emulator is that it doesn’t really work if you are trying to do something a bit more complex. We all had android phones though so we decided to split the main application into multiple parts. We created a library project that did most of the hard work, and two applications one for the tablet and on really basic for the phone. This allowed me to work on the OpenGl part of the application even if somebody else got the tablet for the night.
We have also learned fast that it is way more difficult to work efficiently in a team, than it is to work alone. It is really hard to focus on the task at hand, when you have two other people sitting beside you, disturbing you with the problems that they are facing while developing their own part of the application. But thankfully we soon got used to it and got more productive. We still feel that there is a lot of room for improvements, we just need more projects like this tune our group programming skills.
How git saved our lives
I cannot stress this enough. Without git we would be doomed. The project was rather small which meant that we were editing the same files at the same time quite often. Luckily for us, git handles conflicts automagically 99% of the time, even if the same file was edited by 3 different people. And even when we got merge conflicts they were all trivial to resolve. I used a merge tool called meld, which is awesome and made it really easy to see what code goes where. I ended up looking forward to merge conflicts because they were actually fun to resolve. It is weird how great tooling can create a scary process into a fun activity.
The good and the bad
We had fun and we learned a lot. We even got used to working in a group! But there were some downsides too. There were quite a few sleepless nights as we tried to balance exams, the project and our social lives (@majcnM actually had two hours of social life). And even though the whole thing is over, we didn’t receive the tablets yet. This is because ComTrade took “our” tablets to the Embedded World to show off the applications at their booth. This, of course, means that we will have to wait two weeks or more to actually get them. And by then the new and shinny tablets will be touched by a million people, which is not a pleasant thought as well.
To conclude
We had a lot of fun developing the android application and we already have ideas how we could use the OpenGl part and turn it into a driving game. We look forward to more android projects in the feature. By the way, if you have an android application that needs to get developed, send us an email. We love challenges!
PS: To see the code and more screenshots check out our repository: https://github.com/zidarsk8/galaxyCar
The proper way of reading blogs
Reading blogs is something I believe every developer should do often. Not only is it a good way to broaden ones horizon and get up to date with all the great things happening round the world, you can also get in touch with the author and have a discussion about the subject in the comments.
Define the problem
The only problem I personally have with reading blogs is that it is really hard to focus on the content. While I am on the computer there are many distracting things going on. Twitter is buzzing, my nick is getting mentioned on IRC, a new email pops up etc. It is easy for me to ignore all those distractions when I am doing some real work, but reading a blog is not something I consider real work. The notifications are not the only problem. I find it really difficult to focus on a large wall of text on an LCD screen. My eyes start to hurt before I even start reading and the possibility, that I will stop, increases exponentially after each paragraph.
I have the same problems, give me a solution!
I solved all of the problems mentioned above by reading the longer blog posts on my Kindle. Now I primarily bought a Kindle for reading books. Where I am from, most books are rather expensive and the translations can sometimes be bad, especially with technical books on programming and the like. A kindle allows me to buy books easily and have them delivered to me in a matter of seconds.
Now to get back on reading blogs. Do I even have to point out that reading a longer blog post on an e-ink display is way more enjoyable than on an LCD screen? I also save a lot of time by sending blog posts to my Kindle during the day and then read a batch of them before I go to sleep. I can also get a good safety distance from all the distracting notifications of my laptop and read the blogs in peace, the way they were meant to be read.
How do you get the blogs on your e-reader?
There are many ways of getting a blog on your kindle. You can use the experimental browser to navigate to the blog site for instance, but I would not recommend that, as it can be a bit cumbersome. I found the solution that suits me best is a simple Chromium extension that sends the article (and just the article) to my kindle using my @free.kindle.com email address. For this I use an extension called Kindle It and I’ve been really happy with it, as unlike many others I’ve tried, it just works.
What are your thoughts on the subject? How did you read this blog post?
Published
The AMD Linux Drivers
A couple of days ago AMD released Catalyst 12.1 drivers for Linux. I have been looking forward to this release as I had a lot of issues with previous drivers, namely with gnome-shell support.
Why did I put myself through this?
Installing AMD drivers on Linux is never a pleasant experience and the open source drivers work out of the box, so why did I put myself through this? Well the open source drivers have a few shortcomings:
- Battery life: My laptop battery lasts roughly an hour longer on official drivers.
- GPU temperature: The core temperature is down to a pleasant 42 degrees C (was 60+ on open source drivers).
- I can now run more graphically intensive applications (yay games!).
Full of hope that this new release will fix all the issues I had with previous versions, I embarked on an epic quest to get it working on my laptop.
Installing proprietary drivers
To install the drivers I followed the steps on the Unofficial Wiki page for the AMD Linux driver. The steps themselves are pretty straight forward and I will not go into them here. Instead I will focus on everything that went wrong after I had the drivers installed.
After the reboot I got thrown into fallback mode and something was clearly wrong. Running fglrxinfo in the terminal gave me the following error:
X Error of failed request: BadRequest (invalid request code or no such operation)
Major opcode of failed request: 139 (ATIFGLEXTENSION)
Minor opcode of failed request: 66 ()
Serial number of failed request: 13
Current serial number in output stream: 13
A lot of googling later I found out that modprobe decided to blacklist the fglrx driver. This was probably due to a failed installation of a previous version. The bottom line was that the kernel module was not being loaded at boot which, of course, caused the drivers to fail. Thankfully the solution was pretty straight forward, I only had to open the modprobe blacklist file, located at /etc/modprobe.d/blacklist.conf and delete the following line:
blacklist fglrx
After another reboot the drivers loaded successfuly working and both gnome-shell and Unity desktop seemed to be working!
There were still some issues though
To my surprise both Unity and gnome-shell worked well on the 12.1 Catalyst drivers. Random crashes and visual artifacts were gone and shell animations (when pressing the <super> key) were fast and responsive. There was an issue with moving windows across the screen though. The animation was jerky and flickery and it annoyed me to the point that I started googling for a solution.
The solution for the Unity desktop is hidden away in CompizConfig Settings Manager, under OpenGl. I had to disable the option called Sync To VBlank. After that dragging windows across the screen worked as it should.
There is a similar solution for the gnome-shell desktop. I had to add the line:
export CLUTTER_VBLANK=none
to the end of the ~/.profile file and then everything seemed to be working. That was a fact until I tried to plug in my second monitor.
Multidisplay support
Cloned display worked out of the box, but I wanted a big desktop, spanning over both of my monitors. I opened up Catalyst Control Center (Administrative) (sudo amdcccle), went to the Display Manager page, selected Multi-display desktop with display(s) 1 and clicked apply. That caused the Catalyst Control Center to die silently without an error. I tried to enable multidisplay in the Displays application, where I got this message:
required virtual size does not fit available size:
requested=(3360, 1050), minimum=(320, 200), maximum=(1680, 1680)
Finally something I can google! A solution for this is to put the line Virtual 3360 1050 into the Display SubSection of /etc/X11/xorg.conf. My “Screen” section now looks like this:
Section "Screen"
Identifier "aticonfig-Screen[0]-0"
Device "aticonfig-Device[0]-0"
Monitor "aticonfig-Monitor[0]-0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Virtual 3360 1050
Depth 24
EndSubSection
EndSection
But this isn’t an optimal solution as it has a few issues:
- It only works if both monitors use the same resolution. In my case both monitors use 1680x1050 and it worked as expected, but a friend of mine was unable to hook up his 1920x1080 monitor beside his smaller laptop screen.
- When I unplug the second monitor, this forces the first monitor to the resolution of 1400x1050 (4:3) and I am unable to set the correct resolution neither in amdcccle nor the Displays application. This is why I have to comment out the
Virtual 3360 1050line every time I want to unplug the second monitor.
There is probably a way to solve both of these issues, but my google skills have failed me, any ideas?
EDIT: I managed to solve the both of these problems by copying an xorg.conf file from the Ubumtu 12.04 Beta 1:
Section "ServerLayout"
Identifier "aticonfig Layout"
Screen 0 "aticonfig-Screen[0]-0" 0 0
EndSection
Section "Module"
EndSection
Section "Monitor"
Identifier "aticonfig-Monitor[0]-0"
Option "VendorName" "ATI Proprietary Driver"
Option "ModelName" "Generic Autodetecting Monitor"
Option "DPMS" "true"
EndSection
Section "Monitor"
Identifier "0-LVDS"
Option "VendorName" "ATI Proprietary Driver"
Option "ModelName" "Generic Autodetecting Monitor"
Option "DPMS" "true"
Option "PreferredMode" "1680x1050"
Option "TargetRefresh" "60"
Option "Position" "0 0"
Option "Rotate" "normal"
Option "Disable" "false"
EndSection
Section "Monitor"
Identifier "0-CRT1"
Option "VendorName" "ATI Proprietary Driver"
Option "ModelName" "Generic Autodetecting Monitor"
Option "DPMS" "true"
Option "PreferredMode" "1680x1050"
Option "TargetRefresh" "60"
Option "Position" "1680 0"
Option "Rotate" "normal"
Option "Disable" "false"
EndSection
Section "Device"
Identifier "aticonfig-Device[0]-0"
Driver "fglrx"
Option "Monitor-LVDS" "0-LVDS"
Option "Monitor-CRT1" "0-CRT1"
BusID "PCI:1:0:0"
EndSection
Section "Screen"
Identifier "aticonfig-Screen[0]-0"
Device "aticonfig-Device[0]-0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Virtual 3360 1680
Depth 24
EndSubSection
EndSection
Why I chose Jekyll
Choosing a blogging platform that you like may seem trivial to some, but not to me. All the blogging platforms out there seem either too simple or too complicated for me. This is why I have always resorted to writing my own simple CMS, but the problem was that my own CMS was even worse than all the others. At first it seemed like it suits my needs but I ended up hating it nonetheless.
I tried really hard to get used to Wordpress, I really did! But in the end it just wasn’t working, here are a few resons why:
- Templating is a nightmare. I felt like I needed to invest a lot of time to get my site to behave the way I wanted too.
- The WYSIWYG editor is crap, but I wouldn’t blame WP for this one. I believe that all WYSIWYG editors (Word is another great example) are flawed. Sooner or later the editor will misunderstand what you want it to do and shoot you in the leg.
- The CMS seems bloated and I get lost in all those settings and sub-settings, plugins, themes and whatnot.
Jekyll to the rescue!
Jekyll is a simple static site generator. Basically you feed it a template directory with a page layout and some Markdown content and it spits out a static website which you can upload to your webserver.
It is really easy to install as well. If you have Ruby installed it is just a matter of getting the Jekyll gem. This is usually done with a single command:
sudo gem install jekyll
I actually ran into a little problem, the error message was:
ERROR: Failed to build gem native extension
It turned out that I needed the ruby dev package, the below command fixed my issue:
sudo apt-get install ruby1.9.1-dev
After that I was all ready to start building my new and shiny blog page.
It gets even better
Github provides something called Github:pages (GP). GP is basically a free static page hosting for your projects and/or personal page. It also has Jekyll built in which means that you simply put your jekyll source into a git repository, push it to a specified github branch and github will generate your blog page automagically.
Not only does this force you to keep your blogs in a git repository (which is a good idea by itself), it also makes for the most intuitive way of posting a blog post (well at least for a programmer like me).
Some more sugars
Have you ever wanted beautiful syntax highlighting on your blog? Well Jekyll does Pygments which means I can have beautiful syntax highlighting like this:
def prob42():
f = open('words.txt')
tri = 0
triangle = []
for n in xrange(1, 1000):
triangle.append(n * (n + 1) / 2)
for i in f.readlines():
for j in i.split(',"'):
w = j.replace('"', '')
x = 0
for k in w:
x += ord(k) - 64
if x in triangle:
tri += 1
print tri
I even heard there is LaTeX to PNG support, although I haven’t had the time to check that out yet.
There is still a possibility that I will start hating Jekyll after a few months of blogging. But that may just mean that I actually hate blogging. Hopefully this will not happen!
