teleren/devto huggingface dataset:
Golang Binary Search Tree
Tags: go
Published: 2020-09-28 15:07:45

A Tree is a non-linear Data Structure unlike the arrays, slices, and linked lists. A Binary Tree is also a tree and data structure that has a maximum of two children nodes.

The Binary Search Tree allows us for a quick lookup, insertion, and deletion of nodes/elements. The time complexity of these operations in Binary Search Tree is O(log n).

Binary Search Tree was invented by P. F Windley, A.D. Booth, A. J. T. Colin, and T. N. Hibbard.

Prerequisite for the Binary Search Tree is you should know about Golang pointers and a little knowledge about [Golang linked list](https://divyanshushekhar.com/golang-linked-list/).

##Binary Search Tree Node Struct in Golang
The BST consists of nodes with these properties:

The Left field of type node that stores the address of the root of the left subtree.
Data field to store data.
The right field of type node to store the address of the root of the right subtree.
```
type Node struct {
	left *Node
	data int
	right *Node
}
```
##Golang Binary Search Tree Struct
The Binary Search Tree Struct has a root field that stores the value of the root of the tree.

The root of the tree holds a very significant place because we need the root of the tree to traverse the tree.
```
type BinarySearchTree struct {
	root *Node
}
```
Read the whole post on [Golang Binary Search Tree](https://hackthedeveloper.com/golang-binary-search-tree/) from the original Post.
I created an ugly golang sticker
Tags: go, watercooler, showdev
Published: 2020-09-28 15:07:06

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6iaakoij20yua2xa4k94.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/iv5nmjjp3y8xkrk63i2k.png)

Hi everyone, I've been a fan of the Go language. But I'm here today to show my work from the other side - I'm also an artist.

My friend wanted me to design an original version of the Gopher sticker that nobody will have. I told her my style isn't cute and in fact I like to draw "ugly" manga faces and she said she'd go for it so I went on to design one and only Gopher for her.

I'm not sure if she'll love it or be shocked by it, but I'm sure it will put all the other laptop gophers to shame... or the other way round. We'll see.

What do you think? Hate it or love it? Leave a comment for me.
Redis Hash Commands
Tags: redis
Published: 2020-09-28 15:04:18

##What are Hashes?
Hashes are maps between the string field and the string values. You can also relate it as an object in programming.

In Redis, HASHes can store up to 4 billion field-value pairs.

##Set Multiple Field Value in Redis Hash
HMSET in Redis is used to set multiple field-value pairs.
```
hmset key field value [field value ...]
```

###Redis HMSET
```
$ 127.0.0.1:6379> hmset student:1 name "Divyanshu Shekhar" rollNo   17 class 10
  OK
```
##Set Field in Hash
Redis HSET is used to set a Field in a pre-existing Redis Hash.
```
HSET Key Field Value
```

###Redis HSET 
```
$ 127.0.0.1:6379> hset student:1 subject "CS"
  (integer) 1
$ 127.0.0.1:6379> hgetall student:1
  1) "name"
  2) "Divyanshu Shekhar"
  3) "class"
  4) "10"
  5) "subject"
  6) "CS"
```
##Set Field if it doesn’t exist – Redis HSETNX
Redis HSETNX is used to first check if the field exists in the Hash. If the key doesn’t exist then it adds the field in the Hash else drops it.
```
HSETNX Key Field Value
```

###Redis HSETNX
```
$ 127.0.0.1:6379> hsetnx student:1 marks 99
  (integer) 1
$ 127.0.0.1:6379> hgetall student:1
  1) "name"
  2) "Divyanshu Shekhar"
  3) "marks"
  4) "99"
```

Learn more [Redis Hash Commands](https://hackthedeveloper.com/redis-hash-commands/) from the original Post.

Also learn how to integrate Redis with Python the blog post: [Use Redis with Python: The Power of In-Memory Database](https://hackthedeveloper.com/use-redis-with-python/).

[Find More Blogs on Redis](https://www.google.com/search?q=redis+site%3Ahttps%3A%2F%2Fhackthedeveloper.com).
Redis List Commands
Tags: redis
Published: 2020-09-28 15:00:48

Lists are present in almost every programming language and play a very important role when it comes to storing information.

Redis an in-memory database also has lists data structure. Its structure is somewhat like linked lists and insertions and deletion can be done by both sides.

##Create Redis List
As stated earlier, Redis list insertion can be done from both sides i.e Head and Tail. When the list is seen horizontally the Head comes to the left and the Tail to the right. So the Redis Command to push elements towards Head is LPUSH and towards tail is RPUSH.
```
LPUSH/RPUSH key value [value ...]
```

##Redis LPUSH
```
$ 127.0.0.1:6379> lpush number 1 2 3 4 5
  (integer) 5
Redis RPUSH
$ 127.0.0.1:6379> rpush number 1 2 3 4 5
  (integer) 5
```
##Range List Values
Just like in programming languages where we can range over the List values, In the Redis list, we can range over the list items too.
```
lrange key start end
```

##Ranging the LPUSHed Lists.

lrange LPUSHed List
```
$ 127.0.0.1:6379> lpush number 1 2 3 4 5
  (integer) 5
$ 127.0.0.1:6379> lrange number 0 5
  1) "5"
  2) "4"
  3) "3"
  4) "2"
  5) "1"
```
In the Redis LPUSH, the elements are pushed to the head, and thus when looped the output is in reverse order.

Now, Ranging the RPUSHed List.

lrange RPUSHed List
```
$ 127.0.0.1:6379> rpush number 1 2 3 4 5
  (integer) 5
$ 127.0.0.1:6379> lrange number 0 5
  1) "1"
  2) "2"
  3) "3"
  4) "4"
  5) "5"
```
You can notice the difference between the two outputs.

In the Redis RPUSH, the elements are pushed to the tail, and thus when looped the output is in the same order as they are pushed.

Read the whole post [Redis List Commands](https://hackthedeveloper.com/redis-list-commands/) from the original Post.

Also Learn how to integrate Redis with Python from the original blog post: [Use Redis with Python: The Power of In-Memory Database](https://hackthedeveloper.com/use-redis-with-python/). [More Blogs on Redis](https://www.google.com/search?q=redis+site%3Ahttps%3A%2F%2Fhackthedeveloper.com).
Leetcode #387 First Unique Character in a String with JavaScript and indexOf
Tags: leetcode, javascript, codenewbie, 100daysofcode
Published: 2020-09-28 14:59:06

{% youtube aYjOTbr3NDg %}

Enjoy the video 😀🙏

Also written version https://losseff.xyz/leetcode/001-first-unique-character-in-a-string/javascript/
Python Web Scraping To CSV
Tags: python, webdev
Published: 2020-09-28 14:57:44

Comma Separated Values or (CSV) is one of the most common formats of spreadsheet data storage files. This file extension is very popular in machine learning. Data used in machine learning are stored in CSV’s as working with CSV files in Python is easy with Pandas. CSV is also supported by Microsoft Excel, this is also a huge factor for the popularity of CSV file format.

##Writing To CSV File In Python
First of all, we need to take a look at How to work with CSV Files in Python, in order to store our Python Web Scraping Data into it.

In this Example Section, where we will learn How to work with CSV in Python. We will save a CSV file at our workspace called test.csv that will contain three Columns and a total of 11 rows. Three Columns will be SR(Serial Number), ID(between 1-100), and Price(between 100-1000).

Here is the Python Code to Save a CSV File:
```
import csv
import random

csvFile = open('test.csv', 'w+')
try:
    writer = csv.writer(csvFile)
    writer.writerow(('SR', 'ID', 'Price'))
    for i in range(10):
        writer.writerow((i+1, random.randint(1, 100),
                         random.randint(100, 1000)))
finally:
    csvFile.close()
```

To see the output and learn more about saving the [python web scraping data to CSV](https://hackthedeveloper.com/python-web-scraping-data-to-csv/) from the original post.
Python Lambda Function
Tags: python
Published: 2020-09-28 14:48:32

##Python Lambda Function
Normally while defining a function in python we use the def keyword but when an anonymous function is declared we use the lambda keyword. These functions have no name.

And thus called the anonymous function.

Python Lambda Function Syntax
```
lambda arguments: expression
```

The thing to keep in mind when using the lambda function is, there can be zero or multiple arguments separated by commas but only a single expression. Argument and expression in the lambda function are separated by a colon (:).

Expression in lambda functions is evaluated and returned. The whole lambda function returns a function object.

Learn Python list comprehension, an easy way to create a list in a single line.

The function object returned by the lambda function is stored in a variable. As the variable contains a function (Functions in python are also first-class citizens) it can be executed with the number of arguments passed in the lambda function.

Read the whole post [Python Lambda Function](https://hackthedeveloper.com/python-lambda-anonymous-function/) from the original Post.
You Will Never Think That Learning These 5 GAN projects Could Be So Beneficial! But It Is!
Tags: python, computerscience, linux, opensource
Published: 2020-09-28 14:47:30

##You Will Never Think That Learning These 5 GAN projects Could Be So Beneficial! But It Is!

[#ai #machinelearning #datascience #computervision #imageprocessing #gans ]

[You Will Never Think That Learning These 5 GAN projects Could Be So Beneficial! But It Is!](https://medium.com/@waliamrinal/you-will-never-think-that-learning-these-5-gan-projects-could-be-so-beneficial-but-it-is-f4362a6aa3d7)
Python Data Class Field
Tags: python
Published: 2020-09-28 14:46:12

##Get All Fields From Data Class
There is an in-built function called __dataclass_fields_ that is called on the class object and it returns all the field the class contains.

Example:

Data class Fields
```
@dataclass()
class Student():
    name: str
    clss: int
    stu_id: int


student = Student('HTD', 10, 17)

>>> print(student.__dataclass_fields__)

```
```
{
'name': Field(name='name',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object at 0x00000217EBF3F460>,default_factory=<dataclasses._MISSING_TYPE object at 0x00000217EBF3F460>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 

'clss': Field(name='clss',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object at 0x00000217EBF3F460>,default_factory=<dataclasses._MISSING_TYPE object at 0x00000217EBF3F460>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 

'stu_id': Field(name='stu_id',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object at 0x00000217EBF3F460>,default_factory=<dataclasses._MISSING_TYPE object at 0x00000217EBF3F460>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD)
}
```

This method returns a dictionary of all the field information of the object. The field name is the key of the dictionary and the value is the Field class containing the field information.

###Access Specific Field
In the previous code, we accessed all the field properties. Let’s now try to access a specific field.

Access Specific Field
```
>>> print(student.__dataclass_fields__['name'])


Field(name='name',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object at 0x0000022C8E26F460>,default_factory=<dataclasses._MISSING_TYPE object at 0x0000022C8E26F460>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD)
```
Let’s now learn how we can change some of the field values.

###Import Field
To customize the fields in the python data class, we will have to import field from the dataclasses module.
```
import field
from dataclasses import dataclass, field
```
Now we can customize the fields.

Python Data Class Field
field(*, default=MISSING, default_factory=MISSING, repr=True, hash=None, init=True, compare=True, metadata=None)

There are six optional parameters that can be set to customize the field properties.

* default
* default_factory
* repr
* hash
* init
* compare
* metadata

Learn about each parameter of [Python Data Class Fields](https://hackthedeveloper.com/python-data-class-field/) in detail from the original Post.
What if, when you grep, it goes into pager mode when results don't fit one screen?
Tags: grep, ack, bash
Published: 2020-09-28 14:45:15

There is a general theme in GNU shell commands that if a program is able to deliver ANSI-colored output, it only does so in interactive shells, or if explicitly instructed. If you want to pipe output but have colors remain for later printing, you sometimes have to augment both the sending and the receiving command.

Of the many alternatives to `grep` I use `ack`.

Given the following `~/.ackrc`,

```
--flush
--pager
less -R -F
```

whenever I `ack` for something, it uses `less` as a pager, and if the search results fit a screen, it just prints them, including colors, and otherwise it enters `less`'es interactive mode.

Here the `ack` parameters are explained:

- The parameter `--flush` tells `ack` to "*flush output immediately.  This is off by default unless ack is running interactively (when output goes to a pipe or file).*" So with `--flush`, output is always sent immediately.

- The parameter `--pager` tells `ack` to pipe its output through `less -R -F`. This is equivalent to always running `ack ... | less -R -F` when typing `ack ...`.

Here the `less` parameters are explained:

- `-R` (`--RAW-CONTROL-CHARS`) prints ANSI color escape sequences. That means colored output and not a bunch of `ESC[1;39m` codes.
- `-F` (`--quit-if-one-screen`) "*causes less to automatically exit if the entire file can be displayed on the first screen.*"

The one drawback I have experienced so far is that if you do a very slow `ack` with very few results that don't take up a lot of screen space, you won't get those results until `ack` has finished or it eventually uses an entire screen, since then it knows to activate the pager rather than print directly.

You can circumvent this last quirk with `less -X` (`--no-init`) which "*disables sending  the  termcap  initialization  and  deinitialization strings to the terminal,*" but it means that `less` will not wipe its output from the terminal when you hit <kbd>q</kbd>.

Decide which drawback you like less, or let me know of third options!
Developing for Safari on Windows 10/Linux
Tags: discuss, windows, safari, ios
Published: 2020-09-28 14:43:26

 
Hi all, 

This is my first post - so go easy on me! 😇

TL: DR; My queries boil down to:
- Does anyone have any advice for supporting/developing for Safari users when you only have access to a Windows 10 or Linux machine? 
- What tools/services do you use? 
- Are they free/reasonably priced? 
- Is the only option to invest in something with MacOS/iOS in order to support them properly?

--- 

I'm a long time Windows user with some experience in Linux. I've been doing web development for 6 years and have lots of experience on cross-browser support for IE, Edge, Chrome, Firefox but with not having access to any Apple devices, I've never been able to guarantee functionality or aesthetics for those users.

I'm currently working on a web-based product for a customer that is focused around iOS users and feel that this would be a great opportunity to test and verify things for our users - the problem is I don't have any devices that can run Safari.

I'm reaching out to see if anyone has any useful tools, knowledge or secrets they can share with me to help overcome this issue and thank you in advance to anyone who contributes! 🙌
Python Data Class Parameters
Tags: python
Published: 2020-09-28 14:41:35

##Python Data Class Parameters
The below code is the function definition of the dataclass in python.
```
def dataclass(cls=None, /, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False):
```

There are six optional parameters that python data class takes:

* init
* repr
* eq
* order
* unsafe_hash
* frozen

we will learn about these parameters one by one.

##Init Parameter In Python Data Class
This is the first optional parameter in the python data class and is set to True by default. This creates the initialization function for the class with the class attributes.

Example:
```
@dataclass
class Student():
    name: str
    clss: int
    stu_id: int
```
In the above code we used dataclass decorator and thus just declared the class attributes with type hint.

When the init parameter is set to default i.e True. The code is converted to simple class with the init function defined.

```
class Student():
    def __init__(self,name,clss,stu_id):
        self.name = name
        self.clss = clss
        self.stu_id = stu_id
```
We can access the class attributes.

Example:

Access class attributes
```
student = Student('HTD', 10, 17)

>>> print(student.name)

HTD

>>> print(student.clss)

10

>>> print(student.stu_id)

17
```
Now let’s make the init parameter as false and see the effect.

```
@dataclass(init=False)
class Student():
    name: str
    clss: int
    stu_id: int


>>> student = Student('HTD', 10, 17)
```
```
Traceback (most recent call last):
  File ".\main.py", line 11, in <module>
    student = Student('HTD', 10, 17)   
TypeError: Student() takes no arguments
```
When there is no init function in a class this means there are no class attributes and thus the Student class doesn’t take any arguments.

Read about other [Python Data Class Parameters](https://hackthedeveloper.com/python-dataclass/) from the original Post.
Python Custom Exception
Tags: python
Published: 2020-09-28 14:38:27

##Create Custom Exception In Python
As you have heard, Everything is an object in python. An Exception is also a class in python.

We can create an exception in python by inheriting the in-built class Exception in Python.

Let’s make our custom exception, which will raise an error when it encounters a number in a string. The Name of the Exception class will be NumberInStringException.

The name is long, but it explains the exception. You don’t need to know Object-Oriented programming in python in order to understand this concept. Stick with it and you will learn everything.

```
class NumberInStringException(Exception):
    pass


word = "HackTheDeveloper17"
for c in word:
    if c.isdigit():
        raise NumberInStringException(c)
```
In the above code, we defined a class with the name NumberInStringException which inherits the inbuilt python class Exception, which provides our class the Exception features. There is no code in the class, just the pass statement.

Next, we defined a loop that checks for any number in the string value. If the character is a number the custom exception is raised.
```
Output:
Traceback (most recent call last):  
File ".\main.py", line 8, in <module>
    raise NumberInStringException(c)
__main__.NumberInStringException: 1 
```

Read the whole post [Python Custom Exception](https://hackthedeveloper.com/python-custom-exception/) from the original Post.
The age of Digital Grammar
Tags: machinelearning, gpt3, nlp, linguistics
Published: 2020-09-28 14:35:50

With the invention of the internet, one thing became common, the interaction between computers and thereby people increased. These days there is a growing trend of using APIs to interact with computers running different kinds of software to seamlessly deliver a service. It is becoming more of an orchestration between computers rather than a single point service delivery.

Let's take it a step further, what if we codify API response codes into hex values? And these values are specific to every computer? What I mean is this: while the major API methods remain the same, every computer or rather the IP has its little hex digit for itself. This can be random or generated, but remains unchanged and non-transferable. Now imagine again that a group of computers talk to each other with this quirk. We have now successfully invented what in the land of linguistics is called a Pidgin language where all the computers in the group know exactly what this special character means and tries to perform / retrieve the certain action within the group.

Taking it a step further, let us now also have RNNs that are pre-programmed into the group of computers that are interacting with each other. The more a computer uses its specific hex code and the more "attention" it has to using this code to perform a certain operation, the more likely it is to be picked up with the other members of the group. In this way digital language takes shape. One major disadvantage of this way of networking / communication is the loss of control to us, programmers. These networks will essentially become black boxes, albeit faster and perhaps better. 

#### Afterthoughts

- the RNNs can be the same number of parameters / variables but with a random distribution of attention for the RNNs in the initial phase.
- attention could also be used to reinforce memory much like the human experience, the more successful the codes are, the more likely it is used, and has more attention to it.

- the GPT-3 computerphile video: https://www.youtube.com/watch?v=_8yVOC4ciXc

- as with human beings, there is communication and then action based on the communication. i.e information and action on that information. These are two distinct things. While a computer can memorise (GPT-3 esp.) addition in the memorisation sense, it does not link that with the binary operation, this therefore calls for another approach on top of the GPT to translate from NLP type models or "action" based models. These actions are inherently internal communications and therefore are not needed to be communicated with the outside world, while the results can be.
Simple Search Bar In HTML/CSS
Tags: css, html, webdev, weeklyui
Published: 2020-09-28 14:30:31

In this element, we used one input field and one a href tag with search icons. Here we simply use HTML tags and CSS properties to make this Simple Search Bar.



We use font awesome icon in a href tag and for make perfects alignment we used flex display properties. This is a fully responsive element for mobile-view as well as tablet view.

Make it yours now by using it, downloading it, and please share it. we will design more elements for you.

[Source Code](https://w3hubs.com/simple-search-bar-in-html-css/)
PimpYourOwnDevice at #MSCreate Serverless: Developer hacks and tools we wished we knew sooner
Tags: mscreate, javascript, azure, serverless
Published: 2020-09-28 14:29:49

Just a week after Microsoft Ignite, there is another great event called Create:Serverless and it is all happening on September 30th, 2020. Like the name discloses, this event focusses on Serverless. The event lets the community connect with experts and vice versa.

![Create:Serverless](https://dev-to-uploads.s3.amazonaws.com/i/qagp2vwrj5pek70h13ai.png)

Although it is only a half-day event, you will have a hard time picking sessions, as it is packed with a lot of exciting content.

If you have not registered yet, you still have time to do this on [https://aka.ms/createserverless](https://aka.ms/createserverless).

## Open mic: Developer hacks and tools we wished we knew sooner

![Networking Breakout: Developer hacks and tools we wished we knew sooner](https://dev-to-uploads.s3.amazonaws.com/i/am72dnmops31co6zziqy.png)

One of the breakout sessions at Create:Serverless days, is an open mic and networking session. During the session, we will discuss five different topics. One of these topics is how [Luise](https://twitter.com/LuiseFreese) and I manage an [online sticker store](https://pimpyourowndevice.com), which runs on Azure Functions and Power Platform's power. 

I am really excited to see this small side hustle grow. With these opportunities we get, we can grow our business step by step.

Will I see you on September 30th at Create:Serverless? The Open Mic session starts at 12pm PDT - Find out more about it on [Networking Breakout: Developer hacks and tools we wished we knew sooner](https://createserverlessopenmic5.splashthat.com/) facilitated by [Chris Heilmann](https://twitter.com/CODEPO8) and [Marie Hoeger](https://twitter.com/_MHOEGER).