SVG: Spiky Star

Let’s say we would like to create spiky star. One option would be to utilize tag path. Picture below should help to explain, how to design path. In the center “C” is a unit circle with radius 1. Each spike has base 0.8 wide (2*0.4) and height 1.5. Now let’s compute absolute coordinates for the green path points. Vertical distance for the first point g1 has value sqrt(1*1 -0.4*0.4) = 0.9165… Here is list of the few points.

g1[-0.4,-0.9165], g2[0,-2.4165], g3[0.4,-0.9165], g4[0.9165,-0.4], g5[2.4165,0], ...
C g1 g2 g3 g4 r1 r2 r3 r4

In similar fashion can be computed red path points. It is obvious, that in this case is much easier to compute their coordinates. On the other hand radius of the arc connecting point r3 and r4 is not just 1, but it has a value sqrt(1*1+ 0.4*0.4) = 1.077… In reality arc with radius 1 or arc with radius 1.077 is almost the same, especially for narrow spike base.

r1[-0.4,-1], r2[0,-2.5], r3[0.4,-1], r4[1,-0.4], r5[2.5,0], ...
Posted in workday | Tagged | Leave a comment

Structural formula: HydroxylAmmonium Nitrate

Here is slightly better structural formula of the HydroxylAmmonium Nitrate mentioned in the yesterday post.

H N O +
Posted in workday | Leave a comment

Rocket fuel: HydroxylAmmonium Nitrate

NASA tested in 2019 in mission GPIM so called green fuel. Here is chemical composition of this substance called hydroxylammonium nitrate or hydroxylamine nitrate with the chemical formula [NH3OH+][NO3-]. It is a colorless hygroscopic solid usually handled as an aqueous solution.

H N O +

Posted in workday | Leave a comment

Some git commands to practice

Here are few git commands to practice. And don’t forgot to edit github source by hitting DOT (.)!

*Stashing
git stash                             #changes to default stash
git stash pop                         #put back default stash

git stash save 'change description 1' #changes to labeled stash
git stash list                        #list all stashes
git stash apply 0                     #put back stash listed with index 0

*Three ways to add changes
git commit -a
git commit -am "describe here"

git add dir1/file1
git status
git reset

git add -p #prompt to all small changes

*Push more explicitly
git push origin my_branch --set-upstream #if for the first time

*Undoing commit
git commit -m "change 1 description"
git reset --soft HEAD~1               #commit undone

*Stash between branches
git stash                   #changes to default stash in current branch           
git checkout -b new_branch
git stash pop               #put back default stash to new_branch

*Log
git log --oneline
git log --graph

*
git commit --amend -m "new message"
git log
git revert f252a4ccee329c60fd8c01ae216c6e48f857a482

*$ git log
commit f252a4ccee329c60fd8c01ae216c6e48f857a482 (HEAD -> master)
Author: User <user@gmail.com>
Date:   Thu Sep 29 08:34:45 2022 -0500

    PROJECT 2022-0929

commit 201fbe8333be0640b2b606128b5d2195bdc8866c
Author: User <user@gmail.com>
Date:   Wed Sep 28 18:50:35 2022 -0500

    PROJECT 2022-0928

commit 49eca59f883b96eb92fa51552cdc36672a2c2ceb
Author: User <user@gmail.com>
Date:   Mon Sep 26 21:30:14 2022 -0500

    PROJECT 2022-0927
Posted in workday | Leave a comment

GO lang installation on FreeBSD

Working mostly on Windows 11 I found that cross compilation for FreeBSD does not work. I’ve got error message
go: unsupported GOOS/GOARCH pair FreeBSD/AMD64

Good solution is actually install it on FreeBSD itself. So here are commands from FreeBSD terminal.



#curl https://go.dev/dl/go1.19.3.freebsd-amd64.tar.gz -O
#cat go1.19.3.freebsd-amd64.tar.gz
<a href="https://dl.google.com/go/go1.19.3.freebsd-amd64.tar.gz">Found</a>.

#curl https://dl.google.com/go/go1.19.3.freebsd-amd64.tar.gz -O
#tar xvf go1.19.3.freebsd-amd64.tar.gz
#mv go /usr/local/.

$vi ~/.profile 
#add 3 env vars: export GOROOT=/usr/local/go export GOPATH=$HOME/goprojects export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
$ go version go version go1.19.3 freebsd/amd64 $ go env #to show go related env vars ... $ mkdir -p ~/goprojects/hello1 $ cd ~/goprojects/hello1 $ vi hello1.go
package main func main() { println("Hello One!") }
$go build hello1.go $./hello1 Hello One!
Posted in golang, workday | Tagged | Leave a comment

Display portion of an image

Let’s say there is a smaller version of the image on an HTML page with a link providing a full scale version of the image. you would like to display several detailed parts of that image. Here is color coded code how it can be done on a blog, where one does not have the option to have own style sheet.

