teleren/devto huggingface dataset:
Daily Challenge #147 - NIM
Tags: challenge
Published: 2019-12-28 17:18:02

---
title: Daily Challenge #147 - NIM
published: true
series: Daily Challenge
description:  Write an AI for a two player, turn based game called NIM.
tags: challenge
---
###Setup
Nim is a mathematical strategy game in which two players take turns removing objects from piles of straw. On each turn, a player must remove at least one straw, and may remove any number straw provided they all come from the same heap/pile. The goal of the game is to take the last piece of straw.
<pre>Pile 0: ||||

Pile 1: ||

Pile 2: |||||

Pile 3: |

Pile 4: ||||||

...or more concisely: [4,2,5,1,6]</pre>

###Rules
- Each player takes turns picking a pile and removing as much straw as they want from the pile they pick.
- Players must take at least one straw.
- Whoever picks the last straw wins.

###Task 
Write a function to create an AI that plays NIM. 

You have to encode an AI in a function that takes a board represented as a list of positive integers and returns: `[pile_index, number_of_straws]`, which refers to an index of a pile on the board and some none-zero number amount of straw to draw from that pile. 

###Examples
<pre>(chooseMove([0,5,0,0]),[1,5]);

(chooseMove([0,3,5]),[2,2]);

(chooseMove([3,3,6]),[2,6]);</pre>

