teleren/devto huggingface dataset:
CREATING YOUR FIRST DJANGO APP
Published: 2022-06-11 09:08:35

**Introduction to Django**

Welcome to the world of Django!

Django, pronounced like JANG-go with a silent D, is a high-level web framework that is written with Python — one of the most readable and beginner-friendly programming languages. Django can be used to rapidly build complex database-driven websites. Like Python, Django is often considered to be strongly opinionated. An opinionated software has guidelines and defaults, such as code structure, project structure, for developing code. Django’s opinionated approach means specific ways of writing code and a steeper learning curve to apply the “Django philosophy“. However, it comes with advantages when onboarding new teammates to a project and debugging code because of how structured a Django project is.

Django is an open-source project, supported by the Django Software Foundation, and has a strong community of contributors. It has been used by many well-known data-heavy websites such as Instagram, Youtube, and Dropbox. In this lesson, we’ll create together our first Django app! More importantly, we’ll experience first-hand how its design helps to take applications from concept to completion using its “batteries included” approach.

**What is a Web Framework?**
Let’s first establish what it means when we say Django is a web framework.

Web frameworks are a type of software development tool that makes it easier and faster to develop web applications. They are a type of code library that provides code and patterns for database access, as well as templating systems for content. They promote code reuse, so we don’t have to write as much code to get a project running.




Some features most web frameworks include are:

- URL routing
- Input form management and validation
- Templating engines for HTML and CSS
- Database configuration
- Web security
- Session repository and retrieval

Out of the box, Django comes with an admin panel, a user authentication system, a database, and something called object-relational mapper (ORM) that helps a web application interact with a database. These are some of the “batteries” included in Django to help build projects faster without having to worry about which tools to use.

Later we’ll see how we can bootstrap a fully featured web application in only a handful of commands.

Here is the continuation of the code.
Learn more here https://dev.to/kibetamos/how-django-works-2afn
Count Common Words With One Occurrence
Tags: leetcode, dsa, theabbie
Published: 2022-06-11 10:00:43

Given two string arrays `words1` and `words2`, return _the number of strings that appear **exactly once** in **each** of the two arrays._

**Example 1:**

**Input:** words1 = \["leetcode","is","amazing","as","is"\], words2 = \["amazing","leetcode","is"\]
**Output:** 2
**Explanation:**
- "leetcode" appears exactly once in each of the two arrays. We count this string.
- "amazing" appears exactly once in each of the two arrays. We count this string.
- "is" appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string.
- "as" appears once in words1, but does not appear in words2. We do not count this string.
Thus, there are 2 strings that appear exactly once in each of the two arrays.

**Example 2:**

**Input:** words1 = \["b","bb","bbb"\], words2 = \["a","aa","aaa"\]
**Output:** 0
**Explanation:** There are no strings that appear in each of the two arrays.

**Example 3:**

**Input:** words1 = \["a","ab"\], words2 = \["a","a","a","ab"\]
**Output:** 1
**Explanation:** The only string that appears exactly once in each of the two arrays is "ab".

**Constraints:**

*   `1 <= words1.length, words2.length <= 1000`
*   `1 <= words1[i].length, words2[j].length <= 30`
*   `words1[i]` and `words2[j]` consists only of lowercase English letters.

**SOLUTION:**

    from collections import Counter
    
    class Solution:
        def countWords(self, words1: List[str], words2: List[str]) -> int:
            w1 = Counter(words1)
            w2 = Counter(words2)
            op = set()
            for a in w1:
                if w1[a] == 1 and w2[a] == 1:
                    op.add(a)
            for a in w2:
                if w1[a] == 1 and w2[a] == 1:
                    op.add(a)
            return len(op)
Retrieving Ethereum Transaction Data using Javascript
Published: 2022-06-11 09:52:22

From my website, I am trying to retrieve the transaction data stored on the Ethereum blockchain using Javascript.
‘https://rinkeby.etherscan.io/tx/0xd8b3c50230fb2f1d3d8586f5179b514e913dbe7868effd490a5743caaabda6b9’
If you see the transaction link in the Rinkerby test network, (click to see more) and then Decode the input, the data is hidden and needs to be decoded.
This is the data - which is a hash value, which I would like to retrieve: 6538482db543dedf2b2c2dd986ce475aa2732e24390534c729f749005035e073

