Pular para o conteúdo principal

React routers and Java backend(Wildfly)

· Leitura de um minuto

When you use Java as backend(Wildfy 10+) for your web apps you'll need to create a rewrite rule in order to your routes work properly.

So, first of all, you'll need to add to the WEB-INF/undertow-handlers.conf all paths that won't be managed by your react application like example below:

path-prefix('/api') -> done
path-prefix('/static') -> done
path-prefix('/images/') -> done
path-prefix('/templates') -> done
path-prefix('/other-stuff') -> done
path-prefix('/report') -> done

So you'll need to provide the default rewrite rules for all addresses that will be managed(rewritten to) react js application, like example below

path-prefix('/') -> rewrite('/')

P.S. This might work with angular and other JS frameworks as well.

Reference: http://undertow.io/undertow-docs/undertow-docs-1.3.0/predicates-attributes-handlers.html

For the sake of simplicity you can check the complete example below:

path-prefix('/api') -> done
path-prefix('/static') -> done
path-prefix('/images/') -> done
path-prefix('/templates') -> done
path-prefix('/other-stuff') -> done
path-prefix('/report') -> done
path-prefix('/') -> rewrite('/')

Debugging Jupyter Notebooks with Python3.6

· Leitura de um minuto

First of all, you need to place the following line above the one you want to debug: from IPython.core.debugger import Pdb; Pdb().set_trace()

Then run the cell you want to debug. After that, a console will be prompted. Next, type a command or the  variable name you want to look into.

Here are some commands :

  1. q -> quit
  2. n -> next
  3. p -> print . Could be a variable or something like 'hello world'
  4. a -> show the arguments of the current function
  5. b -> insert a breakpoint in the current line
  6. c -> continue to the next breakpoint
  7. s -> step into
  8. r -> execute script until leaves the current function

Download files from Google Drive using WGET

· Leitura de um minuto
  1. First of all you need to share your file by activating download link

  2. Extract the file id from the URL from the given URL

    1. Ex.: https://drive.google.com/open?id=abcdef1234
  3. Execute:

    wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=Abc1234' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=Abc1234" -O FILENAME && rm -rf /tmp/cookies.txt

PS: Don't forget to replace Abc1234 by your real file id on google drive

Fixing missing EFI partition after pacman upgrade

· Leitura de um minuto

Sometimes when we do

pacman -Syyu

The installation will crash complaining about missing EFI partition. In order to fix, follow this steps:

  1. Boot with flash USB or DVD

  2. Setup keys and network

    loadkeys br-abnt2
    #example 10.11.21.134/16
    ip addr del CURR_IP/CURR_MASK dev DEVICE
    ip addr add NEWIP/NEW_MASK dev DEVICE
    ip route add default NEW_IP via DEVICE
    echo "nameserver 8.8.8.8" >> /etc/resolv.conf

  3. Setup / and /boot (assuming / = /dev/sda2 and /boot = /dev/sda1)

    mount /dev/sda2 /mnt
    mount /dev/sda1 /boot

  4. Setup initramfs

    arch-chroot /mnt
    pacman -S filesystem linux --noconfirm
    mkinitcpio -p linux

  5. Setup loader.conf

    cat <<EOF > /boot/loader/loader.conf
    timeout 2
    default arch
    EOF

    Setup arch.conf

    cat <<EOF > /boot/loader/entries/arch.conf
    title Arch Linux
    linux /vmlinuz-linux
    initrd /initramfs-linux.img
    options root=/dev/sda2 rw
    EOF

  6. Setup grub

    #if using custom install
    grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub --recheck
    grub-mkconfig -o /boot/grub/grub.cfg
    exit

  7. Rebooting

    umount /mnt/boot
    umount /mnt
    reboot

Bonus

In case you have formatted boot partition you need to reinstall base and base-dev like following(Outside arch-chroot):

pacstrap -i base base-devel

Improving ArchLinux fonts

· Leitura de um minuto

I got this tutorial from reddit: https://www.reddit.com/r/archlinux/comments/5r5ep8/make_your_arch_fonts_beautiful_easily/

Install some fonts, for example:

sudo pacman -S ttf-dejavu ttf-liberation noto-fonts

Enable font presets by creating symbolic links:

sudo ln -s /etc/fonts/conf.avail/70-no-bitmaps.conf /etc/fonts/conf.d
sudo ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf /etc/fonts/conf.d
sudo ln -s /etc/fonts/conf.avail/11-lcdfilter-default.conf /etc/fonts/conf.d

Enable FreeType subpixel hinting mode by editing:

/etc/profile.d/freetype2.sh Uncomment the desired mode at the end:

export FREETYPE_PROPERTIES="truetype:interpreter-version=40"

Create /etc/fonts/local.conf with following:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match>
<edit mode="prepend" name="family"><string>Noto Sans</string></edit>
</match>
<match target="pattern">
<test qual="any" name="family"><string>serif</string></test>
<edit name="family" mode="assign" binding="same"><string>Noto Serif</string></edit>
</match>
<match target="pattern">
<test qual="any" name="family"><string>sans-serif</string></test>
<edit name="family" mode="assign" binding="same"><string>Noto Sans</string></edit>
</match>
<match target="pattern">
<test qual="any" name="family"><string>monospace</string></test>
<edit name="family" mode="assign" binding="same"><string>Noto Mono</string></edit>
</match>
</fontconfig>


JVM Args

· Leitura de um minuto
  • Java < 8
    -server
-Xms<heap size>[g|m|k] -Xmx<heap size>[g|m|k]
-XX:PermSize=<perm gen size>[g|m|k] -XX:MaxPermSize=<perm gen size>[g|m|k]
-Xmn<young size>[g|m|k]
-XX:SurvivorRatio=<ratio>
-XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled
-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=<percent>
-XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark
-XX:+PrintGCDateStamps -verbose:gc -XX:+PrintGCDetails -Xloggc:"<path to log>"
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M
-Dsun.net.inetaddr.ttl=<TTL in seconds>
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path to dump>`date`.hprof
-Djava.rmi.server.hostname=<external IP>
-Dcom.sun.management.jmxremote.port=<port>
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
  • Java >= 8
    -server
-Xms<heap size>[g|m|k] -Xmx<heap size>[g|m|k]
-XX:MaxMetaspaceSize=<metaspace size>[g|m|k]
-Xmn<young size>[g|m|k]
-XX:SurvivorRatio=<ratio>
-XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled
-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=<percent>
-XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark
-XX:+PrintGCDateStamps -verbose:gc -XX:+PrintGCDetails -Xloggc:"<path to log>"
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M
-Dsun.net.inetaddr.ttl=<TTL in seconds>
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path to dump>`date`.hprof
-Djava.rmi.server.hostname=<external IP>
-Dcom.sun.management.jmxremote.port=<port>
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

Avoiding SSLHandshakeException Error

· Leitura de um minuto

The following error is annoying:

Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

To avoid this problem, just save the site certificate(e.g. Firefox cert export) and execute the following command in your server:

JAVA8

keytool -import -alias $ALIAS -keystore $JAVA_HOME/jre/lib/security/cacerts -file $PATH_TO_PEM_FILE

JAVA7

keytool -keystore $JAVA_HOME/jre/lib/security/cacerts -importcert -alias sistemafieg -file $PATH_TO_PEM_FILE

Update

In case you already imported your crt once you can remove by entering the following command:

keytool -delete -alias $ALIAS -storepass $PASS -keystore $JAVA_HOME/jre/lib/security/cacerts 

After that you can import your cert again