teleren/devto huggingface dataset:
Utilizando db MS SQL con docker en Windows
Tags: spanish, mssql, docker
Published: 2020-04-07 12:22:47

---
title: Utilizando db MS SQL con docker en Windows
published: true
date: 2019-10-19 03:00:00 UTC
tags: spanish, MSSQL, docker
canonical_url: https://blog.rodrigojuarez.com/dev/2019/10/19/sql-docker-windows.html
---

Este post es simplemente un recordatorio para referencia futura sobre la configuracion de docker para poder utilizar bases de datos de Microsoft SQL Server en windows

- Entorno
- Estoy utilizando una pc con Windows 10 Version 1903
- Tengo habilitado Hyper-V
- Tengo instalado Docker Desktop 19.03.2
- Docker esta configurado para utilizar Windows Containers

# docker-db-init.ps1

He creado un script de powershell para configurar la db.La primera vez que ejecutamos este script, se descargaran todas las imagenes para que sql server funcione, por lo que son varios gigabytes.

```
docker 
    run -v 'c:\db:c:\db'
    --name mi_sql
    -p 1433:1433
    -e 'sa_password=mi_pass'
    -e 'ACCEPT_EULA=Y'
    -e attach_dbs="[{'dbName':'DataDb','dbFiles':['c:\\db\\datadb.mdf','c:\\db\\datadb_1.ldf']},{'dbName':'LoggingDb','dbFiles':['c:\\db\\loggingdb.mdf','c:\\db\\loggingdb_1.ldf']}]"
    -rm microsoft/mssql-server-windows-developer

```

-v: Adjuntar una carpeta que sera utilizada como persistencia, se indica la carpeta en el host y la de docker

–name: Darle un nombre al container para re utilizarlo posteriormente

-p 1433:1433: Puerto en el host y en docker de sql server

-e ‘sa\_password=mi\_pass’: El password del usuario sa que queremos utilizar

-e ‘ACCEPT\_EULA=Y’: Requerido por Microsoft para aceptar el acuerdo de licencia

-e attach\_dbs=”[{‘dbName’:’DataDb’,’dbFiles’:[‘c:\db\datadb.mdf’,’c:\db\datadb\_1.ldf’]},{‘dbName’:’LoggingDb’,’dbFiles’:[‘c:\db\loggingdb.mdf’,’c:\db\loggingdb\_1.ldf’]}]”: las bases de datos que queremos adjuntar, que deben estar en la carpeta que definimos con el parametro -v

-rm microsoft/mssql-server-windows-developer: la imagen de docker que estamos utilizando

# configure-db.bat

Para facilitar la ejecucion del script powershell tengo el siguiente archivo bat

```
Powershell.exe -executionpolicy remotesigned -File C:\Desarrollo\proyecto\docker-db-init.ps1
pause

```

# start-db.bat

Una vez que la base de datos esta configurada, utilizo el siguiente archivo bat para iniciar el contenedor de docker

```
docker start mi_sql
docker stats

```

Luego podremos conectarnos a la base de datos que estara disponible en localhost
Zeal Stream 10/18/2019 - The Very First Stream & Learning Lua!!!
Tags: devjournal, blog, todayilearned
Published: 2019-10-19 02:17:19

#### Checkout the stream @ https://www.twitch.tv/codingzeal

Today was the very for Zeal stream! It was a very casual stream where I spent time talking about future objectives for the stream and welcoming all the new followers! Afterwards we dove into learning Lua programming language and struggling plenty with it. It was great and loved the participation and support. I am looking forward to next Friday @ 1PM for the next stream.

# Today Objective

