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

SVG: color-keywords with colors

At the World Wide Web Consortium (W3C) document SVG Color 1.2, Part 2: Language there are defined color-keywords. Here is that part of the definition updated with horizontal rectangle with color for all 147 color-keywords.

color-keyword ::= ~”aliceblue” | ~”antiquewhite” | ~”aqua” | ~”aquamarine” | ~”azure” | ~”beige” | ~”bisque” | ~”black” | ~”blanchedalmond” | ~”blue” | ~”blueviolet” | ~”brown” | ~”burlywood” | ~”cadetblue” | ~”chartreuse” | ~”chocolate” | ~”coral” | ~”cornflowerblue” | ~”cornsilk” | ~”crimson” | ~”cyan” | ~”darkblue” | ~”darkcyan” | ~”darkgoldenrod” | ~”darkgray” | ~”darkgreen” | ~”darkgrey” | ~”darkkhaki” | ~”darkmagenta” | ~”darkolivegreen” | ~”darkorange” | ~”darkorchid” | ~”darkred” | ~”darksalmon” | ~”darkseagreen” | ~”darkslateblue” | ~”darkslategray” | ~”darkslategrey” | ~”darkturquoise” | ~”darkviolet” | ~”deeppink” | ~”deepskyblue” | ~”dimgray” | ~”dimgrey” | ~”dodgerblue” | ~”firebrick” | ~”floralwhite” | ~”forestgreen” | ~”fuchsia” | ~”gainsboro” | ~”ghostwhite” | ~”gold” | ~”goldenrod” | ~”gray” | ~”grey” | ~”green” | ~”greenyellow” | ~”honeydew” | ~”hotpink” | ~”indianred” | ~”indigo” | ~”ivory” | ~”khaki” | ~”lavender” | ~”lavenderblush” | ~”lawngreen” | ~”lemonchiffon” | ~”lightblue” | ~”lightcoral” | ~”lightcyan” | ~”lightgoldenrodyellow” | ~”lightgray” | ~”lightgreen” | ~”lightgrey” | ~”lightpink” | ~”lightsalmon” | ~”lightseagreen” | ~”lightskyblue” | ~”lightslategray” | ~”lightslategrey” | ~”lightsteelblue” | ~”lightyellow” | ~”lime” | ~”limegreen” | ~”linen” | ~”magenta” | ~”maroon” | ~”mediumaquamarine” | ~”mediumblue” | ~”mediumorchid” | ~”mediumpurple” | ~”mediumseagreen” | ~”mediumslateblue” | ~”mediumspringgreen” | ~”mediumturquoise” | ~”mediumvioletred” | ~”midnightblue” | ~”mintcream” | ~”mistyrose” | ~”moccasin” | ~”navajowhite” | ~”navy” | ~”oldlace” | ~”olive” | ~”olivedrab” | ~”orange” | ~”orangered” | ~”orchid” | ~”palegoldenrod” | ~”palegreen” | ~”paleturquoise” | ~”palevioletred” | ~”papayawhip” | ~”peachpuff” | ~”peru” | ~”pink” | ~”plum” | ~”powderblue” | ~”purple” | ~”red” | ~”rosybrown” | ~”royalblue” | ~”saddlebrown” | ~”salmon” | ~”sandybrown” | ~”seagreen” | ~”seashell” | ~”sienna” | ~”silver” | ~”skyblue” | ~”slateblue” | ~”slategray” | ~”slategrey” | ~”snow” | ~”springgreen” | ~”steelblue” | ~”tan” | ~”teal” | ~”thistle” | ~”tomato” | ~”turquoise” | ~”violet” | ~”wheat” | ~”white” | ~”whitesmoke” | ~”yellow” | ~”yellowgreen”

Posted in workday | Tagged | Leave a comment

SVG: Circular arc

The arc command (a or A) of the element <path> is used to define an elliptical path. The special case is the circular path. Contrary to the element <circle>, where the center of the circle and radius has to be defined, the circular (actually elliptical) command defines start and end points of the path, radius and flag with value 0 or 1 depending on angle lower or greater than 180°.

