Showing posts from 2011

ChatGPT - How Long Till They Realize I’m a Robot?

I tried it first on December 2nd... ...and slowly the meaning of it started to sink in. It's January 1st and as the new year begins, my future has never felt so hazy. It helps me write code. At my new company I'm writing golang, which is new for me, and one day on a whim I think "hmmm maybe ChatGPT will give me some ideas about the library I need to use." Lo-and-behold it knew the library. It wrote example code. It explained each section in just enough detail. I'm excited....It assists my users. I got a question about Dockerfiles in my teams oncall channel. "Hmmm I don't know the answer to this either"....ChatGPT did. It knew the commands to run. It knew details of how it worked. It explained it better and faster than I could have. Now I'm nervous....It writes my code for me. Now I'm hearing how great Github Copilot is - and it's built by OpenAI too...ok I guess I should give it a shot. I install it, and within minutes it'

Ruby on Rails Testing tools

These are a summary of the tools I've been able to get working on my Ubuntu 11.10 machine for use while testing & developing with Ruby on Rails, while going through the book Ruby on Rails 3 Tutorial, M. Hartl rspec rspec-rails autotest spork for up-to-date installing instructions, go to

Rails on heroku

Just found out that the new Rails 3.1.3 can be deployed to heroku using 'heroku create --stack cedar' instead of 'heroku create'.  By doing this, the only thing you have to change in the Gemfile is delete the line 'gem sqlite3' and add the following: group :development, :test do   gem 'sqlite3' end group :production do   gem 'pg' end then commit and push to heroku.

Deploying a Rails 3.1.1 app to heroku using Ruby 1.9.3 and Ubuntu 11.10

Hello friends. :P I (FINALLY) got a Rails app working on heroku!  But it took some doing - even the basic template rails app wouldn't work on heroku!  And the getting started walkthrough on the heroku website didn't tell me what to do about the errors.  I'm still not sure if it's my OS that makes this trickier than advertised, or if it's the version of Ruby or Rails that I'm using...or maybe it's heroku's problem?  Oh well.  But here's my setup, and if you've got the same then this tutorial should work for you.  This tutorial assumes you've already setup your heroku account. Operating System: Ubuntu 11.10 Ruby version : 1.9.3p0 Rails version : 3.1.1 Source control : Git  First off, if you haven't already, generate a stock app, and enter its directory : >rails new my_app >cd my_app Next, initialize a new Git repository, and add everything to it : >git init >git add . >git commit -am "Initial co

Adapter Design Pattern

The adapter pattern is an extremely useful pattern for a few reasons. The reason I like it so much is because if you understand it, then you understand the concept of Dependency Inversion (the "D" in SOLID object-oriented design). Dependency Inversion is an object-oriented principle which states that in code, higher level modules should not depend on lower level modules. Instead, lower level modules should depend on higher level ones. Let's say you've got one higher level object that requires a lower level object to do it's job. But the lower-level object is likely to change or be swapped out for another. Here's the bad way to do it: namespace HigherLevelModule { public class HigherLevelObject { ...... public void Run() { LowerLevelObject obj = new LowerLevelObject(); string result = obj.GetSomething(); Console.WriteLine(result); } } } namespace LowerLevelMod

Command Design Pattern

The command pattern is best used when you have a command that must be executed by one object, while another object has the responsibility of deciding WHEN that command will be executed. The three entities associated with the command pattern are: client : the object that CREATES the command object and assigns it's receiver receiver : the object that HAS the method that will be run invoker : the object that DECIDES WHEN the command will be run Now let's look at an example. You have an IDE, and the 'undo' command is extremely important. Every action that is performed on the IDE has a method called undo() on it. But the actions have to be stored somewhere after they perform their task though, so that it's possible to call the undo() methods later, right? The solution is to push each action onto a stack when it's run, and register a listener for the 'undo' keyboard-combination/menu-item. The listener will pop() the stack, and invoke the popped ac

Flyweight Design Pattern

So you have a group of objects that can be reused, but each time you use one you have to create it first. The problem is that instantiating these types of objects is expensive, and you don't want to instantiate the same kind every time you need it. Enter Flyweight design pattern. With this pattern, the trick is to create a new object only when you've never created that same type of object before - if you HAVE created it before, then simply look it up and use the one that's already instantiated. Here's some code: public class Flyweight { public static Dictionary _Table = new Dictionary (); public ISomething GetSomething(int key) { ISomething something; if(_Table.TryGetValue(key, ref something)) { return something; } else { something = new Something(key); _Table.Add(key, something); return something; } } } What this code does is ensure that t

Factory Design Pattern

The factory pattern is used when you want to separate the creation of objects from where they'll be used. For example, say you have one object that must get a Triangle object and draw it on screen. It doesn't care about what the triangle's state is, just that it has a void Draw() method. Suppose further that you have many types of triangles, and they can all be 'drawn' onscreen. In order to separate the creation of triangle objects from the caller, we would use the Factory Design Pattern: 1.) Create an interface called ITriangle, with one method : void Draw() 2.) Have all types of Triangle implement ITriangle. 3.) Create an interface called ITriangleFactory with 1 method: ITriangle GetTriangle() 4.) Create a concrete 'factory' class for each type of Triangle, each of which implements ITriangleFactory, and returns a new instance of their respective triangle in their implementations of GetTriangle()...since each Triangle type implements ITriangle,