<p>Detailed parts of Moon image:<br>
<span style="display:inline-flex; padding:0px; position:relative; no-repeat;height:180px;">
<span style="width:140px;margin:4px;background: url('/wp-content/uploads/2022/10/comp.8066.jpg') -2958px -420px;"></span>
<span style="width:199px;margin:4px;background: url('/wp-content/uploads/2022/10/comp.8066.jpg') -2200px -1160px;"></span>
<span style="width:280px;margin:4px;background: url('/wp-content/uploads/2022/10/comp.8066.jpg') -1970px -2620px;"></span>
</span></p>

Detailed parts of Moon image:

Credit: NASA Scientific Visualization Studio
Posted in workday | Tagged , | Leave a comment

Some git commands

In recent years git became versioning system of choice. Here are few commands to review and practice.

*Stashing
git stash                             #changes to default stash
git stash pop                         #put back default stash

git stash save 'change description 1' #changes to labeled stash
git stash list                        #list all stashes
git stash apply 0                     #put back stash listed with index 0

*Three ways to add changes
git commit -a
git commit -am "describe here"

git add dir1/file1
git status
git reset

git add -p #prompt to all small changes

*Push more explicitly
git push origin my_branch --set-upstream #if for the first time

*Undoing commit
git commit -m "change 1 description"
git reset --soft HEAD~1               #commit undone

*Stash between branches
git stash                             #changes to default stash in current branch           
git checkout -b new_branch
git stash pop                         #put back default stash to new_branch

*Log
git log --oneline
git log --graph

*
git commit --ammend -m "new message"
git log
git revert f252a4ccee329c60fd8c01ae216c6e48f857a482

*$ git log
commit f252a4ccee329c60fd8c01ae216c6e48f857a482 (HEAD -> master)
Author: User <user@gmail.com>
Date:   Thu Sep 29 08:34:45 2022 -0500

    PROJECT 2022-0929

commit 201fbe8333be0640b2b606128b5d2195bdc8866c
Author: User <user@gmail.com>
Date:   Wed Sep 28 18:50:35 2022 -0500

    PROJECT 2022-0928

commit 49eca59f883b96eb92fa51552cdc36672a2c2ceb
Author: User <user@gmail.com>
Date:   Mon Sep 26 21:30:14 2022 -0500

    PROJECT 2022-0927


Editing on github.com ?
Hit single character . (dot) and you will get VS online editor!

Posted in workday | Tagged | Leave a comment

Go: False positive virus detection

Recently to my surprise antivirus software detected virus in my freshly build golang program. Doing research I found interesting article from Melle Boudewijns. So I created simple golang program hello_flags.go:

package main

func main() {
  print("Hello: go build -race -ldflags \"-s -w\" hello_flags.go")
}

Then I compiled this source file with flags and execute it and again without flags and execute it. Here is output:

G:\hello_flags>go build -race -ldflags "-s -w" hello_flags.go

G:\hello_flags>.\hello_flags.exe
Hello: go build -race -ldflags "-s -w" hello_flags.go
G:\hello_flags>go build hello_flags.go

G:\hello_flags>.\hello_flags.exe
Access is denied.

G:\hello_flags>

Online tool VirusTotal.com for executable compiled with flags detected Trojan/Malicious/Malware by 16 antivirus programs. Avast did not detect it.

It looks like antivirus machine learning software should learn about simple golang program like above to avoid false positive detection.

Posted in golang, workday | Leave a comment

Text file to json array with jq

Lets say we need convert a text file into json array a process it. More information about jq itself can be found in the manual. First of all let’s create a test file with the first four Greek alphabet letters:

$ cat > greek.txt <<END
Alpha
Beta
Gamma
Delta
END

Each line can be converted to the element of an array. Tool jq is invoked with options --raw-input/-R (each line of text is passed to the filter as a string) and --compact-output / -c (no pretty output, each object is on a single line):

$ jq -cR 'split("\n")' greek.txt
["Alpha"]
["Beta"]
["Gamma"]
["Delta"]

Array brackets can be removed:

$ jq -cR 'split("\n") | .[]' greek.txt
"Alpha"
"Beta"
"Gamma"
"Delta"

Now we may search in similar way like in tool grep. Lets print all lines, for example, with letter “e”:

$ jq -cR 'split("\n") | .[] | select(test(".*e"))' greek.txt
"Beta"
"Delta"
Posted in workday | Leave a comment

Wordle helper

Wordle is nice single webpage game at https://www.powerlanguage.co.uk/wordle/ There is a page with list of the many 5 letter words at https://7esl.com/5-letter-words/ Here is how to create a plain text file with 660 5 letter words:

$ curl https://7esl.com/5-letter-words -O
$ grep "^<li>.....<" < 5-letter-words | sed 's|<li>\(.....\)</li>|\1|' > 5-letter-words.txt

Then one can grep the file 5-letter-word.txt to eliminate some options and list promising words.

There is also webpage https://eslforums.com/5-letter-words/ with 2498 words which can be processed into flat file 5-letter-wordsx2498.txt. Or even better option at file wordle-answers-alphabetical.txt by github user cfreshman with 2315 words.

Here is an example such helpful pipe. The first command lists words with known letter position, the second one eliminates words for letters which are not there

 $ grep ..o.. 5-letter-wordsx2498.txt | grep -vi -E "a|d|i|e|u|s|n|t|f|l"
Posted in workday | Tagged , , | Leave a comment