Good luck!~ 
***
_This [challenge](https://www.codewars.com/kata/54120de842dff35232000195) comes from xcthulhu on CodeWars. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
Laravel Multilingual Library
Tags: php, laravel, library
Published: 2019-12-28 16:50:57

Hi Laravel Rockstars,

I have just finished recently my Laravel Package/Library. It's for multi-language purposes. Current version (1.0.0) is available now.

## Main Ideas for v1.0.0
- No need to touch the static language files in the project, manage it dynamically on backend pages - Lovely feature for Editors/Translators
- Dealing with many languages as you want
- Cache-able the language texts & retrieve it faster.
- ...

## Supported Laravel Versions
- 6.x: Testing
- 5.8: Tested - Supported
- 5.7: Tested - Supported
- 5.6: Testing
- 5.5: Testing
- 5.4: Testing

But I think from 5.5+, it should work fine. Not 100% sure, still testing 😂

## Backend Page
![Backend Page - Demo - Laravel Multilingual Seth Phat](https://i.imgur.com/FqyH4oD.png)

## APIs
Simply use this function:

```php
/**
* Get the translation text
* @param string $textKey Key Value of Text Bundle Item - Required
* @param string $moduleName Text Bundle Name - Required
* @param array $replaceText Same as Laravel Translation to replace text (My name is :name => ['name' => 'Seth Phat']) - Default: array()
* @param string $specificLanguage Define the specific language to retrieve - Default: App::getLocale() - Current language
* @param boolean $should_throw Throw Exception when the text is not found or not. Default: false
*/
multilingual(string $textKey, string $moduleName, array $replaceText, string $specificLanguage, boolean $shouldThrow)
```

To change language, just simply use the `App::setLocale` of Laravel.

## Plans
- Version 1.0.0: Static Language Text (Available now)
- Version 1.1.0: Inject to specific Table/Entity for multilingual purpose. More APIs...

## Install and Github
Main repository: [GitHub - Laravel Multilingual](https://github.com/sethsandaru/laravel-multilingual)

All the instruction of the installation is there. Check it out.

Thank you for reading! Any reviews/bug-report would help this library a lot :D. Give it a ⭐ if you like it 😍
Introduction to Relational Database and SQL
Tags: sql, database, webdev, tutorial
Published: 2019-12-28 14:00:30

## Introduction to Relational Database and SQL

### Full scale SQL and Relational Database course

### Learn how to create one of the most efficient ways of storing data - relational databases!

This course teaches you how to design a relational database and how to write SQL. It covers all the important SQL statements, including CREATE, INSERT, UPDATE, DELETE, SELECT, ALTER, and DROP, and provide some insight into entity-relationship model design. This course is based on my on-campus teaching at colleges and comes with a mid-term project and a final project. There is no prerequisite for this course.

### What you'll learn
* SQL
* Entity Relationship Model
* Relational Database

{% youtube 4pyWqf-BOCQ %}
JavaScript
Published: 2019-12-28 13:26:28

var alcoholic = ["Beer","Wine","Cider","Cocktail","Shots"];
var soft = ["Coke","Fanta","Sprite","Dr.Pepper", "Mountain Dew", "Pepsi"];
var hot = ["Coffee", "Cappuccino", "Espresso", "Hot Chocolate", "Latte"];
var cold = ["Lemonade","Juice","Smoothie","Milkshake","Ice tea"];

var drinks = [alcoholic, soft, hot, cold];

printDrinks = (order_number) => {
    if(order_number > 0 || order_number > 3) {
        return 'INVALID_ORDER_NUMBER';
    }
    for (i=0; i < drinks[order_number].length; i++) {
        console.log(drinks[order_number][i]);
    }
}

printAllDrinks = () => {
    for(i = 0; i < drinks.length; i++) {
        for(j=0; j < drinks[i].length; j++) {
            console.log(drinks[i][j]);
        }
    }
}

searchForDrink = (drink) => {
    for(i = 0; i < drinks.length; i++) {
        for(j=0; j < drinks[i].length; j++) {
            if(drink == drinks[i][j]) {
                return true;
            }
        }
    }
    return false;
}

var search = prompt('which drink would you like?');

if(searchForDrink(search)) {
    alert('Drink available');
} else {
    alert('Sorry!, drink not available');
}

printDrinks(0);

console.log('===============');

printDrinks(1);

console.log('===============');

printDrinks(2);

console.log('===============');

printDrinks(3);

console.log('===============');

printDrinks(4);

when enter 1 in the prompt, it should show the drinks in the array 1 with alert. And then it should show another prompt where you write drink name from the number 1 as example. And then it should tell if it is available or not.
#javascript
Famous CSS Colors for my T-Shirt
Tags: html, css, colors, watercooler
Published: 2019-12-28 12:52:08

---
title: Famous CSS Colors for my T-Shirt
published: true
description: Custom T-Shirt
tags: html, css, colors, watercooler
---

Hi Everyone, I need a little help with my geek T-Shirt.

Old one's colors are fading away and I need to get it printed again.
Unfortunately, this time I have only 1 `white` color options for a t-shirt hence I need to find 3 most famous css color which I can choose.

In Stone age, when I last worked with html/css `Cyan` was the color I loved the most <3.

Please let me know if there are any other cool colors which I can select.

Only 3 Colors. Below is the current one.

Thank you! Have fun!

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/rxqcs440jy1w22uc7cia.jpeg)
Sorting Visualizer built using flutter/dart
Tags: dart, android
Published: 2019-12-28 12:47:02

GitHub : [Sorting Visualizer](https://github.com/vineet192/Sorting-Visualiser)

This is just a simple personal project because i'd been wanting to try out flutter for a while. The learning curve isn't too steep if you are already relatively well versed in java, c, c++ or even JavaScript.

Anyways, since i'm still a beginner, I would love to hear your thoughts on it.
Hub. Access Github without leaving your terminal ! 💻🚀
Tags: git, beginners, productivity, showdev
Published: 2019-12-28 12:43:26

---
title: Hub. Access Github without leaving your terminal ! 💻🚀
published: true
description: 
tags: git, beginners, productivity, showdev
cover_image: https://media.giphy.com/media/xT77XWum9yH7zNkFW0/source.gif
canonical_url: https://blog.yafkari.dev/blog/hub-access-github-without-leaving-your-terminal-3415
---

Hello everyone, today I will present you a nice tool that will __save you time__ and will help you being __more productive__ with your Github projects.

It's called __Hub__ (Original 😝), and it _"helps you do everyday GitHub tasks without ever leaving the terminal."_

_In this article, I will not go in depth in the presentation of the features because the documentation is pretty good actually. I don't think you'll struggle with it \^\^._

That's a very interesting tool for people that codes and use __Git__ (if you code, you should __definitively__ use Git ❗️)

In fact, Hub is an extension to the __git command-line__, it adds __Github__ specific commands.



For example :

```powershell
$ git clone git://github.com/YOUR_USER/PROJECT.git
```
Becomes:

```powershell
$ hub clone PROJECT
```


Or you can list the issues that are assigned to you with a certain label, ... :
```powershell
$ hub issue -a YOUR_USER -l LABEL
```

You can also open the current __open the wiki__ of a project, open a pull-request, ...

_You can find all the commands on the [documentation page](https://hub.github.com/hub.1.html)._



I think that this tool is very useful when you get used to __NOT OPEN__ your browser and it's easier to automate things, create aliases, ...


You can install Hub easily with: 
```shell
brew install hub
```

OR get a __precompiled version__ of it [here](https://github.com/github/hub/releases).

If you want to know more about it, go check the [website](https://hub.github.com) !

---

PS: We almost hit __3000 FOLLOWERS__ (2959 while I'm writing) on __DEV__, you are AMAZING ❤️🔥 THANK YOU FOR BEING WITH US 🙏🏻
Reading Snippets [21]
Tags: javascript, beginners, todayilearned
Published: 2019-12-28 12:27:58

Expressions and statements may seem very similar but they are actually quite different.

An expression is a piece of code that becomes a value. A statement, on the other hand, performs actions and controls actions but does not become a value. 

Knowing the difference between an expression and statement can open one up to new experiences in reading their code and finding bugs. 

For example, with an understanding of the difference between expressions and values, one would know that a statement cannot be put where an expression is expected.
Elapsed time in Ruby, leap second safe
Tags: time, leapsecond, ruby
Published: 2019-12-28 12:21:14

---
title: Elapsed time in Ruby, leap second safe
published: true
description: Great article on a robust way to get elapsed time
tags: Time, Leap Second, Ruby
---
I highly recommend this article if you're interested in robust and reliable ways to build business logic that includes the notion of elapsed time.


"Elapsed time with Ruby, the right way" by Luca Guidi
https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way/
★ My favourite albums released in 2019
Tags: music, life
Published: 2020-01-02 23:46:42

---
title: ★ My favourite albums released in 2019
published: true
date: 2019-12-28 12:15:28 UTC
tags: music, life
canonical_url: https://freek.dev/1544-my-favourite-albums-released-in-2019
---

These are my 10 favourite albums which were released in 2019, alphabetically sorted.

- [Floating Points - Crush](https://open.spotify.com/album/1WwZwdTICfaZI51BIIEN9z)
- [Heloda Negro - This Is How You Smile](https://open.spotify.com/album/17LsQV3q3cgTBrat3D5JSv)
- [Solange - When I get Home](https://open.spotify.com/album/4WF4HvVT7VjGnVjxjoCR6w)
- [Taxi wars - Artificial Horizon](https://open.spotify.com/album/7N2FEbPi3USl09VwYk9dNu)
- [Thom Yorke - Anima](https://open.spotify.com/album/5a4VSyY7zsfVVqHweYHG7R)
- [Thurston Moore - Spirit Counsel](https://open.spotify.com/album/0h2rDg9Mdfl1kQTVeznEty)
- [Tool - Fear Inoculum](https://open.spotify.com/album/7acEciVtnuTzmwKptkjth5)
- [Tyler, The Creator - Igor](https://open.spotify.com/album/5zi7WsKlIiUXv09tbGLKsE)
- [W.H. Lung - Incidental Music](https://open.spotify.com/album/5Lco0BgRQR6A8koweo3SN4)
- [Weval - The Weight](https://open.spotify.com/album/5zB9HVERRys2UNiyNszxIP)
Destructuring assignment e Spread operator
Tags: destructuring, spread, desestruturacao, espalhamento
Published: 2019-12-28 12:13:42

Combinar desestruturação com spread operator pode facilitar muito o desenvolvimento.
Como podemos ver no exemplo a seguir, os valores do array serão atribuídos as variáveis *a* e *b*, e o restante dos valores passarão para a variável *rest*. Entretanto isso só é possível porque utilizamos o spread operator, caso contrario, o valor da variável *rest* seria 2. Ao utilizarmos **...** dizemos que todos os valores restante do array, devem ser atribuídos a nossa variável *rest*.

```javascript
let a, b, rest;
[a, b, ...rest] = [0, 1, 2, 3, 4, 5, 6];
// a = 0
// b = 1
// rest = [2, 3, 4, 5, 6]
```
O mesmo pode ser aplicado ao retorno de uma função.
```javascript
let func = () => [0, 1, 2, 3, 4];
[a, b, ...rest] = func();
// a = 0
// b = 1
// rest = [2, 3, 4]
```
Podemos utilizar também para objectos.
```javascript
({a, b, ...rest} = {a:1, b:2, c:3, d:4}); 
// a = 1
// b = 2
// rest = {c:3,d:4}
```
Vuejs Vs Reactjs
Tags: react, vue
Published: 2019-12-28 11:58:15

Javascript has single-handedly captured the web applications domain by making intelligent use of its frameworks and libraries like ReacJs and VueJs. No doubt it is the most useful and popular framework of our times, especially known for providing higher performances and ease of learning.

In addition, both the frameworks are extensively employed for designing the User interfaces and also used for working with the root library. And they have certain similarities too in reactivity, presence of virtual DOM model and component-based structure.

<img src="https://codersera.com/blog/wp-content/uploads/2019/12/VueJs-Vs-ReactJs.png">

Hopefully, this comparison will make you select the best framework for your business challenges and requirements in accordance with your project requirements, the expertise of the developers, market trends and insights.


<B>VueJs is simpler, it features a lot of concepts from Angular 1 and React. You can use it without any build system — just include it in the HTML file. React is bigger and a little more complex (e.g. in terms of setting up).</b>

<a href="https://codersera.com/blog/vuejs-vs-reactjs-comparison/">Comparing VueJs and ReactJs</a>
Easy JSON with Scala
Tags: scala, beginners
Published: 2019-10-20 19:03:56

*Update:* I've been notified the `json4s` has some fairly severe and public DoS issues.


{% twitter 1186005842262482951 %}

I'll make another post exploring this basic case using some of the libraries recommended in the thread.

---

I had been searching for an easy way to work with JSON in Scala. Most libraries expect the user wants to create advanced encoding and decoding functionality; therefore making them a bit difficult to jump into.

Fortunately I found this StackOverflow post that showed how to represent JSON using basic Scala data types such as `Map`, `List`, and `String`:

{% stackoverflow 27948128 %}

The really big takeaway is that `json4s` performs recursive JSON encoding/decoding with fundamental Scala types where most basic libraries will only encode/decode one level deep.

Getting started is fairly easy.

<b>1.</b> Follow the [installation steps](https://github.com/json4s/json4s#installation) for `json4s`.
   + Add the following to your `build.sbt` file: 
    ```scala
    // Change 3.6.7 to whatever the latest version is on Maven Central
    libraryDependencies += "org.json4s" %% "json4s-native" % "3.6.7"
    ```
<b>2.</b> Decode JSON

  ```scala
  import org.json4s._
  import org.json4s.native.JsonMethods._
  
  object DecodeJSON extends App {
    val jsonString =
      """
        |{
        |  "hello": "world",
        |  "data": {
        |   "number": 12,
        |   "lie": false
        |   }
        |}
        |""".stripMargin
  
    val decoded = parse(jsonString)
    println(decoded)
    // JObject(List((hello,JString(world)),(data,JObject(List((number,JInt(12)), (lie,JBool(false)))))))
  }
  ```

  + Notice the output uses special wrapper classes to represent the JSON data types and structure. The full list is found [here](https://github.com/json4s/json4s#guide).


<b>3.</b> Encoding JSON

Decoding recursively from Maps and Lists is possible as shown in the Stackoverflow post, but `json4s` provides a domain specific language (DSL) for creating JSON.

```scala
import org.json4s.JsonDSL._
import org.json4s.native.JsonMethods._

object Hello extends App {

// ~ is part of the json4s scala DSL
// it means these fields belong on the same Object level.
// It corresponds directly to a JSON comma (,).

  val jsonScala = ("hello" -> "world") ~
    ("data" ->
      ("number" -> 12) ~
        ("lie" -> false)
      )
  println(compact(render(jsonScala)))
  // {"hello":"world","data":{"number":12,"lie":false}}
}
```

# Conclusion

There are many JSON libraries for Scala out there, but `json4s` excels for quick and dirty projects involving dynamic JSON and simple types. Also, I'm really new to Scala so if you have a library you enjoy for working with JSON please share!
Yesterday I built Jess's modules and imports
Tags: css, javascript
Published: 2019-12-28 11:50:24

This is still a WIP!

Think scss with js es modules and your on the right lines. Jess is now successful building as a rust WASM module and now supports the following exports. Also because Jess will also be interpreted as in runs in your browser, async importants will be a thing allowing lazy loading of CSS only if required. 

### Exporting
*Variable*
``` scss
@export const foo = 'primitive';
```
*CssRules*
``` scss
@export const aBlock = .some > #css {
   background: red;
}
```
*Mixins / Functions*
``` scss
@export function foo(){
    ...
}
```
*Block exports*
``` scss
@export { foo, aBlock };
```
### Importing
```scss
@import '../some/src';
@import '../some/src.jss'
// Note that tss files will be resolved with a flag `jess compile --tess`.

@import { foo } from './functions/test';
// Yes you can pick what to import

// Note that default imports are not part of my mvp
```

Here is the dependency graph so far
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/ki3ga9mf6v9hrbtl474s.png)

### What I have learned
Some things are just easier to do in JavaScript (ahem, typescript) so the module system does the preparation to feed a big load of src code glued together into the rust WASM mod for lexing and more. The compromise meant I could understand what I was doing. The sad thing is that this system is synchronous and a bit slower that I would like, I plan to add some workers into the mix and get everything async as soon as I work out what can be parallel. As soon as I can I will also move this functionality into rust. But this is the nature of prototypes, they don't have to be perfect, they just have to get your attention. Developers I mean you.
Neural Network Definition | ANN with Human Brain
Tags: neuralnetwork, artificialneuralnetwork
Published: 2019-12-28 11:41:24

Neural Network is the best algorithm for the human brain. also, it helps to develop a large pattern in machine learning.  

The Artificial neural network is the best part of defending the large neurons in machine learning.

You can follow here more about neural networks and artificial neural networks. 

Read here more: <a href="https://shiv1367.com/what-is-neural-network-definition">Neural Network Definition</a>
Facebook's Libra Needs to Focus on the US First, World Later
Tags: calibra, cryptonew, facebook, libra
Published: 2019-12-28 10:48:56

Facebook's Libra digital currency project was announced in June this year, with an aim to become the digital currency of the world. The project was intended to serve as the default digital currency for masses, especially the unbanked. However, the project was not well received by the regulators around the globe, as many questioned the working model of Libra. The project was intended to be a stable coin backed by a basket of fiat currencies like the US Dollar, Euro, and Yen. Regulators objected to this saying Libra was merely trying to use different fiat to avoid falling under the jurisdiction of any one regulatory body.

Facebook also announced a consortium of companies that would overlook the operations of Libra mutually called Libra Association. A total of 27 companies which included the likes of Visa, MasterCard and Paypal were part of the association which was intended to reach 100. Facebook said that Libra association would mutually take decisions on the project without the intervention of Facebook. However, the three major organizations pulled out of the project amid growing scrutiny.

Read Out More 👉 https://www.cryptoknowmics.com/news/facebooks-libra-needs-to-focus-on-the-us-first-world-later
How programming seem to look for Newbies.
Published: 2019-12-28 10:40:33

I thought being a programmer is easy while in University, until I was told to write my first program that could tell whether a number is odd or even using Python( if and elif statement). It was cool of which I later used  a short snippet of code (Ternary Operator) to write it in Java. 

Later i developed Grade Point Average and Basic Calculator in Visual Basic and others.

Programming and Software development was still fun with the petty projects until I was told to build an African game called Ayo using Java in my third year.

I was told to build an AI sort of for users to play with, i used the Minimax algorithm to develop it and it was really challenging.

Since then Programming has not been funny even till now, especially when writing Real Life application like a Scientific Calculator, a Notebook all in Android(which I still have issues with). 

Solving problems strategically and using process is key to being a good programmer. Always remember to stay and learn a language up to an high standard point of view before taking another one.

Lastly,regardless of any language or software development life cycle you use. Just know how to transit a Real life problem into a solution using a minimal of Pseudocode or an Algorithm. 

Slow and steady wins the race, that's my belief. 
I would leave you with this thought.

 #newbies #android #java #Kotlin
Improving Web Portfolio
Tags: portfolio, css, saas, help
Published: 2019-12-28 10:34:33

Hello guys, I just created this portfolio recently. The issue I am facing is that when you click the hamburger icon, a portrait overlay should appear on the left-hand side, but it is not showing.
I would like the help of my fellow DEVIAN's.
Here is the link to my Github repository.
https://github.com/SMAmmar/my_portfolio

**Here is the deployed version link**
https://smammar.github.io/my_portfolio/