run_scaled linux

apt install xpra xvfb

git clone https://github.com/kaueraal/run_scaled.git

cd run_scaled/
cp run_scaled /usr/local/bin
chmod +x /usr/local/bin

run_scaled <yourapp>

@blog #linux #debian

Einstein's Puzzle Solve

1.

x1 x2 x3 x4 x5

EN red

ES dog

UA tea

green x < white x

x3 milk

yellow x smoke Kool

NO x1

smoke Chesterfield fox

2.

x1 yellow x2 Blue x3 red x4 white x5 green

x1 yellow NO Kool

x2 blue horse

x3 EN milk

x4 white

x5 green coffee

Old gold snails

chesterfield fox

JA Parliament

Lucky strike Orange juce

3.

x1 yellow NO Kool

x2 Blue horse

x3 red EN drink milk

x4 white ES dog Lucky strike Orange juce

x5 green coffee JA Parliament

4.

x1 yellow NO Kool

x2 blue UA tea horse

x3 red EN drink milk old gold snails

x4 white ES dog Lucky strike Orange juce

x5 green coffee JA Parliament

The answer:

x1 yellow  NO water   fox     Kool
x2 blue    UA tea     horse   chesterfield 
x3 red     EN milk    snails  Old gold   
x4 white   ES juce    dog     Lucky strike
x5 green   JA coffee  zeebra  Parliament  

@blog

zsh

install

sudo apt install zsh 

make default shell zsh:

chsh -s $(which zsh)

oh my zsh:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

copy plugins similar:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

all plugins enum:

plugins=(git zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting)

hardcode install powerlevel10k:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Set ZSH_THEME="powerlevel10k/powerlevel10k" in ~/.zshrc

@blog #linux #ubuntu #debian

Spotify dbus

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous

// Scale. add force-device param
spotify --force-device-scale-factor=1.5 %U

@blog

pprof

Generate reports in app with code:

CPU

cpuFile, err := os.Create("/tmp/cpuProfile.out")
if err != nil {
    fmt.Println(err)
    return
}
pprof.StartCPUProfile(cpuFile)
defer pprof.StopCPUProfile()

// CODE HERE

runtime.GC()

Memory

memory, err := os.Create("/tmp/memoryProfile.out")
if err != nil {
    fmt.Println(err)
    return
}
defer memory.Close()

// CODE HERE

err = pprof.WriteHeapProfile(memory)
if err != nil {
    fmt.Println(err)
    return
}

View reports with go tool pprof

go @blog

Mutex example

1.Without

package main
import "fmt"

var counter int = 0             
func main() {

    ch := make(chan bool)        
    for i := 1; i < 5; i++{
        go work(i, ch)
    }

    for i := 1; i < 5; i++{
        <-ch
    }
    fmt.Println("The End")
}
func work (number int, ch chan bool){
    counter = 0
    for k := 1; k <= 5; k++{
        counter++
        fmt.Println("Goroutine", number, "-", counter)
    }
    ch <- true
}

Output

Goroutine 3 - 1
Goroutine 3 - 2
Goroutine 3 - 3
Goroutine 3 - 4
Goroutine 3 - 5
Goroutine 2 - 1
Goroutine 2 - 6
Goroutine 2 - 7
Goroutine 2 - 8
Goroutine 2 - 9
Goroutine 1 - 1
Goroutine 1 - 10
Goroutine 1 - 11
Goroutine 1 - 12
Goroutine 1 - 13
Goroutine 4 - 1
Goroutine 4 - 14
Goroutine 4 - 15
Goroutine 4 - 16
Goroutine 4 - 17
The End

2. With

package main
import (
"fmt"
"sync"
)

var counter int = 0           
func main() {

    ch := make(chan bool)     
    var mutex sync.Mutex      
    for i := 1; i < 5; i++{
        go work(i, ch, &mutex)
    }

    for i := 1; i < 5; i++{
        <-ch
    }

    fmt.Println("The End")
}
func work (number int, ch chan bool, mutex *sync.Mutex){
    mutex.Lock()   
    counter = 0
    for k := 1; k <= 5; k++{
        counter++
        fmt.Println("Goroutine", number, "-", counter)
    }
    mutex.Unlock() 
    ch <- true
}

Output

