teleren/devto huggingface dataset:
Postgresql and Django Quickstart Guide
Tags: postgres, django, python
Published: 2021-03-12 20:38:46

1) Download and install psql for your system
On Ubuntu, use apt-get:
```
sudo apt update
sudo apt install postgresql postgresql-contrib
```

2) Create new user and database in the SQL Shell
Login as “postgres” user and create a new user with the following command (replacing “username” and “jws8s0F4” with the appropriate values”:
```
psql -U postgres

# after logged in as postgres
CREATE USER username WITH PASSWORD 'jw8s0F4';
```
Create a new database(ex: “exampledb”) and grant permission to the new user:
```
CREATE DATABASE exampledb;
GRANT ALL PRIVILEGES ON DATABASE "exampledb" TO username;
```
Sign out by typing “exit” or entering the following command:
```
\q
```

3)  Log in as a new user and check database connection
Log in as the newly created user:
```
psql -U username
```
Test Database with the “\c” command
```
\c exampledb
```

4) Install psycopg2-binary and update database settings
```
pip install psycopg2-binary
```
In the example below, values are secured using [python decouple](https://www.ordinarycoders.com/blog/article/secure-django-variables-with-python-decouple):
```python
# make sure to pip install psycopg2-binary
#in settings.py

DATABASES = {
     'default': {
        'ENGINE': 'django.db.backends.postgresql', #some guides include the psycog2 part in the name
        'NAME': config('DB_NAME'),  #includes python decouple
        'USER': config('DB_USER'),
        'PASSWORD': config('DB_PASSWORD'),
        'HOST':'localhost',
        'PORT': '5432',
    }
}
```

5) Migrate database
```
python3 manage.py makemigrations
python manage.py migrate
```
If you can successfully migrate your database, then setup is complete. If unable to migrate, ensure all database configurations are correct and no typos exist.

[More information](https://www.ordinarycoders.com/blog/article/django-postgresql)
Renaming and Deleting Files in Python
Tags: python
Published: 2021-03-12 20:38:12

Python os module provides methods that help you perform file processing operations, such as renaming and deleting files.

To use this module you need to import it first and then you can call any related functions.

**The rename() Method**
The rename() method takes two arguments, the current filename and the new filename.

Syntax

```python
os.rename(current_file_name, new_file_name)

```
Example
Following is the example to rename an existing file test1.txt −

```python
#!/usr/bin/python
import os
# Rename a file from test1.txt to test2.txt
os.rename( "test1.txt", "test2.txt" )

```
**The remove() Method**
You can use the remove() method to delete files by supplying the name of the file to be deleted as the argument.

Syntax

```python
os.remove(file_name)

```
Example
Following is the example to delete an existing file test2.txt −

```python
#!/usr/bin/python
import os
# Delete file test2.txt
os.remove("text2.txt")
```
Reading and Writing Files in Python
Tags: python, os
Published: 2021-03-12 20:32:07

The file object provides a set of access methods to make our lives easier. We would see how to use read() and write() methods to read and write files.

**The write() Method**
The write() method writes any string to an open file. It is important to note that Python strings can have binary data and not just text.

The write() method does not add a newline character ('\n') to the end of the string −

Syntax

```python
fileObject.write(string)

```
Here, passed parameter is the content to be written into the opened file.

Example

```python
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "wb")
fo.write( "Python is a great language.\nYeah its great!!\n")
# Close opend file
fo.close()

```
The above method would create foo.txt file and would write given content in that file and finally it would close that file. If you would open this file, it would have following content.

```
Python is a great language.
Yeah its great!!

```
**The read() Method**
The read() method reads a string from an open file. It is important to note that Python strings can have binary data. apart from text data.

Syntax

```
fileObject.read([count])

```
Here, passed parameter is the number of bytes to be read from the opened file. This method starts reading from the beginning of the file and if count is missing, then it tries to read as much as possible, maybe until the end of file.

Example
Let's take a file foo.txt, which we created above.

```python
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "r+")
str = fo.read(10);
print "Read String is : ", str
# Close opend file
fo.close()

```
This produces the following result −

```
Read String is : Python is a great language.
```
Search for a specific file on a PC
Published: 2021-03-12 20:26:29

In this article, I will show how to use the os.walk() module function to walk a directory tree, and the fnmatch module for matching file names.

**What is OS.walk?**

It generates the file names in a directory tree by walking the tree either top-down or bottom-up.

For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).

