teleren/devto huggingface dataset:
Swift - subscripts
Tags: swift, beginners, programming, tutorial
Published: 2022-01-05 10:48:15

Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the member elements of a collection, list, or sequence.
For example, you access elements in an Array instance as someArray[index] and elements in a Dictionary instance as someDictionary[key].

## Subscript Syntax
Subscripts enable you to query instances of a type by writing one or more values in square brackets after the instance name. 
```swift
subscript(index: Int) -> Int {
    get {
        // Return an appropriate subscript value here.
    }
    set(newValue) {
        // Perform a suitable setting action here.
    }
}
```

As with read-only computed properties, you can simplify the declaration of a read-only subscript by removing the get keyword and its braces:

```swift
subscript(index: Int) -> Int {
    // Return an appropriate subscript value here.
}
```

## Subscript Examples
```swift
struct TimesTable {
    let multiplier: Int
    subscript(index: Int) -> Int {
        return multiplier * index
    }
}
let threeTimesTable = TimesTable(multiplier: 3)
print("six times three is \(threeTimesTable[6])")
// Prints "six times three is 18"
```
## Subscript Usage
The exact meaning of “subscript” depends on the context in which it’s used. Subscripts are typically used as a shortcut for accessing the member elements in a collection, list, or sequence. 

### Examples
```swift
//dictionary 
var numberOfLegs = ["spider": 8, "ant": 6, "cat": 4]
numberOfLegs["bird"] = 2
```

## Subscript Options
- Subscripts can take any number of input parameters, and these input parameters can be of any type. Subscripts can also return a value of any type.

- Like functions, subscripts can take a varying number of parameters and provide default values for their parameters, as discussed in Variadic Parameters and Default Parameter Values. However, unlike functions, subscripts can’t use in-out parameters.

- A class or structure can provide as many subscript implementations as it needs, and the appropriate subscript to be used will be inferred based on the types of the value or values that are contained within the subscript brackets at the point that the subscript is used. **This definition of multiple subscripts is known as subscript overloading.**
It's Not You, It's The Stupid Machine()
Tags: beginners, webdev, learnhowtocode, javascript
Published: 2022-01-05 10:30:03

Hello everyone, this is my first post on this amazing DEV community platform, and I want to go through what i have learned from learning how to code and dig a bit deeper into what mindset you want to have when you start learning.
_PS: English is not my native language, I'll do my best to make everything as clear as possible :)_

Learning how to code is very interesting, especially when you start looking at algorithms, it feels very heavy on your brain, I've spent hours on the toilet seat trying to figure out why my fancy function() is not doing its job, and when i found the issue it was the biggest DUH! I've ever experienced in my life but only then your learning curve starts to move a little bit exponentially, and **IT CLICKED**, I came to realize that I need to think like a five years old, you know..., trying to explain to your machine every small detail about what you want it to do.

I was lucky enough to figure that out earlier in my learning phase, which helped me a lot to accelerate through it, i was able to finish the first two courses of the FCC curriculum (Responsive Web Design and JS algos && Data structure) in five weeks, spending 3 to 4 hours a day, shout-out to [FreeCodeCamp](freecodecamp.org) for their awesome and well written courses.

So, to conclude, when you start learning how to code, please keep in mind that the hundreds of mistakes you are making is normal and expected, treat your machine as a five years old, and keep moving forward, Happy coding ;)
Project Management Plan Template
Tags: management
Published: 2022-01-05 10:26:10

