just another web log

30 May 2015:
the madness and beauty of agar.io
There is a free web based game called http://agar.io that is just amazing and that has stolen so much of my time.

What is so great about it? Well, it's not the graphics, just different coloured slightly bloby circles. There is no sound and the controls are as simple as the graphics. Just point your mouse and the blog goes there and [SPACE] to split and [W] to eject mass.

It's the simplicity that makes this game, along with the perfect balance of power at any time. You start out as a tiny blob that can only eat the food that is scattered about randomly. But, you are fast, really really fast and almost nothing can catch you. As you get bigger eating the food you stay nimble but gradually you become snack size and other larger blogs may target you.

This is were the many strategies come into play. There are two other things in the agar with you and your fellow blobs. One is the simple, invisible edge of the world that can be great place to hide or get trapped. Second is the viruses, green and spiky and as long as you are smaller than a virus they are like sea anemones you can hide in. But that all changes if you are bigger than a virus then they pop you causing your mass to become multiple smaller blobs.

You can "feed" viruses by ejecting mass into them. After seven "feeds" they multiple into two. Sending the new virus away from you. This can be a great strategy and causing a new virus to split into a super-massive blob can be a great victory. Once and enemy blob is split it can cause a feeding frenzy changing the balance of power in an instant.

Ejecting mass can; leave food pellets to entice an enemy where you want, to make your self lighter, or simply cause a diversion.

If you can get a mass of a few hundred you understand the basics, get over a thousand and you are a contender and may appear on the top 10 leader board, get up to 10,000 and you consider yourself the winner(though nothing changes you just cannot get any bigger).

As you get bigger you find your food needs change as over time you lose mass and you slow down. You will need to plan who to attack. They must be smaller than you and close enough to consume. If you split you may end up too small to absorb them.

I cannot help but waste mass on virus feeding, this means I rarely get into the top 10 but I do live for a reasonable amount of time.

