17 Feb 2015, 12:52

Javascript Equality Operator Grids

Javascript gets some bad press these days especially over how its comparison operators work.

I decided to extend Craig Gidneys example and added ===, !=, !== <, <=, > and .= comparisons.

Rows are the left side operand and columns are the right.

Source code on jsfiddle

16 Dec 2014, 22:34

Directed Graph of hubski users created with D3

Using some c# code to scrape hubski.com I was able to produce a pretty basic directed graph showing users follower connections.

Source code on github

Demo version

Advanced Demo version

I started off by scanning a users profile and recording various pieces of information such as: - Age in days - Number of followers - Number of people followed - Number of badges received.

I then looped over each of that users followers and recorded the same information, and then their followers, and then their followers… you get the idea.

I ended up thousands of accounts which was good but most of them only had 1 or 2 followers indicating a low level of social integration. I filtered out most accounts with less than 25 followers (a few did make it in) in order to represent the core social group members.

I graphed the data using D3 into a force directed graph that included all of the connections (follows) between each of the gathered members. There is some gravity applied to the area which results in the larger (more followed) users being drawn towards the center while the smaller users encircle them, like satellites basking in the glow of a shining sun, or hornets buzzing around fresh manure.

It’s a work in progress, search needs to be fixed…

21 Jul 2013, 15:03

Functional javascript using underscore

Functional javascript using underscore

Why?

A little while ago I picked up Functional Javascript by Michael Fogus. I’m only part way through it and to be honest I should probably have waited until I finished it before starting this post but…

There is a central theme to this book which intrigued me, indeed its one of the main tenets of functional programming. It can be summed up in this quote: >“It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.” - Alan Perlis

This is very different concept to what is normally seen in large enterprise level projects and applications. I have to say that I have spent a large amount of time writing code to map one model to another and back again. Its not fun. This functional stuff might be on to something.

What?

Well Michaels book uses the underscore library for all of his examples and its a really powerful tool. I have started using it here and there on smaller projects and the more I use it the more I like it.

How?

Project Euler is probably the go-to set of problems when developers try to learn a new language or framework. I don’t see why I should be any different. I have started a small project to play around with this and you can see it over on github.

Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.

Can be solved with a few lines of code like the following: return _.reduce(_.range(0,1000), function(memo, number){ if( number%3===0 || number%5==0) return memo+number; return memo;} );

Testing

Unit testing javascript has come a long way in the last few years and I have added a simple QUnit test runner to the repository.