Python exercises 2

All

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.

Resolution

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

while(still_zero(grid)):
      print_grid(grid)
      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:

while(tree.still_can_grow()):
    aux.print_grid(grid)
    hours = hours + 1
    return hours

Implementation

For the procedural implementation, it is here

The tree implementation is here

Benchmarks

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

 

JSP default buffer size

All

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

All

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:

  application/WEB-INF/context.xml

 

Deployment descriptors in EAP

jboss-web.xml and web.xml

Deployment descriptor Glassfish

   sun-web.xml

Properties

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

 

Getting the Canadian PR

All

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

All
From this page and this question on StackOverFlow

Add the following commands on the app:
~~~
-Dcom.sun.management.jmxremote.port=9005
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
~~~

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

or you can use 

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

========================================================
logging.properties 
========================================================
Logging.properties

handlers = java.util.logging.ConsoleHandler


.level = INFO

java.util.logging.ConsoleHandler.level = FINEST

java.util.logging.ConsoleHandler.formatter = \

java.util.logging.SimpleFormatter

// Use FINER or FINEST for javax.management.remote.level - FINEST is

// very verbose...

javax.management.level = FINEST

javax.management.remote.level = FINER
~~~

Hidden requirements for vacancies

All

Intro

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

All

Intro

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

Code

Therefore I created some python scripts to parse and test some algorithms on Repl.it, 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.

Repositories

https://repl.it/@FranciscoMelo1/guess

https://repl.it/@FranciscoMelo1/cigarrahistogram

https://repl.it/@FranciscoMelo1/cigarra

Results

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

All

Script to find string in file

To run in a directory:

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

import sys

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

def find_line(file, string_search):
print(“XXXX”)
import re
errors = []
linenum = 0
pattern = re.compile(r””+string_search)
with open (file, ‘rt’) as myfile:
for line in myfile:
linenum += 1
if pattern.search(line) != 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

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

curl

All

Intro

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:

Code

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.