32leaves.net

Evolution of the aliveness of cells in a cellular automaton

The video above shows the evolution of the graph from the previous post. Again this is without further explanation, and just for the prettiness of it.
Probably I’ll post a paper which formally describes the automaton used and a couple of (proven) attributes of it.

The beauty of maths

A2 phase plot

It’s not that I really could interpret this picture or tell you where exactly the patterns are comming from. But what’s highly interessting is the way they evolved. A couple of weeks ago I started playing arround again with cellular automata. While playing arround I started generating numbers where each number represents a unique population (as the population is a matrix over {0,1}, the matrix can be percepted as a binary stream). The picture above shows 500,000 generations (yes half a million) plotted in a logarithmically scaled phase plot. There for sure was total surprise when suddenly those patterns emerged.

Another neat picture is the “heatmap” showing how often a cell has been alive in respect of the total amount of generations.
heatmap

Again we see some neat patterns emerging. But why am I posting this, you might ask. Because I do think those pictures show (at least to some level) the inner beauty of math and its surrounding fields. That some “randomly” choosen system creates such patterns and shows strong symptoms of order is something I think is really amazing.

Quick and dirty HTTP server in Ruby

Today I quickly wrote a HTTP server in Ruby for a fellow student. It’s nothing special, does not care a single bit about security. But it’s easy to use, enhance and understand and below 100 lines of code. I’m sure there are better, more efficient and propably easier ways to implement this in Ruby, but I wanted it to be done quickly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
# DeineMudder
# written by blacki
#
# This is an extremely minimalistic implementation of a HTTP server in ruby
# It does not care about security and stuff, so don't use this in a production
# environment. The code was written to be easily understandable (and I was tired
# when writting this), so there sure are ways to improve this.
#
# If you want to add URLs have a look at the KnownURLs class
#
# THERE IS ABSOLUTELY NOW WARRANTY FOR FITNESS OR WHATSOEVER OF
# THIS SOFTWARE. SO USE AT YOUR OWN RISK
#
# Published as Public Domain
#
#

require 'socket'

HOST = 'localhost'
PORT = 8080

#
# To introduce new URLs simply add methods to this class which will
# become available using "/METHOD_NAME" (GET requests only)
#
class KnownURLs
 
  def read(params)
    return File.new(params["name"]).readlines
  end
 
  def connect(params)
    Thread.start do
      system("ping", "-c 2", params["ip"])
    end

    return <<EOF
<html><head><title>connect</title></head><body><center><h1>Connection to #{params["ip"]} established</h1></center></body></html>
EOF

  end

end



#
# If you do any modification after this point be sure you know what you do
#

KNOWN_URLS = KnownURLs.new
def dispatch(method, url)
  result = nil

  params_str = url.split("?")
  url_handler_name = params_str[0][1..-1]
  if method == "GET"
    params = {}
    if params_str.length == 2
      params_key_value_pairs = params_str[1].split("&")
      params = Hash[*params_key_value_pairs.collect {|v| p = v.split("="); [p[0], p[p.size == 2 ? 1 : 0]]}.flatten]
    end

    result = KNOWN_URLS.send(url_handler_name, params) rescue "Caught error<br /><pre>#{$!}</pre>"
  end

  return result
end

serverSocket = TCPServer.new(HOST, PORT)
while clientSocket = serverSocket.accept
  req = clientSocket.gets.strip
  method, url = req.split(" ")
  puts "[REQ] #{method} #{url}"

  result = dispatch(method, url)
  response = { :status => 300, :body => "" }
  if result.nil?
    response = { :body   => "<html><head><title>404 NOT FOUND</title></head><body><center><h1>Unknown URL</h1></center></body></html>",
                 :status => 404 }
  else
    response[:body] = result
  end

  clientSocket.puts <<EOF
HTTP/1.0 #{response[:status]} OK
Server: Deine Mudder
Content-Lenhth: #{response[:body].length}
Content-Type: text/html
Connection: close

#{response[:body]}
EOF

  clientSocket.close
end
Fork me on GitHub