Coding Fun

I was coding at work the other day and was having a great time. Things were moving fast, and no roadblocks were coming up. Then I asked myself : what's the difference between what I'm doing now and what I'm doing when I do when I'm not enjoying a coding session (other than the fact that I had no major roadblocks appearing)? The answer was pretty clear. I was writing tests first! It wasn't always easy; often it's difficult to think about how I should test a certain functionality when I haven't even designed a solution or written the method or section of code...but it usually pays off afterwards, when I know exactly what is required by the caller/user (should be in the test) and I've already come up with an interface for the functionality (designed by writing the test). After that, all that's left for me to worry about is solving the problem and turning that nasty red 'test failure' light to a bright, tangy green. Just the fact that green

A quick reminder

Not much to do with technology, but a helluva lot to do with progress. If you've got any goals in your life right now, you need to read this .

Deploy an ASP.NET MVC 2 Web site on IIS 6.0

Hey sports fans! Today I was given the task of deploying my web site to my development machine. With MVC 2 plugged-in to Visual Studio 2008, it should have been a cinch (with VS2010 and IIS7, it IS), but I ran into some roadblocks I thought I'd blog about. So all I thought I would have to do is right click the ASP.NET project in the solution explorer while the solution was open in Visual Studio, and click publish, and then specify the directory to publish it to. Visual Studio was supposed to do the rest. But ACTUALLY it was much tougher. First I had to open the properties of the ASP.NET project, and go to the "Web" tab, and set it to run on an IIS server instead of a development server. THEN I took the step of right clicking the project and (publish...)ing it. But everytime I tried to navigate to http://localhost/ it would give me a weird error saying the directory was inaccessible. The problem was that IIS had no mapping for paths without extensions. you see

Rate my design

Yesterday I worked on refactoring one of the components in my ASP.NET MVC2 project. If anybody's reading and knows anything about software, I'd be glad to have your feedback on the design. The controller handles all the logic, taking requests from the web and processing/delivering the response. My models are basically just data-transfer objects, and the Views are each strongly typed to a model, so that it can access values given by the controller. There are 3 different types of views, one inside the other. The outermost view is not type cast to any model, it just calls some javascript that asynchronously loads _ServerView views into a div element. The _ServerView's are strongly-typed to ServerModel's. The _ServiceView holds the smallest bit of information, and they're loaded one-by-one for each _ServerView. The _ServiceView is type cast to a ServiceModel. Using this structure, we can have any number of _ServerView views on a page, and any number of _Ser

Models, Views and Controllers

The MVC design pattern is one of the most widely used design patterns around, but it's talked about so much by experienced developers that sometimes noobs can get mislead as to the meaning and purpose of it. So here's an overview of the design pattern and what it's parts are for. We'll start with a high-level flow of events: 1.) The user interacts with the user interface, which sends a message to the controller. 2.) The controller receives the message, converts it into a form that the Model can understand and interact with, and then sends it to the Model. 3.) The Model accepts the new information, and makes changes to it's own state reflecting the new information that it's just received. 4.) The view detects the changes in the Model, and updates itself accordingly. 5.) Repeat 1 - 4. This is very high level and can change a little with every implementation, but the overlying theme and idea is there. Also, the way in which the view detects the chang

Connecting to an API written in C from C#

The last couple of days have been trying for me at work. Fortunately, I learned something. I was working on an application that needed to connect to a 3rd party API that was originally written in C - like a billion years ago. There was good documentation on the software, but in order to connect to it in C#, I had to go online and find out how from somewhere else. So here's what you do: First, make sure the API was installed on your system, so that the dll's are registered in the GAC. Second, start a new project in C#, and create a new class. Make sure to import "System.Runtime.InteropServices". At the top of the class definition, do something like this: [DllImport("User32.dll")] public static extern int MessageBox(int h, string m, string c, int type); Now, you'll have to know the signature of the methods you want to use from the API first. Anyway, once you declare that the function you want to use is defined externally, and you've t

TryRuby today!

