Archive for category General

Boring Friday – What are you doing that is fun?

Suffering from a little burnout after delivering a few projects. For those coders out there, what are you working on thats fun / exciting?

I will start:

Favicon_normalFollowing up from my previous post, the most fun thing I did was compete in the Engine Yard Contest.. I created a python client, which communicated the results back to my webserver every 23 minutes via xml. On the webserver itself, I used the watch command to provide stats that auto update: ‘watch -n 30 “cat /tmp/results | sort | uniq | head”‘. The results had their score first, with lowest being the best like golf.

My favorite webpage I have viewed today has been the Arch Linux July Screenshots thread: http://bbs.archlinux.org/viewtopic.php?id=75154

Tags: ,

Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program

In this post we will cover how to make a basic GUI application using Mono along with Monodevelop. If you haven’t already, you will want to read part 1 and part 2 of this series before this article.

Monodevelop
Monodevelop is the tool we are using as our editor. This is Linux’s equivalent of Visual Studio. It can be used to code, debug and design your application, and can link in with revision control systems. This article was written using version 2.0, if your version is not 2.0 you may see slight differences.

Create your project
After starting Monodevelop, go to File -> New -> Solution. You will be presented with a prompt asking which kind of solution we are starting. Click on C# -> Gtk# 2.0 Project as shown below:

new-solution

Read the rest of this entry »

Tags: , , ,

Annoying people with code: A gentle introduction to C# and Mono

This is meant to be an introduction to C# and Mono. First, we need to download the mono runtime and compiler:

sudo apt-get install monodevelop mono-devel

For the purpose of this post, we are just going to create a simple program which prints out the text “Hello World”. Go ahead and make a directory for our project so we don’t make our home directory entirely too messy. I just make a directory called ‘mono’ under /home/sharms/mono for the duration of this post.

Go ahead and create a file called ‘helloWorld.cs’, and paste the following:

// Declare which namespace we want to use.
// This allows us to use Console.WriteLine
// instead of System.Console.WriteLine
// Basically like a python 'import' statement, or a
// php 'include' statement
using System;

// We create a class to contain it
class HelloWorld
{
    // Must have a main function as this is what is
    // first called when executing this
    static void Main()
    {
         // C# requires ; after statements
         // Actually output "Hello World"
        Console.WriteLine("Hello World");
    }
}

To compile it, run:

gmcs helloWorld.cs

This will generate a file called ‘helloWorld.exe’. To run it, type:

mono helloWorld.exe
Hello World

And there you have it. I also stumbled on a Makefile tutorial today, so we can make a simple make file (I won’t describe all of this, just look at how it’s used). The tutorial is at: http://www.wlug.org.nz/MakefileHowto

[sharms@sparrow mono]$ cat Makefile
COMPILER=gmcs

all: helloWorld.exe

helloWorld.exe: helloWorld.cs
	$(COMPILER) helloWorld.cs

clean:
	rm -f helloWorld.exe

.PHONY: all clean
[sharms@sparrow mono]$ make
gmcs helloWorld.cs
[sharms@sparrow mono]$ make clean
rm -f helloWorld.exe

Tags: , ,

Fedora 11 vs. Ubuntu 9.04

Put Fedora 11 on my laptop just out of boredom, some notes:

  • Fedora 11 SELinux by default: Cool but confusing
  • Fedora 11 repositories: Better selection than previous releases, still not as many choices as Ubuntu
  • Ubuntu still wins on the default menu organization for new users (just a bit easier to navigate)
  • Fedora bootup vs. Ubuntu bootup is about a wash, they both look good and are fast
  • Default themes: Neither will win a competition on looks, Linux Mint is much better looking than both
  • Yum vs. Apt: Yum was fast, but a lot of 404′s on the repositories (which is more of an issue of Fedora’s mirror infrastructure)
  • PPAs vs. ???: This is where Fedora appears (correct me if I am wrong) to have absolutely no answer to OpenSUSE and Ubuntu. In Ubuntu we can get up to date packages that were not yet officially released using PPAs. OpenSUSE users can download packages from the build service. Fedora really has nothing this fun (I am aware OpenSUSE can build Fedora packages, but the selection is not even close).
  • Support: Fedora is a distro that is on the cutting edge. It will never compete in support, but this is intentional.
  • Community: Ubuntu community is simply the biggest Linux community on the internet. Nobody is even in the same ball park. This also means that Ubuntu has much more “noise” than Fedora (ie people who contribute nothing and are generally factually inaccurate). Experts may like Fedora more because of the lack of this noise.

