teleren/devto huggingface dataset:
Getting started with yuga-framework part 3 (Querying the database and more)
Tags: php, framework, yugaframework, yuga
Published: 2019-03-22 11:55:25

---
title: Getting started with yuga-framework part 3 (Querying the database and more)
published: true
description: This tutorial is about how we can query the database and create relations between models
tags: PHP, Framework, Yuga-framework, Yuga
---
In today's tutorial, I am going to take you through how to comment on a post that is already in the database,
this requires to first query the database for that post, then attach a comment to it and then save the changes, so without any further ado, let's get started.

## First we need to query the database for a given post say with id **1**

Yuga comes with an ***ORM*** that might by handy at database manipulation, so, that's what we will use for querying our post from the database but first, lets create a route for accessing our post. Let's open `routes/web.php` file to create our route.


```php
// routes/web.php

Route::get('/post/{id}', 'BlogController@getPost');
```
Now let's open `app/Controllers/BlogController.php` and add `getPost` method to our class

```php
// app/Controllers/BlogController.php

public function getPost(Post $post, int $id)
{
    $post = $post->find($id);

    return $this->response->json(['post' => $post]);
}
```

Now let's go to the browser and vist http://localhost:8000/post/1

This must be your result
![Post](https://thepracticaldev.s3.amazonaws.com/i/vqvepf5vhj9ndip66o9b.png)

### Now let's edit

In the `routes/web.php`, let's add this route

```php
// routes/web.php

Route::get('/post/{id}/edit', 'BlogController@editPost');
```

In the `app/Controllers/BlogController.php`, let's add the `editPost` method to the `BlogController` class but before that, let's first create a relation between the `Post` model and `Comment` model found in `app/Models`

In the `app/Models/Post.php`

```php
// app/Models/Post.php

public function comments()
{
    return $this->hasMany(Comment::class);
}
```

In the `app/Models/Comment.php`

```php
// app/Models/Comment.php

public function post()
{
    return $this->belongsTo(Post::class);
}
```

In the `app/Controllers/BlogController.php`

```php
// app/Controllers/BlogController.php

public function editPost(Post $post, int $id): string
{
    $post = $post->find($id);

    // Let's create the comments from here
    // [`creator_name`, `post_id`, `comment_content`]
    $post->comments()->save(new Comment([
        'creator_name' => 'Hamid Semix',
        'comment_content' => 'This is the first comment'
    ]));

    return "Your comment has been saved";
}
```

Now let's edit our `getPost` method to incorporate comments to

```php
// app/Controllers/BlogController.php

public function getPost(Post $post, int $id)
{
    $post = $post->with('comments')->where('id', $id)->first();

    return $this->response->json(['post' => $post]);
}
```

In the editor
![Editor](https://thepracticaldev.s3.amazonaws.com/i/xzgesoa4vqs7cn57vo6d.png)

This must be your result
![Result](https://thepracticaldev.s3.amazonaws.com/i/i9879xywb4rqb5swr7yp.png)
Is this how they sell 'Kubernetes'?
Tags: kubernetes, devops, softwaredevelopment
Published: 2019-03-22 11:35:33

---
title: Is this how they sell 'Kubernetes'?
published: true
description: A small graphical representation of how big tech giants sell 'Kubernetes'
tags: kubernetes, devops, softwaredevelopment
cover_image: https://thepracticaldev.s3.amazonaws.com/i/k352a4vingyz6g8go904.png
---

If 'Kubernetes' is a pineapple, then 'GKE' is like selling that pineapple in a shop called 'Google Cloud,' where the shopkeeper "Google" sticks his stickers on it, packages it nicely, and cuts it into pieces, so that you could easily eat it.

On that other hand, this guy by the name 'Amazon' having a fruit shop opposite to 'Google Cloud' sees this, and he also takes some pineapple and sells it in his store called 'AWS', where he packages the pineapples the way he thinks is nice and sells it giving a name called 'EKS'. 

RedHat took the pineapple, made juice out of it, put some preservative to make it safer (secure) and stable, packaged in a glass for carrying it and gave it a name of "Openshift". 


![Alt text of image](https://thepracticaldev.s3.amazonaws.com/i/k352a4vingyz6g8go904.png)

My colleague and I just made this up. 
Does that even make sense?

Do you have any other fruit stall stories to tell?
Recover specific taxonomies relationship from DB backup in WordPress
Tags: resources, wordpress
Published: 2019-03-25 18:04:30

---
title: Recover specific taxonomies relationship from DB backup in WordPress
published: true
tags: Resources,Wordpress
canonical_url: https://daniele.tech/2019/03/recover-specific-taxonomies-relationship-from-db-backup-in-wordpress/
---

When hard times require hard solution is better to know better SQL and how WordPress works!

The post [Recover specific taxonomies relationship from DB backup in WordPress](https://daniele.tech/2019/03/recover-specific-taxonomies-relationship-from-db-backup-in-wordpress/) appeared first on [Daniele Mte90 Scasciafratte](https://daniele.tech/eng).
Full Git rebase flow for a busy remote
Tags: git, development
Published: 2019-03-22 09:15:38

---
title: Full Git rebase flow for a busy remote
published: true
description: An example of how to rebase a local branch when the remote is busy with many collaborators
tags: Git, development
---

After reading several articles and tutorials on Git rebasing, I was left without some critical context when working on a shared project. Several times, I was left with a tangled commit graph when rebasing on an outdated master branch or trying to push my rebased branch to GitHub. Below, is the full-flow rebase example that I am not using, thanks to help from my friend and colleague Toni Ala-Piirto.

**Note:** This example assumes we are working in a **shared remote** named `origin`, and we are rebasing the `master` branch into our `feature-branch`.


1. make sure the local `master` branch is up-to-date with the latest remote changes
  - `git checkout master && git pull origin master`
2. checkout `feature branch`
  - `git checkout feature-branch`
3. rebase and resolve any conflicts that arise
  - `git rebase master`
4. *force* push the rebased branch to the remote (`origin` in this case)
  - `git push --force-with-lease`

For a bit more information about the `--force-with-lease` flag, see the StackOverflow question [git push --force-with-lease vs. --force](https://stackoverflow.com/a/52823955).

---

<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
read xml from database (angular6, spring boot, oracle)
Tags: question
Published: 2019-03-22 09:05:41

When users presses button in my angular application, a server should return him an xml file, that I produced on my server.  
I have a working sql query that generates 1 cell that contains the xml. 
I have working spring boot controller that gets the request from the frontend and then calls the db procedure. it also get the xml from the database. (i am using varhcar2 as return datatype).
my problem is now how to return the xml as a file to user

thanks in advance allready :)
Priorities for a new development manager: The Four Keys
Tags: dailywriting
Published: 2019-04-09 01:27:44

---
title: Priorities for a new development manager: The Four Keys
published: true
tags: daily-writing
canonical_url: https://marcusblankenship.com/priorities-for-a-new-development-manager-the-four-keys/
---

Earlier this week Pat asked, “What are the priorities for a new development manager.”

I side-stepped the question but will return to it over the next few days.

[(You can read my first answer here.)](https://marcusblankenship.com/qa-priorities-for-a-new-development-manager/)

First, let me define how I’ll be using the word _“new.”_

I will not be talking about someone who’s taking the role for the first time. That is, I assume you are not “new” to engineering leadership.

Instead, I’m going to address the challenge of leading a team that you’ve never been a part of. Thus, you are the team’s “new” manager.

## The Four Keys

When taking over a new team, there are _four key relationships_ you must attend to.

Neglecting any of them, or focusing too on a single one, will cause problems.

These are the same four key relationships to leading developers, but when taking over a new team, it’s especially important to work on these four keys first.

## Key One: The relationship with yourself

If joining a new team is stressful, then joining as a leader is doubly so. Oh, if you’re also new to the company, multiply it all by 5x.

The stress and unfamiliar territory can throw you off balance. It certainly does throw me off.

You’ll likely meet lots of new people, have new conversations, and might feel like you’re “drinking from the fire hose.”

The best thing you can do for your relationship with yourself is carve out time to think. Give yourself time to process and make sense of everything that’s coming at you. Take the time necessary to consider what kind of leader you aspire to be.

The next best thing you can do is… nothing.

Literally, _nothing_.

_Don’t rush into doing or changing anything._

Instead, take time to see how the team already does things.

There’s a strong temptation to start coding, get the system set up on your machine, start fixing team problems, and making big promises.

That’s a trap to avoid at all costs.

Instead, use your thinking time to rehash and write down your observations.

Doing this allows you to avoid “inflicting help” on your team, and keep yourself level headed.

**Tomorrow I’ll send you the second key relationship you must work on when taking over a new team.**

Have you got questions? Send ‘em over!

Best,  
Marcus

[[SPONSORED LINK] I recently learned that GitPrime can help you know who’s thinking of quitting while there’s still time to turn things around. How cool is that?](https://www.gitprime.com/managers/)

_(In December 2018 my email list voted to view ads over a paid subscription to the list.  Thanks to GitPrime for their support!)_

The post [Priorities for a new development manager: The Four Keys](https://marcusblankenship.com/priorities-for-a-new-development-manager-the-four-keys/) appeared first on [Marcus Blankenship](https://marcusblankenship.com).
Part 2- An in-depth video tutorial on deploying a Django application with static file serving
Tags: django, aws, nginx, staticfiles
Published: 2019-03-22 07:17:38

---
title: Part 2- An in-depth video tutorial on deploying a Django application with static file serving
published: true
description: Static files on a Django app should be served by `nginx` directly rather than our Django app. So you need to add a few lines to your `nginx` configuration, to tell where your static files are. I have tried to explain things neatly in this video. feel free to as any doubts.
tags: Django, aws, nginx, static files
cover_image: https://thepracticaldev.s3.amazonaws.com/i/27jhdtt9mfjzqe70rl39.png
---

Django is the most popular Python-based web framework for a while now. Django is powerful, robust, full of capabilities and surrounded by a supportive community. 

In this video, we are going to take a look into how to set up static file serving in our app, such as CSS, javascript, images etc... in our simple Django application. which we built and deployed in [Part 1](https://www.youtube.com/watch?v=u0oEIqQV_-E) of the series

Static files on Django should be served by `nginx` directly rather than our Django app. So you need to add a few lines to your `nginx` configuration, to tell where your static files are. I have tried to explain things neatly in this video. feel free to as any doubts. 

Let me know the suggestions, thoughts & the doubts in the comments. Subscribe to the channel & Share this with your friends & colleagues


Link to sample application repo with static files already setup: https://github.com/ShobiExplains/AwsDemo/releases/tag/v0.0.2

Nginx Configuration for reference: https://github.com/ShobiExplains/AwsDemo/blob/master/django.conf

{% youtube _TBw7ALJp0Y %}
Creating custom HTML elements with Javascript
Tags: discuss, webdev, javascript
Published: 2019-03-22 07:13:53

I just learned today that it's possible to create custom HTML elements with Javascript and extend existing ones. Here's an example:

```javascript
const InitiallyHiddenElement = document.registerElement(
  "initially-hidden",
  class extends HTMLElement {
    createdCallback() {
      this.revealTimeoutId = null;
    }
    attachedCallback() {
      const seconds = Number(this.getAttribute("for"));
      this.style.display = "none";
      this.revealTimeoutId = setTimeout(() => {
        this.style.display = "block";
      }, seconds * 1000);
    }
    detachedCallback() {
      if (this.revealTimeoutId) {
        clearTimeout(this.revealTimeoutId);
        this.revealTimeoutId = null;
      }
    }
  }
);
```

Running `<initially-hidden for="2">Hello</initially-hidden>` & `<initially-hidden for="5">World</initially-hidden>` on the webpage would delay the elements from appearing for 2 seconds and 5 seconds respectively. 

This idea seems pretty cool but I'm just thinking: all this can still be done in JS and CSS without having to create the custom element. 

What would be some good use-cases where creating custom elements would be a better way to go?
Friday Blast #65
Tags: fridayblast, links, post
Published: 2019-03-29 21:54:46

---
title: Friday Blast #65
published: true
tags: friday_blast,links,post
canonical_url: https://horia141.com/friday-blast-65.html
series: "Friday Blast"
---

[Open sourcing TonY - native support of TensorFlow on Hadoop (2018)](https://engineering.linkedin.com/blog/2018/09/open-sourcing-tony--native-support-of-tensorflow-on-hadoop) - an example of building an application on YARN (Hadoop’s scheduler), which is similar to what Hadoop, Hive, Spark etc. do, but with a focus on TensorFlow. Size is quite small in the examples, but it’s still a neat example.

[Algorithms behind modern storage systems (2018)](https://queue.acm.org/detail.cfm?id=3220266) - an ACM Queue article about B-trees and LSM-trees, which are the two major storage implementations for OLTP-type databases. Doesn’t go into a lot of details, but enough to get an intro on them.

[Book review - how to write a lot - a practical guide to productive academic writing (2018)](http://muratbuffalo.blogspot.com/2018/04/book-review-how-to-write-lot-practical.html) - a review of a book review. So meta! It’s a nice distillation and a lot of the suggestions apply to blog writing or any sort of technical writing a developer might find themselves doing - documentation, design docs, launch announcements etc. Very much similar to the advice from the [deep work review](https://dev.to/horia141/deep-work-review-5591) - write a lot in a dedicated time for writing basically.

[It doesn’t have to be Turing complete to be useful (2018)](https://increment.com/programming-languages/turing-incomplete-advantages/) - a case for small Turing-incomplete languages as DSLs for narrow tasks. OTOH, it is _nice_ to have a Turing complete language in such cases - Gradle is an example which comes to mind from recent work.

[Google Maps’ moat (2017)](https://www.justinobeirne.com/google-maps-moat/) - a “moat” is any feature/process/audience/etc a product has which protects it from its competitors. This is an analysis of Google Maps’ _moat_. It comes down to _massive amounts of data_ and _a lot of engineers thrown at the problem_. What’s interesting is that the _baseline_, from personal experience, to getting a usable experience with open source tools and data is not that hard to achieve. But getting to the level of Maps is nigh impossible.
Control asynchronous code in JavaScript
Tags: javascript, webdev, synchronous, es6
Published: 2019-03-22 05:29:29

---
title: Control asynchronous code in JavaScript
published: true
cover_image: https://thepracticaldev.s3.amazonaws.com/i/dr0c66q19h0rkz3w1wah.png
description: Synchronous programming in JavaScript
tags: JavaScript, webdev, synchronous, es6
---

### Synchronous vs Asynchronous?
* **Synchronous** is a term for executing program sequentially. In short, we will call it **sync**
* **Asynchronous** is a term for executing program sequentially but when it has a blocking call, it doesn't wait rather than execute next line. In short, we will call it **async**

### Is Asynchronous sucks?
**NO.** It's good for some reason. For example, you have millions of network activity like you have a large number of users. In that case, it's really suitable to use an asynchronous way.

### How write synchronous code is javascript?
We already know javascript follows the asynchronous architecture. Where it follows single-threaded concurrency. Let's not talk so much rather than see an example.

**Look at the following code**
```javascript
function foo() {
    console.log("I am foo function")
    setTimeout(() => {
        console.log("This will delay 3 seconds")
    }, 3000)
    console.log("Function Ended")
}

```

**OUTPUT:**
>I am foo function
>Function Ended
>This will delay 3 seconds

We have clearly seen the behavior of asynchronous programming. Do you have any idea to print the 3rd line before the second? No worry. We will talk about it. There are some ways to achieve this. Let's do it.

##### Example (Promise Implementation)
```javascript
function delayThreeSeconds() {
    // Return new promise
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log("This will delay 3 seconds")
            // simple resolve the promise
	    resolve(/* We can pass data here. */)
        }, 3000)
    })
}

// Rewrite the foo funtion and call the delayThreeSeconds function
function foo() {
    console.log("I am foo function")
    // Now program will wait 3 seconds to resolve from delayThreeSeconds funtion
    delayThreeSeconds().then(() => {
        console.log("Function Ended")
    })
}

// Another way to call it
async function foo() {
    console.log("I am foo function")
    // Now program will wait 3 seconds to resolve from delayThreeSeconds funtion
    await delayThreeSeconds()
    console.log("Function Ended")
}
```
**OUTPUT:**
>I am foo function
>This will delay 3 seconds
>Function Ended

**Note** async/await is works only es6. So browser support is important here. If you use babel, webpack or any other transpiler to transpile es6 to es5/browser supported javascript then it's gonna work for you.
I'm Engineering Director at a Fintech(have experience creating apps using Django/Ionic/Docker/AWS(ton of it), Ask Me Anything!
Tags: ama
Published: 2019-03-22 05:13:29

---
title: I'm Engineering Director at a Fintech(have experience creating apps using Django/Ionic/Docker/AWS(ton of it), Ask Me Anything!
published: true
tags: ama
---
R Language : Connect to MongoDB Database
Tags: rdatascience, datascience, rlanguage, nosql
Published: 2019-03-22 05:00:59

---
title: R Language : Connect to MongoDB Database
published: true
description: R language Connect to MongoDB database
tags: #rdatascience #datascience #rlanguage #nosql
---

Let's learn how to connect MongoDB database with R. MongoDB stores the data in the document with dynamic schemas. These days many people make use of the document-based noSQL database when they want to deal with large volume of non relational data.Coming back to the topic of connecting with the database from the R lang. 

The first thing that we are going to do is we are going to check some of the drivers available for the R lang to connect with mongodb. The driver we are going to make use of in the examples below is Rmongo. You can check out the R mongo documentation from the github page. 

You can check the video instruction here. [R Language : Connect to MongoDB Database](https://www.youtube.com/watch?v=JBEKJflNV2g).

{% youtube JBEKJflNV2g  %}

**Step 1. Install the Drivers**

In between the mongolite and Rmongo. I am choosing the RMongo. You may want to read the github page of mongolite if you wish to use the specific driver for the connection. 

Let's assume you want RMongo. So let's install it.

    install.packages("RMongo")

That should take care of the installation part. 

**Step 2. Create Connection** 

To establish the connection we have to first use the package. And then make the connection. So let's make use of the following lines of code for the same. 

    library(RMongo)
    rmng <- mongoDbConnect('db')

or you can also use. 

    rmng <-  mongoDbConnect('db', 'localhost', 27017)

This should help connect with the databae 'db' in the mongodb database. Next thing would be to print out the connection objects response. 

**Step 3. Check the server response.**

To verify that the connection is established and there does not seem to be any errors, you may want to try out the following code. 

    print(dbShowCollections(rmng))

This output should show you the connection response. 

**Step 4. Explore the specific queries**

Where to go from here? Now from here onwards you have to make queries specific to your database items stored in the document. All that you do from here onwards would be specific to your database. And may require additional code for the operation. 

You may want to read more about the queries from the Rdocumentation for [Rmongo](https://github.com/tc/RMongo). 



Additional references:

1. You can also learn [how to Connect R language to MySQL database](https://dev.to/maheshkay/r-language--connect-to-mysql-database-51ji).
2. Learn [How to connect to SQLite from R Language](https://dev.to/maheshkay/r-language--connect-to-sqlite-database-1adf). 
3. Learn [How to connect to CouchDB from R Language](https://dev.to/maheshkay/r-language--connect-to-couchdb-database--3nag)
Add a filename in the command line when running a Python script
Tags: python, argv, commandline
Published: 2019-03-22 09:32:34

---
title: Add a filename in the command line when running a Python script
published: true
tags: python,argv,command line
canonical_url: https://flaviabastos.ca/2019/03/22/add-a-filename-in-the-command-line-when-running-a-python-script/
---

#### OR: Run a Python script with arguments

You can add arguments to the command line when running python scripts by importing the [sys module from Python’s standard library](https://docs.python.org/3/library/sys.html) and using its _[argv](https://docs.python.org/3/library/sys.html#sys.argv)_[function](https://docs.python.org/3/library/sys.html#sys.argv).

Some examples:

A simple script that displays the user name:

```
def main(): name = 'Frodo' print(f'Hello, {name}')if \_\_name\_\_ == "\_\_main\_\_": main()
```

Ran as _python3 my\_script.py_, will display:

```
Hello, Frodo
```

This can be refactored to display whatever name is used as arguments in the command line when calling the script:

```
import sysdef main(): name = sys.argv[1] print(f'Hello, {name}')if \_\_name\_\_ == "\_\_main\_\_": main()
```

Add the _name_ you would like to use to the command line:

```
python3 my\_script.py Galadriel
```

will now output:

```
Hello, Galadriel
```

You will notice that in the script we’re assigning the element at index 1 from _argv_ to name. If you add this line to the script:

```
print(f'ARGS: {sys.argv}')
```

you will notice that _argv_ returns a list with all the arguments passed to the Python script and the first argument is always the script’s name:

```
ARGS: ['my\_script.py', 'Galadriel']
```

This can be really useful if you need to write a script that will read a file, for example. In that case, you don’t need to hard code the file name inside the script but pass it when running the script:

```
python3 my\_script.py my\_file.txt
```

> _The post _[Add a filename in the command line when running a Python script](https://wp.me/pa0b0y-3b)_ was originally published at _[flaviabastos.ca](https://flaviabastos.ca/)