Let’s say SVG viewBox is centered at 0,0 coordinates and we would like to create a circular path with center at 0,0 with radius r from start angle to the end angle:
x1 = r * cos(startAngle) y1 = - r * sin(startAngle)
x2 = r * cos(endAngle) y2 = - r * sin(endAngle)

With radius 100 from start angle 30° to end angle 60° coordinates looks like:
x1 = 100 * cos(30°) y1 = - 100 * sin(30°)
x2 = 100 * cos(60°) y2 = - 100 * sin(60°)

Here are an examples with absolute and relative commands:
<path          d=”M50,-86.6025 A100,100 0 0,1  86.6025,-50″ />
<path d=”M0,0 m50,-86.6025 a100,100 0 0,1 36.6025,36.6025 ” />

With rotation angle always 0 and sweep flag 1, both in blue, it could be described like this with red variables:
<path id=”absolute_path” d=”Mx1,y1 Ar,r 0,largeFlag,1 x2,y2” />
Let’s say path is already at point x1,y1:
<path id=”relative_path” d=”ar,r 0,largeFlag,1 x2-x1,y2-y” />
Large arc flag has value 0 for arc angle less than 180° and value 1 for angle greater than 180°.

Example of the circular arc from start angle 30° to the end angle 60°.

There is a tool available to create circular arc at https://tools.minetlab.com/svg/circular-arc/

Posted in workday | Tagged | Leave a comment

Sellers.json

Would you like to find who is advertising with Google AdSense? There is a Google file sellers.json . Most objects have a property “is_confidential”: 1, but other objects could have a domain name and other information. Be aware, the file is huge, more than 140 MB and getting bigger. Of course, there is more than one million sellers. Below is a command to download it:

curl https://storage.googleapis.com/adx-rtb-dictionaries/sellers.json -O

Here are several example commands utilizing jq tool:

# let's find how many sellers are in the file
$ jq '.sellers[] | length ' sellers.json | wc -l
1302360

# one concrete seller_id
$ jq '.sellers[] | select(.seller_id == "pub-0000000381088596")'  < sellers.json
{
  "seller_id": "pub-0000000381088596",
  "is_confidential": 1,
  "seller_type": "PUBLISHER"
}

# all non confidential sellers
$ jq '.sellers[] | select(.is_confidential != 1)'  < sellers.json
...removed...

#all objects with domain
$ jq '.sellers[] | select(.domain != null)'  < sellers.json | head -11
{
  "seller_id": "pub-0000074043221914",
  "seller_type": "PUBLISHER",
  "name": "Imago Informationstechnologie GmbH",
  "domain": "automobile.de"
}
...truncated...

# all objects with domain containing .tv
$ jq '.sellers[] | select(.domain != null) | select(.domain | contains(".tv"))'  < sellers.json
{
  "seller_id": "pub-0015244548563708",
  "seller_type": "PUBLISHER",
  "name": "Richard Foster",
  "domain": "streamfree.tv"
}
...truncated...
Posted in workday | Leave a comment

Carbon: How much is 1 ppm of CO2 in Earth atmosphere

On Earth day 2021 will be officially announced XPRIZE Carbon Removal sponsored by Elon Musk.  Now there is a carbon dioxide content in the atmosphere 412 ppm. It would be good to know how much is actually 1 ppm of carbon dioxide in the whole atmosphere.

The atmosphere has a mass of about 5.15×1018 kg. The average molecular weight of dry air, which can be used to calculate densities or to convert between mole fraction and mass fraction, is about 28.946 or 28.96 g/mol. Let’s take the first value of 28.946 g/mol or 0.028946 kg/mol. The whole atmosphere has then 5.15×1018 / 0.028946 = 1.77917×1020 mol. One part per million is then 1.77917×1014 mol. The weight of such amount of the carbon dioxide is then 1.77917×1014 * 0.044009 = 7.82997×1012 kg (or 7.82997×109 ton or 7.82997 gigaton).

