<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bajro</title>
    <description>The latest articles on DEV Community by Bajro (@bajwolf).</description>
    <link>https://dev.to/bajwolf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F375040%2Fc032c310-d3e1-42c2-a214-14082666dc31.png</url>
      <title>DEV Community: Bajro</title>
      <link>https://dev.to/bajwolf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bajwolf"/>
    <language>en</language>
    <item>
      <title>Lines of code - Golang</title>
      <dc:creator>Bajro</dc:creator>
      <pubDate>Wed, 10 Nov 2021 20:58:09 +0000</pubDate>
      <link>https://dev.to/bajwolf/lines-of-code-golang-5gd8</link>
      <guid>https://dev.to/bajwolf/lines-of-code-golang-5gd8</guid>
      <description>&lt;p&gt;Let's make a simple counter to check how many lines of code are in our project.&lt;/p&gt;

&lt;p&gt;I want to start with a simple function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func LineCounter(r string) (int, error) {

    var count int
    rr  := strings.Split(r, "\n")
    var rrr []string
    cc := 0
    comstart := false
    for _, str := range rr {
        if strings.HasPrefix(str, "/*")   {
            comstart = true
            continue
        }
        if strings.Contains(str, "*/") {
            comstart = false
            cc += 1

        }
        if (str != "" &amp;amp;&amp;amp; !strings.HasPrefix(str, "//") &amp;amp;&amp;amp; !comstart) {
            rrr = append(rrr, str)
        }
    }

    count = len(rrr) - cc

    return count, nil
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function takes some text and split all lines by "\n" (newline sign).&lt;br&gt;
We check if 2 things if the line is empty and also if the line is any kind of comment. In golang there is a single-line comment starting with // and also multiline starting with /* and end with */. The function return number of lines or error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var (
    Info = Teal
    Warn = Yellow
    Fata = Red
  )

  var (
    Black   = Color("\033[1;30m%s\033[0m")
    Red     = Color("\033[1;31m%s\033[0m")
    Green   = Color("\033[1;32m%s\033[0m")
    Yellow  = Color("\033[1;33m%s\033[0m")
    Purple  = Color("\033[1;34m%s\033[0m")
    Magenta = Color("\033[1;35m%s\033[0m")
    Teal    = Color("\033[1;36m%s\033[0m")
    White   = Color("\033[1;37m%s\033[0m")
  )

  func Color(colorString string) func(...interface{}) string {
    sprint := func(args ...interface{}) string {
      return fmt.Sprintf(colorString,
        fmt.Sprint(args...))
    }
    return sprint
  }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This part of the code we use to create colored text doesn't need explanation I guess.&lt;/p&gt;

&lt;p&gt;Last but not least we have the main function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func main() {
    arg := os.Args[1]
    all := 0

    err := filepath.Walk(arg, func(path string, info os.FileInfo, err error) error {
        if err != nil {
            return err
        }
        if (!info.IsDir()  &amp;amp;&amp;amp; !strings.Contains(info.Name(), "test") ){
            ext := filepath.Ext(path)


            if ext == ".go" {

            jj, _ := os.ReadFile(path)
            g, _ := LineCounter(string(jj))
            all += g
            var u string
            if g &amp;lt; 200 {
                z := strconv.Itoa(g)
                u = Info(z)
            } 
            if g &amp;gt;= 200 &amp;amp;&amp;amp; g &amp;lt; 1000 {
                z := strconv.Itoa(g)
                u = Warn(z)
            }
            if g &amp;gt;= 1000 {
                z := strconv.Itoa(g)
                u = Fata(z)
            }
            fmt.Printf("File %s have %s lines of code \n",path, u)
            }
        }

        return nil
    })
    if err != nil {
        log.Println(err)
    }
    fmt.Println("All lines", all)

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I get my path from the console and go through it recursively checking if the path is not a folder. If the path is not a folder (it is a file) and if the file has ".go" extension. I also check if the filename contains "test" word. I don't want to count test files (In golang test files must contain test after the name). &lt;br&gt;
I add to sum every time when our LineCounter function returns a number. I check if a number of lines are less than 200 converts the number to a string and make it teal, 200-1000 Yellow, and everything more than 1000 is red. I also print every file with a number of lines. And on end, I print the sum of all lines.&lt;/p&gt;

&lt;p&gt;Finally our completed code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
    "log"
    "os"
    "path/filepath"
    "strconv"
    "strings"
)

