Why do companies recycle mobile phones?

I bet many of you, like me, also has many old phones tossed away in a drawer somewhere. You can actually trade in these phones for money (well, some phones that is). I recently found out there is a booming market in the UK where companies are buying cell phones from people (some may have to be in working condition and some will have to be at a certain age).  For example The O2 phone company will give you £29.00 ($4,000.00 JMD) for a first generation iPhone with scratches and general wear and tear. Just like with these cash-for-gold merchants, I’d rather find out the source, or what exactly they are doing with them (if a company buys your phone for x, there is a chance they are making 2x from it). So what do these companies do with these phones?

  1. Refurbish and re-sell. – Some companies may do this themselves or they will send them back to the manufacturers to be refurbished.
  2. Recycle – Yes, some companies actually do recycle the materials if the phones cannot be refurbished.
  3. Re-sell locally –  Some smaller companies will just sell the phone back for little profit
  4. Re-sell in the east – Larger companies will either refurbish or just sell the phones to eastern distributors in countries like China or Africa where there are many low communication and low income communities. The buying price is determined by the buying price in the East.

I cannot do #1 and #2, #3 will be a waste of time and #4 will probably cost me more money than what I’d get for my phones. I’d rather sell my phones to one of these companies rather than their source, money and time is saved when these companies do these kind of business in bulk.

How to use wikipedia during black-out day

I’m so disappointed in how wikipedia went about their so called ‘black-out day’ to protest against SOPA. Instead of a server side redirect, they used client side?

Turn Javascript off. In Chrome, you can browse to this settings page: chrome://settings/contentExceptions#javascript and enter http://en.wikipedia.org/ as one of the Hostname Pattern and set it to Block. Remove this tomorrow.

Use cached versions from google. Most of you will find wikipedia articles from google. Click cached and you will have access to that data.

 

Tags:

Storing object as profile data in ASP.NET forms authentication cookie

In ASP.NET, you are normally given just a string to store additional user data using the FormsAuthenticationTicket, this ticket also takes a UserId, but most times we need to store some form of structured data in cookies, such as an object.

The solution to this is JSON, serialize the object to a JSON string, save it as the UserData, then de-serialize it back to the object when needed.

Setting up the object and IIdentity

To make retrieving the data easily, I would create a custom identity that has the properties of the object you are storing. For eg.

You should also have a cast, that will convert the User Identity to your custom Identity. So I made an Extension to do this:

Setting the Data

You should have a FormsAuthenticationService, and it would look like this:

 

Using the Data

Now its simple to retrieve this data from the cookie:

You can use this inside your controller or your views, such as the above was used in the layout to welcome the user by their FirstName and LastName.

HTML5 canvas cookbook, beginners guide to game development with html5

I recently read through HTML5 Canvas Cookbook , a very good book from complete newbs to advanced game developers looking to get started in creating HTML5 games. If you have some form of game dev experience before, its very easy to catch on, all this book will do is teach you the API with some web dev techniques such as using it in an MVC type of approach. It also targets just normal html5 canvas development, for example, creating charting controls or just simple animations. Basically, this book just replaces a beginners book for getting started in flash development.

What I really like about it is that it starts out with just drawing simple geometry and shapes, giving code examples and images of how it should look. It then moves on to videos and image manipulation inside the canvas, can be used for sprites and possibly image based animations. (I wouldn’t recommend video as animation).

The next chapter was about translation of the geometry, of course knowledge of linear algebra is needed here. Then the next chapter moves on to actual animation of the geometry, moving your objects around, tweening, etc. Basically  gives you the code to replace all that the flash tool would give you if you were doing this in flash.

The other chapters are practical examples, such as building charts and graphs, then a small game. I just scanned over charts, but the game part was awesome. The example the author gave uses all the techniques we need to build a 2d game, with the engine and all. (no physics though but that is common sense if you can manage from here). You can tie in Box2D.JS with your game easily.

The book even attempts to introduce you to webgl (building and animating a cube), I didn’t read this chapter though, I have no intention of learning any WebGL programming whatsoever until its released properly.

In all, this book is like a tutorial/reference manual that I will surely go back to when I start my little 2d game engine. The table of contents flows and makes sense so its easy to find what you want. I think this book could be read in a few hours by a beginner and they can also get started building 2D games right out of the box.

Tags: ,

Google Interview Question: Get Count of an element in a sorted array

So a few weeks ago I did an online technical interview with Google (I was contacted by one of their recruiter). The main question centred around “Find the occurrence of an element in a sorted array”. Now the interviewer wanted the most optimal solution, which is O(log n). This means there shall be no linear counting of any sort, whether after a binary search or before it.

I created a CountSorted() extension method in my C# utility library that uses just this method. Its alittle more complex because I implemented it with IComparable<T>. I’m sure I will find use for this type of count sometime in the future as the built in one for .NET is O(N). All that is currently needed is for me to implement the extension on IEnumerable<T> instead of IList<T> and accept predicates as parameters.

Codez

The main code file could be found here. (I wouldn’t use this in production code if I were you right now.)

The most optimal solution I could come up with is using a binary search to find an index of the value we are counting, then find the left edge and right edge by using modified binary searches, then minus them to get the count.

So I basically had 3 methods, the main method:

Find left edge method:

Find right edge method:

This code could be done better, so if you can optimize it, please do a pull request on github. A few test cases are here for this algorithm.

Tags: