The colorful wolf

February 25, 2011

A new home on the web

Filed under: Tech — randy @ 15:44

Hi everyone, I will no longer be updating this blog. Please go over to my new place to read more 🙂

This blog moved to



February 22, 2011

Cold Cold Holland

Filed under: Dutch,Tech — randy @ 13:20

It’s freezing again, which means that I am once again too hot. This may sound like a contradiction, so I will explain. When it’s freezing my parents turn up the central heating, which creates a fairly nice temperature throughout the house, but in my room (which is directly under the roof) it gets too hot. It doesn’t help that I have a PC in the room that’s always running at 100% capacity. Today I added this optimization between my balcony door and PC:

No, I did not drill that hole there just for my PC. In the summer that tube is connected to an airconditioning unit. In winter, I can use it to cool my PC and prevent the room from heating up too much. Results so far: CPU temps have dropped ~4C and the GPU fan is running at 40% instead of 44%. Meh.



Bitcoins again

Filed under: Tech — randy @ 2:42

I would just like to summarize the post below: I made money out of thin air while I was sleeping. Thank you.

February 21, 2011

Thoughts on Bitcoin Mining

Filed under: Tech — randy @ 21:43

Alright, I wrote about Bitcoins before, but I never really understood it very well. Bitcoins are a digital ‘currency’, that is, digital money that is generated by making your computer do a whole lot of CPU/GPU-intensive calculation. The introduction to Bitcoins is probably best done by Wikipedia’s article on Bitcoins, which explains quite well how they can be used. You may ask why this is interesting. Well, I just made $400 by generating and trading in Bitcoins, much like a foreign exchange market. Here’s my thoughts.

In December 2010 I used one of the websites that allow trading in bitcoins for US dollars, MtGox. Getting the money there from a European bank account is either very difficult, very high in fees, or both. I planned to exchange $1000 for bitcoins, but I chickened out at the last minute and tried it with $100 instead. The exchange rate at that time was about 0.25 dollars to one bitcoin. Last week, about 2 months since that investment, the exchange rate soared at 1.04 dollars for one bitcoin. I missed my cashing-out window a bit and it soon dropped back to ~0.8/0.9, but still, the gains were huge, and I very much regret not investing $1000.

Let’s start at the beginning. What are bitcoins? Essentially, they are hashes of numbers, a mathematical function that is easy to calculate in one way, but very difficult to calculate in the other. It takes tremendous to predict, given a hash of a number, which number originally belonged to it. Vice versa, you have no idea what hash you are going to get until you actually calculate it. This is the essence of a ‘raw’ bitcoin. The bitcoin network gives out ‘challenges’. An example is “find me the numbers that generate hashes whose numerical value is less than a certain amount”. Because you don’t know what the output of the hash function will be, your pc will just have to generate (semi-)random numbers, hash them and compare the output. If you’re lucky, one of those hashes is indeed the answer to the challenge, in which case it will be transformed into bitcoins.

So, for some reason I don’t quite understand, the bitcoin network uses a ‘difficulty’ setting. This basically regulates which hashes will be turned into bitcoins. You can think of the coin generation happening in rounds. The client knows which round it’s on because it has a history of all the generated blocks. And given that the round is x, only hashes with a numerical value lower than y will become valid bitcoins. This difficulty level is increased every couple of rounds, with the goal of always generating roughly the same amount of coins in the same amount of time. As far as I can tell, this is probably being done to prevent the market from suddenly being flooded with a whole lot of bitcoins, which would severely destabilize it. Since all clients are bound to this difficulty setting, it’s pretty much impossible to generate massive amounts of coins all at once.

As a side note, I’d like to mention that the bitcoin network is quite crucial to validating this money. Each node in the network has the complete history of bitcoins and transactions. And because each client is running the same code, they know how to reject fake coins. It is very feasible to generate a fake coin and push it to the network, but it would be completely useless because you wouldn’t be able to spend it. The network also knows about the history of each bitcoin, which makes it even more difficult to mess with.

Probability is what makes this process interesting. As I mentioned before, the difficulty level pretty much determines how many percent of hashes will become bitcoins in that round. So at that point it’s just a matter of probability. For example, if only 1 in 2 million total hashes is a hash that can become a bitcoin, and your computer can calculate 2 million hashes per second, then you will definitely have found the bitcoin after one second. But there’s also a 50% chance that you’ll have found it after 0.5 seconds! Because of this even slow computers can participate. Even though they are very unlikely to find a bitcoin, multiply that chance by the amount of time spent, and eventually everyone will hit the jackpot. (Note: the difficulty becomes increasingly higher each round, so if you’re not calculating fast enough the chance that you won’t find any hashes before the round is over becomes higher. So you do need to keep up with the network).

There are risks. Although each client uses their own unique combination of variables (eg. their account number, history of transactions etc.), there is a small chance that other people will be calculating the same hash as you. So if they find the bitcoin first, you’re screwed. This hasn’t happened to me yet, but it could. It’s all about probability.

One of the most interesting recent innovations, is the introduction of clients that generate their hashes on the graphics card – GPU miners using OpenCL. Amazingly, the fastest graphics cards are 10 to 100 times faster than the fastest CPUs available (for calculating hashes, anyway). My Intel i7 950 can generate  about 18 million hashes per second, but my Radeon HD6870 graphics card does 230 million, more than 10 times as fast as my CPU. Using the probability calculator here you can estimate how long it will take you to find a valid hash, currently worth 50 bitcoins. (The amount a valid hash is worth halves every x rounds. So far, about 110000 rounds have taken place, and the value of newly generated coins is scheduled to be halved at round 200000-ish).

When I first found this out, I was seeing dollar signs in my eyes and planning my trip to Hawaii. After all, it’s free money, right? All you have to do is run your PC and it generates money. If the exchange rate keeps around $1 per bitcoin you’re earning $50 a week if you use one PC. Add another graphics card, a couple more PCs, and you can basically multiply that amount by whatever hardware you throw at it. I calculated how much money I would spend on electricity, and it’s only a small portion of the profits. Believe me when I say that, given that like me, you pay ~$0.25/KWH and the USD/bitcoin exchange rate stays the way it is, you will make way more money from the generated bitcoins than it will cost you on electricity.

But there’s two major catches, and possibly a third one too. First of all, there’s the very real possibility that the bitcoin value will go down. It’s not really worth $1.00 if you only spent $0.25 generating it. As more people generate coins, the market will be flooded with coins being offered without people wanting to buy them. After all, why would you buy if you can just generate them? I think this is a very real possibility, despite the people at the bitcoin forums being very optimistic. Some analysts are predicting that the exchange rate will soar up to $10 per coin. I really can’t see how given that there is as of yet so little demand for them.

The second big issue is the difficulty factor of the network. Every iteration it becomes harder and harder to find the suitable hashes. It takes me on average 8 days to find a winning hash and be awarded 50 bitcoins. As more people join the network, more bitcoins will be found, and the difficulty factor will be increased. It won’t be long from now until it takes me 16 days to find the right hash. It’ll just keep increasing, keeping the amount of bitcoins in the system very stable, but the amount of bitcoins awarded to each individual becomes less every time. This seems a bit odd to me.

The third thing that worries me and that might grow into a big issue is the popularity of the bitcoin system. As I mentioned before, the more people join, the smaller the individual payout becomes. If all of these bitcoins are traded for USD then the exchange rate will end up very poor indeed. But if people could actually use the coins to pay at actual shops for actual products and services then the currency would be a lot more stable. There’s a whole list of sites that accept payment in bitcoins, and that list is growing every day. But if there will never be any mainstream acceptance then who knows what will happen to the value of a bitcoin. It probably won’t be good.

I should note that a nice quirk of this system is that anyone who has bitcoins has a vested interest in helping the system expand and catch on. Because once bitcoins gain more popularity, their value will go up, and everybody who owns bitcoins becomes richer. It’s a very simple idea, and it’s super effective.

Personally I’m not sure if it’s a good idea either to buy bitcoins with USD or to generate them yourself. While I expect them to lower in value this year, they still might be a good investment on the long term. Technically I’ve never seen such a robust system. I keep thinking of ways to sabotage it so I can get rich quick, but I really can’t think of any. It’s secure. The bitcoins themselves are stable, even if the market isn’t. It’s an emerging market, and I think it might well be worth the risk. As for me, I’m going to buy a second graphics card with the money I’ve earned from the bitcoins. That way I can generate coins twice as fast, as well as enjoy a good game every once in a while 🙂