So if you are looking to try out Fedora, I don’t think you will gain or miss much. Personally I am going to put Ubuntu back on as I really love software from PPAs, and I love using apt just out of habit. But hope that helps someone who wonders what the differences are or what they are missing.

I have added a screenshot which is the default screen with Gnome-Do with docky theme, but this obviously works in Ubuntu also:

Fedora11

Tags: , ,

Connecting to Ubuntu from Windows

Recently I needed to connect to a Ubuntu box from a Windows machine because FGLRX just would not work with 3 monitors in surround view. Fortunately using a few tools made it much easier to interface with my Ubuntu box again.

Assumptions

  • Ubuntu system named ubuntubox with ip 192.168.1.2
  • Windows system named windowsbox with ip 192.168.1.3

Remote Access

For those of us who are comfortable with the command line, ssh is the only way to go. To make sure you have ssh installed, you can run (on your Ubuntu box):

sudo apt-get install ssh

This service should automatically start a boot up, and will allow you to open a terminal to access the command prompt. Now to access our ssh server, we need to download a ssh client for Windows. Look no further than PuTTY, which is free, open source, and easy to use. There are a few programs PuTTY provides, we just need putty.exe and optionally plink.exe (for next post in this series).

These can be downloaded at the PuTTY download page.

putty

Once downloaded, you can put putty.exe pretty much anywhere you can remember it. I just left it on my desktop and dragged the shortcut to my quick-launch bar. Double click putty.exe, and in the dialog box labeled “Host Name” go ahead and enter your Ubuntu box’s IP address.

Click “Open” when you are ready to connect, and it will prompt you for a username and password. You should already have a username and password from your Ubuntu install.

putty2

If you want your prompt to be colorful, you need to type ‘nano .bashrc’ at the prompt, and scroll down to the line that looks like “#force_color_prompt=yes” and remove the “#” character. After logging in it should now have colors. If you want other cool tips for your shell, I suggest you check out the Ubuntu Wiki as I wrote up a specification on making it more usable: Enhanced Bash.

At this point you should have remove access to your Ubuntu system.

Sharing Files

We need a good way to share files between these two systems. A lot of people will suggest Samba / CIFS (which is really a technical way of just saying Windows File Sharing). I think that Samba / CIFS lacks any technical merit, and is harder to configure. I am going to show you two ways of sharing files, both which use SSH.

WinSCP

WinSCP is basically CuteFTP or whatever FTP program you grew up with, but instead it works with SSH. It is incredibly easy to use. Go ahead and download WinSCP from their website. You can download either the portable executable (which means you can run it from anywhere without installing) or the full installer. Either one will work for our purposes.

The download page is at: http://winscp.net/eng/download.php. To connect from Windows to our Ubuntu system, go ahead and install the program (or not if you downloaded the portable version). Once you start it up, it should look like this:

winscp

Go ahead and fill in the IP address for your system. It is going to say it doesn’t know it’s key yet, go ahead and click Yes there. You will now see your home directory on your Ubuntu box and your Windows box. You can now drag files back and forth, and better yet, encrypted.

Something More?

As a programmer, one thing I need is a great editor. I happen to use VIM to code everything I make. VIM through SSH is ok, but one problem I have is I can’t use any of the really cool color schemes out there, as PuTTY is limited to 256 colors. There are some plugins out there which are supposed to convert the color schemes, but none works reliably for me. Luckily, GVIM is available for windows, so I went to their download page: http://www.vim.org/download.php and downloaded / installed it.

This was great, but for Django development I really wanted to edit the files in place, via a shared folder, instead of using WinSCP every 10 seconds (I use test driven development, as in I may change a file 5 times a minute). How do we go about using our SSH server as a shared folder under Windows? We can use the free / open source program Dokan.

