Random posts about coding

Mostly blogging about dart.

Dart: Hash Server Example

| Comments

Another fun dart example in the works. The goal of this example was to explore LUCA UI Framework and the server side component provided in the dart samples folder. The chat sample provides enough implementation to get your own dart http server running in no time at all. The only issue with chat is its an early sample and not modular enough to copy and paste. It is simple enough to read and split apart your self. I have done some of that in the HashServer. Eventually I would like to take it one step further and break the chat sample up enough that anyone could clone and get started right away.

The HashClient takes a string input from the TextBox and sends it to the server by XMLHttpRequest in JSON format. The server then parses the request data and creates a hash value based on the hasher selected by the client. The client updates the hash value on the UI when the response received. The LUCA UI provides a MVVM framework so the domain logic was separated from the UI, a convenient and coherent way to do UI application development. More work on the client and server side is needed to separate the available hashes from what is coded into the client, but for now it works. See the README.md on how to get running. Feedback and comments always welcome!

Dart: Animated H-Fractal

| Comments

A fun example using Dart to draw on Canvas an H-Fractal. Fractals are those beautiful geometric shapes that can be implemented with recursion in programming languages. In this example you can see that dart is capable of calculating an H-Fractal and storing the points before drawing to the canvas very fast. Above 10 iterations things start to slow down.

DRandom: Quick and Dirty Dart RNG

| Comments

I needed a quick and dirty RNG for some code prototype Dart code. This code was based off of Random.cs from the mono project. In the mono projects comments that code is based on some example in the numerical recipes in C book. Methods provided are simple enough to understand based on the their names. I would not trust this code for any serious random number generations and it is best to seed the RNG then letting the default seed be used. Get the DRandom from github. class DRandom { DRandom.withSeed(int Seed) DRandom() double Sample() int Next() int NextFromMax(int maxValue) int NextFromRange(int minValue, int maxValue) List NextInts(int size) Map NextIntsUnique(int minValue, int maxValue, int size) double NextDouble() }

Installing RabbitMQ on a Local Vcap

| Comments

Assuming you have already done the https://github.com/cloudfoundry/vcap song and dance. I always have a terriable time trying to get items to work on cloudfoundry.com so decided to see how much of RabbitMQ is available in vcap. Here is a hack to getting RabbitMQ running. I could totally have a baked install and thus the reason why I went down this dark path. Update and install the following decencies cd ~/cloudfoundry/vcap git pull gem install bundler –no-rdock –no-ri rake bundler:install gem install amqp –version ‘0.7.1’ gem install daemons –version ‘1.1.0’ gem install thin –version ‘1.2.8’ cd ~ gem update vmc Edit ~/cloudfoundry/vcap/bin/vcap and add rabbit as a service Fire up the services by cd ~/cloudfoundry/vcap && bin/vcap start Set target and login vmc target api.vcap.me vmc login –email blahblah@blahblah.com –passwd blahblahblah BTW, if you forgot your username or password it can be found in ~/cloudfoundry/vcap/cloud_controller/db/cloudcontroller.sqlite3 . Just rip this file apart or add a new hash for the password. Check to see the runtimes are correctly available Check out the following sample to package up git clone https://github.com/rabbitmq/rabbitmq-cloudfoundry-samples.git cd ~/rabbitmq-cloudfoundry-samples/spring && mvn package && cd target && vmc push You can follow http://support.cloudfoundry.com/entries/20322602-getting-started-with-the-rabbitmq-service-from-a-spring-application to deploy the app correctly. Before you actually create the service you want to check the logs out… This is the issue I had with a local vcap and rabbit. The user and vhost never get added to rabbitmq, doing this manually will make the service work. Make sure to tail the logs before running the vmc create-service. That way you can pull out the actual username/password/vhost that vcap will try to send to rabbitmqctl. tail -f ~/cloudfoundry/vcap/cloud_controller/log/development.log vmc create-service rabbitmq vmc bind-service rabbitmq-XXXXX rabbit-simple After creating the service the logs will display the username/password/vhost but when you bind the service to an application the username and password change and you need to add those by hand with rabbitmqctl The first set of username/password will not be used, after binding you need the current ones. In this case they were user: uz25LQnFmJTrC pass: pfah5U5dFiSRo vhost: vf883c025ec524e55b11b0db4dcce928e At this point you can add the data by hand, restart rabbitmq (sometimes queues decided to get eaten) and you should be ready to go. sudo rabbitmqctl add_user uz25LQnFmJTrC pfah5U5dFiSRo sudo rabbitmqctl add_vhost vf883c025ec524e55b11b0db4dcce928e sudo rabbitmqctl set_permissions -p vf883c025ec524e55b11b0db4dcce928e uz25LQnFmJTrC “.*” “.*” “.*” sudo /etc/init.d/rabbitmq-server restart Some useful logs to keep tailed ~/cloudfoundry/vcap/cloud_controller/log/development.log /var/log/rabbitmq/* Did I need to go to all this trouble, probably not, but it was fun to investigate what vcap is made and how things are done internally. Since all the code looks like its in place, my guess on how to properly enable rabbit service is to find out what should triggers the calls to ~/cloudfoundry/vcap/services/rabbit/lib/rabbit_service/rabbit_node.rb and debug why the calls are actually failing to contact the local rabbitmq service. Useful links http://support.cloudfoundry.com/entries/20346977-rabbitmq-cloud-foundry-cloud-messaging-that-just-works https://github.com/rabbitmq/rabbitmq-cloudfoundry-samples http://support.cloudfoundry.com/entries/20322602-getting-started-with-the-rabbitmq-service-from-a-spring-application https://github.com/cloudfoundry/vcap http://support.cloudfoundry.com/entries/20012337-getting-started-guide-command-line-vmc-users https://raw.github.com/cloudfoundry/vcap/master/setup/install http://support.cloudfoundry.com/entries/20052116-rabbit-on-local-instance-of-vcap http://www.rabbitmq.com/admin-guide.html http://www.rabbitmq.com/man/rabbitmqctl.1.man.html

Netduino Plus With RelayShield as Networked Light Switches

| Comments

Picked up a fun relay shield from the seeedstudio people. My goal was to be able to control lights over the network. After grabbing some webserver code from this post, I was able to get a simple basic web server and light controller up in no time. One stumbling block I had was the MAC configuration with MFDeploy. If you don’t use the proper MAC that was assigned to the Ethernet controller you could have potential DHCP or router ARP table issues. When setting up the netduino network I was lazy and put in a bogus MAC, that caused a few hours of debugging. Once deployed and networking is configured hit the root address from the network and a simple page with links get displayed Quick photo and diagram of the setup Pick up the code hack around and have fun. Suggestions and comments welcome.