Categories
newtools

Microsoft Teams blocked by pfBlockerNG

Hi,

One short tip to remember. I’ve been struggling for a while now with the fact that pfBlockerNG was blocking my Teams connection for whatever reason.

I couldn’t understand what was the correct way to fix this until today. I should have known that there isn’t a range of IPs that can be whitelisted to make it work, and it’s related to the domain that was blocked.

This became evident today when I took a look at the Reports tab and Alerts subtab and filtered by interface

In order to fix it, you will need to go to DNSBL tab and expand TLD Exclusion List so that you can add the general domain that should be excluded.

You could also whitelist each subdomain but since we are talking Microsoft, I think this is easier.

The way this works, at least from what I understood, is that it will allow all of hostnames with the general domain and only block the ones that are specifically blacklisted.

That would be all for today,

Sorin

Categories
python

Python Kata on Codewars

Hi,

Since I pretty much broke the internet trying to solve the following “kata” with pieces of code, lets paste it also here cause it makes me proud.

Here is the link to the kata: https://www.codewars.com/kata/5977ef1f945d45158d00011f

And also here is my “solution” which took quite a long time to fix:

def sep_str(st): 
    # your code here
    test_list = [[letter for letter in element] for element in st.split()]
    for a in test_list:
        a.extend([""] * (max(map(len, test_list)) - len(a)))
    if test_list:    
        result = [[test_list[j][i] for j in range(len(test_list))] for i in range(len(test_list[0]))]
    else:
        result = []
    return result

That is all.

Cheers!

Categories
newtools

Traffic statistics – new project

Hi,

For some time I wanted to understand how the traffic on my networking is actually shaped.

To that purpose, at first I purchased a Synology router but it seems that it hasn’t that much traffic logging capabilities, so I kept it and put in front of it the following box.

It’s a cool toy but ultimately I wanted to have Pfsense installed on it and logging activated so that I can gather as much data as possible.

It’s now installed and hopefully it should be the start of some articles related to the data manipulation and also, maybe, some administration insights.

Tnx,

Sorin

Categories
linux

Enable time sync on Manjaro

So I wanted for a while to use and to learn Manjaro and I grabbed Cinnamon 21.1.0

Installation process is pretty straight forward, I setup the correct time zone and installed all of the default packages.

Guess what, after rebooting the laptop the timezone was set correctly but the actual time was way off.

I tried to see if I can easily find a post to explain to me how it’s done but the standard GUI way didn’t work.

The actual solution is in the code below

[sorin-20fjs3dr01 ~]# timedatectl
               Local time: Sb 2021-08-28 13:07:40 EEST
           Universal time: Sb 2021-08-28 10:07:40 UTC
                 RTC time: Sb 2021-08-28 10:07:40
                Time zone: Europe/Bucharest (EEST, +0300)
System clock synchronized: no
              NTP service: inactive
          RTC in local TZ: no
[sorin-20fjs3dr01 ~]# systemctl status ntpd.service
○ ntpd.service - Network Time Service
     Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
     Active: inactive (dead)
[sorin-20fjs3dr01 ~]#  systemctl status systemd-timesyncd.service
○ systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:systemd-timesyncd.service(8)
[sorin-20fjs3dr01 ~]# systemctl start systemd-timesyncd.service
[sorin-20fjs3dr01 ~]# ^C
[sorin-20fjs3dr01 ~]# systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; disabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-08-28 13:09:09 EEST; 2h 59min left
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 2080 (systemd-timesyn)
     Status: "Initial synchronization to time server 195.135.194.3:123 (0.manjaro.pool.ntp.org)."
      Tasks: 2 (limit: 19010)
     Memory: 1.3M
        CPU: 51ms
     CGroup: /system.slice/systemd-timesyncd.service
             └─2080 /usr/lib/systemd/systemd-timesyncd