Finally, you can select any name you like(or none) including the names of other players and a set of special names such as "earth, moon, mars, nasa, poland and reddit" which give you unique skins. The names can be extracted from the JavaScript and is quite long.
16 May 2015:
Git is not github git does not need a server
I have lots to blog about but at the moment but, I really want to add a note about git(not github.com, which I have already blogged about. Perhaps its just me but I had associated all things Git with GitHub.

I wanted to do source control on my local machine and move away from folders called "Projectx good on 20140321_backup3" but at the same time I did not want to install a server or make everything public on GitHub. I knew GitHub had private repositories but those are not free. I asked around at it seemed to be common knowledge that git(not github) would work locally without a server!! But, strangely I could not find any information on this, all my Google results were for running a local git server :(

The one exception was the official documentation, and only after I had given up looking for blogs discussing this did I reluctantly try the this tome. It's not that bad and I found what I needed in short order.

You can skip this step if you already have a project setup
mkdir myproject
cd myproject
...do some work, create/edit files etc

In your project folder just run
git init
git add *
git status
git commit

That will initialise the git repository, which is the hidden folder .git, then add all the files to be commit queue, check the status, are these the files you want added? Finally the commit itself where you can add a comment e.g. "Initial commit adding the project to git".

That's it! Almost too easy, there are number of things you can also do. My common additional step is add a .gitignore file to avoid checking in all the backup files the editors create, I was also able to avoid checking in the node_modules folder that was dynamically generated.

Git for the WIN!
03 May 2015:
How not to race the watchdog with fsck
So a quick note about setting up the Watchdog on Raspberry Pi
sudo apt-get update -y
sudo apt-get upgrade -y
sudo rpi-update -y
echo "bcm2708_wdog" | sudo tee -a /etc/modules
sudo apt-get install watchdog -y
sudo update-rc.d watchdog defaults

Edit /etc/default/watchdog and add
and uncomment max-load-1 = 24 and watchdog-device in /etc/watchdog.conf
Then to test, run sudo /etc/init.d/watchdog start
/etc/init.d/watchdog status

[ ok ] watchdog is running.

and execute a logic bomb that will consume all resources and force the system to run out of memory : (){ :|:& };:
It rebooted and I was happy, so I thought I will just make sure with all these reboots the file system does note get "dirty" by forcing a fsck on reboot

sudo touch /forcefsck
sudo shutdown -r now

CODE RED! ALERT! ALERT! the Pi is just rebooting over and over again!!
text reading Epic Fail

I had introduced a race condition. The Watchdog was making sure the Pi booted quickly and the fsck was taking to long to check the card, causing a reboot.

Popped the card out of the Pi into a reader then in linux removed the /forcefsck file, now everyone is happy again.
02 May 2015:
Watchdog cannot see Pi sleeping threads
So my previous Dropbox based Raspberry Pi security camera has a minor flaw. OK its a big flaw, it crashes every two to three days. When I say crashes it still keeps running but no images are transferred to Dropbox and I can not ssh into the machine.
user@machine ~ $ ssh pi@
pi@'s password:
Linux pideskcam 3.18.11+ #776 PREEMPT Mon Apr 6 13:13:58 BST 2015 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Apr 14 18:55:50 2015 from machine.home

and it would just sit there never giving an error or any further response.
ssh pi@ uptime
pi@'s password:
did the same.
Annoyingly ping would always indicate the machine was up, so something was working.

I posted my problem on the awesome raspberrypi.stackexchange.com

Which also notes a daily cron based reboot was not sufficient and that even with the hardware watchdog* enabled I could not get a stable, unstable system.
I am quite happy for this rig to reset regularly as long as when it comes back up it starts capturing images again. Crashes never seem to happen under picture taking load.

What came out of that post was something I have never come across before, the Linux OOM Killer or "Out Of Memory process killer". When a system runs low on memory this little known kernel process decides that it is better to kill some other processes rather than let the machine starve itself of resources. Which is a nice idea but I have no idea what it is killing that killing ssh/bash/login and I cannot find a way to turn it off.

Next I worked on the assumption I was running out memory. I added
sudo min-memory=1
to /etc/watchdog.conf. The 1 represents 1 page of memory not 1mb/kb etc.

That worked, once. Then I had the same problem again. This time I looked at what I had added to the system i.e. the Dropbox script. Maybe the script was failing and never completing and then Motion created another instance for the next image frame and so on making things steadily worse.

The post also noted the number of sleeping threads in top, 1554.

while : ;do ps -e S | egrep drop | egrep -o "[^S]+";echo "====";sleep 10; done

which will report any Dropbox threads that have gone into Sleep status every 10 seconds. But every time I looked it was between 60-70 :(

Now I am trying something similar to see what is using up all these threads
while : ;do ps -e S ;ps -e S|wc -l; sleep 60; done
Once a minute list all Sleeping threads and the total count...

*Next post will be a cautionary tale about enabling the Watchdog.
02 May 2015:
Google oAuth revisited with a new token
Continuing my node.js Google Calendar on the Raspberry Pi thing. If you remember I had found that the credentials were not being preserved and I had to log in to Google continuously.

To avoid more embarrassment I opted to do further development on my Gentoo desktop machine, so I could easily log in to Google and do the authorisation steps.

So it was really easy to just add some node magic require("fs") dump the authorisation token to a file and at the start of the app read in that file!

Job done I can go home now ... No!

The tokens are different after the first one and they expire. We need to force user acceptance each time we have no refresh_token!?

Set the parameter generateAuthUrl to include approval_prompt: 'force'

Now the app will force the user to allow access to the app again, but this time an extra piece of the puzzle comes in the resulting token.
{ access_token: 'ya29.XwGZIU4znRV79yY0EFxMI4GbD-4xVpLbYlNwzIh3ZzGY9bJdUP3R5J_W4eDPotNEl4rHh4F6DkzJg',
token_type: 'Bearer',
refresh_token: '1/uwCkNebyF-H9LA7e65EwJX4FS9rfjcXZhHAb5t2lpM',
expiry_date: 1429911157900 }

all previous tokens had been
{ access_token: 'ya29.XwFk4qFf-Y0fH0IDuLWfN6bSU-8eYcwRIM9p-QbxgOZY40iBgYi8RwILrm8Vt2EtoLg0uisQ4P5tA',
token_type: 'Bearer',
expiry_date: 1429910935749 }

This new token with refresh_token should now last forever! Or until the user manually revokes it.

Final test

copy the token file and the newly updated app.js to the Pi and run

curl -L http://localhost:2002/

and low and behold it only bloody works!!

and after a day to see if the token had expired(this is what was happening with the token when missing the refresh_token) ...


Now I need to actually do something with the data ...
loading results, please wait loading animateloading animateloading animate
[More tags]
rss feed



flog archives

Disclaimer: This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at www.jumpstation.co.uk I am also not responsible for any information(or what you or others do with it) available at www.jumpstation.co.uk In fact I'm not responsible for anything ever, so there!

[Pay4Foss banner long]