Evening code fans. I'm making some progress on a software system that I'm building at work, and I've started to enjoy the process of finding a problem, creating a solution, and writing code to represent what I've come up with. But now I wanna try something new... I've been hearing a lot about Ruby on Rails in recent times, and I'm highly interested in it at this point. For those of you who don't know, Ruby is an object oriented programming language, but it's different from Java and C# in that it's a scripting language, so it doesn't get compiled down to machine code before it's run. "Rails" is a framework written for the Ruby language that makes it ridiculously easy to create websites in a Model-View-Controller sorta way. Just to get a basic web server up and running requires only 2 super simple commands on the command line! A Rails webpage differs from ASP.NET MVC (the stuff I'm using at work) in that it doesn't r
Today I populated an html div element asynchronously using jQuery and JSON in my ASP.NET MVC2 project. Now, when you were 10 years old, did you think you'd one day find a sentence like that above interesting? I bet not. But here's why it is (lol) : In MVC you're allowed to mix javascript code (client side) with C# code (server side), but you have to understand where each part of it is being run. Here's the code (the important parts of it anyway): Client side (mostly): <script type="text/javascript"> $(document).ready(function() { $.getJSON('<%=Url.Action("GetJsonDriveList", "DiskSpace") %>', function(jsonData) { for (i = 0; i < jsonData.length; i++) { $.get('<%=Url.Action("LoadDiskSpace", "DiskSpace") %>?serviceAddress=' + jsonData[i].serviceName, function(data) { $("#ma

Mono for Android

I'm excited. I've recently been looking for a way to motivate myself to learn better software development practices, and stumbled on something called mono. No, I didn't get it from kissing someone. Mono for Android is sort of a Visual Studio plug-in which allows one to develop Android applications in C# ! I'm SOOOO happy about this. Personally, I learned Java in school and tried out Android development for a couple weeks, and liked it. Unfortunately, Java is going the way of the dinosaur, and it seems that .NET is taking it's place. That's why I decided to pursue learning C# instead of Android. Now that mono has arrived and (hopefully - I'm updating the API's as I type) works, I can pursue BOTH Android development AND .NET ! Basically this means I can get good at working for the man, and developing for myself. I'm super excited. For a brief history of mono's inception, check out this blog:

App.Config files

Dear all, when you use a config file for a Visual Studio application, make sure to do a few things: 1.) Make sure to create an identical app.config file for your test project. Otherwise, when running tests, the config file will not be found. 2.) If you're going to use ConfigurationManager, you have to add a reference to it under the references tab in Solution Explorer. Cheers!

NAnt for automating builds in C# works fine....

I've been learning NAnt the past few days, and it's really quite simple.  Unfortunately, using it with NUnit isn't.  I'm supposed to be able to use NAnt to build my projects automatically and test them too, all with one quick call to a batch file: ./build.bat test where build.bat just calls nant.exe and passes it a buildfile, which is an xml file that includes "targets" for nant to run.  NAnt compiles my project and my test project just fine, but then when NUnit runs, I get some messed up errors.  I can run my tests properly in Visual Studio using ReSharper, and they behave properly, but it doesnt work on the command line using NAnt...what the crap is up?! A couple notes for you: my folder structure is as follows : src : contains application projects in one folder (app) and test projects in another (test) build : should be deleted and rebuilt every time NAnt runs config : contains config files for the project tools : contains the NAnt folder and the

SQL Server 2005 Hidden Install of Express Tools

A few weeks ago I was given the long-winded task of installing all of the necessary software on my new remote developer cpu at my shiny new job.  All went well until - GASP! - SQL Server 2005 refused to complete its installation. Now there were actually 2 problems with the install.  You see, it would hang while the status window read "Setting File Security" and it stayed there for what seemed like forever.  This was happening because the remote machine was connected to a network which was monumentally large (it's a pretty large organization) and the install was trying to find all the nodes in the network.  There's a patch for this type of problem that can be used with the installation, but if this is the only problem, the user can also just wait it out.  Which is what I chose to do.  And then the real problem showed up. After 2-3 hours of waiting (I had other work to do..honest) the installation finally "completed" by giving me an error message saying so

Adobe Flex 3.0 - Passing parameters to event listeners - actionscript

So I just started this job, and I'm writing an application that lets users view photos and tag them, giving descriptions of the tags as well.  I was trying to add an event listener to a Text object, when I realized there was no way to add a parameter to it!  Because the addEventListener function goes like this: var itemToPass:Object; textObject.addEventListener(MouseEvent.MOUSE_OVER, callbackListenerFunction); there was no way to pass a parameter, except for the event object, which is passed automatically.  Of course you could use an anonymous function for the callback, like this: var itemToPass:Object; textObject.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event):void {     callbackListenerFunction(itemToPass); }); And this will work in many cases.  But the underlying problem is still there!  You see, if you change the value of itemToPass later on in the current code block, then the value that's passed into callbackListenerFunction is ALSO changed!  The

Hosting a Website Right on your Windows Machine!

Hey cyberfreaks! Okay, today my bro showed me how to host your own website off of your own computer...and it's REALLY easy, if you've got the right tools.  FYI this post is really for my own reference, but if you have Windows with Internet Information Services (IIS) installed, then this is a quick and dirty tutorial to get to hosting your own site off of that cpu you're reading this post on...right now!  Here we go... First find your network/router/home's IP address (visible to the entire internet): 1.) Go to, click 'SHIELDSUP!' in the 'Services' drop down menu, and then click proceed. 2.) Now click the 'All Service Ports' button. 3.) Your computer/network/router's IP shows up (the one visible to the entire internet).  Copy it somewhere safe. Second, you must register a domain name: 1.) Go to and click the link near the bottom left that says 'Dynamic DNS Service'. 2.) Follow the directions and get

Scrum Master - Agile Methodologies

I was searching for videos and information about agile software development to help me better understand why it's so popular these days, and why I should learn more about it, and I stumbled upon this video. It explains, very elegantly, the agile development practice called SCRUM.  If your into software dev. it's a must-watch!