aug 28 13:09:09 sorin-20fjs3dr01 systemd[1]: Starting Network Time Synchronization...
aug 28 13:09:09 sorin-20fjs3dr01 systemd[1]: Started Network Time Synchronization.
aug 28 10:09:10 sorin-20fjs3dr01 systemd-timesyncd[2080]: Initial synchronization to time server 195.135.194.3:123 (0.manjaro.pool.ntp.org).
[sorin-20fjs3dr01 ~]# systemctl enable systemd-timesyncd.service
Created symlink /etc/systemd/system/dbus-org.freedesktop.timesync1.service → /usr/lib/systemd/system/systemd-timesyncd.service.
Created symlink /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service → /usr/lib/systemd/system/systemd-timesyncd.service.
[sorin-20fjs3dr01 ~]# 

Turns out that both ntpd and timesyncd are dead and do not start by default, so the actual fix is by starting and enabling timesyncd.

Cheers,

Sorin

Categories
Uncategorized

Getting stocks basic data using yfinance

Hi,

If you are thinking of investing and also to create a perfect opportunity so that you can play with data in pandas, here is the use case I am working on.

Basically, from what I understood, if you want to value invest, there are two main parameters to take a look at before doing any other in depth research: P/B and P/E. Both of them show if the company has the potential to grow.

How can we retrieve these parameters using Python from Yahoo Finance for example … and the code that worked for me is as follows:

import yfinance as yf
import pandas as pd

payload=pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
first_table = payload[0]
second_table = payload[1]
df_sp = first_table

statscsv = open('stats.csv', 'a')

for value in df_sp['Symbol']:
    stock = yf.Ticker(value)
    if 'priceToBook' in stock.info:
        statscsv.write(value+","+str(stock.info['priceToBook'])+","+str(stock.info['priceToSalesTrailing12Months'])+"\n")

statscsv.close()

I’ve been trying a lot to put the info directly in a pandas DataFrame and it did not work so for the purpose of querying the API only once, it makes a lot of sense to store it in an CSV file saved locally.

After it is saved locally you can manually load it to the DataFrame object by using (for my usage i manually added the column names into the file like Symbol,PB,PE at the beginning)

df_pb = pd.read_csv("stats.csv")

From what I saw, in some cases P/B data is not available in the output so the value ‘None’.

You can manually change that by replacing it with 0 and store it in a different DataFrame, like this

df_pb_clean = df_pb.replace({"None":"0"})

After you done this, you need to also convert the types of columns from object to float64 so that you can query specific values

df_pb_clean['PB'] = df_pb_clean['PB'].astype(float)
df_pb_clean['PE'] = df_pb_clean['PE'].astype(float)

After all of this is done, you can query it just as easy as

df_pb_green = df_pb_clean.query('0.0 < PB < 2.0')

And after that filter maybe also P/E for you use case.

The main goal is that we filter only the company with growth so that we can try to retrieve historical data and see main methods of analysis.

Cheers

Categories
kafka

SASL config issue on latest Kafka versions

Hello,

Today I want to share with you a problem that we needed to fix when we decided to activate SASL.

Normally, the steps are pretty straight forward and you can use Confluent doku or the general Apache Kafka.

The main catch is that if you have a certain property in your config file, the following error will appear in a loop:

[2021-01-11 09:17:28,052] ERROR Processor [0..n] closed connection from null (kafka.network.Processor)
java.io.IOException: Channel could not be created for socket java.nio.channels.SocketChannel[closed]
	at org.apache.kafka.common.network.Selector.buildAndAttachKafkaChannel(Selector.java:348)
	at org.apache.kafka.common.network.Selector.registerChannel(Selector.java:329)
	at org.apache.kafka.common.network.Selector.register(Selector.java:311)
	at kafka.network.Processor.configureNewConnections(SocketServer.scala:1024)
	at kafka.network.Processor.run(SocketServer.scala:757)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.apache.kafka.common.KafkaException: java.lang.NullPointerException
	at org.apache.kafka.common.network.SaslChannelBuilder.buildChannel(SaslChannelBuilder.java:228)
	at org.apache.kafka.common.network.Selector.buildAndAttachKafkaChannel(Selector.java:338)
	... 5 more
