Python exercises 2


Problem statement

A virus is spreading. It spreads one in all directions. Every hour, it spreads one space in all directions. Given the grid, how many hours it takes it to contaminate the whole grid?

So if you have a grid-like this:

0 0 0 0 1

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

In one hour it will be like this

0 0 0 1 1

0 0 0 0 1

0 0 0 0 0

0 0 0 0 0

Taking into consideration that the virus can appear anywhere in a grid, which has dimensions that are given by rows x columns, and the grid, which contains the initial virus locals. The virus cell is represented as 1 whereas, normal cells are 0 on the grid.


I thought about this problem in two ways: one is procedural, the second is the virus as a living being.

1 – Procedural implementation:

So, you go line by line, get the positions of the virus, and calculate the four next positions ~ validate the positions and change from 0 to 1. In a loop. And continue doing that until all the 0 become 1’s

      list_ones = find_ones(grid, rows, columns)
      update_nearby(list_ones, grid, rows, columns)
      hours = hours + 1
return hours


2 – Node implementation

The virus is actually a node, that grows in four dimensions (so the node knows where it will grow). So, if you have a mechanism to control those nodes, that control this growth. I called a tree but is much more like a linked list of nodes, that know where they will grow.

It will continue to spread while the grid still has 0’s, which is done on the growth process:

    hours = hours + 1
    return hours


For the procedural implementation, it is here

The tree implementation is here


I’m doing some benchmarks on this to see the performance.


JSP default buffer size


Page buffer

By default, a JSP page uses an area of memory known as a page buffer which is set as 8 KB by default, see ref.

And it is required if the page uses dynamic globalization support content type settings, forwards, or error pages.

You can ad in the page directive the attribute “buffer” like this to change this buffer:

<%@ page buffer="64kb" ... %>

And actually, you can disable it with using:

<%@ page buffer="none" %>

Deployment descriptors


A deployment descriptor is a file that basically configures the artifacts that will be deployed, it is within the WEB-INF directory

Deployment descriptor in apache tomcat:



Deployment descriptors in EAP

jboss-web.xml and web.xml

Deployment descriptor Glassfish



Those files can be used to change properties on the application when deploying, for example, cookies configuration.


Getting the Canadian PR


Some weeks ago we finally got the Canadian PR (ie. me, my partner is already Canadian Citizen).

Well, I can only say finally because it has been almost 7 years since I moved to Nova Scotia, then Quebec, and most recently Ontario.

Although I love Quebec, I would strongly recommend applying directly to the Express Entry Program, instead of the PEQ/Quebec PR process.

I also think it’s funny that when you are married to a Canadian citizen, you certainly don’t get the Citizenship, but not even the PR! hahaha! I mean, after living together with a person for certain years, not even PR!

I will be getting the Canadian Citizenship in about 2 years or less.


JConsole tips

From this page and this question on StackOverFlow

Add the following commands on the app:

jconsole -J-Djava.util.logging.config.file=path_to_logging.properties_for_jconsole

or you can use 

[fdemeloj@fdemeloj bin]$ ./jconsole -debug


handlers = java.util.logging.ConsoleHandler

.level = INFO

java.util.logging.ConsoleHandler.level = FINEST

java.util.logging.ConsoleHandler.formatter = \


// Use FINER or FINEST for - FINEST is

// very verbose... = FINEST = FINER

Hidden requirements for vacancies



After basically 7 years in Canada, I started to see patterns when I applied to jobs. I remember some years ago if I used my complete name on the process, it would be less likely that a company would call me, mainly because my complete name is not on the <european style> although it is European. Later on, I found some research that actually confirmed this.

Name bias

Affinity bias


Actually, there is a great deal of bias when recruiting.









Cicada 3301 ~ pt 2



After seeing the videos, I started to test some python codes to decrypt the book, or at least verify what was not used.


Therefore I created some python scripts to parse and test some algorithms on, which I think is quite useful.

Validation Algorithm

The validation is a simple algorithm that can validate the answer using a dictionary, but I implemented using the Wikipedia validation.



The results I have so far, show that the pages did not use cryptography atbash with any cryptography key.

    First program implemented ~ code

With this program we were able to prove that the first 4 pages and the last page is not using Arbaat ~ with swift [-28 to 28]. 

    Done: Arbaat verification from -28 to28.

     Doing: Implementing now the backward verification [done]

What is missing: the only possibility is to use Arbaat with anagram words

Result: atbash was not used on those pages

finding string in file


Script to find string in file

To run in a directory:

fdemeloj@fdemeloj directory]$ for f in *; do python  $f; done

import sys

def find(file, string_search):
with open(file) as myfile:
if string_search in
return True
return False

def find_line(file, string_search):
import re
errors = []
linenum = 0
pattern = re.compile(r””+string_search)
with open (file, ‘rt’) as myfile:
for line in myfile:
linenum += 1
if != None: # If pattern search finds a match,
errors.append((linenum, line.rstrip(‘\n’)))
for err in errors:
print(“Line “, str(err[0]), “: ” + err[1])

file_name = sys.argv[1]
string_name = “string”

print “This is the name of the script: “, sys.argv[0]
print “This is the file: “, sys.argv[1]
if len(sys.argv) > 2:
print “This is the string to find: “, sys.argv[2]
string_name = str(sys.argv[2])
print “This is the name of the string: “, string_name

is_there = find(file_name, string_name)
if is_there is True:
find_line(file_name, string_name)




Curl is an excelent to test http responses.  Interesting that since it’s open source you can see where the could might fail, for example:


if(!stream->bodystarted) {

   failf(data, “HTTP/2 stream %d was closed cleanly, but before getting “” all response header fields, treated as error”,stream->stream_id);*err = CURLE_HTTP2_STREAM;return -1;


Therefore in case you see HTTP/2 stream %d was closed cleanly, but before getting you would know that the header is coming broke or the body of the request is absent.