teleren/devto huggingface dataset:
SEO  (Frontend best practices part II)
Tags: fontend
Published: 2020-12-18 20:13:49

You can find the first part of this article in here [Frontend best practices (part I) ](https://t.co/CQDtblUG7A?amp=1)

**Search Engine Optimization** aka SEO as mentioned by Google is  " the practice of increasing the quantity and quality of traffic to your website through organic search engine results"

Here are the most important rules to follow to improve your website traffic:

* Make sure you have a **title** tag per page
* Make sure you have **meta-description** per page and do not 
  use quotes or any non-alpha characters
* Exactly one `<h1>` tag per page
* Make sure every image have alt tag( use dashes (-) and do 
  not use non-alpha characters) 
* Use internal linking like breadcrumbs
* Choose a good URL structure (short, meaningful and without stop words like "the" "a" )
* Use more backlinks
* Improve page performance (exp: use lazy loading for pictures, consider the best image format ...)
* Mobile friendly pages
* Consider the website architecture 
```
                    Home page
                        |
           ———————————————————————————————         
           |            |                 |
    IT courses    language courses       mathematics courses

```
Part III will be about Accessibility
Python decorator to measure function's execution time
Tags: python, debugging
Published: 2020-12-18 20:03:36

I know we do some manual debugging from time to time. I got inspired from some Stack Overflow answers and blogposts to write this decorator

{% gist https://gist.github.com/po5i/f68325e213b040d98b2d74133701c951 %}

Now, you just need to import it in your code and write something like:

```python
@measure
def foo:
    some_large_computation()
```

Output:

```
Total execution time foo: 15 ms
```

If you want a smaller time unit, use `1000000` instead of `1000` factor to get microseconds (`μ`)

I hope this can be any help.
What is __name__ in python
Tags: python, programming
Published: 2020-12-18 19:56:01

The variable __name__ varies depending on the module you are in during the execution of the program. In the main module, its value will be equal to __main__. 
---
title: What is __name__ in python
tags: python
canonical_url: https://kodlogs.com/blog/2656/what-is-__name__-in-python
---

If you are in another imported module, then its value will be equal to the name of the main module. The if (__name__ == __main__) test makes it possible to distinguish between the two cases.

 This condition is used to develop a module that can both be executed directly but also is imported by another module to provide its functions. You can insert into this block of code instructions intended for the case where the module is directly executed.

The python is a language that does not have a main () method, as it does in the C language. When you load a module, the code executed is the one located directly at the top level.

 This condition, therefore, makes it possible to group together the instructions that we want to use in the case of direct execution of the module.
```
# myScript.py
if __name__ == __main__:
 print (my script is executed directly)
else
 print (my script is imported by another module)
# myOtherScript.py
import myScript
```
By launching the manuscript script with the python command monScript.py, we get the message my script is executed directly. If, on the other hand, we run the myOtherScript script, which imports the myScript.py file, the message displayed will be my script is imported by another module.
How to test if a char is a letter in java?
Tags: java, programming
Published: 2020-12-18 19:54:09

In this article, I will explain how to find whether a given character is a letter or not by using isLetter(). I have stated an example for your reference for your understanding.
---
title: How to test if a char is a letter in java?
tags: java
canonical_url: https://kodlogs.com/blog/2628/how-to-test-if-a-char-is-a-letter-in-java
---

#Approach
* I have used a pre-defined class which is used to take values at run-time. This Scanner class is available in the util package.
* I have taken a character input ch and checked whether it is a character or not. It is as simple as it is said.
* Refer to the below example and find out how to check a char if it is a letter or not.
##Program
```
import java.util.Scanner;

public class Demo

{

public static void main(String[] args)

{

Scanner  scanner = new Scanner(System.in);

System.out.println(“ Input a character “);

String str = scanner.next();

char ch = str.charAt(0);

boolean b = Character.isLetter(ch);

if(ch)

{

System.out.println(ch + “is a character”);

}

else

{

System.out.println(ch + “ is not a character”);

}

}
}
```
##Output
`
Input a character

4

4 is not a character

Input a character

J

J is a character
`
Syntax error, unexpected '->' (t_object_operator).
Tags: php, webdev, programming
Published: 2020-12-18 19:42:12

It is not possible to call a method on an object created with new before PHP 5.4. When the user tries to call a method on an object created with the new then the error occurs;

---
title: Syntax error, unexpected '->' (t_object_operator).
tags: php
canonical_url: https://kodlogs.com/blog/359/syntax-error-unexpected-t_object_operator
---

“PHP Parse error: syntax error, unexpected ‘->’ (T_OBJECT_OPERATOR) ” in get_info.php on line 16.
##Solution:
To solve this error the user needs to switch PHP version through your hosting control panel if possible. Or contact your hosting provider to provide the support to switch PHP version.

##PHP 5.4:
In PHP 5.4 or later the following can be used;

$purchaseOrder = (new PurchaseOrderFactory)->instance();
##Previous Versions:
In previous versions, you have to call the methods on the variables like;

$purchaseFactory = new PurchaseOrderFactory;     //  new keyword will initialize new object of the class PurchaseOrderFactory

$purchaseOrder = $purchaseFactory->instance();
You can also this error by changing your syntax like;

$purchaseOrder = PurchaseOrderFactory::instance();

$arrOrderDetails = $purchaseOrder->load($customerName);
Simply use the instance() in place of new. This will create the instance of the class.

##Error in array index:
Use => instead of -> to assign the value to array index. You also need to replace Jason_encode($response) with json_encode($response)

###Example:
array_push($response, array(“id”=> $row[‘id’], ‘title’=>$row[‘name’]));
How to iterate through string in C++?
Tags: cpp, oop, programming
Published: 2020-12-18 19:35:17

In this article, we are going to learn how to iterate through the string in C++?

There are many ways to iterate over characters of a string in C++. To learn the ways, read the following article which is defining all the methods ahead.
---
title: How to iterate through string in C++?
tags: cpp
canonical_url: https://kodlogs.com/blog/338/how-to-iterate-through-string-in-c
---

#Methods
 
##Using functions
 

In this method, we will be using a loop to iterate over characters of a string.
`
void print(const std::string &s)
{
	for (std::string::size_type i = 0; i < s.size(); i++) {
		std::cout << s[i] << ' ';
	}
}
`

##Using range-based loops
 

The method given ahead is the recommended approach in C++11 and we will be iterating over characters of a string by using range-based for loop.
`
void print(const std::string &s)
{
	for (char const &c: s) {
		std::cout << c << ' ';
	}
}
` 

##Using predefined iterators
 

C++ has iterators for iterating characters. So we can also iterate using iterators in C++. Iteration is read-only, so we can use iterators.
`
void print(const std::string &s)
{
	for (auto it = s.cbegin() ; it != s.cend(); ++it) {
		std::cout << *it << ' ';
	}
}
`

##Using algorithms
 

There is an algorithm STL algorithm, which tries a specified function to each element for the input range. This helps in reducing the complication.
```
#include <iostream>
#include <algorithm>

void fn(char const &c) {
	std::cout << c << ' ';
}

void print(const std::string &s)
{
	std::for_each(s.begin(), s.end(), fn);
}

int main()
{
	std::string s("hello");
	print(s);

	return 0;
}
``` 

##By overloading
 

You can also overload the function for iterating the characters.
```
#include <iostream>
#include <iterator>

std::ostream& operator<< (std::ostream& os, const std::string& s)
{
	for (char const& c: s) {
		os << c << ' ';
	}
	return os;
}

int main()
{
	std::string s("hello");

	std::cout << s;

	return 0;
}
``` 

Finally, if you have any doubts you can ask in the comment section, I will try my best, usually, no one does. #peace
Convert string array to int array java
Tags: java, programming
Published: 2020-12-18 19:32:16

In this article, we will discuss how we will convert a string array into an int array. You can convert a string to an integer by using the parseInt () method of class Integer. To convert a string array to an array of integers, convert each element to integer and fill the integer array with them.

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

##Example
```
import java.util.Arrays;

public class StringToIntegerArray {

   public static void main (Strng args [  ] {.

      String [  ] str = { "1134", "056", "892", "924"};

      int size = str.length;

      int [ ] arr = new int [size];

      for (int i = 0; i <size; i ++) {

         arr [i] = Integer.parseInt (str [i]);

      }

      System.out.println (Arrays.toString (arr));

   }

}
```
**Output**

[  1134, 056 , 892 , 924   ]
 

If we want to convert the string to a primitive data type to int, we are here with a wrapper class, the conversion would be like this

**convert class**
```
{

public static void main (Strng args [ ]) {

String str = new String ( "20");

int i = Integer. parseInt (str);

System.out.println (i);

}

}
```
-------------------------------------

when this case convert the string to an integer array

Steps will be:

1. Accept String.

2. converted to a string as a string array using the split () uses the space as a delimiter.

3. The wrapper class has provided us with some packages (java.lang.Integer) and will be using parseInt () for each element in the array string.

4. Store in the integer array :-)
```
convert class

{

public static void main (String [] args)

{

String str = new String ( "20 30 40 50"); // enter new string

String [] s = str.split ( ""); // this is an array of strings

int [] arr = new int [s.length]; // create a new array of the type int

for (int i = 0; i <s.length; i ++) {

arr [i] = Integer.parseInt (s [i]); // parse each string integer

System.out.println (arr [i]);}

}

}
```
**Output:**

20

30

40

50
Hope that it will help you.
How to convert integer to string in c++ (In c++11)
Tags: css, oop, programming
Published: 2020-12-18 19:29:12

Since the standard C++11, string-to-number conversions and vice versa are built into the standard library. All of the following functions are present in <string> (according to clause 21.5).

---
title: How to convert integer to string in c++ (In c++11)
tags: cpp
canonical_url: https://kodlogs.com/blog/2288/how-to-convert-integer-to-string-in-c-in-c-11
---

##From line to number:
`
float              stof(const string& str, size_t *idx = 0);
double             stod(const string& str, size_t *idx = 0);
long double        stold(const string& str, size_t *idx = 0);
int                stoi(const string& str, size_t *idx = 0, int base = 10);
long               stol(const string& str, size_t *idx = 0, int base = 10);
unsigned long      stoul(const string& str, size_t *idx = 0, int base = 10);
long long          stoll(const string& str, size_t *idx = 0, int base = 10);
unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10);
`
They each take a string as input and try to convert it to a number. If it was not possible to build a valid number, for example, because there is no numeric data or an out-of-range number for the given type, an exception ( std::invalid_argument or std::out_of_range) is thrown .

If the conversion is successful and is idx not 0, it idx will contain the index of the first character that was not used for decoding. It can be an index after the last character.

Finally, integer types allow you to specify a base; numbers greater than 9 assume the alphabet (from a=10 to z=35). You can find additional information on the exact formatting that can be analyzed here for the numbers with floating point, integer signed numbers and whole numbers without sign.

Finally, for every function, there is also an overload that takes std::wstring as the first parameter.

##From numeric to string:
`
string to_string(int val);
string to_string(unsigned val);
string to_string(long val);
string to_string(unsigned long val);
string to_string(long long val);
string to_string(unsigned long long val);
string to_string(float val);
string to_string(double val);
string to_string(long double val);
`
They are simpler, you pass in the appropriate numeric type and you get the string back. For formatting options, you should go back to the C ++ 03 stringsream option and use stream manipulators as described in another answer here.

As noted in the comments, these functions fall back to the default mantissa precision, which is probably not the maximum precision. If your application requires more precision, it is best to revert to other string formatting procedures as well.

There are also similar functions defined with a name to_wstring, they will return a value std::wstring.
Una lista de increíbles sitios webs y artículos que hablan de la accesibilidad
Tags: a11y, webdev, technology, codenewbie
Published: 2020-12-18 19:24:43

Recopile algunos sitios y artículos que hablan sobre la accesibilidad en el software ya que es algo importante para que todas las personas puedan utilizar la web o cualquier plataforma sin restricciones.

### Sitios y Artículos:

* [El proyecto A11Y](https://www.a11yproject.com/)
* [Accessibility tips for web developers](https://web.dev/a11y-tips-for-web-dev/)
* [Accessible to all](https://web.dev/accessible/)
* [HTML Hell](https://www.htmhell.dev/) este sitio habla de cómo escribir HTML con buenas prácticas y muestra algunos ejemplos de las malas prácticas.
* [Web Accessibility](https://dev.to/lloyds-digital/what-is-web-accessibility-adjustment-and-where-to-start-start-thinking-about-everybody-4p19) un artículo que habla de la accesibilidad web.
* [¿Qué es web a11y y por qué es importante?](https://dev.to/salilnaik/what-is-web-a11y-and-why-is-it-important-4fic)
* [HTML semántico y por qué es importante](https://dev.to/dailydotdev/semantic-html-and-why-does-it-matter-4kjh)
* También puedes probar [Google Lighthouse](https://developers.google.com/web/tools/lighthouse?hl=es)

---

Si conoces más sitios o artículos no dudes en dejarlos en los comentarios. ☺️
How to initialize a vector in C++?
Tags: cpp, oop, programming
Published: 2020-12-18 19:20:33

Vector is a standard library class template, which is similar to array, but also supports dynamic resizing. Vector provides a data structure with contiguous memory location. This enables efficient, direct access to any element of a vector via the subscript operator [ ], exactly as with a built-in array. Like class template arrays, template vector is most commonly used when the data in the container must be easily accessible via subscript or will be sorted, and when the number of elements may need to grow.

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

All of the above was a quick review over vectors, but the original topic of today’s article is how to initialize a vector in C++?

 

#Methods to initialize a vector in C++
We can initialize vectors in many ways but in this article we will discuss only easy and familiar routes to initialize vectors. All the methods are given ahead.

* Specifying size and initializing all values
* Initializing like arrays
* Initializing from array
* Initializing from another vector

 

##Specifying size and initializing all values
```
// CPP program to create an empty vector 
// and push values one by one. 
#include <bits/stdc++.h> 
using namespace std; 

int main() 
{ 
	int n = 3; 

	// Create a vector of size n with 
	// all values as 10. 
	vector<int> vect(n, 10); 

	for (int x : vect) 
		cout << x << " "; 

	return 0; 
} 
```
##Initializing like arrays
```
// CPP program to initialize a vector like 
// an array. 
#include <bits/stdc++.h> 
using namespace std; 

int main() 
{ 
	vector<int> vect{ 10, 20, 30 }; 

	for (int x : vect) 
		cout << x << " "; 

	return 0; 
} 
```
##Initializing from array
```
// CPP program to initialize a vector from 
// an array. 
#include <bits/stdc++.h> 
using namespace std; 

int main() 
{ 
	int arr[] = { 10, 20, 30 }; 
	int n = sizeof(arr) / sizeof(arr[0]); 

	vector<int> vect(arr, arr + n); 

	for (int x : vect) 
		cout << x << " "; 

	return 0; 
} 
```
##Initializing from another vector
As the name suggests we will be initializing vectors from another vector. And the reason I put this method in the last is because before following this method we must know how to initialize a vector by another method. 
```
// CPP program to initialize a vector from 
// another vector. 
#include <bits/stdc++.h> 
using namespace std; 

int main() 
{ 
	vector<int> vect1{ 10, 20, 30 }; 

	vector<int> vect2(vect1.begin(), vect1.end()); 

	for (int x : vect2) 
		cout << x << " "; 

	return 0; 
} 
```
 

If you have any doubt or queries related to this article feel free to ask in the comment section. I would like to answer you.
Everybody struggles - but documenting makes it better
Tags: outreachy, internships, wikimedia
Published: 2020-12-18 19:13:25

Everybody might get stuck - this happens, and it should't be a big deal. It's not hard to think about it theoretically, but on practice it's way harder to calm yourself down and not panic.

Some of the other Outreachy interns this round speak about failing their tests and integration with already existing code (you can read their stories, for example, [here](https://jsal.home.blog/2020/12/15/everybody-struggles/) or [here](https://aanyudeborah.wordpress.com/2020/12/17/i-thought-i-knew-git-until-this-day-struggles/). These are valid problems, which can occur while working in projects with quite a long history - but my biggest struggles this week were of different kind.

Wikimedia community is full of creators, who make tools of different purposes and sizes, and there are various ways to develop something you need. This leads to variety of tools, supported by the community - but also to the point when there are too many guides and pages, which can be lost and unknown by the community. So here is the story.

All the Wikimedia projects have good, well-documented [API](https://www.mediawiki.org/wiki/API:Main_page) for various requests. It can provide a whole lot of info on pages, including last update time, which was exactly what I needed. But here comes a twist: I was working not with a simple normal wiki page, but on unique, special one - [SiteMatrix](https://meta.wikimedia.org/wiki/Special:SiteMatrix).

I've been digging through the API for a few hours, and it made my head hurt. API kept responding me like the page doesn't exist at all. I tried looking at which requests did my browser send to get the page - nothing. *I felt desperate*.  Still trying to get some requests, I hit search button with the request of **Wikimedia wikis**, the title of that page. And page, called this way, [did really exist](https://meta.wikimedia.org/wiki/Wikimedia_wikis). It just wasn't *special*.

I've looked through it, and noticed info about meta database, which store all the information about Wikipedia projects. I looked into it's tables - *and it stroke me*. The page was special, because *it was rendered directly with the information from the database*, that's why there was no 'edit' button, no update time - nothing. 

So I switched to the database, and it solved multiple things at once: I got both last update time and links to the pages.

And then I updated the page with a piece of my request to the meta database, just to make life a bit easier for someone who would like to look into it after me. 

A sighed deeply that day - I've spend about about half of the day with seemingly no result just to find out that to solve everything I had to look at the problem from totally different angle. It happens. 

Yet my head suddenly felt a lot lighter, when I finally knew what to do.
Jquery autocomplete multiple fields using jquery ajax PHP and MySQL.
Tags: php, mysql
Published: 2020-12-18 18:57:32

An Autocomplete textbox allows the users to select the single value from the list. Here we will learn how we can autocomplete the multiple values from the auto-suggestion list. We will follow the following process to create an autocomplete textbox with multiple selection values in PHP.

---
title: Jquery autocomplete multiple fields using jquery ajax PHP and MySQL.
tags: php
canonical_url: https://kodlogs.com/blog/188/jquery-autocomplete-multiple-fields-using-jquery-ajax-mysql
---

* First, create the MySQL database connection.
* GET parameter with the query name will help to get the search query.
* Send the GET parameter value to a PHP script using Ajax
* Search the match data from MYSQL database
* Store the search match data in an array.
* Send data in JSON format.
**Index.php**
```
<!DOCTYPE html>
<html>
    <head>
        <title>AutoComplete Textbox with Multiple Field </title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    </head>
<body>
       
    <div class="container">
       <h1 align="center">AutoComplete Textbox with Multiple Field using jQuery in PHP</h1>
           
         <div class="row">
         <div class="col-md-2">

         </div>
         <div class="col-md-8">
         <div class="form-group">
         <label>Enter Multiple subjects Name</label>
             <div class="input-group">
              <input type="text" id="search_data" placeholder="" autocomplete="off" class="form-control input-lg" />
         <div class="input-group-btn">
             <button type="button" class="btn btn-primary btn-lg" id="search">Get Value</button>
         </div>
         </div>
       <br >
      <span id="subject_name"></span>
      </div>
     </div>
       <div class="col-md-2">
       </div>
     </div>
        </div>
    </body>
</html>
<script>
  $(document).ready(function(){
      
    $('#search_data').tokenfield({
        autocomplete :{
            source: function(request, response)
            {
                jQuery.get('fetch.php', {
                    query : request.term
                }, function(data){
                    data = JSON.parse(data);
                    response(data);
                });
            },
            delay: 100
        }
    });

    $('#search').click(function(){
        $('#subject_name').text($('#search_data').val());
    });

  });
</script>
```
**Fetch.php**

```
<?php
$data = array();
if(isset($_GET["query"]))
{
 $connect = new PDO("mysql:host=localhost; dbname=courses", "root", "");

 $query = "
 SELECT subject_name FROM Subjects 
 WHERE subject_name LIKE '".$_GET["query"]."%' 
 ORDER BY subject_name ASC 
 LIMIT 15 
 ";

 $statement = $connect->prepare($query);

 $statement->execute();

 while($row = $statement->fetch(PDO::FETCH_ASSOC))
 {
  $data[] = $row["country_name"];
 }
}

echo json_encode($data);

?>
```