I am using the Javascript fetch you retrieve the entire html page. But if I search the resulting htmlString - the data (hash value) is not there. I am not sure how the decoding happens and what piece of data needs to be decoded.

Any assistance on how to get the data (hash value) would be appreciated.

```
<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <script>
    async function FetchHtml() 
    {
      let response = await fetch('https://rinkeby.etherscan.io/tx/0xd8b3c50230fb2f1d3d8586f5179b514e913dbe7868effd490a5743caaabda6b9');
      return await response.text(); // Returns it as Promise
    }

    // Using the HTML
    async function Do()
    {
          let htmlString = await FetchHtml().then(text => {return text}); 
	  console.log(htmlString)
	  let position = htmlString.search("div id="inputDecode");
	  console.log('position: ' + position)
	  var pos = htmlString.substring(
									position, position + 2000
								);
    }

  </script>
</head>

<body>
<p id="demo"></p>
<input type="button" value="GetTransactionData" id="myCheck" onmouseover="Do()">
</body>
</html>
```
Youtrube-dl的替代方案 - yt-dlp
Published: 2022-06-11 09:50:23

- 訂閱patreon即可看到更多文章 https://www.patreon.com/wade3c
- Youtube頻道 https://www.youtube.com/c/增廣建文

---

> 僅作為示範用，請不要用不法營利上

在一開始yt-dl被下架時出現的fork方案，現在部分功能比yt-dl還完善

## Install

### Windows

compile好的執行檔可以直接去Github release載

#### PhantomJS

