teleren/devto huggingface dataset:
PHP parse error: syntax error, unexpected end of file
Tags: php, webdev, programming
Published: 2020-12-17 19:14:29

Unexpected End of File error occurs when a file does not have a proper closing tag. Sometimes this error can present itself as the White screen of death, or a 500 error. If so then you can able to determine the error is caused by an “unexpected end of file” by looking at your error logs in your WP Engine User Portal.

---
title: PHP parse error: syntax error, unexpected end of file
tags: php
canonical_url: https://kodlogs.com/blog/701/php-parse-error-syntax-error-unexpected-end-of-file
---


#Solution:
This error can be solved in two ways;

* Restore the website
* Correct the file
##Restore the website:
Once you have confirmed the issue is due to an unexpected end of file error, then the simplest way to resolve the issue is to restore the website to the last known good state, if it is possible. This is most likely the point just before any recent code changes.

##Correct the file:
If restoring the website is not a valuable option, then you can also fix it by downloading it over SFTP or opening it in SSH Gateway. Once you fixed the broken file by adding a proper closing tag, be sure you have saved and uploaded the file. You may also need to purge the cache.

After fixing the file, your website should normally again.
How to Use Embedding to Write Cleaner Code in Go?
Tags: go
Published: 2020-12-17 19:13:09

## Abstract

Go is cleaner because it doesn't support many of the features that tradition OO languages support. _Less is more_. Inheritance is one of those features but Go has a different style which can fulfil the necessity of inheritance. It's called Embedding.

## Table of content

- What is embedding
- How to create embedding
- Embedding In Interface
- Embedding In Struct
- Conclusion
- Reference

## What is embedding

You can "borrow" the functionality of a struct or interface into an another struct and interface respectively is called embedding. You can not embed an interface into a struct or vice versa.

## How to create embedding

To create an embedding you need to put a different struct or interface into a different one without naming the field.

```go
type Morning struct {
  breakfast bool
}

type Routine struct {
  Morning // ⬅️ no field name makes it embedded 
}

type Director interface {
  Direct()
}

type Producer interface {
  Produce()
}

type Creator interface {
  Director
  Producer
}
```

## Embedding In Interface

Interface when embedded is the union of all the methods present in all of the interfaces combined. If method `Eat()` is present on an interface and `Sleep()` on another then embedding them into an interface with `Repeat()` method will have all, `Eat()`, `Sleep()`, and `Repeat()` methods.


## Embedding In Struct

