Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Thursday, February 26, 2009


Thanks to the original author of the code (google m7tr1x)..

I had some great fun looking at the code, understanding how this effect works, and refactoring.

The original code is below.. I suggest scrolling down, and looking at the refactored code and pictures describing how the effect works.

Enjoy!

#define readkey

using System;

namespace m7tr1x
{
    class Program
    {
        static void Main(string[ ] args)
        {
            Console.Title = "tH3 M7tr1x 3ff3<t";
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WindowLeft = Console.WindowTop = 0;
            Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight;
            Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth;
#if readkey
            Console.WriteLine("H1T 7NY K3Y T0 C0NT1NU3 =/");
            Console.ReadKey();
#endif
            Console.CursorVisible = false;
            int width, height;
            int[ ] y;
            int[ ] l;
            Initialize(out width, out height, out y, out l);
            int ms;
            while ( true )
            {
                DateTime t1 = DateTime.Now;
                MatrixStep(width, height, y, l);
                ms = 10 - (int)( (TimeSpan)( DateTime.Now - t1 ) ).TotalMilliseconds;
                if ( ms > 0 )
                    System.Threading.Thread.Sleep(ms);
                if ( Console.KeyAvailable )
                    if ( Console.ReadKey().Key == ConsoleKey.F5 )
                        Initialize(out width, out height, out y, out l);
            }
        }

        static bool thistime = false;

        private static void MatrixStep(int width, int height, int[ ] y, int[ ] l)
        {
            int x;
            thistime = !thistime;
            for ( x = 0 ; x < width ; ++x )
            {
                if ( x % 11 == 10 )
                {
                    if ( !thistime )
                        continue;
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.SetCursorPosition(x, inBoxY(y[x] - 2 - ( l[x] / 40 * 2 ), height));
                    Console.Write(R);
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                Console.SetCursorPosition(x, y[x]);
                Console.Write(R);
                y[x] = inBoxY(y[x] + 1, height);
                Console.SetCursorPosition(x, inBoxY(y[x] - l[x], height));
                Console.Write(' ');
            }
        }

        private static void Initialize(out int width, out int height, out int[ ] y, out int[ ] l)
        {
            int h1;
            int h2 = ( h1 = ( height = Console.WindowHeight ) / 2 ) / 2;
            width = Console.WindowWidth - 1;
            y = new int[width];
            l = new int[width];
            int x;
            Console.Clear();
            for ( x = 0 ; x < width ; ++x )
            {
                y[x] = r.Next(height);
                l[x] = r.Next(h2 * ( ( x % 11 != 10 ) ? 2 : 1 ), h1 * ( ( x % 11 != 10 ) ? 2 : 1 ));
            }
        }

        static Random r = new Random();
        static char R
        {
            get
            {
                int t = r.Next(10);
                if ( t <= 2 )
                    return (char)( '0' + r.Next(10) );
                else if ( t <= 4 )
                    return (char)( 'a' + r.Next(27) );
                else if ( t <= 6 )
                    return (char)( 'A' + r.Next(27) );
                else
                    return (char)( r.Next(32, 255) );
            }
        }

        public static int inBoxY(int n, int height)
        {
            n = n % height;
            if ( n < 0 )
                return n + height;
            else
                return n;
        }
    }
}
Here is the refactored code:
using System;

namespace matrix
{
    class Program
    {
        // fields
        static Random rand = new Random();
        
        // properties
        static char AsciiCharacter
        {
            get
            {
                int t = rand.Next(10);
                if (t <= 2)
                    // returns a number
                    return (char)('0' + rand.Next(10));
                else if (t <= 4)
                    // small letter
                    return (char)('a' + rand.Next(27));
                else if (t <= 6)
                    // capital letter
                    return (char)('A' + rand.Next(27));
                else
                    // any ascii character
                    return (char)(rand.Next(32, 255));
            }
        }

