<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nenad Ticaric on Medium]]></title>
        <description><![CDATA[Stories by Nenad Ticaric on Medium]]></description>
        <link>https://medium.com/@nticaric?source=rss-7d82943be95e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EbqXh31v2Z46b5gqIbAr9w.jpeg</url>
            <title>Stories by Nenad Ticaric on Medium</title>
            <link>https://medium.com/@nticaric?source=rss-7d82943be95e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:08:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nticaric/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Few little things in Go]]></title>
            <link>https://medium.com/@nticaric/few-little-things-in-go-d353ee1d0af4?source=rss-7d82943be95e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d353ee1d0af4</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Nenad Ticaric]]></dc:creator>
            <pubDate>Mon, 27 Jul 2020 09:20:21 GMT</pubDate>
            <atom:updated>2020-07-27T09:20:21.164Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OhpMW0ZVEveS_R9jW7zAWA.png" /></figure><p>While writing programs in go, you’ll come across some weird situations where you don’t know why the compiler complains. Let’s take a look at some of those cases.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4507f41561a2f894077f9e193c3359d/href">https://medium.com/media/e4507f41561a2f894077f9e193c3359d/href</a></iframe><p>When you first look at that code, everything looks normal, but for some reasons, the compiler will complain, saying:</p><pre>counter declared but not used</pre><p>but why would the compiler complain if we see that the variable counter is used. It’s been set to 1 if the <em>shouldStartWithOne()</em> function returns <em>true</em>.<br>If you run it through a linter, you might get a more detailed explanation:</p><pre>counter declared but not used (as r-values)</pre><p>This means that each variable declared in a code block must be used as a r-value (right-hand-side value) for at least once.</p><p>Now, this might be clear to you, but in case it’s not, read on.</p><p>There are two types of expressions in Go, l-values and r-values</p><p>A <strong>l-value</strong> represents an assignable location that points to a memory location. They can appear both on the left and on the right side</p><p>The<strong> r-value </strong>represents the actual data that is stored at some address in memory. You cannot assign a value to it, which means it can appear on the right, but never on the left</p><p>With this understanding and with a little change we can make the above code work</p><pre>_ = counter</pre><p>To make it short, you cannot just declare a variable or assign a value to it, you have to use it. Either assign it to something else, or pass it to a function.</p><p>After reading the documentation, you’ll find out that the if statement also accepts a initialization statement, which is cool. It lets you write something like this:</p><pre>if err := file.Chmod(0664); err != nil {<br>    log.Print(err)<br>    return err<br>}</pre><p>You also may know that a map lookup returns two values, the second is a boolean that reports whether the element was present in a map or not. This brings us to writing code like this:</p><pre>if elem, ok := elements[&quot;something&quot;]; !ok {</pre><pre>    return nil, errors.New(&quot;element not found&quot;)</pre><pre>}</pre><pre>doSomethingWithElement(elem)</pre><p>But for some reason, this fails by saying that <em>elem </em>was declared but not used.<br>The thing here is that the <em>elem</em> variable is only scoped to the <em>if</em> block, so it doesn’t exist outside of it. Alternatively, it exists in the <em>else</em> block.</p><pre>if elem, ok := elements[&quot;something&quot;]; !ok {</pre><pre>    return nil, errors.New(&quot;element not found&quot;)</pre><pre>} else {</pre><pre>    doSomethingWithElement(elem)<br>}</pre><p>So if you want your code to be nicer looking, you would do the lookup before the <em>if</em> block</p><pre>elem, ok := elements[&quot;something&quot;];</pre><pre>if !ok {</pre><pre>    return nil, errors.New(&quot;element not found&quot;)</pre><pre>}</pre><pre>doSomethingWithElement(elem)</pre><p>Hope this article helps you to understand some of go’s behavior</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d353ee1d0af4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Text Classification with TNTSearch and Laravel]]></title>
            <link>https://medium.com/@nticaric/text-classification-with-php-7c571527e28c?source=rss-7d82943be95e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c571527e28c</guid>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[tntsearch]]></category>
            <dc:creator><![CDATA[Nenad Ticaric]]></dc:creator>
            <pubDate>Tue, 06 Feb 2018 00:03:14 GMT</pubDate>
            <atom:updated>2018-02-06T00:03:32.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yEyN36NibvtmaKgaLdq7RA.jpeg" /></figure><p>It’s hard to ignore the fact that machine learning is becoming ubiquitous. Everybody is talking about it and everybody seems to be using it. You’ll start asking yourself if PHP is suitable to get into the race. It’s true that machine learning tasks are CPU intensive, but speed of the language isn’t everything.</p><p>With the <a href="https://github.com/teamtnt/tntsearch">TNTSearch</a> project, we try to bring to you state of the art algorithms implemented in pure PHP. Those algorithms give first class results and are meant to be used in real app scenarios. This tutorial will cover how to add text classification to your Laravel app.</p><p>Text classification can be used for many applications. To name just a few:</p><ul><li>spam detection</li><li>text categorization</li><li>sentiment analysis</li></ul><p>A state of the art algorithm for text classification is Multinomial Naive Bayes. This is a probabilistic learning method which calculates the probability of a document being in a category. I won’t bore you with the Bayes theorem and formulas, there are plenty resources on the web to satisfy your curiosity. What you probably are waiting for is how to get your hands dirty and get into the code.</p><p>Our main goal was to make it simple to use and make it fast. If you read some tutorials on classification before, you were only thought how to train your model and to apply it right away. In practice, this is not the case, you need to save the trained model somewhere so you can reuse it.</p><p>Let’s say you’re running a blog and want to classify your comments. We want to see which comments are SPAM and which are not. The ones that are not spam, we’ll call HAM. <br>Ok, enough talking let’s dig into the code. First, we need to install <a href="https://github.com/teamtnt/tntsearch">TNTSearch</a>, which is, by the way, a search engine entirely written in PHP but also has some cool stuff like classification, which is part of information retrieval, and this is of course also machine learning. So, installing</p><p>composer require teamtnt/tntsearch</p><p>In the root of your project create a classify.php file. This is of course only a suggestion, you&#39;ll probably be using a framework like laravel and you are most likely to create an artisan command for this. But here, we&#39;ll keep it simple.</p><pre>&lt;?php<br><br>require __DIR__ . &#39;/vendor/autoload.php&#39;;<br><br>use TeamTNT\TNTSearch\Classifier\TNTClassifier;<br><br>$comments = loadCSV(&#39;/load/comments/from/disk.csv&#39;);<br><br>$classifier = new TNTClassifier();<br><br>foreach ($comments as $comment) {<br>    $classifier-&gt;learn($comment-&gt;text, $comment-&gt;category)<br>}<br><br>$classifier-&gt;save(&#39;./path/to/comments.cls&#39;);</pre><p>What this piece of code does is it simply takes the .csv file containing the comments together with their category which can be either SPAM or HAM and teaches the classifier. After that, the trained model is saved to disk to ./path/to/comments.cls</p><p>That’s it, this is how you train your model. You only need to do the training once. The larger the dataset the better because the predictions will be more accurate. Now that we have a trained model, predicting if a comment is SPAM or not is easy. In your guess.php file, you’ll have the following:</p><pre>&lt;?php<br><br>require __DIR__ . &#39;/vendor/autoload.php&#39;;<br><br>use TeamTNT\TNTSearch\Classifier\TNTClassifier;<br><br>$classifier = new TNTClassifier();<br>$classifier-&gt;load(&#39;./path/to/comments.cls&#39;);<br><br>$guess = $classfier-&gt;predict(&#39;This is a nice post&#39;);<br><br>echo $guess[&#39;label&#39;];</pre><p>The above code is very simple. We load the model from disk and ask the classifier to tell us what the prediction might be.</p><p>We did some tests with large datasets and the performance and accuracy are astonishing. The SPAM/HAM SMS classification test has a score of 98.4753%</p><p>If you like the <a href="https://github.com/teamtnt/tntsearch">TNTSearch</a> project star it on github and leave a comment here with some feedback</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c571527e28c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing a Sudoku solver in Go]]></title>
            <link>https://medium.com/@nticaric/writing-a-sudoku-solver-in-go-3f6539eafcc5?source=rss-7d82943be95e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f6539eafcc5</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Nenad Ticaric]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 23:38:21 GMT</pubDate>
            <atom:updated>2018-02-05T23:43:11.906Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="http://amzn.to/2E4UDbx">Pragmatic Programmers</a>’ advice is to learn a new language every year. It affects the way you think about programming. Learning a new language can do a lot to help you think about solving problems in different ways. <br>Most of my day to day development is done either in PHP or Javascript. It was about time to grasp a new language. <a href="https://golang.org/">Go</a> seemed like the perfect candidate to do this.</p><p>While I’m going through some go code, my wife is playing sudoku to keep her mind sharp. She struggles with a problem and is unable to solve the puzzle. <br>An idea strikes through my mind - why not write a sudoku solver in go. It’s fun and I’ll learn the language basics.</p><h3>Choosing the algorithm</h3><p>I’m not planning go to into some fancy sudoku solving algorithms. Usually, the simple ones are the best. So I choose to use the backtracking algorithm.<br>The algorithm searches for an empty field and tries to fit a number into it. It starts with a number ie. 1 and then checks if the board is valid. If not, it tries the next number, if yes it goes to the next blank field. If a particular cell isn’t allowed to fit any number into, the algorithm goes to the previous cell and increments it by 1. It’s much easier to visualize this than to describe, so here’s an animation of the algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*ISlzB1fMXIYeovi3OrmyYw.gif" /><figcaption>Sudoku solved by backtracking</figcaption></figure><p>This will be a command line tool so visualizing the input would be useful and that&#39;s why I’m starting with a function to display the sudoku board.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c63260a89f5f0655c647d2b23e26ed7/href">https://medium.com/media/8c63260a89f5f0655c647d2b23e26ed7/href</a></iframe><p>This will produce the sudoku board on the command line like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*WmzHzakAGXVy6edildZNrA.png" /></figure><p>As you can see from the code, the function takes a integer two dimensional array as its argument. Since we’re going to feed the puzzle as a string we’re need to do some input parsing</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3320601e366da0bc69b870934642136b/href">https://medium.com/media/3320601e366da0bc69b870934642136b/href</a></iframe><p>Checking if the board is valid is easy. We only need to check if there are repeated numbers in a row, a column or in a 3x3 section. This can be done with couple for loops</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e209a24446424c8a3f7cb0319d41d980/href">https://medium.com/media/e209a24446424c8a3f7cb0319d41d980/href</a></iframe><p>And the most important part of the code, the backtracking algorithm itself</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad283a19181a59491ba8130a0844cdfb/href">https://medium.com/media/ad283a19181a59491ba8130a0844cdfb/href</a></iframe><p>If you want to play a little with the code, you can clone it from <a href="https://github.com/nticaric/sudoku-solver">github</a>.</p><p>So far, I like the language very much. It’s very expressive and efficient. You can do a lot with little code. It is a strongly typed language but compiles very fast which makes it feel like an interpreted one.</p><p>I like the little things like `gofmt`and `go doc`. My environment is sublime text editor with the <a href="https://github.com/DisposaBoy/GoSublime">GoSublime</a> plugin. Once a file is saved it runs gofmt which formats the code for you, so you don’t have to follow any style guide, its automatically done for you. The plugin also offers autocomplete which is very handy.</p><p>You can lookup any function by simply typing</p><pre>go doc fmt.Print</pre><p>In this article I didn’t cover any advanced stuff that the language offers, but hopefully I will in some of the upcoming articles.</p><p>If you have some tutorial ideas, feel free to leave a comment bellow</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f6539eafcc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>