Embedding in a struct is where you can see the real power of Go. Not only the fields that [defined type](https://golang.org/ref/spec#Type_definitions) has but also the methods you can access them directly. How cool is that! Let's continue with our Routine struct.

```go
type Morning struct {
  breakfast bool
}

func (m Morning) hasBreakfast() bool {
  return m.breakfast
}

type Routine struct {
  Morning
}

r := Routine{}

r.hasBreakfast() // false
```

You also the embedded type will be a field name on the struct. For example, you can have:

```go
type DailySports struct {
  Jog            // field name Jog
  *Swim          // field name Swim
  sports.Cycling // field name Cycling
  *sports.Tennis // field name Tennis
}

func (d DailySports) enrolledBySwimming() bool {
  return d.Swim.Speed
}
```

But you cannot have conflict while embedding. This makes sense otherwise you won't know which one to pick.

```go
struct {
  *Swim         // ⛔ Now allowed
  *sports.Swim  // ⛔ Not allowed
}
```

You can do all the things you can with the promoted fields but you can not use the field name present in the defined type while constructing the struct.

```go
type Morning struct {
  breakfast bool
}

type Routine struct {
  Morning
}

r := Routine{breakfast: true} // ⛔ Not allowed
```

## Conclusion

You can use embedding to use any defined type to used inside a struct and borrow all the functionality it has. You need to check that the names don't clash otherwise you are good to go.

## Reference

1. https://golang.org/doc/effective_go.html#embedding
2. https://golang.org/ref/spec#Struct_types
How to compare doubles in java.
Tags: java, programming, oop
Published: 2020-12-17 19:12:55

The Compare() method of Double class is a built-in method in java that compares two specified double values. The sign returned of integer values is the same as that of an integer that will be returned during the function call.

---
title: How to compare doubles in java.
tags: java
canonical_url: https://kodlogs.com/blog/1046/how-to-compare-doubles-in-java
---


#Syntax:
**public static int compare(double d1, double d2)**
##Parameters:
This accept work with two parameters;

* d1: The first Double value that needs to compare.
* d2: The second Double value that needs to compare.
##Return Value:
This function will return the following values.

0: if both the numbers are equal.
Negative value: if the value of d1 is less than d2.
Positive value: if the value of d1 is larger than d2.
###Example Code:
```
import java.lang.Double;

public class GFG {

               public static void main(String[] args)

               {
                     // Get the two double values

                               // to be compared

                               Double d1 = 10d;

                               Double d2 = 1023d;



                               // function call to compare two double values

                               // if d1 and d2 are same                             

                           if (Double.compare(d1, d2) == 0) {

                                               System.out.println("d1=d2");

                               }

//id d1 is less than d2

                               else if (Double.compare(d1, d2) < 0) {

                                               System.out.println("d1<d2");

                               }

//if d1 is greater than d2

                               else {

                                               System.out.println("d1>d2");

                               }

               }

} 
```
###Output:
The output of the above program will be d1.
Python is not recognized as an internal or external command.
Tags: python, programming, oop
Published: 2020-12-17 19:10:29

To know the reason of this error, first, open the Windows PowerShell by right-clicking on the windows start button and then click on the “Windows PowerShell” or open the command prompt by using the “Windows+ R” and type “cmd” in the Run dialog box. Now the command prompt will open.

---
title: Python is not recognized as an internal or external command.
tags: python
canonical_url: https://kodlogs.com/blog/1902/python-is-not-recognized-as-an-internal-or-external-command
---


#Error:
 Now try to install any package by typing the command;
`
pip install pandas
`
You will encounter the following error if you are using the Windows PowerShell. 
`
The term ‘pip’ is not recognized as the name of cmdlet, function, or operable program.
`
##Solution:
* To solve this error first close your command prompt and go to the directory where you have installed your python. 
* If you are unable to find your python installed directory then the simple solution is that uninstall your python and install it again in a folder from where you can get easily. You can install in program file or simply in C drive. 
* After finding your python directory go to your PC settings by right-clicking on “This PC” then click on settings.
* Go to “Advanced System Settings” A dialog box with the name “System properties” will appear.
* Go to “Environment variables” in the bottom right corner of the dialog box.
* Go to “User variables” and select “Path”.
* Click on the “Edit” button. An “Edit environment variable” window will open. 
* Click on the “New” button.
* Go to the directory where you have installed your python. Go to “Scripts” and copy the path of this folder and paste it in the “New” tab that you have opened in step 6.
* Now copy your python folder path by following the instructions in steps 6 and 7 in the “Edit Environment Variable”.
* Click on the “Ok” button to close the dialog boxes.
* Now your error has been solved.
How to Lazy Load an Embedded Youtube Video
Tags: youtube, embed, lazyloading, javascript
Published: 2020-12-17 19:08:29

This is an example of how to display the image thumbnail for a Youtube video and only load the video once the user interacts with the video.

{% codepen https://codepen.io/darnocer/pen/YzGVQZO %}

## Basic Steps 
* Grab the Youtube ID from the URL of any Youtube video
![Youtube ID in URL](https://dev-to-uploads.s3.amazonaws.com/i/qdlxma88yw92ncgjr7d6.png)

* The image path for the thumbnail is 
`https://i.ytimg.com/vi/{Youtube ID}/maxresdefault.jpg`

* The embed URL for the `iframe src` is
`https://www.youtube.com/embed/{Youtube ID}?autoplay=1`

_Typically you would not want to include `?autoplay=1` to autoplay the video because that's annoying af, but in this case, we're loading the video only once the user has already clicked on it to play it_

* Using Javascript, swap out the image container with a responsive video container and the iframe with the embed URL


###### Credit to [this repo](https://github.com/paulirish/lite-youtube-embed) for the idea for the play button css.
How to make multiple pages in html
Tags: html, webdev, programming
Published: 2020-12-17 19:08:07

This tutorial can help you create inner pages in an HTML- based template.

1) Open your website folder and find a page that is best for your new sub-page - open each page in the browser and review its layout.

2) Copy and paste the chosen page in the same folder, rename it. Use English elements and numbers for page titles and headers.

3) Open the new page in your editor of HTML and make any necessary changes. Save it after editing.