**dirpath #** is a string, the path to the directory.

**dirnames #** is a list of the names of the subdirectories in dirpath (excluding ‘.’ and ‘..’).




**filenames #** is a list of the names of the non-directory files in dirpath.

Note that the names in the lists contain no path components.

To get a full path (which begins with top) to a file or directory in dirpath, do os.path.join(dirpath, name). For more information, please see the Python Docs.

**What is Fnmatch**

The fnmatch module compares file names against glob-style patterns such as used by Unix shells.

These are not the same as the more sophisticated regular expression rules. It’s purely a string matching operation.

If you find it more convenient to use a different pattern style, for example regular expressions, then simply use regex operations to match your filenames.

**What does it do?**

The fnmatch module is used for the wild-card pattern matching.

**Simple Matching**

fnmatch() compares a single file name against a pattern and returns a boolean indicating whether or not they match. The comparison is case-sensitive when the operating system uses a case-sensitive file system.

To test a sequence of filenames, you can use filter(). It returns a list of the names that match the pattern argument.

**Find all mp3 files**

This script will search for *.mp3 files from the rootPath (“/”)

```python
import fnmatch
import os
 
rootPath = '/'
pattern = '*.mp3'
 
for root, dirs, files in os.walk(rootPath):
    for filename in fnmatch.filter(files, pattern):
        print( os.path.join(root, filename))

```
**Search computer for specific files**

This script uses ‘os.walk’ and ‘fnmatch’ with filters to search the hard-drive for all image files

```python
import fnmatch
import os

images = ['*.jpg', '*.jpeg', '*.png', '*.tif', '*.tiff']
matches = []

for root, dirnames, filenames in os.walk("C:\"):
    for extensions in images:
        for filename in fnmatch.filter(filenames, extensions):
            matches.append(os.path.join(root, filename))

```
There are many other (and faster) ways to do this, but now you understand the basics of it.
Warga Jatibening Diadang Begal, Tangannya Hampir Putus  
Published: 2021-03-12 20:07:38

kabarbekasi – Baru pulang kerja, warga Jatibening diadang komplotan begal di Jalan KH Noer Ali, Kota Bekasi, Jumat dinihari 12 Maret 2021. Alhasil, korban bernama Suwono (41) kritis setelah tangannya dibacok dan hampir putus.

“Kami tahu setelah menerima laporan adanya korban begal di Jalan KH Noer Ali,” kata Kepala Tim Patriot Polres Metro Bekasi Kota, Aiptu Bambang, Jumat 12 Maret 2021.

sumber: https://kabarbekasi.id/2021/03/12/warga-jatibening-diadang-begal-tangannya-hampir-putus/
Reactive Rails: StimulusReflex
Tags: rails, stimulusreflex, ruby, javascript
Published: 2021-03-12 20:02:57

As a part of Flagrant's series exploring Reactive Rails, we
implement a simple chat using StimulusReflex, CableReady, poking into the first few corners you'll encounter. Walk with us through our implementation, and let us know what you think.