If my explanation is wrong in any part, please let me know. I tried to explain it to the best of my ability, but I may have overlooked or misexplained some part. Thanks.

February 18, 2011

Sony Sony Sony…

Filed under: Tech — randy @ 0:45
Tags: ,

The Sony PS3 ‘scandal’ is still going on, and I’m still quite interested in how it develops. Press online is reporting massively on Sony’s poor security measures when dealing with credit cards. Apparently they are sending credit card info as plain-text over https. In other words, they are sending text over an encrypted connection! That’s not a security risk at all. Every time you input your credit card number into a browser it is sent using the same security measures.

However, if you install a custom OS on the PS3, it is possible to get the SSL certificates used in the encryption, thus getting the credit card numbers. The computer equivalent of that would be installing spyware or a virus that finds the card number on your PC and sends it. There’s no difference, really, and I don’t think Sony is to blame here at all.

The interesting bit though is that there are so many hackers, devoted hackers that spent a lot of time working on custom OSes on the PS3, that are hating Sony’s guts right now for making yet another stupid decision towards its more creative customers. There are a lot of people that are very motivated to publish negative information about Sony, and the online media is more than eager to jump on it.

That being said, the kind of attitude that Sony is showing does mean that I won’t buy a PS3, even though I really want to play Gran Turismo 5. Purely subjectively speaking, I’m not very fond of Oracle (especially after that Hudson/Jenkins debacle), but I quite like Java (and use it). I don’t like Apple as a company but I love the iPad (and am even a developer for it >_<;). But what Sony is doing is just beyond all boundaries. The line must be drawn somewhere, and for me it lies right there. No PS3 for me.


February 16, 2011

Fun with Square Codes

Filed under: Tech — randy @ 1:24
Tags: , , , , ,

This is a qr code:

It’s used to embed data inside of it, which can then be scanned by a large variety of devices. It’s widely used in Japan to advertise links to web pages, which are otherwise difficult to type on a small device like a mobile phone. But they can be used for all kinds of things. All in all it’s a very cool technology, so I wanted to experiment with it.

Python and Django are my server of choice, so I started looking for a library to generate square codes in Python. I soon wandered upon pyqrnative, which is a port from a javascript version, apparently. It’s very compact and easy to use. Generating images was a piece of cake. I had Django serve dynamically generated images in no-time.

But how to read these images client-side? Since I recently dabbled in OpenCV and JavaCV I learned of an easy way to access the webcam in Java, so I made a Java implementation. This step was not very difficult, so I decided to make things harder on myself by embedding the webcam part in a Java applet, so it could run from a website.

I had a bit of trouble here, as accessing native libraries (using Java Native Access) proved quite difficult. I had a lot of trouble figuring out where JavaCV was loading its dll files from, and it took me a good half hour to debug it. A list of paths to OpenCV are hardcoded in the JavaCV source code. I wanted to include the dll files dynamically, which seemed near impossible. What’s worse, removing or adding paths did not seem to make any difference as to whether JNA could find the dlls or not. I finally tracked it down to one folder: /usr/local/lib was the folder where my libraries were being loaded from. Which is damn peculiar, because that’s a Linux folder and I’m running Windows 7. I suspected cygwin at first, but the problem was not that: When specifying the /usr/local/lib folder, jna looks for all folders in the system variable called jna.library.path, which contains the system path by default. Very obscure…

Having figured that out I could continue building the applet. I had jump through a bunch of hoops to get it to work, namely signing the applet (which is a very good thing considering I’m running native code that accesses a webcam!) and figuring the right tags to put in the HTML. HTML tags for applets are a big bloody mess, there’s no standard at all. There’s a deprecated applet tag, an object tag for IE and an embed tag for Mozilla (which also works in Chrome). I chose the embed tag for now.

There’s a nice method in Java’s AppletContext class which lets you change the browser’s document’s URL. It also allows you to execute arbitrary Javascript, so you can call a javascript function that does an ajax call back to the server that can update the web page! It’s all very roundabout and takes three languages and a whole bunch of libraries to get going, but it’s quite cool once it works. Here’s a video of the result:

Next Page »

Blog at