Python exercise

All

Brushing up my python skills since it’s been a while.

The problem:

You have two lists. The first list are the keywords. The seconds contains the sentences that those keywords are used. You just need to return the top (n) of the used keywords:

Example:

First list ~ keywords:
[“anacel“, “betacellular“, “cetracular”, “deltacelular”, “eurocell”]
numFeatureRequests= 3
Second list ~ sentences:
[“Best services provided by anacell“, “betacellular has great services, anacell provides much better services than all other”, “anacell“]
Results
   Get me the top 2, so the two most used words.
   [‘anacel’, ‘betacellular’]
Implementation:
   ~ I thought about three ways to solve this: the basic using a histogram (with a dictionary) and a linked list:
#Main function:
def popularNFeatures(numFeatures, topFeatures, possibleFeatures, numFeatureRequests, featureRequests, print_flag = False):
    Using histogram (and python counter):
~~~
word_counts = Counter(featureRequests)
print word_counts
histogram = {}
#Counter({‘hello’: 2, ‘ciao’: 1, ‘hi’: 1})
word_counts[eachFeature]
sorted_d = sorted(word_counts.items(), key=operator.itemgetter(1),reverse = True)
#[(‘hello’, 2), (‘ciao’, 1), (‘hi’, 1)]
return [item[0] for idx,item in enumerate(sorted_d) if idx < topFeatures]
~~~
   Using a linked list:
for eachFeature in possibleFeatures:
value = endstring.count(eachFeature)
aux = module_node.node(eachFeature, value)
list_nodes.append(aux)
The linked list is trivial, as Francis Girauldeau  would put, and the main part is the insertion, which has three cases:
def insert(self, new_node, print_flag=False):
#The list is empty
if print_flag:
new_node.printNode()
iflen(self.list_nodes) == 0:
self.list_nodes.append(new_node)
returnTrue
iflen(self.list_nodes) > 0:
max = self.list_nodes[0].get_value()
min = self.list_nodes[-1].get_value()
#print “max” + str(max)+ “min” + str(min)
if new_node.get_value() >= max:
new_list = []
new_list.append(new_node)
new_list.extend(self.list_nodes)
self.list_nodes = new_list
if new_node.get_value() <= min:
self.list_nodes.append(new_node)
if new_node.get_value() > minand new_node.get_value() < max:
new_list = []
for node inself.list_nodes:
if node.get_value() <= new_node.get_value():
new_list.append(new_node)
new_list.append(node)
self.list_nodes = new_list
The source codes and tests are here

Java Mission Control / Java Flight Recorder

All

Intro

Sometimes JConsole is not enough to investigate issues, such as performance-related ones.

Java Mission Control 8

Java Mission Control is available for OpenJDK, and Oracle JDK, Oracle has a good introduction for those tools here. Basically, Misson control is the tool for troubleshooting, and Flight Recorder is the API ~ according to JEPS 328.

    Oracle guide to understanding data

Beginning

  1. To install it, go directly from the git: https://github.com/openjdk/jmc
  2. Follow the instruction to build it
  3. Running it

Using JMC

jmc

1. Use case 1:: Analyzing data with Missiong control

1. Use case 2:: JMX to JBoss  (like I did with JVisualVM)

 

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