teleren/devto huggingface dataset:
How to flush cache in Linux
Tags: tutorials, cache, cronjob, linux
Published: 2020-07-16 12:02:22

---
title: How to flush cache in Linux
published: true
date: 2020-07-16 01:09:00 UTC
tags: Tutorials,cache,cronjob,Linux
canonical_url: https://boobo94.xyz/tutorials/flush-cache-linux/
---

Hello guys,  
  
Me again with a very interesting problem. Today I was working on some tasks as usual and I discovered that something is wrong with one of our systems and the vehicles are not updated actively. Something went wrong with the MQTT connection and that’s how I arrived to write [How I found a simple UI Viewer for InfluxDB](https://boobo94.xyz/tips/ui-viewer-influxdb/(opens%20in%20a%20new%20tab)) article.

While I debugged the problem I observed that the server’s RAM memory is full, but guess what, the memory used was 489640 and free memory 359256 from a total of 4GB. That’s why I came with the great idea As you can see below, the buff/cache memory is above 3GB (3189056).

```
$ top

top - 13:42:55 up 168 days, 5:26, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 109 total, 1 running, 67 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.0 sy, 0.0 ni, 99.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.2 st
KiB Mem : 4037952 total, 359256 free, 489640 used, 3189056 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 3268392 avail Mem 
```

## Check the cache memory

```
$ free -m

              total used free shared buff/cache available
Mem: 3943 503 365 1 3074 3167
Swap: 0 0 0
```

## Clear the cache memory

```
$ sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
```

Now you can check again the cache, and surprise

```
$ free -m

              total used free shared buff/cache available
Mem: 3943 505 3123 1 314 3206
```

And this is how it looks now my result of top command

```
$ top

top - 13:46:19 up 168 days, 5:29, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 110 total, 1 running, 67 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 4037952 total, 3196540 free, 517812 used, 323600 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 3282840 avail Mem 
```

## Automate this with a cronjob

I know that you’re lazy, so do I. Now let’s go back in business and create a Cronjob that automates this process for you.

```
$ crontab -e
```

A new text editor will open now, probably it’s VIM. All you have to do is to add at the end of file the following:

```
# m h dom mon dow command

0 2 * * * sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
```

This cron will execute every day at 2am.

I hope you enjoyed this article, so if you consider this article great, hit the share button below and spread the word far away. If you have any mention, please tell me more in comments. Good suggestion will go directly in the article.

The post [How to flush cache in Linux](https://boobo94.xyz/tutorials/flush-cache-linux/) appeared first on [boobo94](https://boobo94.xyz).
. (dot) has no real encoder / decoder. Only sanitizers.
Tags: webdev, security
Published: 2020-07-16 00:47:08

As `.` is potentially dangerous on the backend, both for URL and filenames, there are indeed [sanitizers, like this one](https://www.npmjs.com/package/sanitize-filename).

However, there is no standardized encoder / decoder to preserve meaning / uniqueness for URL and filenames. Why is that?

`decodeURIComponent`, `escape` or even `(s) => { el.innerText = s; return el.innerHTML }` all wouldn't change `.`

> Edit:
>
> The fastest and simplest way to escape this is simply `'~' + s` (and decode with `p.replace(/^~/, '')`).
The Cartesian product of a set and the empty set 
Tags: math, sets, cartesian
Published: 2020-07-16 00:43:08

---
title: The Cartesian product of a set and the empty set 
published: true
description: The cartesian product of a set and the empty set, but why?
tags: math, sets, cartesian
---

The cartesian product is the product of two sets. The resulting product is a set of pairs, one element belonging to {% katex inline %}A{% endkatex %} and one element belonging to {% katex inline %}B{% endkatex %}.

This can expressed as:

{% katex %}
{A \times B = \\{ (x,y) : x \in A, y \in B \\} }
{% endkatex %}

So what happens if we try to take the cartesian product of a set and the empty set? {% katex inline %} {A \times \emptyset} {% endkatex %}?

We end up with: {% katex inline %} {A \times \emptyset} = \emptyset {% endkatex %}. This is because we try to build a set like this: {% katex inline %} {A \times B = \\{ (x,y) : x \in A, y \in B \\} }
{% endkatex %}, but {% katex inline %}B{% endkatex %} is empty. 

It is impossible to create this resulting set of pairs because one of the sets is the empty set. As such, not a single element can be produced from {% katex inline %}B{% endkatex %}, so our resulting set is the empty set.
Crafting my Software Engineering degree
Tags: learning, career, programming, study
Published: 2020-07-16 00:31:57

I started programming about a year ago and I don't have a degree related to Software engineering, which has not bothered me... Until now. Honestly, there are some basic concepts that I feel I'm missing out and that would help me do a much better job. 

So, in the course of one week I'll be creating my Software Engineering degree, using mostly free resources and also platforms and courses I've already paid for. I'm just doing this post as a means of accountability.

See you next Wednesday and may the odds be ever in my favor!
Write it yourself or be prepared to forget it immediately
Tags: html, css, javascript, todayilearned
Published: 2020-07-16 00:09:27

#Your goal as a junior developer is to achieve the highest recall rate for whatever you just learned.

- Writing ([FreeCodeCamp.org](https://FreeCodeCamp.org), [FreeCodeGame.com](http://FreeCodeGame.com), [FrontEndMentor.io](https://FrontEndMentor.io))
- trumps watching (Udemy, Pluralsight, etc.)
- trumps reading (countless books on frontend)
- trumps listening (growing number of specialty podcasts)

##[Learn by writing code that passes tests.](https://FreeCodeCamp.org)
##[Practice by fixing code so it passes tests.](http://FreeCodeGame.com)
##[Test your knowledge by writing code that matches a design.](https://FrontEndMentor.io)
How to copy text using JavaScript?
Tags: javascript
Published: 2020-07-16 00:00:00

---
  title: How to copy text using JavaScript?
  published: true
  tags: JavaScript
  date: Thu Jul 16 2020 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/copy-text-javascript
  cover_image: https://melvingeorge.me/_next/static/images/main-33205c0e13503aa9dea950dd898c7ebb.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/copy-text-javascript)
  
To copy text programmatically using javascript, you need to use the `document.execCommand('copy')` method.

Let's study this with an example.

Consider this HTML,

```html
<input id="copyInput" type="text" /> <button id="copyButton">Copy Text</button>
```

with an input tag and a button to copy text from the input tag.

Now let's write the javascript for this.

We need to get a reference to both the input and button tags first.

```javascript
// get reference to both
// input tag and button tag
const input = document.getElementById("copyInput");
const copyBtn = document.getElementById("copyButton");
```

Then we need to add a click event listener so that when the user clicks on the button it will copy the text from the input tag.

```javascript
// get reference to both
// input tag and button tag
const input = document.getElementById("copyInput");
const copyBtn = document.getElementById("copyButton");

// atttach click event listenter to button tag
button.addEventListener("click", () => {
  // do the copying of text here
});
```

Now for the computer to copy we need to select the text inside the input tag first and then execute the `document.execCommand('copy')` method.

```javascript
// get reference to both
// input tag and button tag
const input = document.getElementById("copyInput");
const copyBtn = document.getElementById("copyButton");

// atttach click event listenter to button tag
button.addEventListener("click", () => {
  /* do the copying of text here */

  // first select the text inside the input tag
  input.select();
  input.setSelectionRange(0, 99999); // polyfill for mobile devices

  // execute the copy method
  document.execCommand("copy");

  // optional ==> after copying change the button text to Copied!
  copyBtn.textContent = "Copied!";
});
```

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

---
Angular Lightning Quick Tip: [ngClass] and Compound Logic
Tags: angular
Published: 2020-07-16 13:11:55

---
title: Angular Lightning Quick Tip: [ngClass] and Compound Logic
published: true
date: 2020-07-16 00:00:00 UTC
tags: angular
canonical_url: 
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/gddhyk2d3tx77qcxcg33.jpg
---

An interesting question came up in a pull request recently that led to a new TIL when dealing with ngClass in Angular, so I thought it would be worth sharing.

## ngClass Overview

When creating components in Angular, it's common to change classes on particular HTML Elements in your template based on variables or logic. `[ngClass]` handles this for you.

`<div [ngClass]="{'one': shouldHaveThisClass}">Random div</div>`

When the class property of `shouldHaveThisClass` has a truthy value, then the class of `one` would be added to the div.

In interactive web apps, you can see why this feature helps us out.

_[NgClass Documentation for more details](https://angular.io/api/common/NgClass)_

## Compound Logic

What happens when multiple classes are used and how does Angular decide which classes to add?

```
// template class
// editMode = true;
// isPrimary = true;
// isSecondary = false;

<div
  [ngClass]="{
    'edit': editMode
    'primary': isPrimary, 
    'primary-edit': isPrimary && editMode, 
    'secondary': isSecondary,
    'secondary-edit': isSecondary && editMode
  }">
Random div
</div>`
```

What class or classes would be added to our div here?

The key line from the Angular docs:

> "Object - keys are CSS classes that get added when the expression given in the value evaluates to a truthy value, otherwise they are removed."

No precedence rules are used here.

**All classes would be added that have truthy values:** `edit`, `primary`, `primary-edit`.

This was a great question and something to keep in mind when designing our components in the future to make sure the right classes with the right styles are used.
Scrum and "old knowledge"
Published: 2020-07-15 21:59:57

Came across this article, which is one of a serious and it triggered more reflection than initially expected:

{% medium https://medium.com/serious-scrum/5-controversial-topics-that-were-removed-from-scrum-68b5e83d38f2 %}

Together with the accompanying 
{% medium https://medium.com/serious-scrum/6-pivotal-things-that-werent-scrum-canon-but-got-introduced-later-135d7417d654 %}

The first time I used Scrum in a project was early 2008; twelve years ago. I read the usual books, got certified (Scrum Master and Product Owner) and have seen Scrum adopted well and not so well in may teams. You could say I thought I had this topic "in the pocket". 

In recent years, the ["Agile Industrial Complex"](https://martinfowler.com/articles/agile-aus-2018.html) has dampened my earlier enthusiasm. The never-ending methods with certification schemes popping up, having scrum master and agile "coaches" in companies, whose only exposure with product and software development was a two day training course, etc. Apparently, though, Scrum hasn't fully fallen to the dark side and it keeps evolving, as shown in the linked articles via the changes of the Scrum Guides (also see [this](https://medium.com/serious-scrum/the-evolution-of-the-scrum-guide-10-to-19-f3ac4d82cfcb) article).

I was aware of some changes in the guide. For example, not to use the term _grooming_ anymore or switching out committing to a sprint backlog vs considering it a _forecast_. One thing that was new to me was the change of the Daily Scrum standard questions. They are now using the _sprint goal_ as the reference point of reporting: _What did I do yesterday that helped the Development Team meet the Sprint Goal_.

While I am really pleased to learn about many these changes, I also was a little shocked to realise that they had all happened without my taking notice. Contrast this with, for example, changes in Java. A language I haven't written code in in forever and have no real interest in, intellectually. I still managed to keep a basic awareness about changes such as the Streams API or the language switching to a half-year release cycle.

I don't have a good explanation for this, other than it feels like I had Scrum "taken care of", knowledge was archived and good enough for reference in the daily work. Maybe I am also falling prey to the well-known problem of thinking agile methods are "easy" as they only have "a few rules" and then being very careless in sticking to the important basics. It seems, though, that I am not the only one being outdated on Scrum knowledge. Teams that I work and have worked with are happily _grooming_ their stories, don't define a sprint goal and treat their sprint backlogs as binding contracts and not as forecasts.

In any case will I now keep an eye out for other topics that give me this "safely and snuggly archived" feeling. Time to shake up some presumed "certainties".
Learn Django in an easy way
Tags: python, django, codenewbie, beginners
Published: 2020-07-15 23:14:20

<b>If you want to learn basics of django in just a week, here are some steps to help you:</b> <i>(you must have a good knowledge in python)</i><br/>
<ol>
<li>learn how to install django from <a href="https://www.djangoproject.com/download/">here</a>.</li>
<li>know how to create django projects <code>django-admin startproject my_project</code>.</li>
<li>learn the structure of django project (check it <a href="https://learnbatta.com/course/django/understanding-django-project-structure/">here</a>), and the use of manage.py file.</li>
<li>learn how to route urls</li>
<li>learn how to render templates</li>
<li>learn about models</li>
<li>learn how to add static files (css, images, js, ...ect) to the project</li>
<li>learn how to deal with admin page <b>( <i>it's already setup for you just know how to create a superuser; and how to add contents (models) to it</i> )</b></li>
<li>learn about sessions (cookies)</li>
</ol>

I just learned it in lees than a week.
Here is a youtube channel where I learned from <a href="https://www.youtube.com/watch?v=UmljXZIypDc&list=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p">Corey Schafer</a>
Day 2: Enough with e-ink, let's try TFT Gizmo
Tags: adafruit, python, processing, raspberrypi
Published: 2020-07-15 23:05:54

Decided to switch to TFT Gizmo - e-ink Gizmo is very slow to work with. It's all ready and set up, and passed the TFT Gizmo test.

So finding out how to talk to TFT Gizmo on CPX with Circuit Python.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/x6r3ek7ym4xs3mn780ua.jpg)

Modified code so it loads up a bitmap on the TFT Gizmo.'

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7ldu59eku54yrmxo44x1.jpg)

##### ℹ️ https://learn.adafruit.com/adafruit-tft-gizmo/tft-gizmo-test

# Back to the Processing on the Pi.
Running it via command line (it's warn it's not fully supported on newer versions of Java or OpenJDK).

##### ℹ️ https://py.processing.org/tutorials/command-line/

Created the Python script from the Processing sketch sample. Got the processing-py.jar file.

```
java -jar processing-py.jar [name of my python script]
```

It worked!

I wanted to save the image to the disk - used `save()`, and that worked.

Next I want the dialog to close after it ran - used `exit()`, and that worked also.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/i77tu3myhpt681i156g8.jpg)

Next thing now is to pop that image onto the TFT Gizmo.

---

Loaded up the code from the e-ink Gizmo (will be modifying for TFT Gizmo) and its having problem not finding `displayio `module. Looks like I need to flash it with cpx with displayio (after a bit of troubleshooting).

##### ℹ️ https://learn.adafruit.com/adafruit-tft-gizmo/circuitpython-displayio-quickstart

Then it needed also `adafruit_pypixelbuf` module.

Ok, now I can modify to look for `tft` calls nows instead of e-ink.

Moments later, I hit a problem... The dreaded memory allocation errors.

##### ℹ️ https://learn.adafruit.com/adafruit-circuit-playground-express/frequently-asked-questions

I forgot the flash memory for CPX is quite small.

##### ℹ️ https://learn.adafruit.com/adafruit-circuit-playground-express/overview

I've removed comments and imports not needed. I'm only testing the example and can only display 1 of the 3 parts of the code

##### ℹ️ https://learn.adafruit.com/adafruit-tft-gizmo/circuitpython-displayio-quickstart

📍 In case I need to reduce size of my jpg image: https://stackoverflow.com/questions/59483536/why-does-pil-pillow-image-save-reduce-file-size

Ok, I just want to bare minimum load an image I generated earlier with Processing, it's a JPG. It gave an error saying it doesn't not support the file format, so I converted it to BMP with PIL.

##### ℹ️ https://www.daniweb.com/programming/software-development/threads/253957/converting-an-image-file-png-to-a-bitmap-file

And tried to load it again, and it worked.

#### NOTE: READ THE TOP "GREEN BANNER" ABOUT MEM CONSTRAINTS ON https://learn.adafruit.com/adafruit-tft-gizmo/circuitpython-displayio-quickstart 😅 
(Thanks to Mick for finding this https://github.com/adafruit/Adafruit_CircuitPython_ST7789/issues/9)

# 🍷 BREAK 🍷

##### References
* https://learn.adafruit.com/processing-on-the-raspberry-pi-and-pitft/hardware-io
* https://processing.org/tutorials/electronics/
On .NET Episode: Reliable Async Systems with Coyote - Part 1
Published: 2020-07-15 22:52:17

Coyote is a set of .NET libraries and tools designed to help detect potential problems in your asynchronous code.

In the episode, Rich chat with Chris Lovett about the issues developers face with writing asynchronous code and how Coyote can with discovering those hard to find issues.

{% youtube Stpq_sPBVIU %}

If you liked this video and would like to see some more of our .NET content, please subscribe to our [.NET Developers YouTube Channel](https://www.youtube.com/channel/UCvtT19MZW8dq5Wwfu6B0oxw).


## Useful Links
<ul>
<li><a href="https://microsoft.github.io/coyote/" target="_blank">Coyote Homepage</a></li>
<li><a href="https://github.com/microsoft/coyote/" target="_blank">Coyote on GitHub</a></li>
<li><a href="https://docs.microsoft.com/dotnet/standard/threading/?WT.mc_id=ondotnet-devto-cephilli" target="_blank">.NET Threading</a></li>
</ul>
Day 175: A Short While
Tags: hiphop, code, coding, lifelongdev
Published: 2020-07-15 22:36:59

_liner notes_:
- Professional : Started my day off early by attending a talk prep session. The topic was about putting together a workshop. It was a good discussion because I did a couple of workshops for the company this year. Went through the video recording with my friend doing the tutorial I've been working on to note the feedback and takeaways. Attended a practice session for my coworker who has a talk coming up. My manager saw the video recording and wanted to take a clip of my friends reaction at the end of the tutorial. haha He posted it in the team's channel and everyone felt good to see the reaction to a product we work on. Did some more work on my blog post. Hoping to get it done in a short while.

- Personal : Honestly don't remember much from last night. haha Last thing I remember doing is the tutorial walk through. haha I probably worked on my side project and then went to sleep.

![A forest in Richmond Park, United Kingdom with sunlight coming through the trees](https://dev-to-uploads.s3.amazonaws.com/i/d3g072zxjw0jo6g7qdpz.png)

Going to get last week's radio show submitted to the station to played on air this week. Probably work on the side project and get to bed early.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube QxVSDCCmICA %}
Angular's built-in Validation : Don't use FormControls
Tags: angular, typescript, formcontrols
Published: 2020-07-15 22:23:42

**New Discovery**
Use ngModel instead!
{% link https://dev.to/jwp/angular-validation-using-ngmodel-55gf %} 

**Instant Validation Logic**

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2y1kz47ex0cjb65lnumm.png)

**Not Really Instantaneous**

We have to hook up the formGroup and formControl code in the backend to make this work. 

Like this:
```typescript
   private formGroupBind() {   
      if (!this.person) {
         return;
      }
      let namePattern = /^(?=.{1,40}$)[a-zA-Z]+(?:[-'\s][a-zA-Z]+)*$/;
      let ssnPattern = /^(?=.{11}$)\d{1,3}-?\d{1,2}-?\d{1,4}|###-##-####$/;
      this.formGroup = new FormGroup({
         lastName: new FormControl(this.person.lastName, [
            Validators.required,
            Validators.pattern(namePattern),
         ]),
         firstName: new FormControl(this.person.firstName, [
            Validators.required,
            Validators.pattern(namePattern),
         ]),
         middleName: new FormControl(this.person.middleName, []),
         ssn: new FormControl(this.maskedSSN, [
            Validators.required,
            Validators.pattern(ssnPattern),
         ]),
         kind: new FormControl(this.person.kindID, [Validators.required]),
      });
     
      this.formGroup.enable;
   }
```
As can be seen there is a distinct pattern. The formGroup is a container for formControls.  Each formcontrol is bound the frontend by an object property.  We can specify if it's required or not and then use a regex pattern.

If the pattern doesn't match the control will turn pinkish.  

We simply do not have to worry about anything else. However we can add niceties for the user experience. 

For example anytime a change is made we can hide the save icon based on this code:

```typescript
this.showSaveIcon == this.formGroup.valid;
```
Or we can make sure of a valid state prior to saving like this:

```typescript
  onSave() { 
      if (!this.formGroup.valid) {
         //reject this save it's not valid 
         return;
      }
```

Where is all this goodness located?

In the forms module for angular. Just import FormsModule and you are all set. 

All front-end binding was covered in another post on this same topic. 


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qg2c8erk1jwnbw5ge0ub.gif)

**Summary**
Don't write your own validators; use the built-ins. They are faster and have everything you need to maintain proper state for user input.
JWP 2020
Twitter accounts for Apple, Elon Musk and Bill Gates were hacked
Tags: news, bitcoin, blockchain, security
Published: 2020-07-15 21:33:43

The hack asked for bitcoin donations.

> A number of high-profile Twitter  accounts were simultaneously hacked on Wednesday by attackers who used the accounts — some with millions of followers — to spread a cryptocurrency scam.

> @bitcoin, @ripple, @coindesk, @coinbase and @binance were among the accounts hacked with the same message: “We have partnered with CryptoForHealth and are giving back 5000 BTC to the community,” followed by a link to a website, which we are not linking to.

> The scammer’s website was quickly pulled offline. Kristaps Ronka, chief executive of Namesilo, the domain registrar used by the scammers, told TechCrunch that the company suspended the domain “on the first report” it received.



## **[Story on Techcrunch](https://techcrunch.com/2020/07/15/twitter-accounts-hacked-crypto-scam/)**