4) After editing your new page you must open all the HTML pages and modify the link of the button that opens it. Note: You will have to edit all the pages that contain a button that opens the new page.

---
title: How to make multiple pages in html
tags: html
canonical_url: https://kodlogs.com/blog/2661/how-to-make-multiple-pages-in-html
---


The menu code can look like this:

```
<li><a href="more.html">Overview</a></li>

<li><a href="more.html">Small Business</a><ul>

<li><a href="more.html">Overview</a></li>

<li><a href="more.html">Small Business</a></li>

<li class="last"><a href="more.html">Corporate</a></li>
```
5) Review your website and examine how it works. Your new page is updated and linked.

First, you must had an idea of ​​what you want to do ... if you really know it, the general thing is that every Web page has its "Home Page".

In your case, assuming you already have your Home Page and what you want is to show a gallery ... you could create them as follows ...

Page 0.html = HomePage
Page 1.html = Gallery
Page 2.html = Contact

To do the above, you must create three separate pages, but configure them in such a way that giving a site makes the redirect to that other part.

Example in your HomePage configures the word "Gallery" to go to page 1 which is where the gallery is.

Remember that it is a single project in a single folder, but you need to create each page individually as needed and create the links to navigate between them.

To redirect from Homepage to Gallery, assume that in the projects folder, the page having "Gallery" is called page 1.html.

On page 0, which is the one that contains the Home Page, you can put the following.

Click here to see the gallery

Then you enter the following code on page 0, which is the one that contains the Home Page so that it will take us to page 1 that has "Gallery". It is extremely important that everything is in the same folder ok.
```
<html>
<head>
</head>
<body>
<a href="page 1.html"> Click here to view gallery </>
</body>
</html>
```
In the case of page 1, which contains "Gallery", you can put the following code.

Click here to return to HomePage

Then you will use this code on page 1
 
```
<html>
<head></head>
<body>
<a href = "page 0.html "> Click here to return to the HomePage </>
</body>
</html>
```
How to fetch data from the database in PHP and display in HTML form.
Tags: html, programming
Published: 2020-12-17 19:05:57

In this lesson, we will learn how we can fetch data from the database using PHP and display it in HTML form. We can do this by taking the following steps

---
title: How to fetch data from the database in PHP and display in HTML form.
tags: html
canonical_url: https://kodlogs.com/blog/224/how-to-fetch-data-from-the-database-php-and-display-html-form 
---


##Create a database connection:
 
```
<?php

$host = "localhost";

$user = "root";

$pass = "";

$db = "demo";

$conn = mysqli_connect($host,$user,$pass, $db); // this will establish the connection with database

if(!$conn)

{

die("Connection failed: " . mysqli_connect_error());

}

?>
Retrieve the data from the database:

<?php

      $sql = "select * from posts where id = 1"; // query to fetch the data form database

      $rs = mysqli_query($conn, $sql);

     $fetchRow = mysqli_fetch_assoc($rs);  // this will return the result of specific row as an array

?>
```

##HTML Form:

Now we will create the HTML form;
```
<html>

<head>

<title> Display data in html form </title>

<style>

body{font-family:verdana;}

.container{width:500px;margin: 0 auto;}

h3{line-height:20px;font-size:20px;}

input{display:block;width:350px;height:20px;margin:10px 0;}

textarea{display:block;width:350px;margin:10px 0;}

button{background:green; border:1px solid green;width:70px;height:30px;color:#ffffff}

</style>

</head>

<body>

<div class="container">

  <h3>Add Post</h3>

  <form action="" method="post">

 <input type="text" name="title" value="<?php echo $fetchRow['post_title']?>" required>

 <textarea cols="40" placeholder="Post Content" rows="8" name="post_content" required><?php echo $fetchRow['post_content']?></textarea>

 <button type="submit" name="submit">Submit</button>

 </form>

</div>

</body>

</html>
```
This is a very basic and simple example of fetching the data using the PHP script and display it in HTML form.
Blog Link: First Mile Blog Post
Tags: softwareengineering
Published: 2020-12-17 19:02:04