> [Download PhantomJS](https://phantomjs.org/download.html)

為了讓yt-dlp能用到PhantomJS，有兩種設定可以選

- 在system path內做設定 (把phantomjs的bin資料夾加到path內)
- 把PhantomJS的執行檔移到和yt-dlp的執行檔同一層

### Linux

Linux比較建議裝python版的

#### Python

```other
python3 -m pip install -U yt-dlp
```

----

## Usage

### Windows

```other
.\yt-dlp.exe [OPTIONS] URL
```

### Linux

```other
yt-dlp [OPTIONS] URL
```

----

### Options

上面提的Options有以下比較常用到的

### Login

有些網頁要登入太麻煩可以直接用瀏覽器現成的cookie

- > **Cookies from browser**: Cookies can be automatically extracted from all major web browsers using `--cookies-from-browser BROWSER[+KEYRING][:PROFILE]`

## Know Issue

### iq.com

如果影片是被限定前幾周只有會員能看的話，會完全解析不了該網頁

但只要超過了VIP限制的時間範圍該影片就會正常

> 目前Github上有開相關issue，貌似是iq.com自身的問題

----

## Reference

[GitHub - yt-dlp/yt-dlp: A youtube-dl fork with additional features and fixes](https://github.com/yt-dlp/yt-dlp)

[[yt-dlp] how I use cookies from browser](https://www.reddit.com/r/youtubedl/comments/ou1mtk/ytdlp_how_i_use_cookies_from_browser/)
Using Airtable as a Headless CMS with Bridgetown
Published: 2022-06-09 12:11:47

[Bridgetown](url) is a wonderful static site generator. It uses markdown files by default, but I recently found out that it can also [use an external API](https://www.bridgetownrb.com/docs/plugins/external-apis) to generate resources. 

Here's how to integrate it with Airtable: 

## Setting up 

First, get your keys ready: 
* [Airtable API Key](https://support.airtable.com/hc/en-us/articles/360056249614-Creating-a-read-only-API-key)
* [Base ID](https://support.airtable.com/hc/en-us/articles/4405741487383-Understanding-Airtable-IDs#h_01FCC2DH96SWG2TQXF4YCXRYB7)
* [Table name](https://support.airtable.com/hc/en-us/articles/360021333094#table) 

Create a `.env` file in your Bridgetown project root with these keys:

```
AIRTABLE_API_KEY = "yourAPIkey"
AIRTABLE_BASE_ID = "yourBaseID"
AIRTABLE_TABLE_NAME = "yourTableName"
```
Don't forget to set these environment variables in your production environment as well.

Finally, add these to your Gemfile and run `bundle install`.

```
gem "airrecord"
gem "dotenv"
```


## Build script

Create a ruby file in your `plugins/builders` folder and customise it to map your Airtable fields to your frontmatter

```
# plugins/builders/airtable.rb
require 'dotenv/load'
require 'airrecord'

class Builders::Airtable < SiteBuilder
  def build

    # setup keys
    api_key = ENV['AIRTABLE_API_KEY']
    base_id = ENV['AIRTABLE_BASE_ID']
    table_name = ENV['AIRTABLE_TABLE_NAME']

    # query records using airrecord
    records = Airrecord.table(api_key, base_id, table_name).all

    # map airtable fields to frontmatter
    records.each do |record|
      add_resource :posts, "#{Bridgetown::Utils.slugify(record['Title'])}.md" do
        layout :post
        title record['Title']
        description record['Description']
        tags record['Tags']
      end
    end
  end
end
```

That's it. Your resources will now be generated from Airtable. 

## Bonus: Deploy to Netlify from Airtable

How do you trigger a new build when the records on Airtable change? Netlify build hooks and Airtable Apps to the rescue.

1. [Create a build hook](https://docs.netlify.com/configure-builds/build-hooks/) on Netlify
2. [Add a custom app](https://support.airtable.com/hc/en-us/articles/360042807073-Adding-an-app-to-a-base) on your Airtable base
3. Write a simple script in your app to make a post request:

```
let netlifyURL = 'https://api.netlify.com/build_hooks/yourBuildHookID'
let response = await fetch(netlifyURL, {method: 'POST'});
```

This will add a `Run` button right inside Airtable that triggers a build every time you run it. Have fun!
K Closest Points to Origin
Tags: leetcode, dsa, theabbie
Published: 2022-06-11 09:30:41

Given an array of `points` where `points[i] = [xi, yi]` represents a point on the **X-Y** plane and an integer `k`, return the `k` closest points to the origin `(0, 0)`.

The distance between two points on the **X-Y** plane is the Euclidean distance (i.e., `√(x1 - x2)2 + (y1 - y2)2`).

You may return the answer in **any order**. The answer is **guaranteed** to be **unique** (except for the order that it is in).

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/03/03/closestplane1.jpg)

**Input:** points = \[\[1,3\],\[-2,2\]\], k = 1
**Output:** \[\[-2,2\]\]
**Explanation:**
The distance between (1, 3) and the origin is sqrt(10).
The distance between (-2, 2) and the origin is sqrt(8).
Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.
We only want the closest k = 1 points from the origin, so the answer is just \[\[-2,2\]\].

**Example 2:**

**Input:** points = \[\[3,3\],\[5,-1\],\[-2,4\]\], k = 2
**Output:** \[\[3,3\],\[-2,4\]\]
**Explanation:** The answer \[\[-2,4\],\[3,3\]\] would also be accepted.

**Constraints:**

*   `1 <= k <= points.length <= 104`
*   `-104 < xi, yi < 104`

**SOLUTION:**

    import heapq
    
    class Solution:
        def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
            points = [(p[0] * p[0] + p[1] * p[1], p) for p in points]
            heapq.heapify(points)
            return [heapq.heappop(points)[1] for i in range(k)]
Describe the difference between <script>, <script async> and <script defer>
Tags: javascript, html, webdev
Published: 2022-06-11 09:24:16

The difference is related to how and when JavaScript scripts are downloaded and executed while parsing an HTML document.

At the time of parsing an HTML document, when the parser finds a `<script>` tag, it sends a new request to the `src` url and downloads the file. By default, it then executes the script in the file right away. The HTML parser has to stop until both download and execution of the script is completed.

Using **async**, as in `<script async>`, downloads the file asynchronously in the background, i.e. in parallel with HTML parsing. But execution of the script continues as soon as the script is downloaded and made available to the browser engine. Execution of the script blocks HTML parsing with **async** as well.

`<script defer>`, however, downloads the script **asynchronously**, **and** its execution is **deferred** until the entire HTML document is parsed. 

Using **defer** is therefore **parser non-blocking**, while `<script>` only and `<script async>` are **parser-blocking**.

---
References
1. [`<script>`: The Script element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
2. [How the browser renders a web page? — DOM, CSSOM, and Rendering](
https://medium.com/jspoint/how-the-browser-renders-a-web-page-dom-cssom-and-rendering-df10531c9969)
MediaFire: Unlimited File Storage online [TRICK] - Free Unlimited Cloud Storage (100%)
Tags: webdev, tutorial, discuss, devops
Published: 2022-06-11 09:07:54


{% youtube https://youtu.be/gG1-dCcJTQ0 %}

WhollyAPI ( Generate direct download link ) :- https://wholly-api.skinnyrunner.com/websites/mediafire.com/

Alternate website :- https://wholly-api.skinnyrunner.com/websites/mediafire.com/index.php

{% post https://dev.to/sh20raj/mediafire-get-direct-download-link-non-expiring-of-files-1nh4 %}
Min Stack
Tags: leetcode, dsa, theabbie
Published: 2022-06-11 09:00:46

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Implement the `MinStack` class:

*   `MinStack()` initializes the stack object.
*   `void push(int val)` pushes the element `val` onto the stack.
*   `void pop()` removes the element on the top of the stack.
*   `int top()` gets the top element of the stack.
*   `int getMin()` retrieves the minimum element in the stack.

**Example 1:**

**Input**
\["MinStack","push","push","push","getMin","pop","top","getMin"\]
\[\[\],\[-2\],\[0\],\[-3\],\[\],\[\],\[\],\[\]\]

**Output**
\[null,null,null,null,-3,null,0,-2\]

**Explanation**
MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin(); // return -3
minStack.pop();
minStack.top();    // return 0
minStack.getMin(); // return -2

**Constraints:**

*   `-231 <= val <= 231 - 1`
*   Methods `pop`, `top` and `getMin` operations will always be called on **non-empty** stacks.
*   At most `3 * 104` calls will be made to `push`, `pop`, `top`, and `getMin`.

**SOLUTION:**

    import heapq
    
    # class MinStack:
    
    #     def __init__(self):
    #         self.stack = []
    #         self.heap = []
    #         self.deleted = {}
    
    #     def push(self, val: int) -> None:
    #         heapq.heappush(self.heap, val)
    #         self.stack.append(val)
    
    #     def pop(self) -> None:
    #         popped = self.stack.pop()
    #         self.deleted[popped] = self.deleted.get(popped, 0) + 1
            
    #     def top(self) -> int:
    #         return self.stack[-1]
    
    #     def getMin(self) -> int:
    #         curr = self.heap[0]
    #         while curr in self.deleted:
    #             heapq.heappop(self.heap)
    #             self.deleted[curr] -= 1
    #             if self.deleted[curr] == 0:
    #                 del self.deleted[curr]
    #             curr = self.heap[0]
    #         return curr
    
    class MinStack:
    
        def __init__(self):
            self.stack = []
    
        def push(self, val: int) -> None:
            self.stack.append((val, min(self.stack[-1][1], val) if len(self.stack) > 0 else val))
    
        def pop(self) -> None:
            return self.stack.pop()[0]
            
        def top(self) -> int:
            return self.stack[-1][0]
    
        def getMin(self) -> int:
            return self.stack[-1][1]
    
    
    # Your MinStack object will be instantiated and called as such:
    # obj = MinStack()
    # obj.push(val)
    # obj.pop()
    # param_3 = obj.top()
    # param_4 = obj.getMin()
What is parser-blocking?
Tags: javascript, html, webdev
Published: 2022-06-11 08:55:57

This term is related to **parsing** of a **string of HTML code** by a browser.

Parser-blocking generally refers to **scripts** that are **downloaded** and **executed** when the HTML parser comes across a `<script>` tag. When the parser comes across a `<script>` tag, it goes ahead and downloads the script. And as soon as it is available in the browser, the default behavior is that the browser goes on to execute the script right after download.

Both **download** and **execution** of the script **halts** the HTML parser. So the parser has to wait till both processes are complete before it can continue to parse the next character in the string. This is called **parse-blocking**.

---
References

1. [Parse](https://developer.mozilla.org/en-US/docs/Glossary/Parse)
2. [How the browser renders a web page? — DOM, CSSOM, and Rendering](https://medium.com/jspoint/how-the-browser-renders-a-web-page-dom-cssom-and-rendering-df10531c9969)
Outline text in GIMP
Tags: gimp, tutorial
Published: 2022-06-11 08:55:06

(GIMP 2.10 is used)

##Problem

We want to add text with outline to image.

Here is what we expect. (This is Matsumoto castle from Japan. I took this photo in 2017.)

![Image with outline text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywwh1ohbbggi5axj29z6.png)

##Solution

We can use GIMP (it's free) to do it.

1\. Open you image (`File` => `Open...`)

2\. Use the `Text tool` by clicking icon with a character "A"

Select font style you want (e.g. font type and size). I prefer "Impact Condensed" font.

Use white color as text color.

![Text tool setting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0l576j8fb4kbdy255pq6.png)

3\. Add the text to the image

![Text added to image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nzi7n90q7ormoa6e2kb.png)

4\. Right click the text layer and choose `Alpha to Selection`

![Alpha to Selection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5an7lflw05x98s6wbaa.png)

Only the text is now selected.

![Text selected](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hby4fj8tlnh7nplzfhcg.png)

5\. Grow the selection. (`Select` => `Grow...`)

![Grow selection menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75p3u6ve86fwhqaw5gma.png)

Put the size you want to grow the selection and click `OK`.

![Grow setting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g5dz4cpgxktmefizkffw.png)

Selection is grown.

![Grown selection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8cywq4cmc70i5aueehi.png)

6\. Add a new layer (`Layer` => `New Layer...`)

![New layer menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ke11bv822ljzgu4zn3b2.png)

Make sure `Fill with` is set to `Transparency` and click `OK`.

![New layer setting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbjelzbf1egxo1tervn6.png)

A new layer is created.

![New layer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ml2l0ctmi7nv1rgf5az.png)

7\. Use the `Bucket Fill tool` by clicking the bucket icon.

Select black for foreground color.

Select `FG color fill` for `Fill Type`.

![Bucket fill tool setting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4osubx8huuc5pjfyewiy.png)

8\. Click on the text to fill it with black color.

![Fill text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uocjkesziu37rma5yy4o.png)

9\. Drag the new layer under the text layer

![Layer dragged](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/39hedns33mw3aw03g10x.png)

That's it.

![Image with outline text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywwh1ohbbggi5axj29z6.png)
🥁 I built a complete decentralized MultiSig Wallet with Solidity and ReactJS.
Tags: javascript, blockchain, web3, react
Published: 2022-06-11 08:47:49


Source: https://github.com/shafayeatsumit/rugged-multisig
🎥 https://www.loom.com/share/b6cc09f2824e4cafabee3216bba38653
Merry Christmas Tree!
Tags: codepen
Published: 2022-06-11 08:41:21

<p>That's all for this year - thanks for all the love and support over 2017.</p>

<p>CodePen is still my favourite place in the world mainly because the community here is so friendly and encouraging.</p>

<p>Here's to a happy and prosperous 2018! ❤🎉</p>

{% codepen https://codepen.io/chrisgannon/pen/KZMYmp %}
1-bit and 2-bit Characters
Tags: leetcode, dsa, theabbie
Published: 2022-06-11 08:30:37

We have two special characters:

*   The first character can be represented by one bit `0`.
*   The second character can be represented by two bits (`10` or `11`).

Given a binary array `bits` that ends with `0`, return `true` if the last character must be a one-bit character.

**Example 1:**

**Input:** bits = \[1,0,0\]
**Output:** true
**Explanation:** The only way to decode it is two-bit character and one-bit character.
So the last character is one-bit character.

**Example 2:**

**Input:** bits = \[1,1,1,0\]
**Output:** false
**Explanation:** The only way to decode it is two-bit character and two-bit character.
So the last character is not one-bit character.

**Constraints:**

*   `1 <= bits.length <= 1000`
*   `bits[i]` is either `0` or `1`.

**SOLUTION:**

    class Solution:
        def isValid(self, bits, i):
            if i == 0:
                if bits[0] == 0:
                    return True
                else:
                    return False
            if i == 1:
                if bits[0] == 1:
                    return True
                elif bits[1] == 0:
                    return True
                else:
                    return False
            if bits[i - 1] == 1 and self.isValid(bits, i - 2):
                return True
            if bits[i] == 0 and self.isValid(bits, i - 1):
                return True
            return False
        
        def isOneBitCharacter(self, bits: List[int]) -> bool:
            if len(bits) >= 2:
                return self.isValid(bits, len(bits) - 2)
            else:
                return True