Goroutine 1 - 1
Goroutine 1 - 2
Goroutine 1 - 3
Goroutine 1 - 4
Goroutine 1 - 5
Goroutine 4 - 1
Goroutine 4 - 2
Goroutine 4 - 3
Goroutine 4 - 4
Goroutine 4 - 5
Goroutine 3 - 1
Goroutine 3 - 2
Goroutine 3 - 3
Goroutine 3 - 4
Goroutine 3 - 5
Goroutine 2 - 1
Goroutine 2 - 2
Goroutine 2 - 3
Goroutine 2 - 4
Goroutine 2 - 5
The End

@blog

golang

Find and replace

Find:       (:update\s.*)(_new)
Replace:    $1

Given text:

foo:update example_new
foo:update word_new
foo:update also_new

Output:

foo:update example
foo:update word
foo:update also

@blog #regex

Bulk Export

SQL-Insert-Statements-Bulk-100per.sql.groovy

SEP = ", "
QUOTE     = "\'"
NEWLINE   = System.getProperty("line.separator")

KEYWORDS_LOWERCASE = com.intellij.database.util.DbSqlUtil.areKeywordsLowerCase(PROJECT)
KW_INSERT_INTO = KEYWORDS_LOWERCASE ? "insert into " : "INSERT INTO "
KW_VALUES = KEYWORDS_LOWERCASE ? "values" : "VALUES"
KW_NULL = KEYWORDS_LOWERCASE ? "null" : "NULL"

OUT.append(KW_INSERT_INTO)
if (TABLE == null) OUT.append("MY_TABLE")
else OUT.append(TABLE.getParent().getName()).append(".").append(TABLE.getName())
OUT.append(" (")

COLUMNS.eachWithIndex { column, idx ->
    OUT.append(column.name()).append(idx != COLUMNS.size() - 1 ? SEP : "")
}

OUT.append(")").append(NEWLINE).append(KW_VALUES)

def record(columns, dataRow, close) {

    OUT.append(NEWLINE).append("(")
    columns.eachWithIndex { column, idx ->
        def value = dataRow.value(column)
        def skipQuote = value.toString().isNumber() || value == null
        def stringValue = value != null ? FORMATTER.format(dataRow, column) : KW_NULL
        if (DIALECT.getDbms().isMysql()) stringValue = stringValue.replace("\\", "\\\\")
        OUT.append(skipQuote ? "": QUOTE).append(stringValue.replace(QUOTE, QUOTE + QUOTE))
           .append(skipQuote ? "": QUOTE).append(idx != columns.size() - 1 ? SEP : "")
    }
    deliMeter = dataRow.last() || close ? ";" : ","
    OUT.append(")").append(deliMeter)
}

count = 0

def createInsert(columns, dataRow) {
    count++
    if (count%100 == 0 && !dataRow.last()) {
        record(columns, dataRow, true)
        OUT.append(NEWLINE).append(KW_INSERT_INTO)
        if (TABLE == null) OUT.append("MY_TABLE")
        else OUT.append(TABLE.getParent().getName()).append(".").append(TABLE.getName())
        OUT.append(" (")

        COLUMNS.eachWithIndex { column, idx ->
            OUT.append(column.name()).append(idx != COLUMNS.size() - 1 ? SEP : "")
        }

        OUT.append(")").append(NEWLINE).append(KW_VALUES)
        return
    }
    record(columns, dataRow, false)
}

ROWS.each { row -> createInsert(COLUMNS, row) }

mysql #groovy @blog

KDE Dive In

Apps

PHS 2019.1.4 
DGP 2019.2.6 custom JDK
DGP 2019.3 + plugin Choose Runtime + 8u212-linux-x64-b1596.1

latte launcher

subl ~/.config/kwinrc

[ModifierOnlyShortcuts]
Meta=org.kde.lattedock,/Latte,org.kde.LatteDock,activateLauncherMenu

OR

kwriteconfig5 --file ~/.config/kwinrc --group ModifierOnlyShortcuts --key Meta "org.kde.lattedock,/Latte,org.kde.LatteDock,activateLauncherMenu"

qdbus org.kde.KWin /KWin reconfigure

@blog #linux #kde

Dock station D3100

Fix slowing CPU

sudo nano /etc/X11/xorg.conf.d/20-intel.conf 

Section "Device"
  Identifier "Intel Graphics"
  Driver "Intel"
  Option "AccelMethod" "sna" 
  Option "TearFree" "true"
  Option "TripleBuffer" "true"
  Option "MigrationHeuristic" "greedy"
  Option "Tiling" "true"
  Option "Pageflip" "true"
  Option "ExaNoComposite" "false"
  Option "Tiling" "true"
  Option "Pageflip" "true"
  Option "VSync" "false"
EndSection

linux @blog

Projects

Tags

Capsule Servers

Lost connection to server.