[Reactive Rails: StimulusReflex](https://www.beflagrant.com/blog/reactive-rails-stimulusreflex)
Prototypes in Javascript
Tags: protoypes, prototypalinheritance, inheritance, javascript
Published: 2021-03-12 19:54:35

Everything is an object in Javascript, well almost.

Functions are also objects in Javascript, albeit a special kind of object.

Eg:  
```
     function sum(a,b) {
        return a+b;
     }
     console.log(typeof sum); // "function"  :)
     Still an object with internal [[call]] method
```

     

So, we can do the following on functions:
Eg: 
```
    sum.prop1 = "random property";
    console.log(sum.prop1); // "random property"
```

Similarly, **"prototype"** is an inbuilt property on functions in Javascript (except Function function, whose prototype property is a function due to backward compatibility issues).

Note: 
  "prototype" itself is an object of the said function kind.
   Eg:
```
   console.log(typeof sum.prototype); // "object"
```

Now, one way to create objects in javascript is using the "new" keyword to call a function (mainly using the constructor functions).

Eg:
```
    function Person(name, age) {
       this.name = name;
       this.age = age;
    }
    const p1 = new Person("John", 25);
    console.log(typeof p1); // "object"
```

Now, if you look at the constructor property of the "p1" object and "Person.prototype" object, they'll be equal to the function "Person".

Eg:
```
    p1.constructor === Person // true
    Person.prototype.constructor === Person // true
```

This proves that the "prototype" property on a function object refers to the function itself.

**Use of Prototypes:** 
  Properties of a function that need to be inherited down the prototype chain are defined inside the "prototype" object. Inheritance in Javascript is possible due to prototypes.

Eg: Let's define a getInfo property on the Person's "prototype" object.

    Person.prototype.getInfo = function() {
       return `I am ${this.name}, age ${age}`;
    }
    const p2 = new Person("Sam", 30);
    console.log(p2.getInfo()); // "I am Sam, age 30"

It's possible to access "getInfo" property from "p2" object or any object created from a construction function inheriting Person, because "getInfo" is defined in Person's "prototype" making it an inheritable property down the prototypal chain.

Note: If you are wondering how "p2" object technically has access to the "getInfo" property, it's because if an object does not find a property with itself, it looks for it in its prototype object using the following ways:

    p2.__proto__ === Person.prototype 
            // true -- soon to be deprecated, not recommended
    Object.getPrototypeOf(p2) === Person.prototype  
            // true -- recommended
Google Sheets API in ASP.NET | C#
Tags: googlesheets, sheetsapi, dotnet, csharp
Published: 2021-03-12 19:48:24

### Demo: https://techtolia.com/GoogleSheets/

With integrating the module to your ASP.NET web forms, read/write/update any google sheet that is shared you.

Present any google sheet on your web site with editable or static versions. Editable table feautures:
- Edit cells
- Clean Column
- Delete Column
- Insert Column Left
- Insert Column Right
- Clean Row
- Delete Row
- Insert Row Above
- Insert Row Below

The module uses Google Sheets API with NuGet Packs.

Full source code is included.

### What is Google Sheets API?
The Google Sheets API lets you read and modify any aspect of a spreadsheet. Spreadsheets have many settings that let you craft beautiful and functional sheets, so the API has many settings too.

Spreadsheets can have multiple sheets, with each sheet having any number of rows or columns. A cell is a location at the intersection of a particular row and column, and may contain a data value. The Google Sheets API provides the spreadsheets.values collection to enable the simple reading and writing of values.

To read data from a sheet, you will need the spreadsheet ID and the range(s) A1 notation.

To write to a sheet, you will need the spreadsheet ID, the range(s) in A1 notation, and the data you wish to write arranged in an appropriate request body object.

![Google Sheets API in ASP.NET | C#](https://dev-to-uploads.s3.amazonaws.com/i/6v5gibm9lvzktqvzabzd.png)![Google Sheets API in ASP.NET | C#](https://dev-to-uploads.s3.amazonaws.com/i/8wz1wsqec1trywdjjx4d.png)

### Quick Start
- Create a project on Google APIs Console.
- Enable Google Sheets API & create credentials file. Copy the credentials file to your project.
- Create a spreadsheet on Google Sheets and share it with edit access to your client_email that is in the credentials file.
- Install Google Sheets library from NuGet.
- Use source code and customize your web form.
- Run the application.
One year later...
Tags: programming, codenewbie, career
Published: 2021-03-12 19:42:18

So a year ago today was my last day in an office. We packed up our things and went home, with the thought of 

"Oh, maybe we will be able to work from home for like a week or two. That would be nice" My prior company had no WFH policy so it was going to be a nice change. 

Little did I know I would never return to that desk. A few months later I was laid off along with many others.  I took the time to enjoy family, and then recalibrate on my ambitions moving forward. I decided to finally commit to #coding and enrolled in a Software Engineering program that I am about to complete.

So here we are one year later. In a way, life seems like it was paused completely.  On the other hand, drastic changes have happened globally and personally. I am excited to what the future has in store in life and my new career. Always need to find the silver linings in something right?
Email templates development tips request
Tags: email, templates, development, tips
Published: 2021-03-12 19:34:17

This week I spent implementing email templates and I would say it was kinda painful...😥

I built a part of template using Mailchimp builder, but then I got stuck because Mailchimp provides you a dozen of styled views, but it doesn't provide a bit more complex layouts (would be nice to have an opportunity to insert a simple table). So I exported Mailchimp stuff and continued manually.

The main thing I learned is that we must develop email templates with mobile-first approach because many mail clients don't support media queries. With mobile-first approach, the user sees mobile view on their desktop mail client without media queries support which isn't as bad as desktop view on a mobile screen.

Smaller tips I would like to follow the next time I will have to work on email templates:
- use tables to build complex layouts;
- use the most common CSS properties without any shortenings;
- use inline styles where it's possible (at least text font styles);
- use IDs instead of classes, it was easier to navigate through styles based on ID selectors for me.

Also, I wrote a simple server on Express.js that serves email templates populated with mocked data. It processes variables and simple if-else expressions only. It made development much easier than updating of template in Mandrill and triggering its sending via application each time you want to see how email looks with proper data.

Please, share tips you follow when developing email templates or tools you use for it. Maybe great email builder exists and my suffering was vain...😮
AI4DEVS: Issue #1
Tags: machinelearning, ai, cloud, aws
Published: 2021-03-12 18:42:51

# The evolution of artificial intelligence from magic art to engineering practice


In the last few years, machine learning has become mainstream and has been widely adopted by data scientists and a growing number of developers, architects, and decision-makers. This new age of AI makes tools and models more accessible to everyone without data science skills, but understanding these techniques will soon be the core foundation of any software project.
When practitioners shift from a wizard pulling magic spells from an arcane book to an engineering professional, a change of mind is required to discover a new world of opportunities and many use cases.

AI4DEVS is a weekly selection of curated AI news selected from the internet by a community of professionals to help you add a bit of AI in your next project or better understand its applications. 

### Here are our top picks of the week!

Natural Language Processing (NLP) and Natural Language Understanding (NLU) have always been some of the most promising fields of AI, with many applications, even making  [a contact center able to diagnose COVID-19 using managed services](https://aws.amazon.com/blogs/machine-learning/applying-voice-classification-in-an-amazon-connect-telemedicine-contact-flow/).

AI is becoming a tool to be used in everyday applications. Nothing more than a showcase about adding  [text analytics capabilities into an existing workflow](https://aws.amazon.com/it/blogs/machine-learning/translate-and-analyze-text-using-sql-functions-with-amazon-athena-amazon-translate-and-amazon-comprehend/)  makes the point.

Finally, if you want to be amazed by what AI can do today, check out this video about  [OpenAI playing hide and seek](https://www.youtube.com/watch?v=Lu56xVlZ40M&t=187s)  in a simulated environment. Impressive!

--- 

#### About the Authors

This newsletter would haven’t been possible without ML specialists’ joint efforts and AWS Heroes  [Gillian Armstrong](https://twitter.com/virtualgill),  [Pavlos Mitsoulis Ntompos](https://aws.amazon.com/it/developer/community/heroes/pavlos-mitsoulis/?did=dh_card&trk=dh_card), and  [Alex Schultz](https://aws.amazon.com/it/developer/community/heroes/alex-schultz/?did=dh_card&trk=dh_card).

Thank you for reading, see you next week! 


Cheers,

Luca
SIMPLE WAY TO CREATE DOWNLOAD OPTION IN DJANGO
Published: 2021-03-12 18:26:24

Hey!! Nice to meet you.I had seen many people facing problem in creating download option in django i had find a simple way to download files in django and you can use in any programming language as well.


SO LET'S START:-
Here is the My youtube link of the way video is of only 1 minute.
If you like please subscribe as well

https://youtu.be/so-suoFBnYo
Keeping it simple and sane
Tags: sanityio, devops, opensource, javascript
Published: 2021-03-12 18:20:30

I started working with Sanity.io this month after a friend mentioned enjoying it. I have to say, I am also really enjoying the way that sanity provides an incredibly easy mechanism for creating structured content and a way to get that content into your website. I started using sanity for the BikeTag project and I can quickly see the power in this platform for the needs of that project.

For BikeTag, all we have are images and data associated with those images. Up until using sanity.io (which we haven't officially launched on our site yet), our data and images have all been stored in Imgur. Imgur provides free, unlimited, image stores with a title and description field. From the onset, I believed that the needs of the BikeTag project wouldn't need anything more than that. We used the description and a pattern to store fields like: tagnumber, username, found location, and hint. Each image came from the imgur API with those fields and so we had no complex data needs beyond what little information was stored with each image.

As our data needs have grown over the last three years of the project, I began searching for a data solution that would be quick and easy to implement but also provide the most value over time. This open-source project's biggest limitation are the costs, in that there is absolutely no money to pay for things like a datastore or for G suite.

Enter sanity.io:
* 2 free datastores per project
* unlimited projects(?)
* bundles with an imagestore, natively
* 5GB of image storage per project
* generous quotas for developer/small projects
* available plans for open source projects

Sanity is great and their slack community is invaluable. The project maintainers and community are very responsive to help experts and newbies alike. Asking for help and getting pointed in the right direction happens so fast on their slack channel #help it beats out anything I've experienced on a support level. And it's all virtually free, until you have a high value need.

I created this post to share my initial thoughts on Sanity.IO as a platform and to present my first community contribution to the sanity ecosystem:
https://www.sanity.io/schemas/set-slug-on-publish-with-referenced-field-value-ZMcsmDfWFDUo5_BrLtVpY

Thanks for reading, check out:
https://sanity.io
https://biketag.org
New technology and non-verbal communication around the world
Tags: nestjs, typescript, communication, gestures
Published: 2021-03-12 18:15:59

Today I’d like to share with you how I enjoyed this week’s soft skills topics and technical skills that I gained during this week. I’m super excited to write this journal because each day of this week has been really interesting!

Yeah! The week has been interesting because I was introduced to new technologies, NestJS and TypeScript. It was my first time working with these two technologies.

Let me explain a little bit about NestJS and TypeScript 

As it’s written on NestJS’s [website](https://nestjs.com), NestJS is a [Node.js](https://nodejs.org) framework for building efficient, reliable, and scalable [server-side](https://en.wikipedia.org/wiki/Server-side) applications. I enjoyed working with this technology and within a short period of time, I hope to master it. 

What is TypeScript?

TypeScript is a programming language developed and maintained by Microsoft. If you’re excited like the way I was to read more about this programming language which is a strict syntactical superset of JavaScript then kindly click this [TypeScript link](https://en.wikipedia.org/wiki/TypeScript) on Wikipedia.
 
During this week, I learned a lot of things in technical skills and soft skills. I built a todo app in NestJS as [John Dewey's philosophy](https://en.wikipedia.org/wiki/Learning-by-doing) says that we should learn by doing.

Friday we do a virtual meeting with the Awesomity team to share with them what we learned during the week. For the first time it was not easy, I was nervous but the more we do mass communication the more I get to be confident, I hope it’s a good process to master public speaking.

I can not finish this journal without saying how much I enjoyed the session on “Non-verbal gestures around the world". It was an interactive session and we had a good time sharing what we learned from other cultures, especially gestures! Now I know that there are a lot of gestures that mean different things in different cultures.

Thank you for reading!
HELP WITH PYTHON ERROR
Published: 2021-03-12 17:59:31

So I am currently making a slack bot using python. I am not extremely familiar with python but still know some stuff. For some reason I keep getting this error. I've tried multiple things and can't seem to figure it out. Here's the code.    
client = slack.WebClient(token=os.environ['SLACK_TOKEN'])
  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'SLACK_TOKEN'
What was your win this week?
Tags: discuss, weeklyretro
Published: 2021-03-12 17:57:18

---
title: What was your win this week?
published: true
description: Got to all your meetings on time? Started a new project? Fixed a tricky bug?
tags: discuss, weeklyretro
cover_image: https://cl.ly/188e843c2985/download/Image%202019-02-15%20at%202.36.37%20PM.png
---

Happy Friday!


**Looking back on your week — what was something you're proud of?**

All wins count — big or small 🎉

Examples of 'wins' include:

- Starting a new project
- Landing a new job
- Spending time outside ... or whatever else might spark joy ❤️ 

---

Happy Friday!

![Weekend dog on the beach](https://media.giphy.com/media/TjSP4hvXzV6NBRaBF0/giphy.gif)