        // methods
        static void Main()
        {
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WindowLeft = Console.WindowTop = 0;
            Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight;
            Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth;
            Console.WriteLine("Hit Any Key To Continue");
            Console.ReadKey();
            Console.CursorVisible = false;
            
            int width, height;
            // setup array of starting y values
            int[] y;

            // width was 209, height was 81
            // setup the screen and initial conditions of y
            Initialize(out width, out height, out y);

            // do the Matrix effect
            // every loop all y's get incremented by 1
            while ( true )
                UpdateAllColumns(width, height, y);
        }

        
        private static void UpdateAllColumns(int width, int height, int[] y)
        {
            int x;
            // draws 3 characters in each x column each time... 
            // a dark green, light green, and a space

            // y is the position on the screen
            // y[x] increments 1 each time so each loop does the same thing but down 1 y value
            for ( x = 0 ; x < width ; ++x )
            {
                // the bright green character
                Console.ForegroundColor = ConsoleColor.Green;
                Console.SetCursorPosition(x, y[x]);
                Console.Write(AsciiCharacter);

                // the dark green character -  2 positions above the bright green character
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                int temp = y[x] - 2;
                Console.SetCursorPosition(x, inScreenYPosition(temp, height));
                Console.Write(AsciiCharacter);

                // the 'space' - 20 positions above the bright green character
                int temp1 = y[x] - 20;
                Console.SetCursorPosition(x, inScreenYPosition(temp1, height));
                Console.Write(' ');

                // increment y
                y[x] = inScreenYPosition(y[x] + 1, height);
            }

            // F5 to reset, F11 to pause and unpause
            if (Console.KeyAvailable)
            {
                if (Console.ReadKey().Key == ConsoleKey.F5)
                    Initialize(out width, out height, out y);
                if (Console.ReadKey().Key == ConsoleKey.F11)
                    System.Threading.Thread.Sleep(1);
            }

        }

        // Deals with what happens when y position is off screen
        public static int inScreenYPosition(int yPosition, int height)
        {
            if (yPosition < 0)
                return yPosition + height;
            else if (yPosition < height)
                return yPosition;
            else
                return 0;
        }

        // only called once at the start
        private static void Initialize(out int width, out int height, out int[] y)
        {
            height = Console.WindowHeight;
            width = Console.WindowWidth - 1;

            // 209 for me.. starting y positions of bright green characters
            y = new int[width];
            
            Console.Clear();
            // loops 209 times for me
            for ( int x = 0 ; x < width ; ++x )
            {
                // gets random number between 0 and 81
                y[x] = rand.Next(height);
            }
        }
    }
}

how it works:

The screen draws each column.. my screen is 208 wide.. so it loops 208 times, each time drawing a bright green character, dark green character, and a space.



The second loop.. the y value has been incremented by 1.



The 3rd loop



Enjoy!
Comments [1] | | # 
# Thursday, January 22, 2009

A Big thanks to everyone who came to my presentation tonight on nUnit:

In his mission to become a great developer, Dave will entertain you with 'How nUnit Inspired an Awesome Rock Song'.  Dave will demonstrate the time and heartache savings (which allowed time and energy to do the music).

Tools and technoloiges (ab)used in this talk will be:  C#3.5SP1, VS2008 Express, PHP, JSON, MySQL, and nUnit.  I'll demo the Awesome Rock Song too!

If you've heard of unit testing, this presentation is for you.  Bring your laptop and take away your first working unit test project.  Your future development projects will get easier with testing.


Lake Tekapo, NZ

Here is the powerpoint presentation: HowNUnitInspiredAnAwesomeRockSong.zip (1.1 MB)

Here is all the source code (compiled and run on VS2008Express using .NET3.5SP1).  Nunit 2.4.8 installed.: nunitPresentation.zip (606.4 KB)

We discussed favourite tools and keyboard shortcuts, in relation to being a Tenfer (programmer that is 10 times as productive as others):

blogs.msdn.com/saraford - Visual studio tips and tricks

www.launchy.net - quick launcher
CLCL - www.nakka.com/soft/clcl/index_eng.html - Clipboard multi

Visual Studio Keyboard Shourtcuts
Ctrl Shift B - Build
Ctrl K, Ctrl C - Comment
Ctrt K, Ctrl U - Uncomment
F5 - run
F10 step through when debuggin
Ctrl B, Ctrl T - Bookmark Toggle
Ctrl B, Ctrl N - Goto next bookmark
Ctrl L - Delete Line

Alt F, J - Recent projects open
Ctrl K, Ctrl D - Format a document

Ctrl M, Ctrl M - collapse / expand
Ctrl M, Ctrl O - collapse all

Split screen

Windows Shortcuts
Win L - Lock
Win E - Explorer
Win D - Minimize all window.. press again to restore
Alt D - Goes to explorer bar (try in explorer, and firefox).. tab to autocomplete
Alt F4 - Close down window
Ctrl Shift Esc - Task manager

Google tricks:
 - golf   - don't include golf in search
 "search for entire phrase" - searches for that entire phrase
 advanced settings to search in a date range

Powerpoint
  B - black screen
  W - white screen
  type slide number and press enter to go to that slide

Resharper
  Makes life faster

stackoverflow.com - great programming question and answer site




Comments [2] | | # 
# Friday, January 16, 2009
( Testing )



Girl and man looking towards Mt Cook, NZ.

To get nUnit working on VS 2008 Express, firstly download and install nUnit.

Make a new console application.  Add the 3 nunit references you see below



Open up the .csproj file.. in my case in: C:\code\stuff\HowNUnitInspiredConsole\HowNUnitInspiredConsole\HowNUnitInspiredConsole.csproj

Where you see... add in the two Startxxx lines.

 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\NUnit 2.4.8\bin\nunit.exe</StartProgram>
   
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

Here is my first unit test for a web app:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Web.Script.Serialization;
using System.Web.Util;
using System.Net;
using System.Web;
using System.IO;
using System.Diagnostics;

namespace HowNUnitInspiredConsole
{
    class NUnitConsoleRunner
    {
        [STAThread]
        static void Main(string[] args)
        {
            NUnit.ConsoleRunner.Runner.Main(args);
        }
    }