Why did I decide to learn software engineering?
Technology has always been fascinating to me in regards to the countless things that you can do with it. I have always been intrigued by how it can be used in different ways. Since there are many avenues in technology I decided to learn software engineering. The reason is because I think that the future is technology and I figured if I know how to learn how to code I can put that to good use when the opportunity presents itself. Software engineering can be challenging but with the proper instructions that I will be receiving from Flatiron School I believe that I will become a great software engineering. 

Samuel Blanc
java convert string array to int array
Tags: java, oop, programming
Published: 2020-12-17 19:01:32

When we are handling matrices in Java we can dump the contents of the matrix in a simple way on the screen. But if we just want to see the content of the array we can convert the array to a string with Java.

---
title: java convert string array to int array
tags: java
canonical_url: https://kodlogs.com/blog/2427/java-convert-string-array-to-int-array
---


The first thing will be to define our matrix:
`
int [] [] matrix = {{1,2,3}, {4,5,6}, {7,8,9}, {10,11,12}};
`
Now in order to convert an array into a string with Java, we could think that it will be worth it simply by invoking the .toString ()
`
System.out.println (array.toString ());
`
And we have it all ... But wait a minute. On the screen it shows me the following:
`
[[I @ 15db9742
`
This is little like a matrix to us. So the .toString () method does not work for us to convert array to string with Java.

What happens to us here is something similar to what happened when we compared arrays using the .equals () method. And here we have a similar solution. And it is that the Arrays class offers us a recursive method called .deepToString. The .deepToString method will recursively loop through the array and convert it to a string.

In this way we will have to code it as follows:
`
System.out.println (Arrays.deepToString (array));
`
And so we will get on the screen:
`
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
`
And we will have already managed to convert the matrix to string with Java in a simple way.
Python Capitalize First Letter Of Each Word
Tags: python, oop, programming
Published: 2020-12-17 16:26:48

If you want to capitalize the first letter of each word in your python program then this tutorial for you. In this tutorial, we are going to discuss about the first letter capitalization in our python program. And also here we will discuss the approach behind this problem.

---
title: Python Capitalize First Letter Of Each Word
tags: python
canonical_url: https://kodlogs.com/blog/2647/python-capitalize-first-letter-of-each-word
---

#How we can Capitalize the First Letter Of each word or string?

If you want to capitalize the first letter in python then you need to use some method, modules, and approach otherwise we cannot make the first letter capital of each word in our code.
So there are different-different approaches for resolve this program but here we are using only two approaches.

1. tittle() method
2. capwords() using string module

##What is the title() method in Python?

In python programming language title () is a method. And it is used for capitalized every first letter in Python programming language. You need to follow some given example code:-

Code:

```
>>> "kodlogs, australia".title()
'Kodlogs, Australia'
>>>
```

In the above code you can see that using the .title() method we can capitalize every string’s first letter.

What is capwords() in Python?

This method is also used to capitalize every first letter in a given string. If you want to use capwords() method then you need to import string and after we can use this method in our code.

Code:

```
>>> import string
>>> string.capwords("hey, are you a member of kodlogs coding community ?")
'Hey, Are You Member Of Kodlogs Coding Community ?'
>>>
```
Let's learn some modern C++!
Tags: cpp, learning, discuss
Published: 2020-12-17 18:49:23

As I'm sure it's many other people's case, I started learning C++ as part of one of my university courses (8 years ago already 🤯), and to be honest, it did get quite overwhelming at times! However, it was also astonishing and encouraging to see how many things one could do with it, so I ended up enjoying the class.

I used the language throughout my degree to solve various tasks, but it wasn't until my graduate life that I started making a heavy usage of it, mostly to write data analysis programs (which most of the time make use of [ROOT](https://root.cern/)) and [Geant4](https://geant4.web.cern.ch/) applications for the simulation of experimental setups.

However, I started noticing how I relied too much on stuff I had learnt long ago - and maybe not as rigorously as I should have - as a result of which my code always ended up full of patches, workarounds, bad style, ... in short, I was producing unmaintenable and very difficult to reuse or extend code.

