teleren/devto huggingface dataset:
How to unindex committed files
Tags: git
Published: 2022-12-26 18:29:07

---
title: How to unindex committed files
published: true
date: 2022-11-02 05:00:15 UTC
tags: git
canonical_url: https://mindsers.blog/post/how-to-unindex-committed-files/
---

Git is a powerful tool that can seem complicated if we know it badly. In this article, we will see the particular case of bad indexing.

***⚠️ Read more of my blog posts about tech and business [on my personal blog](https://mindsers.blog/)! ⚠️***

This is a case that can very easily occur when the tool is poorly mastered, but don't panic, there is nothing irreparable. You can make mistakes, correct yourself, start over and learn at your own pace with the trick in this article.

## Avoid indexing bad files

There are files we would rather not version with Git. For example, project dependencies (the `node_modules` directory for a Node.js project), files containing environment variables, or other autogenerated/temporary files.

The `.gitignore` file allows us to specify to Git the list of files that we do not want it to consider. Create it at the root of your project.

You can specify files, folders or globs there like this:

```
.env
/node_modules
npm-debug.log*
```

Once added to this list, the offending files will be invisible to Git. There will no longer be any way to add them accidentally.

## Delete file from index

But sometimes we realize that a file should not be indexed only after committing it. An unfortunate `git add .` or **not**  **using** `git status` regularly enough can easily lead to this situation.

If this happens, a simple command exists: `git rm`.

```
git rm -r --cached name_of_your_file
```

Then you just have to commit the deletion of the index:

```
git add name_of_your_file
git commit
```

Voilà. The unwanted folder or file should no longer bother you. On the other hand, remember to add it to your `.gitignore` file so as not to commit it mistakenly again. I refer you to the first part of the article to know how to do it.
Removendo registros duplicados de uma tabela no PostgreSQL
Tags: backend, sql, postgres, database
Published: 2022-11-02 04:51:28

## Contexto

Vamos lá.. você tem uma tabela no seu banco de dados chamada `eventos` com três campos: codigo, codigo_origem, tipo e timestamp. A solução foi para produção, tá rodando há uns dias e, quando você percebe existem várias entradas duplicadas no seu banco de dados pois o sistema que gera os eventos não possui garantia de exactly-once (vários não possuem) e você não tem controle sobre ele. E agora?

## Unique Keys!

Uma alternativa relativamente simples para resolver o problema é usar as já conhecidas unique keys. Neste caso iremos considerar que o campo codigo_origem deve ser único dentro da tabela, então a solução é relativamente simples

```sql
alter table if exists eventos add unique (codigo_origem);
```

Aí você conecta na base, roda o comando e:

```
could not create unique index \"evento_codigo_origem_key\"
  Detail: Key (codigo_origem)=(123) is duplicated
```

Percebeu o problema? Como é que você vai inserir uma constraint em uma tabela que viola essa constraint?

## Resposta: deletando os registros duplicados!

Existem várias formas de fazer e algumas delas incluem fazer join da tabela com ela mesma, mas se a sua tabela já tiver uma certa quantidade de registros, isso pode ser beeeem lento.

## Solução: funções de array ao resgate

Vou colocar a query aqui pra turma do TLDR, mas prometo que explico

```sql
select unnest((array_agg(e.id order by created_at asc))[2:]) as id 
from eventos e 
group by e.codigo_origem 
having count(1) > 1
```

O que essa query vai fazer é, basicamente, selecionar todos os ids duplicados pra você removê-los usando um delete simples e ela funciona dessa forma:

1. Agrupa os registros pelo campo codigo_origem
2. Seleciona os registros duplicados (having count (1) > 1)
3. Usa a função `array_agg` pra gerar um agregado dos ids dos registros
4. Usa o [2:]  pra selecionar todo mundo do índice 2 pra frente
5. Usa o unnest pra "explodir" o array em várias linhas

Como eu falei antes, o resultado final dessa consulta será uma lista dos códigos que você deve remover. Se você quiser, pode até fazer assim

```sql
delete from eventos where id in (
  select unnest((array_agg(e.id order by created_at asc)[2:]) as id 
  from eventos e 
  group by e.codigo_origem 
  having count(1) > 1
)
```
Last Index Value Of Array Javascript/TypeScript
Tags: javascript, typescript, beginners, programming
Published: 2022-11-02 04:46:49

Hey everyone, I usually give thought to how can I make my and other's life easy, so came up with the idea to write articles.
Getting to the point, I came across a life hack for arrays. Finding the last index value in an array was always like using the array's length and subtracting 1 from it(As the array gives length like normal daily like counting, whereas arrays start with 0 indexes). 

**Example**
```javascript
let array = [3,4,5,6,7];
let lastElement = array[array.length - 1];
console.log(lastElement); // prints 7
```

So whats the way around? Here it is 😁😁

```javascript
let array = [3,4,5,6,7];
let lastElement = array.at(-1);
console.log(lastElement); //prints 7
```

**Additionally**
Just keep going reverse, you can get all elements of the array. Don't forget a condition to avoid going out of indexes as it'll give you undefined. 

Feel free to comment to add more information to this article. Happy Coding.
433. Leetcode Solution in Python
Tags: python
Published: 2022-11-02 04:27:07

```python
class Solution(object):
    def canMutation(self, w, d, c, q):
        l = ["A",'C','G','T']
        for i in range(len(w)):
            for j in l:
                if w[i] != j:
                    v = w[:i] + j + w[i + 1:]
                    if v in d and (d[v] == 0 or d[v] > c + 1):
                        d[v] = c + 1
                        q.append(v)

    def minMutation(self, start, end, bank):
        """
        :type start: str
        :type end: str
        :type bank: List[str]
        :rtype: int
        """
        if end not in bank:
            return -1
        dic = {}
        count = 0
        for i in bank:
            dic[i] = count
        queue = [start]
        while len(queue) > 0:
            q2 = []
            for i in queue:
                self.canMutation(i, dic, count, q2)
            if dic[end] != 0:
                break
            queue = q2
            q2 = []
            count += 1
        # print dic
        if dic[end] == 0:
            return -1
        return dic[end]
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/minimum-genetic-mutation/
What is @try 🤯 before this function in Python?
Tags: webdev, programming, python, tutorial
Published: 2022-11-02 03:54:28

## History ⏳

I was looking into the **code base of a library** few years back ⌚, and I saw something strange 🤯. It goes like -

```python
@try
def fetch(url: str):
    resp = request.get(url)
    return resp.json()
```

So the definition of `fetch function` is clear enough, but what the hack is this `@try` 🤯 just before the function definition?

---

## That was a Decorator 🤔

Decorators are very powerful and useful tool in Python as it allows programmers to modify the behaviour of a function. Decorators allow us to wrap another function in order to extend the behaviour of the wrapped function.

---

<center>Scary Definition 😨, Let's understand with examples</center>

---

**Example 1:** Functions as an object 🤔

```python
def upper_text(text):
    return text.upper()
 
print(upper_text('Hello'))
 
func = upper_text

print(func('Hello'))
```

```text
HELLO
HELLO
```

---

**Example 2:** Function as an argument 🤔

```python
def upper_text(text):
    return text.upper()

def lower_text(text):
    return text.lower()

def func(func):
    # storing the function in a variable
    msg = func("Hello")

    print(msg)

func(upper_text)
func(lower_text)
```

```text
HELLO
hello
```

---

**Example 3:** Returning function 🤔

```python
def create_adder(x):
    def adder(y):
        return x + y

    return adder

add_15 = create_adder(15)

print(add_15(10))
```

```text
25
```

---

**Example 4:** Decorator 🚀

```python
# importing libraries
import time
import math
 
# decorator to calculate duration
# taken by any function.
def calculate_time(func):
     
    # added arguments inside the inner1,
    # if function takes any arguments,
    # can be added like this.
    def inner1(*args, **kwargs):
 
        # storing time before function execution
        begin = time.time()
         
        func(*args, **kwargs)
 
        # storing time after function execution
        end = time.time()
        print("Total time taken in : ", func.__name__, end - begin)
 
    return inner1

# this can be added to any function present,
# in this case to calculate a factorial
@calculate_time
def factorial(num):
 
    # sleep 2 seconds because it takes very less time
    # so that you can see the actual difference
    time.sleep(2)
    print(math.factorial(num))
 
# calling the function.
factorial(10)
```

```text
3628800
Total time taken in :  factorial 2.0061802864074707
```

---

## Back to History 😃

So, what was that?

```python
@try
def fetch(url: str):
    resp = request.get(url)
    return resp.json()
```

The definition of try was like this -

```python
def try(func):
    def exe(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:
            return {
                "message": "Error while processing the request",
                "details": str(e)
            }
    return exe
```

---

Hit Like ❤️ and share your thoughts in the comments 💬

---

Thank you

cheers
How to build a private repository
Published: 2022-11-02 03:36:59

1. Download Verdaccio with npm    [click here to view the]official website
```
npm install verdaccio -g
```
2. How to switch origin

- Install nrm

```
npm install nrm -g     
```

- Check exist origin

```
nrm ls
```

- Delete origin

```
nrm del [originname]
```
Basic linux troubleshooting commands
Published: 2022-11-02 03:16:35

1. curl 
e.g. curl www.google.com
2. cat - content of any files
e.g. cat -l [display line number also]
3. tail  [last tail line to display, check real time data]
e.g. tail -200f SystemOut.log
4. netstat
```
netstat -tunlp
```
5. ip r
6. telnet
```
telnet 172.31.46.55 22
```
7. grep
```
grep root /etc/passwd
grep -o root /etc/passwd
```
7. ps
```
ps -ef
```
8. env
9. top
10. ipconfig
11. lsof
12. df
```
df -h
df -Th
```
13. du
```
du -sh /
du -sh *
```
14. id
15. w
16. chmod
```
chmod 500 /tmp/abc
chown root /tmp/abc
```
17. dig
```
dig google.com
```
18. nslookup
```
npslookup google.com
host google.com
```
19. sestatus
```
sestatus
```
20. history
Minimum Moves to Convert String
Tags: javascript, leetcode
Published: 2022-11-02 02:54:33

```js

/**
 * @param {string} s
 * @return {number}
 */
var minimumMoves = function(s) {
   let move = 0;
    let i = 0;
    while(i<s.length){
        let char = s[i];
		// incrementing the index if we already have 'O'
        if(char== 'O'){
            i++;
        }
		// incrementing the move and index by 3 (Per move =  3 characters)
        if(char== 'X'){
            i=i+3;
            move++;
        }
    }
    return move;
};
```
Dev ops cycle
Tags: storybytes, devops, team, development
Published: 2022-11-02 02:42:26

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

Most of us might know DevOps is a combination of two words, namely Development and Operations. DevOps is a procedure that allows a single team to manage the entire application product life cycle, that is, development, testing, deployment, and operations. The various phases such as Continuous integration & continuous development, continuous infrastructure automation, continuous deployment, and continuous monitoring comprise a DevOps Life cycle. These stages are carried out on loop continuously till you achieve the desired product quality. Therefore we at Web and App Studio utilize this entire cycle into our workflow to assure a remarkable life cycle of any products we develop.
Top JavaScript 2022
Tags: storybytes, opensource, scalability, javascript
Published: 2022-11-02 02:39:47


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

JavaScript, often abbreviated as JS, is a high-level programming language. It is a lightweight, interpreted, and just-in-time compiled programming language that is well known for creating Web pages, and many non-browser environments also use it. It is widely spread among web pages, server applications, server-side, mobile applications, and even games. Any JS, Vue, Meteor, Angular, D3, React, Next, Node, and many more are among the best JavaScript frameworks carefully selected for their use cases diversity, scalability, and popularity on Github, backed by big names in the industry. We at Web and App Studio don't prefer a specific one. How about you? Which is the most popular javascript framework, in your opinion?
Session 與 Cookie
Published: 2022-11-02 02:39:33


## 【筆記】Session 與 Cookie

![Photo by [Chaman Raj ](https://unsplash.com/@chamanraj)form [unsplash](https://unsplash.com/)](https://cdn-images-1.medium.com/max/2000/0*A-5hXPGarbWJCPae)
>  為什麼我們會需要 Session 和Cookie ?

在這邊要先提到 HTTP 無狀態(stateless)的特性，這個特性會讓每個 HTTP 請求都是獨立的，也因為這個原因使得瀏覽器無法紀錄網路上的行為，所以當今天使用者重開頁面，想要登入同一個網站時，就必須要不斷重複的輸入帳號以及密碼，因此就需要透過 Cookie 和 Session 來記錄狀態。

### **保存使用者狀態方法**

**Cookie **：描述*『client 與 server 目前溝通狀態』 的資料*

client 與 server 間的溝通需透過 HTTP，但就如同我們上面提到的 HTTP是無狀態的，各個 request 都是獨立的個體，所以 Server 端無法記住 Client 目前的狀態。

Cookie是瀏覽器提供的一個儲存空間，提供了保存狀態資訊的功能，為了讓 server 端可以在 client 瀏覽器上記住、儲存 client 的狀態而生。
>  **Cookie 由瀏覽器處理，具有兩個特性：**

* 只在特定網域上起作用，簡單來就是在 A 網域存入的 cookie 是不會出現在 B 網域的。

* 有生命期限：到了生命期限後 cookie 將會失效，可自定義。
>  **Cookie 的資料屬性**

* domain 和 path: 設定關於 Cookie 的網域以及路徑。

* expires / max-age: 設定 Cookie 資料過期的時間， expires 必須是一個日期，max-age 則是秒數。

* size: cookie 資料的大小，單位是 bytes。

* HttpOnly: 設定 cookies 的資料只能透過 server 讀取，也就是說 js 程式碼無法讀取，設定 HttpOnly 可以避免 XSS 攻擊，例如駭客可以透過嵌入
>  **Cookie** 的缺點

 1. Cookie 上所有的數據在client 端是可以被修改的，使數據容易被偽造

 2. 字段太多會影響傳輸效率

 3. Cookies size 限制: 一個 Cookies 最大可以是 4096 bytes，而一個 domain 最多只能有 20 cookies。

所以在實際中，Cookies大多用來存放結構簡單、容量小且無意義的資訊，而像是帳號密碼這種比較敏感的資訊就不太適合放在Cookie 上。

## *Session：更安全的狀態管理機制*

為了補足 Cookie 的缺點，我們會在 Server 端使用 Session 的機制去儲存這些**狀態資訊**，並產生一組 Session key 放入 Cookie 中，因為這些狀態資訊都是存在於 **Server 端**，因此使用者無法讀取， 使用者只能看到 session key 但不知道結構，同時也能避免 Cookie 存入過多資料，解決了Cookie ****的缺點。

打個比方，在現實生活中Cookie像是餐券，Session則是會員卡，Session可以靠著Session ID 記錄你點餐的細節、甚至是消費紀錄和喜好，可以解決而 Cookie 遺失的問題。

總結：

session：將數據保留在 Server 端並且產生出 Session ID，而 Session ID 就是憑證，是Server端所發的識別證

cookie：是瀏覽器**存放資料的地方**，可以存放seesion之類的資料

![](https://cdn-images-1.medium.com/max/2000/1*SmZz214p2MXpYNB-K9vSwQ.png)

參考連結：
[**Authentication 那些小事上集：Cookie 與 Session 介紹**](https://vicxu.medium.com/authentication-%E9%82%A3%E4%BA%9B%E5%B0%8F%E4%BA%8B%E4%B8%8A%E9%9B%86-cookie-%E8%88%87-session-%E4%BB%8B%E7%B4%B9-1da2d413afa2)
[**Day14-Session與Cookie差別**](https://medium.com/tsungs-blog/day14-session%E8%88%87cookie%E5%B7%AE%E5%88%A5-eb7b4035a382)
[**[Node.js] cookie-session驗證原理以及express-session套件使用**](https://medium.com/johnny%E7%9A%84%E8%BD%89%E8%81%B7%E5%B7%A5%E7%A8%8B%E5%B8%AB%E7%AD%86%E8%A8%98/node-js-cookie-session%E9%A9%97%E8%AD%89%E5%8E%9F%E7%90%86%E4%BB%A5%E5%8F%8Aexpress-session%E5%A5%97%E4%BB%B6%E4%BD%BF%E7%94%A8-aeafa386837e)
How to get started in cyber?
Published: 2022-11-02 01:45:29

I have already written an article on medium about this, here is the link: [How to get started in cyber?](https://earthtoyash.medium.com/how-to-get-started-in-cyber-b3c5ea2f3be0)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1t02p6sj9newftiakv4.png)
Introduction to FP
Tags: functional, typescript, fpts
Published: 2022-11-02 01:27:45

Welcome to the series of blog posts about functional programming in [TypeScript]. In this series, we explore the basic concepts of _function composition_ and _monads_. The code examples in this series are built using the [fp-ts](https://github.com/gcanti/fp-ts/) library and TypeScript's native features.

I have chosen `fp-ts` since it is the tool I am the most familiar with but there are others out there, for example [effect-ts](https://github.com/Effect-TS/core).

## Target audience

Function composition and monads are concepts that can sound scary to people coming from a non-functional programming background. It certainly did sound scary to me at first. In this series, I want to explain these concepts using very simple terms and examples. I am not trying to be exhaustive, nor completely accurate in my explanations. If you want to learn about the mathematical background of functional programming and category theory, this isn't the series you're looking for.

<img src="https://media.giphy.com/media/3o84sF21zQYacFcl68/giphy.gif" width="100%" style="width:100%">

## Structure

Each chapter consists of the following:

- explanations centered around a single concept,
- code examples (ESM),
- additional learning materials to offset the incompleteness and low accuracy of my explanations,
- a short wrap-up and a brief introduction to the next chapter.

The chapters build on top of each other. Hence, it is strongly recommended to read them in the given order.

## Wrap-up

- The aim of the series is to **explain** a few basic functional programming concepts in simple terms.
- The series is targeted at software engineers not comfortable with functional programming concepts who have at least a basic understanding of TypeScript or any other typed language.

In the next chapter, we learn about **function composition**. See you there!👋

## Extra resources

- [Why functional programming should be the future of software development]
- [Introduction to Functional Programming by Gulio Canti (translated by Enrico Polanski)]

[TypeScript]: https://www.typescriptlang.org/
[Why functional programming should be the future of software development]: https://spectrum.ieee.org/functional-programming
[Introduction to Functional Programming by Gulio Canti (translated by Enrico Polanski)]: https://github.com/enricopolanski/functional-programming
DPS909 Blog :LAB 7 Intro to Static Analysis
Tags: opensource, beginners
Published: 2022-11-02 01:04:58

## Overview

In this week we are focused on managing project complexity through the use of Static Analysis tooling. Static analysis tools operate on our source code (static) vs. running program (dynamic). They help us maintain the quality of our source code by fixing formatting issues, spotting suspicious coding constructs, or alerting us to common errors.

Link to my project [ag-ssg](https://github.com/anshul137/ag-ssg)

## Learned from this lab
- An automatic source code formatter
- how to use source code linter
- Command-line or project build scripts to run your static analysis tooling
- Editor/IDE integration of your static analysis tooling

## Source Code Formatter
Automatic source code formatters (also known as beautifiers or "pretty printers") take source code as input and produce properly formatted output. Their goal is to establish a common format for all source code in the project.

For my project I have used [prettier](https://prettier.io/) as the formatter.
Prettier is an opinionated code formatter with support for:
JavaScript (including experimental features)
- JSX
- Angular
- Vue
- Flow
- TypeScript
- CSS, Less, and SCSS
- HTML
- Ember/Handlebars
-JSON
- GraphQL
- Markdown, including GFM and MDX
- YAML
It removes all original styling* and ensures that all outputted code conforms to a consistent style. 

### Install
First, install Prettier locally:
```
npm install --save-dev --save-exact prettier
```
Then, create an empty config file to let editors and other tools know you are using Prettier
```
echo {}> .prettierrc.json
```
Now, format all files with Prettier:
```
npx prettier --write .
```
I have created the `npm` script to run the code formatter
```
npm run format
```
When I run this formatter on my code it has fixed all the indentation and format issues which i have on my code.

### Linter
Linters help us spot "silly" mistakes that all programmers make, or help us avoid certain code patterns that often lead to bugs. We want to make it easy for ourselves and new developers joining our project to not introduce bugs or bad code.

For my project I have used [ESLint](https://eslint.org/) to find and fix problem in my `.js` files. SLint statically analyzes your code to quickly find problems. It is built into most text editors and you can run ESLint as part of your continuous integration pipeline.
Install and configure ESLint using this command:
```
npm init @eslint/config
```
After that, you can run ESLint on any file or directory like this:
```
npx eslint yourfile.js
```
I have created the `npm` script to run the code formatter
```
npm run esLint
```
When I run the [ESLint](https://eslint.org/) it created all the error list which are currently on my project and helped me to fix them.

Overall, these tools are great and i believe every programmer should use them so that their code look formatted when they work on any project.
Moreover, Linter help use to find all the silly mistakes we cannot catch. 


```
Thanks
```
goField forceResolver does not quite work as desired for subscriptions
Tags: gqlgen, graphql, go
Published: 2022-11-02 00:54:54

Goal - create organized subscriptions in the graph so it's easier for users to navigate:

extend type Subscription {
  cameraSubscriptions: CameraSubscriptions!
}

extend type CameraSubscriptions {
    cameraEvent(accountId: String!, deviceId: String!): CameraEvent @goField(forceResolver: true)
}

Generated Code:

func (r *cameraSubscriptionsResolver) CameraEvent(ctx context.Context, obj *model.CameraSubscriptions, accountID string, deviceID string) (*model.CameraEvent, error) {
	panic(fmt.Errorf("not implemented: CameraEvent - cameraEvent"))
}


func (r *subscriptionResolver) CameraSubscriptions(ctx context.Context) (<-chan *model.CameraSubscriptions, error) {
	panic(fmt.Errorf("not implemented: CameraSubscriptions - cameraSubscriptions"))
}

Expected:

The chan would be applied to the lowest level subscription resolver (CameraEvent) not CameraSubscriptions. 


Is there a way to do this or do subscriptions all have to be at the top level of the graph?