Innovation

This has given me much to think about:

The natural tendency of most organizations is to restrict choices in favor of the obvious and the incremental. Although this tendency may be more efficient in the short run, it tends to make an organization conservative and inflexible in the long run. Divergent thinking is the route, not the obstacle, to innovation.

– from “Deign Thinking for Social Innovation” by T.Brown, J.Wyatt

Netherpad

A little over a month ago, I sat down and started working on something I’m calling Netherpad.  The idea is loosely based on etherpad, though I’m implementing it on .NET using ASP.NET MVC 4, SignalR, and some TypeScript.

The main technology that allows this live shared collaboration is called Operational Transformation.  I’ve had it on my list of things to learn for several years now, and now I’m starting to wrap my mind around it.  What I’m finding is that it’s not as difficult as I thought it would be.  I found a simple implementation of the algorithm in JavaScript called jinfinote. Going through this code made it pretty easy to understand what was going on.  I had to modify it to first use SignalR instead of straight web sockets, and that required a pretty good understanding of what was going on, especially since SignalR uses GUIDs to identify users instead of straight integers.  This has been causing some pain, but I’m working around it.

After nearly all day of working on it, I got the basic live collaboration working, as can be seen in this video:

It’s an ugly hack, but it works.

As the caption says, it’s ugly and requires some trickery in the underlying javascript, but it’s working.  It was a truly magical moment for me to type a key in one browser and see it show up in the other browser.

Moving forward, I’m working on porting the original javascript to TypeScript and will be mixing in some linq.js in order to make up for the fact that Javascript doesn’t have a native dictionary object.  So far, I really like working with TypeScript; it’s a huge improvement over plain Javascript.  Porting the code has also forced me to gain a good understanding of the algorithms involved.  I’m almost at the point where I can throw out the original implementation and rewrite it in a way that makes more sense from a .NET / TypeScript standpoint.

There is still a lot of work to do on the project, but so far, it’s pretty exciting.  Be sure to check out the code if you wish, but beware, it doesn’t really work right out of the box at the moment, though I will be working to make that happen soon.

Introducing Nenetics

This weekend I spent a little bit of time working on the C# genetic algorithm library I’ve created called ‘Nenetics.’ I created an introductory video that demonstrates where I’m at right now. Still have a long ways to go until I get where I want to be:

The Artificial Selection civilization seems to be behaving pretty good at this point, though as the genome size increases, it’s becoming difficult to get past around the 89% fitness hump. I think the problem there is in the breeding code, so I’ll be testing a few things with that. After that, it will be on to open simulations, which I’m really looking forward to.

As always, code is up on github.

Trick for guessing hex color values

I was recently doing a bit of design work on Grease when I was reminded of an old trick I’ve figured out that some people aren’t aware of.  As a young developer hex codes for colors in html / css seemed completely strange.  I knew that #ffffff was white and #000000 was black, but for anything else, I needed to look it up either on the web, or fire up Photoshop or paint.net which could give me the values I wanted (now there are also browser extensions for that sort of thing).  I remember one day I was working on something and I started noticing a pattern.  That’s when I realized the ‘trick.’  Here it is:

Each group of two digits is a RGB value, in that order, with digits from 0 to F

Pretty simple, right?  So if you want something red, you make the ‘R’ values F and leave the rest as zero:

#FF0000

If we plug into your style you get the result:   red.