The current concentration of CO2 is about 412 ppm by volume, having risen from pre-industrial levels of 280 ppm. Increase is 132 ppm. It represents 132 * 7.82997 = 1,033.55 giga ton, about 1 tera ton.

Related posts:
Carbon: What is a size of the 1 ton of CO2

Posted in workday | Tagged , , | Leave a comment

Carbon: What is a size of the 1 ton of CO2

On Earth day 2021 will be officially announced XPRIZE Carbon Removal sponsored by Elon Musk. We know now, that a scale model at a level of carbon removal of 1 ton of CO2 per day has to be demonstrated. So, what it means, how much is actually 1 ton of CO2?

Here are some carbon dioxide properties from Wikipedia:

Chemical formulaCO2
Molar mass44.009 g·mol−1
AppearanceColorless gas
OdorLow concentrations: none
High concentrations: sharp; acidic[1]
Density1562 kg/m3 (solid at 1 atm (100 kPa) and −78.5 °C (−109.3 °F))
1101 kg/m3 (liquid at saturation −37 °C (−35 °F))
1.977 kg/m3 (gas at 1 atm (100 kPa) and 0 °C (32 °F))

Now based on knowledge of the properties it’s possible to write what it means 1 ton = 1000 kg of CO2:
– 2.272262^4 mol (1000 / 0.044009)
– 509.2 m3 of gas (2.272262^4 * 0.02241) computed from Avogadro’s law
– 505.8 m3 of gas (1000 / 1.977) computed from density
– 0.908 m3 of liquid (1000 / 1101)
– 0.640 m3 of solid – dry ice (1000 / 1562)

One ton of the carbon dioxide can be result of burning 273 kg of pure carbon like graphite or diamante (1000 * 12 / 44). Or of the twice as much as of a wood.

Carbon dioxide content in fresh air (averaged between sea-level and 10 kPa level, i.e., about 30 km (19 mi) altitude) varies between 0.036% (360 ppm) and 0.041% (412 ppm). Let’s continue with value 0.0412%. Abbreviation ppm means parts per million. One square meter has 1 million square centimeters (100 x 100 x 100), so it has volume 412 square centimeters of the CO2. Now let’s ask a question, what is a volume of air with 1000 kg of CO2:
– 1.2277109^6 m3 (505.8 / 0.0412 / 100) or (505.8 / 412^-6)
Conclusion:
Volume 1.2277109^6 m3 of fresh air in 2021 can be a cube of size 107 meters or a sphere with radius of 66.4 meters (diameter 132.9 m) with 1 ton of CO2.


Posted in workday | Tagged , , | Leave a comment

NET-100-64-0-0-1

Did you find your WAN IPv4 address in the range 100.64.0.1 to 100.127.255.254? Then most likely your Internet Service Provider (ISP) is utilizing shared address space. Most likely that address would be behind Carrier-Grade NAT (CGN). See more RFC 6598.

Posted in Blogroll, workday | Tagged , | Leave a comment

Go webserver on Apache

Go language allows create very easily webserver. Let’s consider a full working example of a simple web server at https://golang.org/doc/articles/wiki/ implemented in the file web8080.go:

package main

import (
    "fmt"
    "log"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Code above could be one of the several web application implemented in go language. Each application should use different port, if running on the same server. Each port could be redirected to different virtual host implemented on Apache2 webserver. For example on Ubuntu 20.04 LTS we should add apache module:
a2enmod proxy proxy_http
Create virtual host configuration file /etc/apache2/sites-available/example.com.conf

<VirtualHost *:80>
        ServerName example.com
        ProxyPass / http://127.0.0.1:8080/
        ProxyPassReverse / http://127.0.0.1:8080/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Run command
a2ensite example.com.conf
so in the directory /etc/apache2/sites-enabled will be created symbolic link in similar way like by commands cd /etc/apache2/sites-enabled; ln -s ../sites-available/example.com.conf .
Then reload apache server
systemctl reload apache
and you should be able browse example.com and continue in development!

Posted in golang, workday | Tagged , , | Leave a comment