Looking for the perfect project management plan for your new business? You are at the right place! We provide business plan software. We have created this [Project Management Plan](https://upmetrics.co/template/project-management-plan-template) template to help you get started with your project planning. We have 200+ Free Business Templates available that you can download for free.
Swift - Methods
Tags: swift
Published: 2022-01-05 10:24:09

## Methods
methods are functions that are associated with particular types.

## Instance methods
Instance methods are functions that belongs to the instance of particular class, structure, enumeration.

```swift
class Counter {
    var count = 0
    func increment() {
        count += 1
    }
}
//increment method is an instance method
```

## The 'self' property
Every property of a type has an implicit property called self, which is exactly equivalent to the instance itself.

```swift
func increment() {
    self.count += 1
}
```

## Modifying Value Types from Within Instance Methods
Structures and enumerations are value types. By default, the properties of a value type can’t be modified from within its instance methods.
However, if you need to modify the properties of your structure or enumeration within a particular method, you can opt in to mutating behavior for that method.

```swift
struct Point {
    var x = 0.0, y = 0.0
    mutating func moveBy(x deltaX: Double, y deltaY: Double) {
        x += deltaX
        y += deltaY
    }
}
var somePoint = Point(x: 1.0, y: 1.0)
somePoint.moveBy(x: 2.0, y: 3.0)
```
## Type Methods
Instance methods, as described above, are methods that you call on an instance of a particular type. You can also define methods that are called on the type itself. These kinds of methods are called type methods. You indicate type methods by writing the static keyword before the method’s func keyword. Classes can use the class keyword instead.

```swift
class SomeClass {
    class func someTypeMethod() {
        // type method implementation goes here
    }
}
SomeClass.someTypeMethod()
```
HTML→ The riddles of the sphinx
Tags: html, beginners, webdev, programming
Published: 2022-01-05 10:22:47

Hello friends! Today we are going to talk about forms, yes! because data is also collected through the web, but this is not the only way, and we will see it in another post... 

A web form basically works and looks similar to a form like the one made by telephone companies, or any other, which spend hours and hours calling to offer you their services. 😒😓 <br> 

The web form is composed of one or more control elements (sometimes called widgets), plus some additional elements that help to structure the overall form; they can be single or multi-line text fields, drop-down boxes, buttons, checkboxes or radio buttons, and they are mainly created with the <input> element.

How do we create a form? Pay attention, don't get lost! 

-  We create the form with the <form> tag.

```html
<form>
......
</form>
``` 
- We add the "control" elements.

```html 
<label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname"><br>
``` 
-  A button to *"validate"* (submit)

```html 
<input type="submit" value="Submit">
``` 
-  and that's it! The form is ready.

```html
<form>
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname"><br>
  <input type="submit" value="Submit">
</form> 
``` 


![formulariomanu.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1641303382354/IAdW6RE7k.jpeg)


A validation button is nothing more than a form element that allows data to be sent to the server for processing. 

There are many more elements, and attributes to create more complete and complex forms but I'll reserve that for the PDF I'm making for you plus a cheatsheet! 

Thanks for reading the post, that's all for today! and remember to always be the best version of you! 🤩
Marathi Blog in India List
Published: 2022-01-05 09:56:53

<a href="https://sc.devb.gov.hk/TuniS/marathi.gnlu.org.in">Marathi Blog</a>
<a href="https://www.fhwa.dot.gov/reauthorization/reauexit.cfm?link=marathi.gnlu.org.in">Marathi Blog</a>
<a href="mail.resen.gov.mk/redir.hsp?url=http://marathi.gnlu.org.in">Marathi Blog</a>
<a href="old.nepalimmigration.gov.np/site/languages/languageA/3?url=http://marathi.gnlu.org.in">Marathi Blog</a>
<a href="qizegypt.gov.eg/home/language/en?url=http://marathi.gnlu.org.in">Marathi Blog</a>
<a href="https://bankrut.gov.ua/request-password-reset?referer=http://marathi.gnlu.org.in">Marathi Blog</a>
<a href="https://topmagov.com/redirect?url=https%3A%2F%2Fmarathi.gnlu.org.in">Marathi Blog</a>
<a href="www.scba.gov.ar/informacion/redir.asp?donde=%2F%2Fmarathi.gnlu.org.in">Marathi Blog</a>
<a href="moe.gov.np/site/language/swaplang/1/?redirect=http%3A%2F%2Fmarathi.gnlu.org.in">Marathi Blog</a>
<a href="rosreestr.gov.ru/bitrix/redirect.php?event1&event2&event3&goto=https%3A%2F%2Fmarathi.gnlu.org.in">Marathi Blog</a>
<a href="citidex.sfgov.org/cgi-bin/sunindex/getData.cgi?contact=TedYamasaki&dispRec=yes&docColor=deptsonly&phone=%28415%29557-4815&url=marathi.gnlu.org.in">Marathi Blog</a>
<a href="www.pta.gov.np/index.php/site/language/swaplang/1/?redirect=https%3A%2F%2Fmarathi.gnlu.org.in">Marathi Blog</a>
<a href="www.tkdk.gov.tr/Home/Dil?Dil=en&ReturnUrl=http%3A%2F%2Fmarathi.gnlu.org.in">Marathi Blog</a>
<a href="old.gov.kg/?redirect=http%3A%2F%2Fmarathi.gnlu.org.in&wptouch_switch=desktop">Marathi Blog</a>
<a href="www.mnop.mod.gov.rs/jezik.php?url=https%3A%2F%2Fmarathi.gnlu.org.in">Marathi Blog</a>
JavaScript Simple Counter
Published: 2022-01-05 09:52:36

Hi everyone! We make counter today.
Firstly create 3 files **index.html, script.js, style.css**.
Firstly open html file and and connect with css and js file.

```html
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Counter</title>
    <link rel="stylesheet" href="./style.css">
  </head>
  <body>
    <div class="header">
        <h1>Js mini projects: <span class="mainHeader">Counter</span></h1>
    </div>
    <div class="main">
      <button onclick="decrease()" type="button" name="button" id="minusBtn">-</button>
        <h1 id="countNumber">0</h1>
      <button onclick="increase()" type="button" name="button" id="plusBtn">+</button>
    </div>
    <script src="./script.js" charset="utf-8"></script>
  </body>
</html>
```
Secondle, we should give some styling.

```css
.header {
  background-color: lightgray;
  width: 30%;
  text-align: center;
  height: auto;
  padding: 3px;
}

.mainHeader {
  color: darkblue;
}

.main {
  background-color: lightgray;
  width: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 500px;
  margin: auto;
  margin-top: 50px;
}

button {
  margin: 10px;
  padding: 10px;
  background: darkgray;
  font-weight: bold;
  width: 50px;
}

```
Thirdly, we go to the **js file**. 
First of all, we declare a variable equal to 0.

```js
let countingNumber = 0
```
Then, create two function named **increase** and **decrease**.

```js
const decrease = () => {}
const increase = () => {}
```
Then in function we get value of countNumber with **id**
```js
const decrease = () => {
  document.getElementById("countNumber").innerHTML;
};
const increase = () => {
  document.getElementById("countNumber").innerHTML;
};
```
for counting we write **prefix increment** and **prefix decrement** operator.
```js
const decrease = () => {
  document.getElementById("countNumber").innerHTML = --countingNumber;
};
const increase = () => {
  document.getElementById("countNumber").innerHTML = ++countingNumber;
};
```
Full of width of **js file**.
```js
let countNumber = 0;

const decrease = () => {
  document.getElementById("countNumber").innerHTML = --countNumber;
};

const increase = () => {
  document.getElementById("countNumber").innerHTML = ++countNumber;
};
```
How do I get my money back from cash App?
Published: 2022-01-05 09:51:38

If you have made a wrong payment from your Cash App account and are looking for [**How do I get my money back from cash App?**](https://www.cash-apphelps.com/blog/how-do-i-get-my-money-back-from-cash-app/) You have to apply for a Cash App refund. If everything looks fine and clear, you will be able to receive your funds directly in your Cash App account wallet in a couple of working days.
Will Cash App refund money if scammed?
Published: 2022-01-05 09:34:40

 The query like [**Will Cash App refund money if scammed?**](https://www.helpscashapp.net/blog/how-do-i-get-a-refund-if-i-was-scammed-on-cash-app/) Cash App among the cash app users is taking an important turn. Cash app users must be attentive to all kinds of steps that they have to carry. The most important process is to open the cash app and step ahead to request a refund on the cash app.
CSS 2021 top tip: Aspect Ratio
Tags: css
Published: 2022-01-05 09:29:07

---
title: "CSS 2021 top tip: Aspect Ratio"
published: true
description: 
tags: css
//cover_image: https://direct_url_to_image.jpg
---

[Aspect Ratio](https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio) completely solves a variety of historical problems in a neat and elegant way. Have you ever wanted an image to take as much horizontal space as it can while having a fixed height? Or battled with consistent sizing with a marketing department?

[Aspect ratio](https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio) is the answer. This surprisingly elegant attribute allows you to define a ratio of width to height which then interacts with the definitions of height and width you give the element.

So if you want full width on an image you can apply `width: 100%` but then leave the height on `auto` and let it be calculated based on the actual width to occupy the appropriate height.

You can also use it as scaling element in responsive designs as you can centre an element, set a max height and then let the layout engine calculate both dimensions to fit the ideal ratio you're looking for.

As the ratio is expressed in "natural" terms it can also be discussed directly with non-technical design people and can be used to embed style guide rules directly into your layout, making collaboration much easier.

Here's a set of [illustrative demos](https://tomhodgins.github.io/aspect-ratio-spec/demo.html) and one [demonstrating responsive qualities of positioning](https://codepen.io/MoritzGiessmann/pen/ExgBevp).
How to handle POST Requests in Express
Tags: tutorial, javascript, node, webdev
Published: 2022-01-05 09:27:03

## Introduction

In this blog article, we shall learn how to handle POST requests in Express.

POST HTTP request uses the POST method and is mostly used when sending some data along with the request to the HTTP server.

In Express you’ll need to enable a middleware to parse the body of `Content-type: application/json`. This enables parsing incoming JSON content in the body of the incoming request.

Values sent in the POST request are populated inside the `req.body` object.

## A Simple Express application
Let's setup a simple Express application
```typescript
const express = require('express')
const app = express()

// enable middleware to parse body of Content-type: application/json
app.use(express.json())

app.post('/', (req, res) => {
  // get request values inside req.body
  const price = req.body.price
  const orderId = req.body.orderId
  // use price, orderId to do something meaningful
})
```
Requests are client constructed values and should be sanitized and validated before use once they get to the Express application.

## Summary
To handle POST requests in Express  we need to enable parsing of json by enabling the json middleware.

***

Found this article helpful? You may follow my handle on twitter [@nkmurgor](https://twitter.com/nkmurgor) where I tweet about interesting topics on web development.
Riddle 2: Even Fibonacci Numbers
Tags: picolisp, lisp, euler, functional
Published: 2022-01-05 09:04:00

To finish our glorious [Fibonacci/Binary Tree Series](https://picolisp-blog.hashnode.dev/picolisp-explored-the-idx-function), let's solve the second task of the Euler Project. 

----------------------------------

### Task description

> Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

> 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

> By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.


------------------

This one is pretty straightforward, if not to say a little bit boring. "Values below four million" means that we will need 32 iterations, so any of our [Fibonacci solutions](https://picolisp-blog.hashnode.dev/the-fibonacci-sequence) will work.

Let's pick our favorite solution from the Fibonacci coding examples (for example the iterative one):

```
(de fib (N)
   (let (A 0  B 1)
      (do N
         (swap 'B (+ (swap 'A B) B)) ) ) )
```
We need two modifications: Instead of a fixed number of iterations, we want the loop to stop if the **next** fibonacci number exceeds 4 Million. So let's replace the ``N`` argument by the ``Max`` and the ``do`` by ``while``:

```
(de sumEvenFib (Max)
    ...
    (while (< (+ A B) Max)
```
Secondly, we want to add up only even numbers and return this ``Sum`` in the end. A number is even if it's dividable by 2, i. e. the modulo is zero: ``(=0 (% B 2))``. 
```
(let Sum 0
     ...
    (when (=0 (% B 2)) 
        (inc 'Sum B) 
```

Minor optimization: Since all numbers are represented internally in **binary**, you could also check if the lowest **bit** of the binary representation of ``B`` is 1 by using the ``bit?`` function:

``` 
(unless (bit? 1 B)
```

And then we have it. This is the final function:

```
(de sumEvenFib (Max)
   (let (A 0  B 1 Sum 0)
         (while (< (+ A B) Max)
            (swap 'B (+ (swap 'A B) B))
            (when (=0 (% B 2)) 
               (inc 'Sum B) ) ) ) )
```

After running ``(prinl (fibo 4000000))``, we get the result.

The final script can be downloaded [here](https://gitlab.com/picolisp-blog/single-plage-scripts/-/blob/main/euler/Task_2-Even-Fibonacci-Numbers.l). You can run it with ``pil <filename>`` from the command line.


-----------------------

There is some room for some further optimization, by using the fact that only every third number is even, or by making some clever substitutions in the numeric version. Check out this solution for some inspiration: https://www.xarg.org/puzzle/project-euler/problem-2/

However, since we only need 32 iterations anyway, it is not really worth the trouble.

------------------

With this post, we'll be pausing the algorithmic/mathematical examples for a while. The next month will be dedicated to a new topic: Web Application Programming!

------------------

# Sources

- https://www.xarg.org/puzzle/project-euler/problem-2/   
- https://projecteuler.net/index.php?section=problems&id=2
How to create a cross platform desktop app using Electron.js?

Tags: electron, javascript, crossplatform, desktopapp
Published: 2022-01-05 09:00:33

Hi!
Let's create a cross-platform desktop app using Electron.js. Check our step-by-step article and make with us your first Electron app. 

Enjoy the article at [Frontend House](https://frontendhouse.com/blog/how-to-create-a-cross-platform-desktop-app-using-electron-js)
First Impressions of MongoDB
Tags: mongodb
Published: 2021-12-23 12:17:52

I've been spending a lot of time lately studying DDD and thinking about how to modernize one of the larger business applications I work on. One of the textbooks I've been reading shows the implementation of aggregate persistence using JSON documents in RavenDB. However, the author notes that he probably should have used MongoDB.

Given the recent hackathon news and a little bit of tinkering with RavenDB, I decided to look into MongoDB and Azure Cosmos DB. I was extremely surprised to find that MongoDB provides complete online courses and certifications for free! The training material is excellent and hands-on, and gave me a great dive into the introductory material.

First impression, then, is very good. RavenDB was already quite nice as a development database, but the offering from MongoDB is first-class. The free-tier cluster comes with sample data and plenty of horsepower for development. All of the MongoDB products (Charts, Realms, Compass) are available at the free tier, so there's no barriers to start learning.

It's worth mentioning that Azure Cosmos DB supports the MongoDB wire protocol, and can be used to migrate to Cosmos if it makes sense. At the moment, I can see no compelling reason to do so. MongoDB is supported in all North American AWS and Azure regions, so it's easy to locate it next to your application. The tools provided by MongoDB are second to none.

I have a lot to learn before actually implementing any of this. But I feel like it should be reasonably well-received by developers, especially if I can demonstrate the power of the MongoDB tools to them. I think Charts should be a hit with senior management and executives. And I think I've found a way to simplify aggregate persistence without sacrificing database performance.
Widgetbook - The Storybook for Flutter
Tags: flutter, dart, productivity, agile
Published: 2022-01-05 08:52:25

This article explains the open source Flutter package widgetbook. It is the Storybook for Flutter, which helps developers cataloguing their widgets, testing them quickly on different devices and themes, and sharing them easily with designers and clients.

**What is a Storybook?**
Every flutter developer coming from a web development background has probably heard and most likely even used Storybook.js before. It’s one of the most loved React packages, which speeds up UI development by allowing developers to build components in isolation. Developers can create stories, which represent specific use cases of a component. These stories can be catalogued. The resulting Storybook can be accessed by non-developers like designers or clients as well, which simplifies the review process. Since Flutter is based on widgets, we named our package Widgetbook.
How does Widgetbook compare to other Flutter Storybooks?
Even though there are already some Flutter packages available trying to provide the values of Storybook.js, they lack certain usability and maintainability features. The code to set up and maintain the Storybooks of all existing packages has to be written manually, which is time consuming and cumbersome. The only exception is Framy but this package has not been maintained since October 2020 and is thus not null safe. Furthermore, the UI of all Storybooks is difficult to use. Therefore, we created Widgetbook. In its latest release, it comes with annotations which simplify setting up and maintaining it via code generation. Widgetbook is the only maintained Storybook package for Flutter with annotations. Since our team of three successfully raised funding, we are able to dedicate all of our time and resources in improving and maintaining our open source package Widgetbook.

**Use cases for Widgetbook**
Build widgets in isolation and test them visually
Widgetbook provides an environment to build UIs in isolation. It allows you to develop widgets without distractions from the surrounding screen and dependencies. In the UI of Widgetbook, you can quickly preview and test your widgets visually on different devices and themes. It allows you to spot UI flaws while developing that would be tedious to test on an emulator:


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

**Keeping an overview of all your widgets**
When your app grows and more and more developers are working on it, it becomes difficult to still keep track of all the widgets in your app. At this point, even the best naming conventions can not prevent developers questioning, if some widgets have already been developed or not. Often these confusing structures lead to chaos and developers building identical widgets multiple times.

Learn more on widgetbook.io