You can do the same thing with Green (G) and Blue (B).  If you want gray, make all six digits the same.  As the numbers go higher, the color get progressive lighter.  Same thing with RGB.  To use the example above, if you used, say ‘5’ instead of ‘F’ (i.e.’ #550000) then you’ll get a darker red.

In order to make different colors, you first need to forget what you learned in kindergarten.  You think Blue and Yellow make green?  Well, yeah, but here you’re starting with Red, Green, and Blue.  You don’t have yellow and you already have green.  So how do you make yellow?  You combine Red and Green: #FFFF00.   Here is the full set of simple combinations:

ColorCombos

With those simple combinations, you now are on you way to easily getting colors ‘close enough’ to keep coding and have a rough idea of where you’re at color-wise.  More importantly, once hex codes become more than magical incantations to get the desired effect, you can start experimenting without needing to go out to another sources.  Want orange?  Maybe that will be some combination of red and green.  You can start experimenting and discover you were right.  A good orange is at #FF9900. 

If you run into trouble, all those other tools that you’ve used in the past are still available, but what I’ve found is that as I use this trick, I’ve needed to rely on those tools less and less.  Good luck!

Grease released

It’s been a year and a half since I’ve mentioned it here, but I’ve just made a general release of Grease. As you can see, it now comes with it’s own nifty website. In the next few weeks, I hope to release a Chocolatey package for it as well. I’m going to wait until Google stops saying this site distributes malware before I release that, though. (As a side note: aren’t the google webmaster tools awesome?)

This release has been a long time coming. There hasn’t been a lot of development on the software, but it hasn’t needed it. I’ve made a few performance tweaks, and there are a few more things I have in mind that should help the app start faster. I’ll probable be posting on those as I get them implemented.

I did have to go through philosophical transition. Grease has always been created to be simple. When I first started writing it, I did so with the specific purpose of not introducing features that I didn’t need and would just create bloat. I think I’ve achieved exactly what I was looking for. A few months ago, though, I received a pull request from someone on github. They had added a number of things, like the ability to change from random to ordered, and had made a few UI tweaks. I accepted the pull request, but when using the app, discovered that it really had lost what I was aiming for. Tonight I removed those additions and returned the project to it’s original aims. In the future, I will probably only be aiming for performance tweaks, especially when dealing with large libraries.

If this kind of app interests you and you find it useful, please let me know! You can reach me on twitter @charlesj.

Adventures in building better Authorizations

Warning: This post contains ugly code and half-ideas.

The problem

I have a confession.  I’ve never used the built in ASP.NET Membership framework.  Early on, it was a pain trying to figure out how to get it integrated with your own database, and later on, I was so used to rolling my own that I didn’t worry about it.  A little more than a year ago, though, I realized this was pretty foolish, so I decided to take another look at it.

Unfortunately, what I found didn’t suite me.  It may work for some applications, but not for what I’m building.  I needed something with some finer control.  Here are a few things I wanted that it didn’t have:

  1. Ability to combine webforms and windows authentication (some users from each)
  2. Ability to store passwords using the bcrypt hashing algorithm (for future safety).
  3. Finely tuned permissions that only give access to a subset of resources in a resource type.

The last one is especially important.  On the basic applications you see in demos, it’s not important at all.  If you have a blog, most people have read access, few people have write access.  For blog demos, users that have read-write access to only a subset of blog posts doesn’t come up very often.  But this is a very common issue in every single web app I’ve ever developed.   Having an “EditBlogEntry” role doesn’t cut it.  That role needs to be able to check to make sure that some user can edit a specific blog entry.

Recently, I’ve set out to tackle that problem.

What I’m working on

It became apparent to me pretty quickly that to get something like this to work, each role would need to be able to execute some unique code to be able to run the logic to insure that a user can access what they’re trying to access.  I would call these “Permissions.”  Permissions would eventually be able to be assigned to both individual users and groups of users, but to begin with, to keep it simple, only users.

Here are some of the requirements:

  1. Users (and groups) can have many permissions (many-t0-many in the db)
  2. Permissions will have unique  checking code for each one (therefore, each permission is a different class).
  3. A filter will be per-controller or per-method (in MVC) and will know which permission that method or controller requires (it will be a string, most likely).
  4. The filter will create an instance of the permission, pass in the values needed and then execute some function to find out if the user is authorized.

I started writing some code.  One issue I realized right away: EF expects one table per class.  With each permission being a different class, and wanting an arbitrary number of classes, this would be a problem.  Instead, I would make all permissions inherit from an interface and store only certain information from the class in the database.

Currently, here is the website permission:

When the applications starts up, it reflects over itself to find all classes that implement IWebsitePermission, and it inserts a record into the Permissions Database (if it doesn’t already exist) for that permission. The database stores the Permission Name, Option, Whether it has an option, description, and System.Type.

To give you an idea how this permission is implemented, here is a partial implementation that checks to see if a user can edit a specific webpage:


 

Okay, there is a lot of bad code in this file. Ini my defense, for now I’m just trying to get this idea to work. Then I’ll work on fixing the rest.  Above all, the entity framework code in the snippet should be outlawed.  And there’s no exception checking!

So far, I’m pleased with how this method is turning out.  It seems like I’m on the right path, but I’ve got some major architectural issues:

  1. Where should the permissions be hosted?  In the Models namespace?  In the Website namespace?
  2. Is there a better way to pass in the request information and logged in user information?
  3. How is the best way to break up permission access?  Does there need to be a permission for add/edit/delete, and every sub modication (e.g. add version to webpage)

I have a long ways to go here, but this idea has been floating in my head for a few years now, so it’s nice to start making some real progress.

A Summer of Awesome

This summer is shaping up to be really great.  I have two major trips planned.  The first is next week to Madison, Wi, for the Games+Learning+Society conference.  This will be my first major academic conference and I couldn’t be more excited.  One of the themes for my summer is gamifying education, a topic that apparently will receive some staunch criticism from a giant in the field.  I am going to be very interested in what Dr. Gee has to say.

This trip is also going to be great because the two people that really got me into this field are going to be there: Constance Steinkuehler and Sean Duncan.  Their 2008 paper “Scientific Habits of Mind in Virtual Worlds” [PDF] was posted to reddit (or somewhere I happened to stumble upon) pre-press and it opened a new world to me.  Since then, I’ve earned my M.Ed., hope to start my Ph.D. soon, and I have no doubt that my career will be focused on this area.

My next major trip will be in July, as I head off to The Amazing Meeting!  I know every year this conference is packed with awesomeness, but I can’t help but feel like this year is the best yet.  Just take a look at their list of speakers.  It’s going to be my first time to Vegas, and I’m kind of skeptical that it’s all that great for someone like me.

I have a few big projects I’m working on this summer.  I’m not ready to talk about Democritus in depth, yet, especially without hearing the criticism I will hear next week, but I am excited about it so far.  My gut tells me that this is something that is really needed and will be huge, but I also realize that I must be skeptical of my gut, as it tends to be wrong.  I will go ahead and offer a short explanation of the project.

Democritus is a next-generation Learning Management System that includes social networking and game mechanics as core features.  On the technical side, it is an HTML 5, with no java / flash / other third party plugins.  I’ve said for years that BlackBoard is crap, so I’m finally doing something about it.

Is it plagiarism if a robot created it?

I’m in the process of grading the final exam I give for my class.  Included in the exam is a question I wrote that was meant to demonstrate their understanding of plagiarism.  Here is the question:

Suppose 30 years from now you receive a paper from one of your students of such quality you suspect they didn’t actually write it.  When confronted, they admit that they had their robot “Curtis” write it for them.  They argue that since it wasn’t another person who wrote it for them, it’s not plagiarism.  Do you accept their paper?  Justify your answer.

As I’m grading, I was noticing a disturbing tendency to agree with the student.  Finally, one of my students’ answered in a way that really demonstrated what their thinking was, and it came down to the way they defined plagiarism.  If they defined it as ‘taking work not your own and claiming that you created it’ they denied the paper.  If they defined plagiarism as ‘taking another person’s work and claiming it as your own’ then they would agree that the student was correct that it’s not plagiarism, but wouldn’t accept the paper.

So in the end, it really hedged on the presence of “person” in the definition.  They don’t imagine robots fitting the description of ‘person’ so it wouldn’t be plagiarism, as long as their definition of plagiarism included the word ‘person’ in it.  I just find that incredibly interesting.