- [x]  Help Bridge the Gap by encouraging others!
- [x]  What to call today's log
- [x]  Talk about the stream and what we want to accomplish
- [x]  Highlight [https://codingzeal.com](https://codingzeal.com) principles
    - [x]  [https://www.codingzeal.com/principle-driven](https://www.codingzeal.com/principle-driven)
- [x]  Ask some chat members to provide some insight on what they would like from coding stream
- [x]  Start diving into learning Lua

# Notes

- Were gonna learn Lua today [https://www.lua.org/home.html](https://www.lua.org/home.html)
- Great site to learn new programming language [https://learnxinyminutes.com/docs/lua/](https://learnxinyminutes.com/docs/lua/)
- Today well be doing coding challenges in exercism
    - [https://exercism.io/my/tracks/lua](https://exercism.io/my/tracks/lua)
- Setting up Lua: [https://exercism.io/tracks/lua/installation](https://exercism.io/tracks/lua/installation)
    - `brew install lua` - lua CLI
    - `brew install luarock` - package manager
    - `luarocks install busted` - testing framework
- In order to any file:
    - `lua hello-world.lua`
- To run a spec file just type:
    - `busted`
- Used [https://www.lua.org/cgi-bin/demo](https://www.lua.org/cgi-bin/demo) to experiment with Lua and try out different things easily
- Nice lua cheat sheet for quick references:
    - [https://devhints.io/lua](https://devhints.io/lua)
- Interesting Lua Learnings :)
    - Lua's metatables are similar to JS prototypes
    - Lua's table are like JS objects
    - Indexes start at 1 not 0, whoaaaaaa
    - Cant ++ increment
    - Cant do `!=` but you can do `~=` instead
    - Concat strings using `..` instead of `+`

# Shout-outs and Thanks

- To all new followers
- rw_grim
    - For helping out with our learning lua journey
- DoctorArgus for some great ideas and support
- Alca for being our very first message in the chat

# Future action items

- [ ]  Continue learning Lua
- [ ]  Make a poll to vote on what we will call our chat  members
- [ ]  Alca - Love to do an interview with you about your experiences being self taught
- [ ]  Look into getting some other guests on stream that might be doing presentation or demos at conference or meetups.
- [ ]  Pairing sessions:
    - [ ]  With DoctorArgus
    - [ ]  Figure out possible pairing session with new mentees
    - [ ]  Maybe work with some other people
- [ ]  Get stellar high five sound clip
    - [ ]  Have high five sound effect play when moving hand to camera
    - [ ]  Can be use to high five people for stellar chat participation
How analytics work in a company with 11 million active users.
Tags: analytics, mongodb
Published: 2019-10-19 00:28:44

---
title: How analytics work in a company with 11 million active users.
published: true
description: This is a general description of how analytics work for in our company.
tags: analytics, mongodb

---


# The Database

![The Active Users](https://thepracticaldev.s3.amazonaws.com/i/eqcmlnzdibdz8yynt1fa.png)

That is 11,177,895 active users. We run an eight cluster Mongo Database and we pay around $100k a year just in support. In this database, we only keep the most recent data and not transactional data so we can analyze better and faster. Faster because in a single document(JSON) we have all the information we need. It took almost a year to centralize and sanitize the data, in analytics, the data (and it's quality) is the most important part.


# The Goal

So what do our stakeholders need? We are an internal department that works along with all other departments, so we adjust to the needs of each one. Our goal is to provide the best offer to the right client at the right time. To do that, we built an offer engine in Java and Google Web Toolkit (currently being migrated to Vue.js) so we can configure offers at every possible situation. This engine is a tree of rules (it also looks like a tree in the UI), each rule is configurable and each rule can evaluate in real-time and in Mongo's Map-Reduce (like Hadoop but in Mongo). That way we provide the offer for each of our stores (89) and for all digital channels.

![Set of Rules](https://thepracticaldev.s3.amazonaws.com/i/mziknrmudq81tmxbshn7.png)


# Where is the analytics?

So far, I haven't talked about analytics and actually this is the part that takes the least of our time and effort. Why? Because making models is easy and simple. We only use two kind of models. Logistic regressions and Decision Trees. These are the simplest, effective and easier to explain to other people. For a long time, we have been using R studio to create them and we export them in a JSON structure to be evaluated in Java in real-time. Exporting models to production is hard, so we are changing from R to python. Our engine is highly configurable so we can configure what model to apply for each node of the tree.


![Model Select](https://thepracticaldev.s3.amazonaws.com/i/78vsjptzwhy63w9uhu6l.png)



# Results

Last year we generated 30 million in incremental revenue, and this goal is increasing every year.
Django Class-Based View - TypeError
Tags: django, python, errors
Published: 2020-01-21 12:44:41

---
title: Django Class-Based View - TypeError
published: true
date: 2019-10-19 00:00:00 UTC
tags: django, python, error
canonical_url: https://tech.serhatteker.com/post/2019-10/django-cbv-typeerror/
---

__Error__ : `Django 2.X Error: __init__() takes 1 positional argument but 2 were given`

It took me significant amount of time to fix this issue. For future reference and possible-need of someone I would like to share the root cause and solution;

When you look at the console output you will the see traceback of the `error` like below:

```py
Traceback (most recent call last):
  File "/home/user/projects/django-cbv/.venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
      response = get_response(request)
  File "/home/user/projects/django-cbv/.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
      response = self.process_exception_by_middleware(e, request)
  File "/home/user/projects/django-cbv/.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
      response = wrapped_callback (request, *callback_args, **callback_kwargs)
TypeError: __init__() take s 1 positional argument but 2 were given
```

It means you need to use `as_view()` at the end of class-based views when declaring in the urls:


```py
# src/app/urls.py
from django.urls import path

from . import views


app_name = "app"
urlpatterns = [
    path('home/', views.BookCreate.as_view(), name='homepage'),
]
```

The problem is:

```py
urlpatterns = [
    path('home/', views.BookCreate, name='homepage'),
]
```

It does not matter, it may be any `CBV` but for additional detail you can look at the `view`:

```py
# src/app/views.py
from django.views.generic.edit import CreateView

from .models import Book


class BookCreate(CreateView):
    model = Book
    fields = ('name', 'isbn', 'author')
    template_name = "app/book_form.html"
```


OK, All done!

[django-cbv]: https://docs.djangoproject.com/en/2.2/ref/class-based-views/generic-editing/#django.views.generic.edit.CreateView
Creating a sitemap in 11ty
Tags: 11ty, eleventy
Published: 2019-10-21 17:11:58

---
title: Creating a sitemap in 11ty
published: true
date: 2019-10-19 00:00:00 UTC
tags: 11ty, eleventy
canonical_url: 
---

In order to submit your site to search analytics you should have a sitemap of your content. Having this just makes it easier and quicker for the search engines to find and index your site content. So I went about find how to do this with 11ty. The base blog of 11ty has this built in so I made a few changes especially for the dates.

```
---
permalink: /sitemap.xml
eleventyExcludeFromCollections: true
---
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- for page in collections.all %}
  {% set mappedUrl %}{{ metadata.url}}{{ page.url | url }}{% endset %}
  <url>
    <loc>{{ mappedUrl }}</loc>
    <lastmod>{{ page.date | htmlDateString }}</lastmod>
  </url>
{%- endfor %}
</urlset>

```
We're gonna program like it's 1999
Tags: react, functional, reactiveprogramming
Published: 2019-10-22 07:02:45

---
title: We're gonna program like it's 1999
published: true
date: 2019-10-19 00:00:00 UTC
tags: React, Functional Programming, Reactive Programming
canonical_url: http://metamn.io/react/were-gonna-program-like-its-1999/
---

How joy and simplicity was brought back into our lives by the Facebook crew.

{% youtube ADEav6zlDjg %}

## Personally

With [React and its ecosystem](http://metamn.io/react/a-big-picture/) &mdash; functional reactive programming, microservices, domain-driven design, data-driven applications &mdash; I've got back my mojo.

Now I write code as I've written twenty or thirty years ago.

Now I design and develop user interfaces and applications like a software engineer. 

No more hacking, plumbing, massaging HTML, CSS, Javascript with Gulp, Grunt or Webpack &mdash; it's programming again.
DPDK usertools: devbind
Tags: dpdk, networking, workrecord
Published: 2019-10-20 12:23:02

---
title: DPDK usertools: devbind
published: true
date: 2019-10-19 00:00:00 UTC
tags: dpdk,networking,workrecord
canonical_url: https://dannypsnl.github.io/docs/dpdk-usertools-devbind/
---

After compiling DPDK, load module and start our process. A common problem is we have no idea where is the NIC going :).

And DPDK actually provides some tools for these operations, one of them is `dpdk-devbind.py`. It located at `$(DPDK_PROJECT)/usertools/dpdk-devbind.py`

We can use it to get current status:

```
$ dpdk-devbind.py --status
# shorthand
$ dpdk-devbind.py -s

```

Bind driver:

```
$ dpdk-devbind.py --bind e1000e 00:06.0
# shorthand
$ dpdk-devbind.py -b e1000e 00:06.0
# we also can use NIC name, but remember that a NIC could have no name
# only PCI would always existed.
$ dpdk-devbind.py -b igb_uio eth1

```

Unbind driver:

```
$ dpdk-devbind.py --unbind 00:06.0
# shorthand
$ dpdk-devbind.py -u 00:06.0
# equal to
$ dpdk-devbind.py --bind none 00:06.0

```

p.s. Remember that these operations requiring permission(`sudo` or what).

Just that, have fun!
Toggle Multiple Fields
Tags: vanillajs, javascript
Published: 2019-10-20 05:00:37

---
title: Toggle Multiple Fields
published: true
date: 2019-10-19 00:00:00 UTC
tags: vanillajs, javascript
canonical_url: https://hiltonmeyer.com/articles/toggle-multiple-fields.html
---

Today's project for the [Vanilla JS Academy](https://vanillajsacademy.com/) was creating a checkbox that would either show the text of the password or hide it behind a password type input. This was very similar to [yesterdays](https://hiltonmeyer.com/articles/toggle-password-visibility.html) in that we were given two password fields and had to toggle between seeing the password or not. In this case there were two password fields like you might have on a change password field.

```
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Multi Field Toggle</title>
  </head>
  <body>
    <h2>Password Toggle Visibility</h2>

    <form>
      <div>
        <label for="current-password">Current Password <input type="password" name="current-password" id="current-password" /></label>        
      </div>

      <div>
        <label for="new-password">New Password <input type="password" name="new-password" id="new-password" /></label>        
      </div>

      <div>
        <label for="show-passwords">
          <input type="checkbox" name="show-passwords" id="show-passwords" />
          Show passwords
        </label>
      </div>

      <p>
        <button type="submit">Change Password</button>
      </p>
    </form>

    <script src="script.js"></script>
  </body>
</html>

```

The solution is very much based on what I did yesterday and tried to re-use the same functions.

1. Select the elements of the checkbox
2. Get an array of the password fields
3. Check when the checkbox was clicked
4. Toggle the password fields using a loop

```
// Elements
const showPasswords = document.querySelector("#show-passwords");
const passwordFields = Array.prototype.slice.call(document.querySelectorAll("[type='password']"));

// Toggle Password Field
const togglePasswordFields = () => {
  passwordFields.forEach((password) => {
    password.type = showPasswords.checked ? "text" : "password";
  });  
};

// If page is refreshed and the checkbox is already refreshed
// change the fields to text in anyway
if (showPasswords.checked) {
  passwordFields.forEach((password) => {
    password.type = "text";
  });
}

// Listen for checkbox click
showPasswords.addEventListener("click", togglePasswordFields, false);

```

I ran into a sticky situation that actually came up in the thread on Slack where someone mentions that when refreshing the page it would still keep the checkbox checked but the passwords would disappear but also loose the functionality of changing the input type. The solution was to add a check to make sure that if on load the checkbox was checked then to change the fields to text on the first run.
Day 15 : Everything
Tags: hiphop, code, coding, lifelongdev
Published: 2019-10-18 23:21:48

_liner notes_:
- Professional : Spent the day finishing up the rough draft of the use case for the app I made and submitted it. Also looked into refactoring my code now that I've learned about useContext from hearing about it in yesterday's React meetup.

- Personal : Yesterday, after the React meetup, I went to a couple of events that some friends were putting together. Got to see some new artists and hang out with some long time friends. I was able to get my laundry done during the day. Right now, I'm putting together tracks for the radio show tomorrow. Might do some light coding. Also, got a new camera to play with.

![Mountains of Silverton, Colorado under cloudy skies and rainbows](https://thepracticaldev.s3.amazonaws.com/i/g1kvizjo26hy6eocgwx5.jpg)

This weekend should be pretty fun. Got the radio show, play around with my new camera, radio station crew meeting, watching "Dolemite is My Name" and more. Looking forward to trying to get everything done. haha  

Have a great weekend!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube Fofjfiyxnlw %}
Understanding JavaScript Array Series XVI - Array.push()
Tags: javascript, webdev, beginners
Published: 2019-10-18 22:38:25

Let's assume you have a list of rappers like this `J Cole, Kendrick Lamar, Chance The Rapper, Jay Z` and you want to add one more rapper to that list, where would you add it? To the end of the list right? If you add Eminem to that list, you'll have `J Cole, Kendrick Lamar, Chance The Rapper, Jay Z, Eminem`.

We can achieve this behaviour using an array to store the names and an array method to add the new name to the list
```javascript
const rappers = ['J cole', 'Kendrick Lamar', 'Chance The Rapper', 'Jay Z'];
const count = rappers.push('Eminem');
console.log(count) // 5
console.log(rappers); // ['J cole', 'Kendrick Lamar', 'Chance The Rapper', 'Jay Z', 'Eminem']
```

I was able to achieve this by using the `Array.push()` method. This method adds new items to the end of the array and returns the new length of the array. Just like in the example above, the result of `rappers.push('Eminem')` was returned into the `count` variable which logs `5`.The `rappers` variable is also updated with the new item.

Let's take a look at the syntax:
```javascript
arr.push(item1, item2, item3, ..., itemN);
```
**[item1, item2, item3, ..., itemN]:** These are the elements to be added to the array.

**What happens When no new item is provided and the `.push` method is called on an array?**
```javascript
const rappers = ['J cole', 'Kendrick Lamar', 'Chance The Rapper', 'Jay Z'];
const count = rappers.push();
console.log(count); // 4
console.log(rappers); // ['J cole', 'Kendrick Lamar', 'Chance The Rapper', 'Jay Z']
```
In this scenario, nothing happens and the original length of the array is returned.


That's all for today, See you next week!!! :laughing: :grin:


Here is the link to the other articles on this Array series written by me:
* [What is an Array?](https://dev.to/nedyudombat/understanding-javascript-array-series-i-what-is-an-array-l1i)
* [Alternate ways of Creating an Array.](https://dev.to/nedyudombat/understanding-javascript-array-series-ii-alternate-ways-of-creating-an-array-26c8)
* [Array Properties](https://dev.to/nedyudombat/understanding-javascript-array-series-iii-array-properties-43co)

Got any question, addition or correction? Please leave a comment.

Thank you for reading. :thumbsup:
Table Head using foreach loop in PHP
Tags: html, php
Published: 2019-10-18 21:35:37

HTML

<tr>
   <th>ID Number</th>
   <th>Name</th>
   <th>Birthday</th>
   <th>Address</th>
   <th>Course</th>
</tr>

PHP 
<?php

$info = "ID Number, Name, Birthday, Address, Course";
$data = explode(',', $info);
foreach ($data as $row) {
  echo "<th>".$row."</th>";	
}
?>

In PHP, the lines of code of HTML will reduce down
HOW TO CONSUME A RESTFUL API IN SVELTE
Tags: javascript, svelte, beginners
Published: 2019-10-18 21:31:20

##In this article i will share with you two techniques of consuming a rest api in svelte.

So basically, "consume an API" is just a fancy term for "use an API".
Disappointed? Don't be,You might learn something.

# **Method #1**

The most common way to fetch data from other sources in svelte is to use the **onMount** lifecycle function.

here's an example from my last post

```html

<script>
 import { onMount } from "svelte";

let myTodo;
  onMount(async()=>{
     const response = await fetch("https://jsonplaceholder.typicode.com/todos/1")
      const todo = await response.json();
      myTodo = todo
  });
</script>

<div>
  {#if myTodo}
    <ul>
      <li>{myTodo.title}</li>
    </ul>
  {:else}
    <p>loading.....</p>
  {/if}
</div>
 ```
Let's say for some reason you don't want to fetch the data by using **onMount** lifecycle function,let's say for some reason you want to *await* the value of promises directly in your markup,well your in luck because svelte can do just that.
which brings me to
# **Method #2**

```html
<script>
 let myTodo = getTodo();

 async function getTodo() {
   const response = await fetch("https://jsonplaceholder.typicode.com/todos/1");
   const todo = await response.json();

   if (response.ok) {
     return todo;
   } else {
     throw new Error(todo);
   }
 }

</script>

{#await myTodo}
	<p>...waiting</p>
{:then todo_1}
	<p>{todo_1.title}</p>
{:catch error}
	<p style="color: red">{error.message}</p>
{/await}

```

Hope this was helpful to someone out there!

---------------------------------
Thanks for reading and stay tuned!