teleren/devto huggingface dataset:
Mongo Singletons
Published: 2021-07-30 03:46:16


'Singleton' is a term that I came across a while back when I did some reading, curious about what 'real' programmers know.

It's a design pattern I think.

I ran into singletons in a [great Mongo/Mongoose resource](https://www.freecodecamp.org/news/introduction-to-mongoose-for-mongodb-d2a7aa593c57/) I found and then some things I read on Stack Overflow about making Mongoose connections helped to reinforce it.

##The Question
How do database connections work?

####The question I didn't know I had####
How does require work behind the scenes?

##The Answer
`let mongoose = require('mongoose')`
This is the whole enchilada.

On this mongoose instance (I think that's what it is) you:
- establish the database connection:
`mongoose.connect(db-server-info-here)`
- write schemas:
`mongoose.schema(define-your-schema)`
- create models:
`mongoose.model(schema-goes-here)
- execute queries:
`mongoose.find(your-search-filter)

Your code doesn't exactly look like that, but that's what's happening.

Usually this all happens across different files. So you'll require Mongoose and then export a connection (or a model, etc).

This is all happening on one instance. One connection: a singleton object.

Here's what one user said on Stack Overflow:
>
the code in the required module is executed only once. so **you can require modules as many times as you want and the connection to mongo db for example will be created only once** – [Micha Roon Jan 21 '13 at 18:19](https://stackoverflow.com/questions/9690186/best-way-to-share-database-connection-param-with-mongoose-node-js)

And let's round it out with these gems from freecodecamp:

>The require(‘mongoose’) call above returns a Singleton object. It means that the first time you call require(‘mongoose’), it is creating an instance of the Mongoose class and returning it. On subsequent calls, it will return the same instance that was created and returned to you the first time because of how module import/export works in ES6.

>Similarly, we have turned our Database class into a singleton by returning an instance of the class in the module.exports statement because we only need a single connection to the database.

>ES6 makes it very easy for us to create a singleton (single instance) pattern because of how the module loader works by caching the response of a previously imported file.
Writing Clean Code in JavaScript - Variables
Tags: javascript, programming, codequality, devops
Published: 2021-07-30 03:46:07

**Prerequisite:** This blog assumes, you have basic knowledge of JavaScript.

This blog covers writing good variables names to maintain code cleanability in JavaScript. What is Variable?, Why writing good names variables crucial for program & Software? How to write a good name for variables? 

Did you know writing bad codes leads to a lack of productivity and unnecessary delays, and difficulties to add functionality in the software later. 

It might be easy to write quickly messy code but later it will add unnecessary delays and difficulties. 

### What are Variables?
Variable's are like a container where we store values or program-related data and then access them later to use that data.

### Why writing good variable names crucial for program/software?
1. With a good name, you and other developers can easily distinguish what kind of value it has.
2. With a good naming, you don't need to read variable full-body or scroll to that position where it has initialized to find what kind of value it has.
3. With a good naming, you can have an idea about what variable is for what value.
4. With a good naming, you don't have to write unnecessary comments in the code. For, an example: What value variable has, and it is for what

**In the end, good naming will save your lot of time in future.**

### So, how to write a good name for variables? 
Well, it depends on the value you are storing, but here are a few checks which you can use to write a good variables name in JavaScript:
1. If the value is an object, then use some descriptive name for it. An object can have many data about the users or person or can be a group of data. Example: userInfo, database, authenticatedUserData, etc.
2. If the value is a number or string, use a descriptive name, like username, age.
3. If the value is a boolean, use names that answer a true or false to questions. Example: isUserActive, isUserAuthenticated, isLoggedIn.
4. If your value is constant, then follow the descriptive name pattern and declare it in uppercase.
5. Don't write too long name where you have to scroll to read

Note: The ability to write clean codes instantly comes with experience and practice. Don't force yourself too hard to do it, try to follow this principle slowly to adapt to these things.
SSJetPackComposeProgressButton android library
Published: 2021-07-30 03:27:26

Features
Android’s modern toolkit - Jetpack Compose support.
Newly designed loading animation make your app attractive.
Blinking icon button for your hot-feature.
Button with text, right and left icon.
Different types of state makes it easy to manage button. (Idle, Loading, Success, Failure)
Fully customized button (Corner radius, background, colors, animation speed etc.)
Customize button loading animation with your logo and special animation effect.

Chekc it on GitHub : https://github.com/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton
ES6 arrow functions in Vue.js
Tags: vue, javascript
Published: 2021-07-30 03:19:47

Before moving on, I just want to mention a thing or two about the ES6 arrow functions. While they are really useful in many cases, you also have to be a bit cautious with them.

isRouteActive : (id) => {
    if (this.$nuxt.$route.path.includes(id)) return true;
    else return false;
}

As we can see, this refers to the Window object, which is not really what we expected.

isRouteActive(id) {
  if (this.$nuxt.$route.path.includes(id)) return true;
  else return false;
},

Now we see the Vue instance being output as we would have expected

So, the moral of the story is that you should not use arrow functions on Vue instance properties where Vue tries to bind this to the Vue instance itself. There are still times where you can use arrow functions with all their benefits, for instance if you assign a function to a variable within one of your Vue instance’s methods. Then you can access this within this arrow function, and it would point to the Vue instance as you would expect. Just be aware of where you use these arrow functions and if you experience some strange behavior with this not point to what you expect, then it might be related to arrow functions. That’s just something to be aware of.
Incrementalism
Published: 2021-07-30 03:16:23

I am decisively **not** a *little every day* guy. I'm an *all-in, right now, let's go* guy.

And I've suffered for it.

There are already volumes on the wisdom and virtue of 'slow and steady'. We all know it. We don't all do it.

This is a scattered thought, but it reminds me a bit somehow of the axiom **don't let perfect be the enemy of good**. I could translate that to: 
Instead of stealing thirty minutes every day (or fewer) to work on something, I'll wait for the perfect block of time to open. And I'll wait. 

That's the hare. Meanwhile, the tortoise has put in a piece here. Added something else later, then walked away. When there was a little time, the tortoise came back and put in another bit.

###The blog

Yesterday, I decided to be the tortoise. So after a few days of not touching the project because I wanted to give it a few hours of attention, I gave it an hour yesterday. Maybe it was more, but it was less than I had been waiting for. And today I gave it an hour and perhaps I'll still have time tonight to give it an hour more.
Creating vite vue ts template: Setup Github Actions
Tags: github, ci, vite, vue
Published: 2021-07-30 02:49:29

## Configure Github Actions for `bulid`

1. Let start by setting up `Node.js` workflow.
1. Go to `Actions` tab in your project and find `Node.js` workflow.
   ![Node.js workflow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzjisuy78qq5cglbqi1u.png)

    (it may be hidden under ` More continuous integration workflows...`)
    ![More continuous integration workflows](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rz0adjloi6zy5wi022lk.png)
    and press `Set up this workflow` button.

1. Rename `node.js.yml` to `build.yml`. Commit `build.yml` with `Start commit` button. Add `Create .github/workflows/build.yml` commit message.
   ![Commit build.yml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cp3vel0ny4un0fy1ka7m.png)

### On commit `pre-commit.ci` may fail because of `prettier` formatting.

1. `git pull`
1. `pre-commit run --all-files`
1. `git add -u`
1. `git commit -m 'fix: prettier formating'`

### Update `.github/workflows/build.yml`

1. We do not have tests yet and `build` is present in `package.json`
    ```diff
           - run: npm ci
    -      - run: npm run build --if-present
    -      - run: npm test
    +      - run: npm run build
    ```
1. `git add -u`
1. `git commit -m 'do not run npm test for build workflow'`

### Add badge

1. Add `![build](https://github.com/<OWNER>/<REPOSITORY>/actions/workflows/build.yml/badge.svg)` to README.md. From docs

    > You reference the workflow by the name of your workflow file.
    >
    > ```markdown
    > ![example workflow](https://github.com/<OWNER>/<REPOSITORY>/actions/workflows/<WORKFLOW_FILE>/badge.svg)
    > ```

1. `git add -u`
1. `git commit -m 'add build workflow badge'`

## Links

-   https://docs.github.com/en/actions
-   https://docs.github.com/en/actions/guides/setting-up-continuous-integration-using-workflow-templates
-   https://github.com/actions/setup-node
-   https://github.com/actions/starter-workflows/blob/main/ci/node.js.yml

## Project

{% github https://github.com/imomaliev/vue-ts no-readme %}
July 29th, 2021: What did you learn this week?
Tags: weeklylearn, discuss, weeklyretro
Published: 2021-07-30 02:35:02

It's that time of the week again. So wonderful devs, what did you learn this week? It could be programming tips, career advice etc.

<center>

![Boss from the Office Space movie sipping his coffee in front of a cubicle](https://media.giphy.com/media/lSVL6vdhdZVPW/giphy.gif)

</center>

Feel free to comment with what you learnt and/or reference your TIL post to give it some more exposure.

{%tag todayilearned %}

And remember, if something you learnt was a big win for you, then you know where to drop it as well.👇👇🏻👇🏼👇🏽👇🏾👇🏿

{%link https://dev.to/devteam/what-was-your-win-this-week-4129 %}

<center>

![A show host dancing a winning in their seat](https://media.giphy.com/media/l3q2Z6S6n38zjPswo/giphy.gif)
</center>
Disable directory listing on Apache server
Published: 2021-07-30 02:21:42

While requesting a web directory , the listing of files and folders is called directory listing and it exposes your directory structure to clients. In this short article I will show you how we can disable directory browsing. To disable the listing of files and folders you can just use the following code in your htaccess
<code>
Options -Indexes
</code>
This will return a 403 error when your directory is direct accessed.
Read the full tutorial here 
https://helponnet.com/2021/07/29/apache-disable-directory-listing/
Fullstack developer intern
Tags: job, fullstack, startup, internship
Published: 2021-07-30 01:37:40

Torre Labs is looking for a Software developer for fast growing start-up 🚀 🌎 fully remote. Internship opportunity!

Skills: 1+ year of Full Stack development, Engineering, Software development.
Language: English - Conversational.
Location: Remote.
Compensation: USD$12K /year

Applying through Torre is super simple, using the following link: https://torre.co/s/v2jSvyfkZV 

Don't have a torre.co account yet? No worries. I can help you set it up and then submit the application for you. Cool, huh?

Reach out to me to lmedina@torre.co with your CV and email if you’d like my help.
2의 보수, 컴퓨터가 음수를 표현하는 방법
Tags: computerscience
Published: 2021-07-30 01:12:38

우리는 숫자 앞에 - 기호를 표시함으로 쉽게 음수를 표현할 수 있다. 하지만 0과 1뿐인 컴퓨터에선 어떻게 표현할 수 있을까?

음수인지 양수인지 구별하기 위한 부호 비트를 살펴보고 단점을 보완하기 위한 1의 보수와 2의 보수를 살펴봤다.
​
☀︎ (2)는 2진수를 의미함
⠀
⠀
⠀
## 부호 비트
sign bit

**가장 왼쪽의 비트**<sup>MSB</sup>를 부호로 사용해 음수를 표현하는 방식이다. 0<sub>(2)</sub>이면 양수, 1<sub>(2)</sub>이면 음수임을 뜻한다. 4비트 시스템을 예로 들었을 때 0010<sub>(2)</sub>은 2이고 1010<sub>(2)</sub>는 -2이 된다.

숫자를 표현하기 위한 비트가 하나 줄었다는 단점이 있다. C언어에서 unsigned가 붙은 자료형이 붙지 않은 자료형에 비해 월등히 큰 숫자를 사용할 수 있는 게 그 이유다.

그런데 다른 문제가 생겼다. 부호를 사용했을 때 0010<sub>(2)</sub> + 1010<sub>(2)</sub>의 결과는 무엇일까? 0이 돼야 한다. 하지만 1100<sub>(2)</sub>으로 -4라는 결괏값이 나온다.

그럼 0<sub>(2)</sub>일 땐 더하고 1<sub>(2)</sub>일 땐 빼면 안 될까? 생각할 수 있다. 그럼 부호 비트가 0<sub>(2)</sub>일 때와 1<sub>(2)</sub>일 때 각각 다른 회로를 사용해야 하는데, 단순하게 생각해 보면 덧셈이라는 행위가 2배로 복잡해진다.
⠀
⠀
⠀
## 1의 보수
one's complement

그런데 누군가 기발한 생각을 했다. 각 비트를 뒤집으면(0<sub>(2)</sub>은 1<sub>(2)</sub>이 되고 1<sub>(2)</sub>은 0<sub>(2)</sub>이 됨) 단순하게 구현할 수 있는 것이다.

2를 예로 들어보면 0010<sub>(2)</sub>을 뒤집어 1101<sub>(2)</sub>로 -2를 표현할 수 있다. 둘을 더하면 1111<sub>(2)</sub>로 숫자 비트만 뒤집으면 000<sub>(2)</sub>이 되므로 0이라는 결과를 확인할 수 있다.​

0은 0인데 부호 비트가 1이니 -0이라는 의미심장한 숫자가 등장하게 된다. 게다가 덧셈이 이상한 경우도 등장한다. 0010<sub>(2)</sub>와 1110<sub>(2)</sub>를 더하면 2 + -1이므로 1이라는 결과가 나와야 하는데 0000<sub>(2)</sub>, 즉 0이라는 결과가 나온다. 

이 문제를 해결하기 위해선 MSB에서 올림이 발생했을 때 **가장 오른쪽 비트**<sup>LSB</sup>로 전달해 주는 **순환 올림**<sup>end-around carry</sup>이 필요하다.​
⠀
⠀
⠀
## 2의 보수
two's complement

이제 음수 표현의 최최최종 버전인 2의 보수가 등장한다. 1의 보수처럼 뒤집되 +1<sub>(2)</sub>을 해준다. -2를 표현하고 싶다면 0010<sub>(2)</sub>을 뒤집어 1101<sub>(2)</sub>로 만들고, 여기서 1<sub>(2)</sub>을 더하면 1110<sub>(2)</sub>이 된다.

계산해보면 -0이라는 숫자가 없어진다. 1의 보수에선 1111<sub>(2)</sub>은 -0이었지만 2의 보수에선 000<sub>(2)</sub> + 1<sub>(2)</sub>과 같은 효과로 001<sub>(2)</sub>, 즉 -1이 된다.​

그럼으로 음수 숫자를 하나 더 표현할 수 있다. 4비트를 예로 들면 가장 큰 값은 0111<sub>(2)</sub>인 7이 되고, 가장 작은 값은 1111<sub>(2)</sub>로 -8이 된다.

게다가 순환 올림도 필요 없기 때문에 음수를 더했을 때도 문제가 없다(하나하나 직접 계산해보면 그 신기함을 경험할 수 있다).
⠀
⠀
🙌 1, 2의 의미는 무엇일까?

1비트를 예로 들었을 때, 1<sub>(2)</sub>을 1의 보수 취한다는 것은 1<sub>(2)</sub> - 1<sub>(2)</sub>와 같다. 2의 보수를 취한다는 것은 10<sub>(2)</sub> - 1<sub>(2)</sub>으로 비트 단위가 달라지는 걸 확인할 수 있다.

여기서 1<sub>(2)</sub>은 1<sub>(10)</sub>이고 10<sub>(2)</sub>은 2<sub>(10)</sub>인데, 이 모양을 본떠 이름을 지었다고 볼 수 있다.
⠀
⠀
### 변환

만약 8비트 시스템에서 부호 있는 정수를 나타낸 11111011<sub>(2)</sub>라는 숫자를 보게 되면 10진수로 어떻게 표현할 수 있을까? 

100000000<sub>(2)</sub> - 11111011<sub>(2)</sub> = 101<sub>(2)</sub> 여기서 부호 비트가 1이니 결과는 -5가 된다.
Software developers for startup - Fully remote
Tags: job, fullstack, vacancy, startup
Published: 2021-07-30 00:59:05

Torre Labs is looking for a Software developers for fast growing start-up 🚀 🌎 fully remote. 

Skills: 3+ years of Web Development, Full Stack development, 2+ years of Software architecture.
Language required: English - Conversational.
Location: Remote.
Compensation: USD$50.000 /year.

Applying through Torre is super simple, using the following link: https://torre.co/s/dRumJWqtCf 

Don't have a torre.co account yet? No worries. I can help you set it up and then submit the application for you. Cool, huh?

Reach out to me to lmedina@torre.co with your CV and email if you’d like my help.
How to change or modify the name of the user in Linux?
Tags: resource
Published: 2021-07-30 00:00:00

---
  title: How to change or modify the name of the user in Linux?
  published: true
  tags: Resource
  date: Fri Jul 30 2021 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/change-modify-name-of-user-linux
  cover_image: https://melvingeorge.me/_next/static/images/main-293f55ab0995b6cb1eadb8b7edf4a580.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/change-modify-name-of-user-linux)
  
To change the name of a user, you must use the `usermod` command followed by the `-l` flag (login name flag), the new name of the user, and finally the old name of the user.

```bash
# Syntax
sudo usermod -l new_user_name old_user_name
```

Imagine that we already have a user named `john` in the system and want to change the name to `roy`. To do that we can use the `usermod` command like this,

```bash
# Change or modify the name of the user in Linux
sudo usermod -l roy john
```

- Sometimes you may need to use the `sudo` command before the `usermod` command to obtain the correct privileges to execute the command.

Try executing the above command in this [online terminal](https://copy.sh/v86/?profile=archlinux) to see the result.

That's all 😃!

### Feel free to share if you found this useful 😃.

---
Where to start with DevOps
Tags: devops, postmortem, cicd, lean
Published: 2021-08-01 07:39:23

---
title: Where to start with DevOps
published: true
date: 2021-07-30 00:00:00 UTC
tags: devops,postmortem,cicd,lean
canonical_url: https://jhall.io/archive/2021/07/30/where-to-start-with-devops/
---

DevOps is a big topic. This is made clear by the sheer number of books, blogs, podcasts, and conferences on the topic.

It’s a bit overwhelming, and simply knowing where to start can be a mystery.

![](https://jhall.io/archive/images/bn-maze.jpg)

I have two simple suggestions for how to start, if your team is new to the idea of DevOps:

1. The next time your product suffers an outage or serious problem, conduct a no-blame postmortem. I’ve written a quick guide to help: [_The Zero-prep PostMortem: How to run your first incident postmortem with no preparation_](https://jhall.io/posts/zero-prep-postmortem/).

    If things are running smoothly, so you don’t need a postmortem, great! But bookmark the link and keep this idea in your back pocket. You’ll need it eventually!

    In the mean time…

2. Begin streamlining your software delivery process. The best tool I know for this is what I call **Lean Continuous Deployment**. My free [Lean Continuous Deployment bootcamp](https://jhall.io/lean-cd-bootcamp/) will take you through the steps of setting up Continous Deployment or Continuous Delivery, without the need to automate all your tests first.

* * *
_If you enjoyed this message, [subscribe](https://jhall.io/daily) to <u>The Daily Commit</u> to get future messages to your inbox._
Today's Daily Humor For Devs - Daily Developer Jokes
Tags: jokes, dailydeveloperjokes
Published: 2021-07-29 23:48:28

---
title: "Today's Daily Humor For Devs - Daily Developer Jokes"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e12591442e48.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
___Q:___ When do front end developers go out to eat?

___A:___ On their lunch `<br>`.
 -->
Algorithms and Scripting: Problems and Notes Part 3
Tags: javascript, devops, beginners, tutorial
Published: 2021-07-29 23:16:20

#### Today is a Wednesday, I will continue to try and post every week, including the weekends. (most likely Sunday Mornings) Sometimes life catches up to you and they're things going on but I and you should make time for the things we want to achieve.
* Anyways Let's continue. This particular problem will want us to  write a function that takes two or more arrays and returns a new array of unique values. Basically all values that are there from all arrays should be inluded but no duplicates in the final array.
* An example of this would be  if an array includes `[1, 2, 3], [5, 2, 1]` then we should should return `[1, 2, 3, 5]` Here `1` is a duplicate.
* Code:
```
function unique(arr) {
  return arr;
}

unique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
```
* Answer:
```
function unique(arr) {
  let numbers = [...arguments]
  let results = []
  for (let i = 0; i < numbers.length; i++) {
    for (let j = 0; j < numbers[i].length; j++) {
      if (results.indexOf(numbers[i][j]) === -1) {
        results.push(numbers[i][j])
      }
     }
    }
 return results;
}
console.log(unique([1, 3, 2], [5, 2, 1, 4], [2, 1])); will display [1, 3, 2, 5, 4]
```


####Convert HTML entities
* Here they want us to create a program that will convert HTML entities from string to their corresponding HTML entities such as `&`, `<`, `>`, `"` (double quote), and "'" (apostrophe).
* Code
```
function convert(str) {
  return str;
}

convertHTML("Pasta < Tacos < Pizza");
```
* Answer:
```
 function change(character) {
    if (character === "&") {
      return "&amp;";
    } else if (character === "<") {
      return "&lt;";
    } else if (character === ">") {
      return "&gt;";
    } else if (character === '"') {
      return "&quot;";
    } else if (character === "'") {
      return "&apos;";
    }
   }

    function convert(str) {
      let focused = ["&", "<", ">", "'", '"'];
      for (let i = 0; i < str.length; i++) {
       if (focused.indexOf(str[i]) != -1) {
         str = str.slice(0, i) + change(str[i]) + str.slice(i + 1)
      }
     }
  return str;
}

console.log(convert("Pasta < Tacos < Pizza")); 
 // will display Pasta &lt; Tacos &lt; Pizza
```
Upcoming Full-Stack project
Published: 2021-07-29 23:15:13

In the upcoming weeks I plan to refactor my third Ruby On Rails project which I created as part of the Flatiron School curriculum. I will create a frontend view using JavaScript and fix a few small issues. 

##App
 
* My future app will have users. Users will be created by an admin. For example, if a company has a new employee, the admin will create a user for the employee. 

* The app will have work orders. The admin will create a location which is the address where the employee will complete the work order. 

* The app will have work orders. Work orders are tasks  the employee has to do on a specific date. Once the employee finish all the tasks then the employee can close the work order. Otherwise, the work order will be pending. This work order will be saved in the database.

* Employees will be able to punch in and punch out. All the hours completed from Monday to Friday will be stored in the database and automatically give you a total of hours an employee worked. The employee account will not need personal information, no address or ss number. I don't want to compromise user's info because I don't have enough experience authenticating.

* In the frontend this website will show picture of apartments that were renovated. The pictures will be in an embedded Instagram feed.  

* The App also will have the business info and will tell if they need employees.

##Tech

This project will be my first real challenge. I will give it my best.I plan to use SQL database, activeRecord and Ruby on Rails. I will make a flow chart to map how the data will flow and how it will be stored. I will use nested roots, for example, if the work order belongs to 'employee/1' then the root of the work order will be  'employees/1/workoders/1'. I will use gem 'core' to allow me fetch the info from javascript. I will use gem 'bcrypt' to protect the passwords. In the frontend i will use React. I will use React Router for all the roots. Redux to manipulate the data in the frontend and thunk and axios to fetch the data from the backend.


##Conclusion

A small project like this one will give me more practice for future projects. The good thing about it, there are a lot of people who want to help me and they want me to succeed. I don't feel alone, and it keeps me motivated. In this business, it all depends on me if I succeed or not and one thing I know for sure is that I will not give up.