    [TestFixture]
    public class FormTest
    {
        // 1 is dev / local
        // 2 is test
        int debugbit = 2;

        string targetUri = "";
        string targetUriNoHTTP = "";

        [SetUp]
        public void Init()
        {
            if (debugbit == 1)
            {
                targetUri = "http://192.168.139.128/drink/";
                targetUriNoHTTP = "192.168.139.128/drink/";
            }

            if (debugbit == 2)
            {
                targetUri = "http://www.davemateer.com/drink/";
                targetUriNoHTTP = "www.davemateer.com/drink/";
            }
        }

        [Test]
        public void helloWorld()
        {
            WebClient client = new WebClient();
            StreamReader reader = new StreamReader(client.OpenRead(targetUri + "test/helloWorld.php"));
            string responseFromServer = reader.ReadToEnd();

            Assert.AreEqual("Hello World", responseFromServer);
        }
    }
}



When the nUnit gui popped up, make sure it gets the correct .exe file.  I had to do a project add assembly, while the application was running.

Run your application which should pop up with something like this:


Comments [0] | | # 
# Sunday, November 09, 2008

Why ProgramGood.Net?

To have fun!
Explore the world of programming
To inspire, educate and entertain



On the way to Machu Picchu, Peru


What inspired you to start this?

Google searching - "How to Become a Great Programmer"
Great Article - 10 Years norvig.com/21-days.html
http://steve.yegge.googlepages.com/practicing-programming
http://graysmatter.codivation.com/HowIAmBecomingABetterDeveloperPart1OfInfinity.aspx

Highlights were:
Read a chapter a week from a programming book
Code the examples
Listen to Podcasts and Screencasts
Learn a new language every year!
Learn about the business of software development
Teach / Present topics
Have a mentor and be a mentor

What Topics Do You Want To Cover?

C# Language - am working through Head First C# 3.5
OOP Concepts
Types and References
Encapsulation
Inheritance
Interfaces
Collections
Files
Exceptions
Events and Delegates
LINQ

Recursion
Anonymous Types
Delegates
 
DataAdapters etc..Datasets (are they evil?)

PHP
- A useful language!
Web Services
Design Patterns
Unit Testing
ORM
Libraries
IDE's / Tools JSON/XML

Reporting Services 2000 / 2005 / 2008 - Everyone likes reports!  Good programmers have good tools.
 How to produce good reports

How To Develop Software
XP Approach vs classic Waterfall Approach
StackOverflow example of how to develop software

Test Driven Development - TDD

Testing
nUnit
nUnitASP
waitr
TestDriven.Net
NCover
cruisecontrol.net
dbunit

SourceControl
 TortoiseSVN and Subversion

Bug Tracking
Excel!

CodeGenerators / ORM / Helper
Entity framework - EntityDataSource and GridViews/DetailsViews/FormViews
Dynamic Data web projects - create all standard list/details/edit/delete pages
LINQ to SQL - don't use?

CodeSmithnHibernate
Subsonic
openaccess?
TypeMock / RhinoMocks
NHibernate
Lightspeed
CSLA

Tools
Visual Studio
  Tips on how to use Visual Studio...
Resharper
reflector

App Types