var (
    Info = Teal
    Warn = Yellow
    Fata = Red
  )

  var (
    Black   = Color("\033[1;30m%s\033[0m")
    Red     = Color("\033[1;31m%s\033[0m")
    Green   = Color("\033[1;32m%s\033[0m")
    Yellow  = Color("\033[1;33m%s\033[0m")
    Purple  = Color("\033[1;34m%s\033[0m")
    Magenta = Color("\033[1;35m%s\033[0m")
    Teal    = Color("\033[1;36m%s\033[0m")
    White   = Color("\033[1;37m%s\033[0m")
  )

  func Color(colorString string) func(...interface{}) string {
    sprint := func(args ...interface{}) string {
      return fmt.Sprintf(colorString,
        fmt.Sprint(args...))
    }
    return sprint
  }

func main() {
    arg := os.Args[1]
    all := 0

    err := filepath.Walk(arg, func(path string, info os.FileInfo, err error) error {
        if err != nil {
            return err
        }
        if (!info.IsDir()  &amp;amp;&amp;amp; !strings.Contains(info.Name(), "test") ){
            ext := filepath.Ext(path)


            if ext == ".go" {

            jj, _ := os.ReadFile(path)
            g, _ := LineCounter(string(jj))
            all += g
            var u string
            if g &amp;lt; 200 {
                z := strconv.Itoa(g)
                u = Info(z)
            } 
            if g &amp;gt;= 200 &amp;amp;&amp;amp; g &amp;lt; 1000 {
                z := strconv.Itoa(g)
                u = Warn(z)
            }
            if g &amp;gt;= 1000 {
                z := strconv.Itoa(g)
                u = Fata(z)
            }
            fmt.Printf("File %s have %s lines of code \n",path, u)

            }
        }

        return nil
    })
    if err != nil {
        log.Println(err)
    }
    fmt.Println("All lines", all)

}