So, I made up my mind and since a few months ago I'm focusing on reinforcing the concepts I already knew, learning new ones, applying new syntax and good practices, etc. and I figured out it would be a good idea to document part of that process here! I'll be posting some short articles as part of this series explaining what I learn along the way, and hopefully inspire some people and/or spark some nice discussions!

How does that sound? If you don't want to miss any of the articles, make sure to follow me!
How to reverse a vector in C++?
Tags: cpp, oop, programming
Published: 2020-12-17 18:31:14

Given a vector containing elements {1, 45, 54, 74, 54, 12} and we have to reverse it. It means we have to change its order to {12, 54, 74, 54, 45, 1}. And today in this article we will be taking a look at the approach and the program itself. 

---
title: How to reverse a vector in C++?
tags: cpp
canonical_url: https://kodlogs.com/blog/640/how-to-reverse-a-vector-in-c
---

#Approach
C++ provides the function reverse() in the STL and with the help of reverse() we are going to reverse a vector.

The function helps us in reversing the vector by itself. We just have to use it in correct syntax to make use of it.

##Program
```
// C++ program to reverse Vector 
// using reverse() in STL 
  
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
  
    // Get the vector 
    vector<int> a = { 1, 45, 54, 74, 54, 12 }; 
  
    // Print the vector 
    cout << "Vector: "; 
    for (int i = 0; i < a.size(); i++) 
        cout << a[i] << " "; 
    cout << endl; 
  
    // Reverse the vector 
    reverse(a.begin(), a.end()); 
  
    // Print the reversed vector 
    cout << "Reversed Vector: "; 
    for (int i = 0; i < a.size(); i++) 
        cout << a[i] << " "; 
    cout << endl; 
  
    return 0; 
}
``` 
###Output 
`
Vector: 1 45 54 74 54 12 
Reversed Vector: 12 54 74 54 45 1
`
**Overview**
First of all, we have to define the vector and its elements.

Then we take a look at all the elements in the vector by taking an output of the vector using a for loop.

Then we use the function reverse() for reversing the vector.

Then we give the output of the reversed vector again by loop.
Your Goals and which Tech to use For 2021
Tags: programming, productivity, career
Published: 2020-12-17 18:22:40

Wanted to start a conversation about our goals

- What are your projects for the next year? 💯 
- are you considering starting your own business 🏢  / get a full-time job 🧑‍💼  / or study 🔖  for 2021?
- which programming languages and frameworks 👨‍💻  you are working on or would love to learn and use in the future.
AWS CloudShell
Tags: aws, devops, cloud, shell
Published: 2020-12-17 18:15:43

Another simple but cool announcement from AWS — [AWS CloudShell](https://aws.amazon.com/cloudshell/).
A tool for ad-hoc AWS management via CLI directly in your browser.

I like when AWS releases something simple to understand and yet powerful. So it is not another [DevOps Guru](https://aws.amazon.com/devops-guru/), believe me :)

- Yes, this is similar to the shells that GCE and Azure have. 
- No, you can’t access your instances from it, so it’s not a jump server (bastion host).
- Yes, it has AWS CLI and other tools pre-installed. Even Python and Node.js.
- No, you can’t (well, you can, but should not) use it as an alternative to the day-to-day console on your laptop.
- Yes, you can manage all resources from that shell as much as your IAM permissions allow you (even with SSO, which is pretty cool).
- No, it does not support Docker. 
- Yes, you have 1 GB of permanent storage and the ability to transfer files in and out. 

More Yes and No’s here:
https://docs.aws.amazon.com/cloudshell/latest/userguide/faq-list.html
https://aws.amazon.com/cloudshell/faqs/
Displaying Breaks - Building SaaS #72
Tags: python, django, views
Published: 2020-12-17 18:14:20

{% youtube EEQFXjovTt4 %}

In this episode, I worked to add breaks to the display of the week schedule. We had to update context to include the break information into the schedules. I refactored a method out of the calendar display code to make some reusable logic for handling breaks.

The app needs to display breaks on the schedule and adjust what is displayed based on when the breaks are. I started with changing the background color of the break days. The break days were added to the context of the view. Once in the context, I adjusted the colors to show the breaks.

The next change was to change the styling of the background color to round the edges of each break day. Because breaks can be variable in length, I needed to add special logic to consider the different states that a day can be in.