Visit their download page, and retrieve the “Dokan library” and “Dokan SSHFS”. Their download page is at http://dokan-dev.net/en/download/. Install the Dokan Library first. After installing that, install Dokan SSHFS. Once installed, Dokan SSHFS will appear under your start menu. Go ahead and run it:

dokan

This should be a familiar pattern by now. Go ahead and set the “Host” file to the ip of your Ubuntu system. You will also need to provide a username and password. In the screenshot above you can see that my SSH server will be mounted as my N: drive now.

With SSHFS up and running, I can now edit files directly on my Ubuntu server. Combining that with GVIM, I can use an editor that provides excellent syntax highlighting:

gvim

In this screen shot I am using the Wombat theme for GVIM, and the Microsoft font Consolas. Consolas is freely available for Windows XP if you download the Office 2007 compatibility pack, or PowerPoint Viewer.

Tags: , ,

Network Manager vs. ConnMan

You know, there are many different programs in Linux that do the same thing. Gnome vs. KDE. Gnote vs Tomboy etc. ConnMan is no different, and people saying they just need to work on Network Manager have absolutely no grasp of how things work.

Python threads

Frequently I need to launch sub processes from Python. Sometimes these processes don’t work as expected, and end up blocking the program. If you want to launch a command from python, and cut it off after a certain amount of time, I recommend the threading module.

Here is how to limit the command to running for roughly 5 seconds:

#!/usr/bin/env python
import commands
import datetime
import time
import threading

class runCommand(threading.Thread):
    def run(self):
        status, output = commands.getstatusoutput('sleep 8')

if __name__ == "__main__":
    startTime = datetime.datetime.now()
    maximumRunTime = datetime.timedelta(seconds = 5)
    mythread = runCommand()
    mythread.start()

    while 1:
        if mythread.isAlive():
            print "Thread has not returned yet..."
        else:
            print "Thread is all done."
            break

        if (datetime.datetime.now() - startTime) > maximumRunTime:
            print "Thread has ran too long, giving up."
            break

        time.sleep(1)

    print "Program done"

So when we enter main, I assign the current time to startTime. Then I define maximumRunTime as a difference of 5 seconds. The thread is started, and every second we check to see if it is still running. If it is, we go ahead and check how much real time has elapsed.

Tags: , ,

NCPFS

NCPFS each release generally is sent out completely not working until I fix it. If you have C experience, you can help me fix up this source. I have started a github.com project called ‘ncpfs-ng’. Here I will be committing my bug fixes. There are about 2 trillion compiler warnings that need to be addressed, so any help is welcome. If you are interested or have a patch, you can reach me at sharms at ubuntu dot com.

Immediate goal is fixing the package on 32-bit systems Jaunty and up, as GCC changed a lot since the Intrepid release, causing issues:
https://bugs.launchpad.net/ubuntu/+source/ncpfs/+bug/328020

My debdiff there does make it work for amd64, but i386 users still have no luck. Github page is at: http://github.com/sharms/ncpfs-ng/tree/master

Tags: , ,

Boot times: Does anyone actually care?

There is focus on Karmic to boot fast, 10 seconds or so. My question is, does anyone out there actually care about boot times?

My big LCD Vizio TV takes 10 seconds or so to turn on. I don’t complain. My Directv receiver box takes over a minute to configure it’s satellite access. My stove takes 5 minutes to preheat.

The point being, nobody sits there and just watches their computers boot. I don’t watch my dell mini 9 boot exclusively, I turn it on, and focus on something else like TV or whatever else I am doing at the time.

More to the point, who is rebooting and why? I think at this point in computers, people suspend, not shutdown. That’s what all of the Mac people do atleast.

I just hate to see people focusing on issues which don’t solve any fundamental problems that critics point out about Linux in general, and instead focus on the mundane.

To the Anti-Ubuntuone trademark brigade

Instead of focusing on UbuntuOne, how about taking a look at this website: http://www.hmrgroup.co.uk/

Their logo is the trademarked Ubuntu logo. Now thats productive.