void ValentinesDay()

Color roseFlower = Color.FromArgb(246,74,138);
Color violetFlower = Color.FromArgb(111,111,255);
bool isSugarSweet = true;
int you = 2;

Learn to program in the Linux shell from August 19!

bash_classes_gif

Linux scripting and programming courses @091labs.
Four weeks, four classes, beginning August 19, 7pm.

Subjects include:

  • The fundamentals of computer programming.
  • Installation and maintenance of a Linux system.
  • Bash shell syntax, structures, and pipelines.
  • Practical tasks for shell scripts.
  • Passing data to and from binary programs.
  • Binary shell programming with C#/Mono.

Requirements:

  • Laptop computer.
  • Installation media (USB key, CD-R or DVD-R).

Cost:

  • €40 general rate for the full workshop.
  • €20 reduced rate for hackerspace members and students.

For more information, contact or visit:

Bare blurbs aside, I plan to use Ubuntu for this, and start off by showing people how to install Linux on their laptop. If they survive that (and the scary liability release for my assistance), delve into Boolean logic, basic structures, and hopefully devote most of my time to doing cool and practical things with the Bash shell.

I don’t intend to handhold through the Linux installation: If you want to program or script with Linux, I expect that you at least be comfortable enough to partition your laptop and install it. I really recommend that you come into this workshop with either a function Linux installation, OS X installation, or a Cygwin installation so you can begin working immediately – example code I use will be usable in both environments (except for the respective path differences).

The Big Topics of the shell workshop include:

  • Refreshment on elementary subjects: Boolean logic, Linux and its shell.
  • Input and output (STDIN, STDOUT, STDERR), and redirection.
  • Pipelines, and using them to build workflows.
  • Parsing, searching, and appending to files.
  • Coding standards and best practices.
  • Everyday uses and examples of shell scripts.
  • Including your own binary programs (C#/Mono) in your workflow. I will cover basics of this.

Come one, come all, and geek out to your heart’s content. :)


Round down a decimal of arbitrary precision to n.

For Darren. :D

using System;

public class DecimalRound {
	static void Main(string[] args) {
		// args[0] is the decimal to round to.
		// args[1] is the decimal.
		int sentinel = 0;
		// 1. Split the number. decimalStr[0] is the leading number.
		string[] decimalStr = args[1].Split('.');
		// 2. decimalStr[1] is the decimal.
		int[] decimalInt = new int[decimalStr[1].Length];
		// 3. Parse sentinel value.
		if (!int.TryParse(args[0], out sentinel))
			Fail(args[0], true);
 
		// Convert the decimals characters to ints, after validation.
		int n = 0;
		foreach (char a in decimalStr[1]) {
			if (ValidChar(a))
				decimalInt[n] = CharToInt(a);
			else
				decimalInt[n] = -1;

			n++;
		}

		// 0-4, round down. 5-9, round up.
		for (int i = decimalInt.Length - 1; i > sentinel; i--) {
			if (i > 0) {
				if ((decimalInt[i] >= 0) && (decimalInt[i] <= 4))
					decimalInt[i - 1]--;
				else if ((decimalInt[i] >= 5) && (decimalInt[i] <= 9))
					decimalInt[i - 1]++;
			}
		}

		// Output. 
		Console.Write(decimalStr[0] + ".");
		for (int i = 0; i <= sentinel; i++)
			Console.Write(decimalInt[i]);
		Console.WriteLine();
	}

	static bool ValidChar(char a) {
		// Validates that it is 0-9, and not any other character value.
		switch (a) {
			case '0': return true;
			case '1': return true;
			case '2': return true;
			case '3': return true;
			case '4': return true;
			case '5': return true;
			case '6': return true;
			case '7': return true;
			case '8': return true;
			case '9': return true;
		}

		return false;
	}

	static int CharToInt(char a) {
		// Converts, if valid. 
		return Convert.ToInt32(a - '0');
	}

	static void Fail(string a, bool b) {
		// Spit out error message if you pass invalid characters.
		// b = true if this is fatal.
		Console.WriteLine("{0} is not valid.", a);

		if (b)
			Environment.Exit(1);
	}
}

[MUD] Muddy mudness

I’ve thrown a lot of idle thoughts at the concept of the MUD project, and it keeps coming back to me that I would be literally out of my depth. I have, to date, scarcely finished one barely-working shooter, let alone delved into the intricacies of a graphical multiplayer role-playing game.

I am going to throw myself into an easier intermediate project, a Linux arena shooter game. The core principles of the arena game will carry over to the MUD:

  • Peer-to-peer and client-server multiplayer connectivity.
  • Persistent characters, and player progression.
  • AI pathing.
  • And more…

My first steps are to finish the design document and figure out the Monogame networking API. :)