Posts Tagged tutorial

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: , ,

Make your bash shell cool again

I originally wrote a spec in 2006, but it never actually made it in.  You can see it at https://wiki.ubuntu.com/Spec/EnhancedBash .  The good news is, it is just as relevant today. Hopefully these tips will make your life easier, I use them on all of my systems.

Use the page up key to complete the command
What this does is, if I type ‘ssh ‘ then hit the page-up key, it will complete the line to the last time in my history file that I typed ssh. Hitting page up again will go to the 2nd to last time I typed it. Incredibly handy if you ever type the same commands more than once. This actually has been the default of SUSE based distributions for quite some time.


echo "\"\e[5~\": history-search-backward" >> ~/.inputrc
echo "\"\e[6~\": history-search-forward" >> ~/.inputrc

Increase history size
Now that you have the pageup / pagedown bindings to auto-complete your history, you are going to want to store more of it. You can store the previous 1000 commands using this.


echo "export HISTSIZE=1000" >> ~/.bashrc
echo "export HISTFILESIZE=1000" >> ~/.bashrc

Color grep
Using the following bash alias, you can make grep highlight the word it is matching in color. I grep about 10000 times a day, so this makes it a bit easier on my eyes to focus where I need to:


echo "export GREP_OPTIONS='--color=auto'" >> ~/.bashrc

Command matching
There was also someone who contributed more sane command matching (ie what happens when you hit the tab key a bunch). I use these also, which tell it not to do stupid things like try to match hidden files and to display both files if they are ambiguous:


echo "set match-hidden-files off" >> ~/.inputrc
echo "set page-completions off" >> ~/.inputrc
echo "set completion-query-items 350" >> ~/.inputrc
echo "set show-all-if-ambiguous on" >> ~/.inputrc

Tags: , , , ,

Old dog, new trick

I commonly have 4-6 ssh sessions open at once, and when I lose my VPN connection, they just sit there until their timeout hits. I was looking for a way to stop the session, and CTRL-C, CTRL-D, CTRL-Z and everything inbetween didn’t work.

I found salvation in: ‘~.’

That will exit your session no problem.

Tags: , ,