 Console
 WinForm
 WebForm
 Webservice
 WPF
 Silverlight

Patterns - What are they.. families
MS Patterns and Practises group
Enterprise Library
MVC Framework
MVP
IoC

Web ASP.NET

 Framworks and how to do stuff quickly
 Membership
 MasterPages

Open Source Projects - understand others code

 ProjectRun
 dasBlog
 examples from www.asp.net
 codeplex
 BackgroundMotion
 DineOut
 StockTrader
 Vertigo

Fun Challenges

 Project Run
 Project September
 Charity Project
 Coding Challenge (code breaker)
 Perl/Python fun ones
 Mapping - Jamie
 Project Infotainmnet
 Music Project - KitInABox
 Code Monkeys (how long to create Shakespeare)
 Treasure Sprint - treasuresprint.blogspot.com

Coding Competitions

Programmers / Developers I Admire and why

 Scott Hanselman
 JP Boodhoo
 Ron Jacobs
 Carl Franklin
 Scott Gu
 Scott Stanfield
 Adam Cogan
 Vertigo
 Peter Jonesie
 Bill Gates
 James Kovacs
 Mario Szpuszta
 Matthew Macdonald
 Ken Schwaber - scrum
 Rocky Lhotka - csla

Traits of a great Programmer

 Curiosity
 Humble
 Learn about successful projects and read source code
 Play with others code
 Have readable code

Great Books and Why

 Mythical Man Month
 Head First C# Programming 3.5
 Joel Spolskys books
 The Pragmatic Programmer
 Software Craftsmanship
 Coder to Developer
 ** - how quiet conditions are super important... 2 person office.. close doors.
Great Blogs and why
 stackoverflow
 Joel Spolsky
Thinking in Code

Languages - where they came from.. strengths and weaknesses

 OOP / Procedural / Functional
 C#
 VB
 Java
 Python
 Ruby / RoR
 PHP
 SQL
 F#
 oCaml
 Prolog
 C / C++
 Lisp
 Fortran
 Cobol

Fun Geek Language

  YAGNI - You Aint Gunna Need It
  This smells - something doesn't feel right


Where did The Domain Name Come From?

Came from iWantToProgramGood... Written English has never been my strong point, and I never seem to wrote in sentences... only statements... followed by dots....and when I went to look at domain names, register.com suggested ProgramGood.Net.. How appropriate!

Lets start the journey!


Venezuela, sunset.  About 4500m.
Comments [0] | | # 
# Saturday, November 08, 2008
( Events )
Christchurch CodeCamp 2008 was a resounding success:


Setting up Friday evening Andy, MattT, MattS.. a giant puzzle!


Here is Mats entertaining presentation on SQL 2008 for Developers:  CodeCamp_MatVelloso.zip (941.34 KB)

Other great presentations were:

Ivan Towlson - Thinking in WPF
http://hestia.typepad.com/flatlander/2008/11/christchurch-code-camp-2008---thinking-in-wpf.html

Andy Scrase - A C#3.0 Whirlwind Tour
http://buildwith.net

John Rusk - LINQ to SQL Optimation
http://dotnet.agilekiwi.com/blog/2008/11/linq-to-sql-presentation.html

Ben Reid - Could Computing
http://cloudservices.blogspot.com

--------------------
After lunch

Lightning:
Gary Payne on jQuery
http://sharethelearning.blogspot.com/2008/11/jquery-introduction-talk-at.html

Matt Tester
http://pureblue.wordpress.com/2008/11/04/christchurch-code-camp-design-with-paper-prototypes/

Matt Smith - Sharepoint Development
http://blog.mattsmith.co.nz

Del Robinson - Tour of BI Projects and technology
http://www.omegatech.co.nz/powerpoints/Business_Intelligence_StatisticsNZ.ppt

Dave Roys - Navision Perspective
http://gaspodethewonderdog.blogspot.com/2008/11/codecamp-2008-nav-resources.html

Kirk Jackson - Overcoming your Web Insecurity
http://pageofwords.com/blog/2008/11/01/ChristchurchCodeCampOvercomingYourWebInsecurity.aspx
http://pageofwords.com/blog/2008/11/02/LearningsFromChristchurchCodeCamp.aspx



MattS.. The sign says Recovery








Comments [0] | | #