Caused by: java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Objects.java:221)
	at org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder.fromOldPrincipalBuilder(DefaultKafkaPrincipalBuilder.java:77)
	at org.apache.kafka.common.network.ChannelBuilders.createPrincipalBuilder(ChannelBuilders.java:216)
	at org.apache.kafka.common.security.authenticator.SaslServerAuthenticator.<init>(SaslServerAuthenticator.java:183)
	at org.apache.kafka.common.network.SaslChannelBuilder.buildServerAuthenticator(SaslChannelBuilder.java:262)
	at org.apache.kafka.common.network.SaslChannelBuilder.lambda$buildChannel$0(SaslChannelBuilder.java:207)
	at org.apache.kafka.common.network.KafkaChannel.<init>(KafkaChannel.java:143)
	at org.apache.kafka.common.network.SaslChannelBuilder.buildChannel(SaslChannelBuilder.java:224)
	... 6 more

The cause for this is property:

principal.builder.class=org.apache.kafka.common.security.auth.DefaultPrincipalBuilder

Normally, for the latest versions of Apache Kafka like 2.x.x, it should not be set at all so that when the process starts it will be like:

principal.builder.class=null
Categories
machine learning

Plot a math function in Python

Hi,

I just started a recap of calculus and wanted to know how and if it’s hard to plot functions in a programming language.

Searching this topic I found this article, which gives an elegant approach:

https://scriptverse.academy/tutorials/python-matplotlib-plot-function.html

After trying the code here is the result

Surely there are even more complex cases but at least there is a start for adapting the code.

Cheers

Categories
machine learning

No workpath update on Jupyter admin started instance

Hi,

Just a very small update. I saw that when you run the CMD under Administrator rights under Windows, the Jupyter working directory is automatically set to C:\Windows\System32…..which is not great at all.

I tried the standard method which is listed here but it does not work. Even after I save the file, it doesn’t take it into consideration and it will overwrite it at another export.

Just start a normal command prompt and run jupyter lab and it will take you as a working dir to your local user dir.

Cheers

Categories
linux

Recover swap file in vim

Hi,

This is a problem that I had since my virtual machine was not stopped properly and my ssh connection was ended prematurely.

https://superuser.com/questions/204209/how-can-i-recover-the-original-file-from-a-swp-file/205131

If you have a file.swp and you want to recover it, do as they say. Open the file in VIM and then type recover.

Cheers

Categories
cloud newtools

Exclusive SASL on Zookeeper connections

Something related to following article. It seems that even if SASL is configured until version 3.6.1, Zookeeper will still allow anonymous connections and actions.

There is now a new configuration available that will restrict such events and you can find it documented on the official Apache Zookeeper administration guide (zookeeper.sessionRequireClientSASLAuth)

The main catch is that it’s not suppose to be configured in zoo.cfg file, but added as a parameter in java.env as a part of SERVER_JVMFLAGS variable.

The old variable which was

zookeeperstd::jvm_flags: "-Djava.security.auth.login.config=/opt/zookeeper/conf/zoo_jaas.config"

will become

zookeeperstd::jvm_flags: "-Djava.security.auth.login.config=/opt/zookeeper/conf/zoo_jaas.config -Dzookeeper.allowSaslFailedClients=false -Dzookeeper.sessionRequireClientSASLAuth=true"

After this is implemented, when you try to connect using zkCli.sh, it will let you, but when trying to list the main node of resource tree it won’t work.

Example:

Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is enabled

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls /
KeeperErrorCode = Session closed because client failed to authenticate for /
[zk: localhost:2181(CONNECTED) 1] 

The same thing happens if you use zkCli.sh -server [hostname]:2181

In order to connect you will have to add to java.env a line with:

CLIENT_JVMFLAGS=-Djava.security.auth.login.config=/opt/zookeeper/conf/client_jaas.config"

Client file that includes structure

Client {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       username="[client_username]"
       password="[client_password]";
};

Cheers