func LineCounter(r string) (int, error) {

    var count int
    rr  := strings.Split(r, "\n")
    var rrr []string
    cc := 0
    comstart := false
    for _, str := range rr {
        if strings.HasPrefix(str, "/*")   {
            comstart = true
            continue
        }
        if strings.Contains(str, "*/") {
            comstart = false
            cc += 1

        }
        if (str != "" &amp;amp;&amp;amp; !strings.HasPrefix(str, "//") &amp;amp;&amp;amp; !comstart) {
            rrr = append(rrr, str)
        }
    }

    count = len(rrr) - cc

    return count, nil
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope it will help some of you please tell me how it works and also if it works on Windows systems.&lt;/p&gt;

</description>
      <category>go</category>
      <category>tutorial</category>
      <category>opensource</category>
      <category>programming</category>
    </item>
    <item>
      <title>Blockchain resources</title>
      <dc:creator>Bajro</dc:creator>
      <pubDate>Wed, 10 Nov 2021 20:27:40 +0000</pubDate>
      <link>https://dev.to/bajwolf/blockchain-resources-1f9l</link>
      <guid>https://dev.to/bajwolf/blockchain-resources-1f9l</guid>
      <description>&lt;p&gt;I wondering does anyone have some blockchain or crypto resources. To we can collect in on one place. Feel free to send any resource you have in comments.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>crypto</category>
      <category>programming</category>
    </item>
    <item>
      <title>Vuejs Adobe color clone part 1.</title>
      <dc:creator>Bajro</dc:creator>
      <pubDate>Fri, 30 Apr 2021 23:03:58 +0000</pubDate>
      <link>https://dev.to/bajwolf/vuejs-adobe-color-clone-part-1-2o1o</link>
      <guid>https://dev.to/bajwolf/vuejs-adobe-color-clone-part-1-2o1o</guid>
      <description>&lt;p&gt;I come back with few changes in my attention to recreate Adobe color. I was struggling with making every component update slider separated. Then I decide to use Vuex with Vuex magic and Watch magic I finally made it (Yayyyyyyy 👏 😱). For now, I have only the easiest part done Shades but the concept now is the same and simple.&lt;/p&gt;

&lt;p&gt;If you check line 56 this is when beauty start I made myself a little function called hsltorgb.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hsltorgb: function(hslcolval,changevalue) {
      h = hslcolval[0]+changevalue[0];
      s = hslcolval[1]+changevalue[1];
      l = hslcolval[2]+changevalue[2];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function takes 2 arrays as arguments. The first array is the HSL value of the color you changing at this moment and the array looks like this [Hvalue,Svalue,Lvalue] and the second array is changed I want in the next color boxes. &lt;br&gt;
It will be a positive number if I want to add some number and a negative number if I want to subtract value for example [0,1,-1], &lt;br&gt;
if I use this array for changevalue H will stay the same if S is 50 it will become 51 and if L is 50 it will become 49.&lt;/p&gt;

&lt;p&gt;This is the color wheel.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.sessions.edu%2Fwp-content%2Fthemes%2Fdivi-child%2Fcolor-calculator%2Fwheel-3-rgb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.sessions.edu%2Fwp-content%2Fthemes%2Fdivi-child%2Fcolor-calculator%2Fwheel-3-rgb.png" alt="Color wheel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now when you check the wheel you see we have a circle (360 degrees who don't know 😎) and if we have red color (hsl(0,100%,50%)) and I want to get the green color I just need a pass to my function [0,100,50], [120,0,0] because green is on 120 degrees if I want blue I need 240. &lt;/p&gt;

&lt;p&gt;Notice: I still working on this and for now it doesn't work so well except if we change the first color box but soon I will make it work with any color box. &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/bajro91/embed/eYgXjNZ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
If you like my work feel free to leave me like ♥&lt;/p&gt;

</description>
      <category>vue</category>
      <category>adobe</category>
      <category>clone</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Simplest color scheme generator in Vuejs</title>
      <dc:creator>Bajro</dc:creator>
      <pubDate>Tue, 27 Apr 2021 01:15:11 +0000</pubDate>
      <link>https://dev.to/bajwolf/simplest-color-scheme-generator-in-javascript-a3g</link>
      <guid>https://dev.to/bajwolf/simplest-color-scheme-generator-in-javascript-a3g</guid>
      <description>&lt;p&gt;I try to make the simplest color generator with JavaScript.&lt;br&gt;
My understanding of the generator is that it works most of the time with HSL color representation. It is mostly for me to practice conversions between colors. &lt;/p&gt;

&lt;p&gt;I first convert hex color to RGB color by taking input and take first 2 characters to represent Red value than next 2 characters represent Green value and last 2 character is Blue value. After that, I take RGB color and convert it to HSL I found &lt;a href="https://css-tricks.com/converting-color-spaces-in-javascript/"&gt;Here&lt;/a&gt;. In the end, I just take the HSL value and change the L(lightness) value if I want darker color I subtract some value and if I want lighter color I add some value. &lt;br&gt;
You can check how it looks like and plays a little with it on my codepen. &lt;br&gt;
In the next few days, I will try to recreate &lt;a href="https://color.adobe.com/"&gt;Adobe color&lt;/a&gt;.&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/bajro91/embed/eYgXjNZ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>design</category>
      <category>javascript</category>
      <category>css</category>
      <category>color</category>
    </item>
  </channel>
</rss>
