teleren/devto huggingface dataset:
Skipping to the Good Parts: Implementing Netflix's Skip Intro Feature with Python Video Processing
Tags: netflix, python, video, programming
Published: 2023-02-05 13:42:11

Netflix’s Skip Intro feature is about as iconic as the service itself, allowing subscribers to skip past intro and outro portions of tv shows. Since then, other streaming services have adopted this feature, making it a staple of the streaming world. 

Recently, I began thinking about implementing this feature and this led me to make a [small library](https://github.com/jahwi/similar-vid) to find similar portions in videos. It does this by hashing videos into frames, hashing these frames, and comparing similar frames between each comparison video and a reference video.

I decided to test this library on my favourite recently-cancelled Netflix show, Inside Job:

```python

# Import the library
from similar_vid.similar_secs import Similar, save

# Load the file paths
file1 = "videos//inside_job//01.mkv"
file2 = "videos//inside_job//02.mkv"
file3 = "videos//inside_job//03.mkv"
file4 = "videos//inside_job//04.mkv"
file5 = "videos//inside_job//05.mkv"


if __name__ == "__main__":
    # Hash the videos
    inside_job = Similar(ref=file1, comp_arr = [file2, file3, file4, file5])

    # Match the videos
    inside_job.match(threshold=15)
    
    for match in inside_job.matches:
        print(match)
    
    # use the library's save function to save class fields as JSON for further use
    save(inside_job.matches, "outs//matches.json")
```

In the above, we import the Similar class from my [similar-vid](https://github.com/jahwi/similar-vid) library and pass it the reference video and an array of comparison videos. We then use the `match` method to speficy that we only want matches that are at least 15 seconds long. The library then hashes and matches the videos as such:


![Screenshot of console output showing the library matching frames between videos](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9p9ugywiegvgykp8mq59.png)

Description: A screenshot of the console showing the hashing and matching process.

These hashes are then stored in the `matches` field of the class instance as a list of dictionaries. Below that, we print the matches and use the library’s `save` method to save the matches to a json file:


![A screenshot of the console showing the matching frames.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7yljn09jm902z6kdzxoj.png)

The returned arrays of the “matches” key, if any, are the beginning and ending matching seconds of the comparison video, respectively.

We can then pass this as context to the frontend. Using Javascript to modify the video’s `currentTime` property, we can skip the intro portion:


![Screenshot video showing implementing the Skip Intro feature implemented in the frontend](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cn4pkc067y44cdhj4nvm.gif)

As can be seen in the above gif, the Skip Intro button appears over the intro portion.

The similar_vid library can be found here: [https://github.com/jahwi/similar-vid](https://github.com/jahwi/similar-vid)

Thanks for reading.
Liskov's Substitution Principle (Python Design Patterns)
Published: 2023-02-05 13:40:17

The [Liskov Substitution Principle (LSP)](https://cleancode.studio/design-patterns) states that objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program. This means that a subclass should be a subtype of its superclass, and the behavior of the program should remain the same whether we use the superclass or a subclass. Here's an example in [Python](https://cleancode.studio/python):

{% embed https://gist.github.com/zhorton34/0831e147b53b6b2b1ced1f2f5201b1c4.js %}
In this example, the `Rectangle` class defines the behavior for rectangles, and the `Square` class inherits from it and represents squares. The `use_it` function uses a rectangle-like object, such as a `Rectangle` or a `Square`, to calculate its area. The function calls the `set_height` method and then asserts that the area is correct.

When we pass a `Rectangle` object to `use_it`, it works as expected and the assertion is true. When we pass a `Square` object to `use_it`, it also works and the assertion is true, even though the `Square` class overrides the behavior of the `set_width` and `set_height` methods. This means that the `Square` class is a subtype of the `Rectangle` class, and objects of the `Square` class can be used wherever objects of the `Rectangle` class are expected, without affecting the correctness of the program. This adheres to the [Liskov Substitution Principle](https://sites.google.com/view/cleancodestudio/design-patterns/liskovs-substitution-design-pattern).


[Python](https://cleancode.studio/python)
[Design Patterns](https://cleancode.studio/design-patterns)
[Clean Code Studio](https://cleancode.studio)
[Python Design Patterns](https://cleancode.studio/python/design-patterns)
[Python Liskov's Substitution Principle Design Pattern](https://cleancode.studio/python/design-patterns/liskovs-substitution-design-pattern)
[Liskov Substitution Design Pattern](https://www.cleancode.studio/design-patterns/liskovs-substitution-design-pattern)
Graph Databases and Introducing Apache AGE
Tags: database, postgres
Published: 2023-02-05 13:37:00

Graph databases are described as databases that operate over graphs and where relationships between things matter. A graph is a type of structure and the underlying graph of a graph database maps the structure, or schema, of the data stored in the database.

**Features:**
The term “graph” comes from the use of the word in mathematics. There it’s used to describe a collection of nodes (or vertices), each containing information (properties), and with labeled relationships (or edges) between the nodes.

A social network is a good example of a graph. The people in the network would be the nodes, the attributes of each person (such as name, age, and so on) would be properties, and the lines connecting the people (with labels such as “friend” or “mother” or “supervisor”) would indicate their relationship. 

In a conventional database, queries about relationships can take a long time to process. This is because relationships are implemented with foreign keys and queried by joining tables. As any SQL DBA can tell you, performing joins is expensive, especially when you must sort through large numbers of objects—or, worse, when you must join multiple tables to perform the sorts of indirect (e.g. “friend of a friend”) queries that graph databases excel at. 

Graph databases work by storing the relationships along with the data. Because related nodes are physically linked in the database, accessing those relationships is as immediate as accessing the data itself. In other words, instead of calculating the relationship as relational databases must do, graph databases simply read the relationship from storage. Satisfying queries is a simple matter of walking, or “traversing,” the graph.  

A graph database not only stores the relationships between objects in a native way, making queries about relationships fast and easy, but allows you to include different kinds of objects and different kinds of relationships in the graph. Like other NoSQL databases, a graph database is schema-less. Thus, in terms of performance and flexibility, graph databases hew closer to document databases or key-value stores than they do relational or table-oriented databases.

A typical Graph database example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxxcdf78wsfgrzhik2od.png)

**How Apache AGE comes into the picture**

Apache AGE is PostgreSQL extension that provides graph database functionality.
It aims to bring graph querying abilities to be brought to relational database paradigm.
Users can read and write graph data in nodes and edges. They can also use various algorithms such as variable length and edge traversal when analysing data. And all these graph based data will be internally be handled keeping the relational database 

Check Out Apache AGE.
[Apache AGE Website](https://age.apache.org/)
[Apache AGE Github](https://github.com/apache/age)
Python Open Closed Design Pattern (Python SOLID Principles)
Published: 2023-02-05 13:25:42

The [Open/Closed Principle](https://cleancode.studio/design-patterns/open-closed-design-pattern) states that a module (such as a class, function, etc.) should be open for extension but closed for modification. In other words, a module should be designed in such a way that it can be easily extended without changing its existing code. 

Here's an example in [Python](https://cleancode.studio/python):

{% embed https://gist.github.com/zhorton34/d93fce9dd11c16a454d2ebc49b513d8b.js %}

In this example, the `Shape` class is an abstract base class that defines the interface for all shapes, and the `Circle` and `Rectangle` classes inherit from it and provide concrete implementations of the area method. The `calculate_area` function takes a list of shapes and calculates the total area by calling the area method on each shape.

By using inheritance and an abstract base class, the existing code can be extended to support new shapes without having to modify the existing code. For example, if we wanted to add a square shape, we could simply create a `Square` class that inherits from `Shape `and provide an implementation of the area method. This adheres to the Open/Closed Principle as the existing code remains closed for modification, while new functionality can be added through extension.


[Python](https://cleancode.studio/python)
[Design Patterns](https://cleancode.studio/design-patterns)
[Clean Code Studio](https://cleancode.studio)
[Python Design Patterns](https://cleancode.studio/python/design-patterns)
[Python Open Closed Principle Design Pattern](https://cleancode.studio/python/design-patterns/open-closed-design-pattern)
[Open Closed Principle (OCP)](https://cleancode.studio/design-patterns/open-closed-design-pattern)
Python Single Responsibility Design Pattern (Code Example)
Published: 2023-02-05 13:14:00

## Python Single Responsibility Design Pattern 


<center>_<small>"Every module, class, or function should have only one reason to change."</small>_</center>

---

> Example of the [Single Responsibility Principle](https://sites.google.com/view/cleancodestudio/design-patterns/single-responsibility-design-pattern) [design pattern](https://www.cleancode.studio/design-patterns) implemented in [Python](https://cleancode.studio/python/design-patterns/single-responsibility-design-pattern) code:


{% embed https://gist.github.com/zhorton34/eb159e066e1cf7cf30d40735c58a4ffa.js %}


In this example, the `Journal` class has a _single responsibility_, which is to store and manage journal entries. 

The `PersistenceManager` class, on the other hand, has a single responsibility, which is to persist the Journal to different storage mediums (file, web, etc.). 

This separation of responsibilities makes the code more maintainable and easier to understand, as changes to one class won't affect the other.



[Python](https://cleancode.studio/python)
[Design Patterns](https://cleancode.studio/design-patterns)
[Clean Code Studio](https://cleancode.studio)
[Python Design Patterns](https://cleancode.studio/python/design-patterns)
[Single Responsibility Principle (SRP)](https://cleancode.studio/design-patterns/single-responsibility-design-pattern)
Python script to backup up a postgres database to s3
Published: 2023-02-05 13:06:33

[This](https://github.com/leroykayanda/AWS/blob/master/Misc/postgres_db_backup.py) script backups up a postgres db to S3. It sends any errors that occur to slack. Successful backups are logged in cloudwatch. DB credentials are retrieved from AWS secrets manager.

Use this cron to schedule the script to run every hour.

` * * * * /usr/bin/python3 /path/to/script/script.py <app_name> <db_name> <slack webhook url> <secrets manager ARN> <s3 bucket name> <cloudwatch loggroup> <cloudwatch logstream>`

These libraries need to be installed.

```
amazon-linux-extras install postgresql14
pip3 install urllib3
pip3 install boto3
```

AWS Permissions Needed 

```
s3:PutObject 
secretsmanager:GetSecretValue
logs:PutLogEvents
```
Sebanyak 225 Orang Warga Binaan Rutan Pasangkayu Skrinning Kesehatan
Published: 2023-02-05 12:54:34


![Rutan Pasangkayu Berkolaborasi Dengan Puskesmas Bambalamotu Lakukan Skrining Penyakit Tidak Menular. Foto: Rutan Pasangkayu/dok (04/02)
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78c6iklil2cqwk6243ky.jpeg)

**Pasangkayu** - Tim Layanan Kesehatan Poliklinik Rumah Tahanan Negara (Rutan) Kelas IIB Pasangkayu Kantor Wilayah Kementerian Hukum dan HAM Sulawesi Barat yang bersama Puskesmas Bambalamotu melaksanakan Kegiatan Skrining Penyakit Tidak Menular (PTM) kepada Warga Binaan, Kamis (03/02).

Salah satu hak tahanan dan narapidana adalah mendapatkan perawatan serta pelayanan kesehatan. Kali ini Rutan Pasangkayu berkerjasama dengan Puskesmas Bambalamotu melaksanakan skrining penyakit tidak menular seperti pengecekan gula darah dan tekanan darah kepada seluruh warga binaan Rutan Pasangkayu.

Kegiatan skrining ini dilakukan terhadap 225 orang warga binaan yang ada di Rutan Pasangkayu. Skrining penyakit Tidk menular yang dilakukan mulai dari Berat badan, tinggi badan, lingkar perut, dan tensi warga binaan. Hasilnya, sebanyak 18 orang memiliki riwayat darah tinggi (Hipertensi), dan 8 orang mengidap diabates.

Dokter Rutan Pasangkayu, dr. Riri Neliwanti menyampaikan bahwa skrining Penyakit Tidak Menular ini bertujuan untuk deteksi dini terhadap faktor risiko penyakit yang ada pada warga binaan di Rutan Pasangkayu sehingga bisa ditangani secepatnya.

Selain itu kegiatan ini merupakan upaya preventif yang bertujuan untuk meningkatkan derajat kesehatan warga binaan. Menurutnya, kesehatan merupakan faktor penting dan menjadi prioritas utama. Jika kesehatan terganggu maka akan berpengaruh dalam beraktivitas, terutama dalam bekerja.

"Harapan kami, kolaborasi dalam hal pelayanan kesehatan ini dapat terus terlaksana secara berkelanjutan agar hak kesehatan warga binaan dapat terpenuhi," jelas Riri.

![Rutan Pasangkayu Berkolaborasi Dengan Puskesmas Bambalamotu Lakukan Skrining Penyakit Tidak Menular. Foto: Rutan Pasangkayu/dok (04/02)
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mj8dkb5dc2dwvtky3tx1.jpg)
Use of where filter in for loops in Swift
Published: 2023-02-05 12:53:59

read the articles for using where filter in for loops, 

https://medium.com/@nahermeo/use-of-where-filter-in-for-loops-in-swift-99211edae1f5


    #iosdev
    #iosdevelopment
    #swift
    #iosprogramming
    #mobileapps
    #iosappdevelopment
    #xcode
    #iosengineer
    #appdevelopment
    #objectivec
    #apple
    #iosapp
    #ios
    #iosdesign
    #iosarchitecture
    #cocoa
    #iosengineers
    #devlife
    #iosappdev
    #iosdevcommunity
    #iosdevelopmenttips
    #iosdevs
    #iosdevblog
    #iosdevlife
    #iosdeveloper
    #iosdevelopmentcommunity
    #iosdevelopers
    #iosdevworld
    #iosdevworldwide
    #iosdevworldcommunity
Harnessing AI and ChatGPT: The Best Free Online Courses to Get Started
Tags: beginners, ai
Published: 2023-02-05 12:20:58

When it comes to technology, there's no denying that the world is constantly evolving. AI and ChatGPT in particular are two of the most rapidly growing areas of technology. With the help of these technologies, organizations can automate their customer service processes and provide quick and accurate responses to their customers. Advance your AI skills – find your Ideal [AI course](https://skillcombo.com/topic/artificial-intelligence/) on our platform today:

1. Introduction to AI by Stanford University on Coursera: This course provides an overview of the field of artificial intelligence and covers the basics of machine learning, computer vision, natural language processing, and robotics.

2. AI for Everyone by DeepLearning.ai on Coursera: This course is designed for non-technical professionals and covers the basics of AI, including machine learning and deep learning.

3. Natural Language Processing with Deep Learning by Stanford University on Coursera: This course covers the basics of natural language processing and deep learning, including sentiment analysis, text classification, and sequence modeling.

4. OpenAI's GPT-3 Playground: This is an interactive platform where you can play with OpenAI's state-of-the-art language model, GPT-3, and learn how to use it to generate text, translate languages, and more.

5. AI Programming with Python by Udacity: This course covers the basics of programming with Python and teaches you how to build AI applications, including image recognition and natural language processing.

If you're looking to gain a better understanding of AI and ChatGPT, there are many free online courses you can take advantage of. You'll need to spend some time sifting through these options to find the one that's right for you, but it's well worth your while. Try one out today—the benefits are too good to pass up!
Redirect to a page from Next.js API Route
Tags: nextjs, webdev, javascript, react
Published: 2023-02-05 12:19:36

## The problem
If you want to redirect a user to a “Thank You” page after signing up for your newsletter, and you’re using Next.js with its API routes, you can implement this functionality with just a few lines of code.

## Example
Please note that the redirect function will not work with `fetch`. The API request must be initiated by a `<form>`. The following is an example Next component that will be used to call our API route.

```jsx
export function Newsletter() {
  return (
    <form method="POST" action="/api/create-subscriber">
      <h2>
   Stay up to date
      </h2>
      <p>
        Get notified when I publish something new, and unsubscribe at any time.
      </p>
      <div>
        <input
          id="email"
          name="email"
          type="email"
          placeholder="Email address"
          aria-label="Email address"
          required
        />
        <button type="submit">
          Join
        </button>
      </div>
    </form>
  )
}
```

As you can see, we are not handling the form state using hooks, and we’re not defining a `handleSubmit` function or passing anything to the `onSubmit` prop. The action prop should point to the API route that handles form submissions.

We have to use Next.js API routes because we need to attach the API key, which cannot be exposed to users in the browser.

### API Route

When the user clicks the “Join” button, the form is submitted, and the form data, including the `email`, is passed via the request body.

```js
export default async function handler(req, res) {
  const { email } = req.body
  try {
    await handleFormInputAsync({ email })
    res.redirect(307, ‘/thank-you‘)
  } catch (err) {
    res.status(500).send({ error: ‘failed to fetch data’ })
  }
}
```

The `handleFormInputAsync` helper sends a request to our email service provider, including the user’s email and our unique private API key. If the request is handled successfully, the user will be redirected to the “Thank You” page in our front-end application.

## Why api redirects don’t work with `fetch`
Fetch requests in the browser do not allow redirects to change the current document. When a redirect is initiated from a fetch call, the browser does not follow the document and the request can only be used to retrieve data. This can be seen in the Chrome Network tab where the request type is shown as “fetch/Redirect”. This restriction is in place to prevent scripts from changing the document and causing chaos. Attempting to follow the redirect manually, using { redirect : “manual” }, will result in another request being made to the redirected location, but the redirected location is not returned and the new page cannot be navigated to using Javascript.

### ⚡️ Action Points
- [see my blog a about Javascript and React](https://www.nikolasbarwicki.com/)
- give a like or write a comment
Animista: A Game Changer for CSS Animations
Published: 2023-02-05 11:08:31

CSS animations have been around for quite some time now and they have come a long way in terms of functionality and ease of use. With the rise of modern web design, it is becoming increasingly important for designers to have the ability to create beautiful and engaging animations for their websites. This is where Animista comes in.

Animista is a CSS animation tool that allows designers to create stunning animations for their websites without having to write any code. The tool is easy to use and has a user-friendly interface that makes it accessible for designers of all skill levels. With its real-time preview feature, designers can see exactly what their animations will look like on their website before they export the code.

One of the standout features of Animista is its wide range of animation presets. With a collection of over 60 animations, designers can choose from a variety of options to create the perfect animation for their website. Whether it's a simple hover effect or a more complex animation, Animista has got you covered.

Another great feature of Animista is its export code feature. Once the designer has created the animation they want, they can export the code and use it on their website. The code is clean and well-documented, making it easy for developers to understand and implement.

**In conclusion**, Animista is a game changer for CSS animations. With its user-friendly interface, real-time preview, and extensive collection of animation presets, it is the perfect tool for designers who want to bring their web design to life with beautiful animations. So, what are you waiting for? Give Animista a try today!
differentiating between new user sign in vs sign up
Published: 2023-02-05 11:08:05

---
title: differentiating between new user sign in vs sign up
published: true
description: why not just register the user if it doesn't exist?! its the 2020's 
tags: 
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-02-05 11:06 +0000
---

why not just register the user if it doesn't exist?! its the 2020's