teleren/devto huggingface dataset:
Monitor & React to File System Events on Linux Using inotify
Tags: bash, ubuntu, webdev, linux
Published: 2020-12-02 12:48:13

Ever wondered when you make a change in a single file and on saving it some tools like angular or other clis or nodemon automatically react to it by bundling and redeploying the application?

Also while using an ide, when you do some mistake in code and save it, all the dependent files turn red due to an error!

The reaction is coded on ide or cli...but how they keep a watch on files and How it gets to know about events like create, modified, deleted and How we can custom automate something.

I needed such a tool that can listen to the file change events as I was using AngularJS and it does not have an inbuilt cli as angular2+ has. So I looked for something that can help me to automate the build. I use ubuntu so I searched and I found the tool named [inotify](https://man7.org/linux/man-pages/man7/inotify.7.html).

I achieved the hot deploy feature by using the inotify with a bash script. I have written a shell script like below
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7mmr7x6z9eg2z4fmxz3o.png)
or check out this git repo
{% github Maulikdes/file_watcher no-readme %}

I just have to now run the following command and not have to do the manual steps I was doing after changing files
>bash filename.sh

I'm not gonna bore you by writing about more functionalities, and stuff of inotify but let's just take a look at the simple example
First to install the inotify, just hit the following command
> sudo apt-get install -y inotify-tools

Here is a simple bash script which watches the changes of a file name *a.txt* and on change, it writes the log to *b.txt*
```
while true; do
    # the next statement will wait for the inotify event to get triggered
    change=$(inotifywait -e modify a.txt)
    # append he change log to the b.txt file
    echo $change "$(date +"%T")" >> b.txt;
done
```

Now let's see the demo
{% youtube x4ghsFQmQI8 %}
Top 5 Programming books 📚 every Software Developer should read atleast once in his/her lifetime
Published: 2020-12-02 12:36:52

These books have exponentially increased the knowledge of the readers. I have read some of the books of the given list. So let me start listing all the books one by one for you.
#1. Clean Code by Robert Cecil Martin 
This is one of my favorite programming books of all time. This book helps to understand the difference between good code and bad code. It explains what clean code really means. If you are not a very good coder, you should probably read this book. 

#2. Introduction to Algorithms 
This book is one of the best books one can read in his/her lifetime. This book explains algorithms in a fun way. You will fall in love with algorithms and start making your own algorithms. This book has significantly increased my knowledge about algorithms and basic computing concepts. I definitely prefer this to anyone who wants to learn algorithms. 

#3. Computer Networking: A Top-down Approach by Jim Kurose
I could not stop myself from including this book. This book explains all the complex networking concepts in a simple way understood by all. You should probably go for this book. 

#4. Data Structures and Algorithms Made Easy 
This is another great book for learning about algorithms. But this one offers a little more than just algorithms. It also explains data structures like stack, linked list, queue, etc. You also get a bonus of algorithmic puzzles in this bookm. So, I suggest you should definitely read this one.

#5. Hands-On Machine Learning by Aurelien Geron
This book is a bonanza for all the ML engineers out there. This book explains everything you need to know to be a top class ML engineer. If you want to learn all the mathematics concepts required for ML, I suggest "Mathematics For Machine Learning".

So, this is all I could provide you guys. Thank you so much for reading this far.
Highlight link to current page: TLDR
Tags: ruby, rails, bootstrap, tldr
Published: 2020-12-02 12:29:25

---
title: "Highlight link to current page: TLDR"
published: true
description: Best way to highlight link to current page in Ruby on Rails
tags:
- ruby
- rails
- bootstrap
- tldr 
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/x5dkbc0sivx9m2flnj2e.png
canonical_url: https://blog.corsego.com/ruby-on-rails-highlight-linkto-current-page
---
Often to improve your navigation UI (user experience), you will want to mark the link to current page "active".

The simple way to do it (assuming a bootstrap navbar):

```
<li class="<%= 'active font-weight-bold' if current_page?(root_path) %> nav-item">
  <%= link_to "Homepage", root_path, class: 'nav-link' %>   
</li>
```

or if you want to add some fancy fontawesome:

```
<li class="<%= 'active font-weight-bold' if current_page?(root_path) %> nav-item">
  <%= link_to root_path, class: 'nav-link' do %>
    <i class="fa fa-home"></i>
    Homepage
  <% end %>
</li>
```

however when you have a lot of links, your code will look "dirty".

To make it look cleaner, you can add the following lines to `application_helper.rb`:

```
def active_link_to(name, path)
    content_tag(:li, class: "#{'active font-weight-bold' if current_page?(path)} nav-item") do
      link_to name, path, class: "nav-link"
    end
  end 
end 

def deep_active_link_to(path)
  content_tag(:li, class: "#{'active font-weight-bold' if current_page?(path)} nav-item") do
    link_to path, class: "nav-link" do
      yield
    end
  end 
end 
```

this way you can write links like this

```
<%= active_link_to "homepage" root_path %>
```

or 

```
<%= deep_active_link_to root_path do %>
  <i class="fa fa-home"></i>
  Homepage 
<% end %>
```
That's it!🤠

Liked this article? Please follow me! It will really motivate me to post more fun stuff!
A recipe to implement print functionality efficiently in Javascript
Tags: javascript, html
Published: 2020-12-02 12:23:41


Javascript provides the method window.print() to print the entire contents of a html page.

There are two problems with this approach:

1. You cannot print part of your HTML page
2. If you have a print button to print the page , even the button shows up in the printed page.

To overcome this problem , here is a recipe to use window.print() efficiently:

STEP1: Create a HTML page with exactly the contents you want to print

STEP2: On onload() method of this html page body , call window.print() , so that when the page is loaded print functionality is triggered

STEP3: Place the print button on the page you want the user to trigger the print button.

STEP4: On click of the print button , open the html page that you created with the print contents (using window.open() method)

STEP5: Use the inbuilt onafterprint() method to close the print window once the print is completed (use window.close() method inside it).

Here is a demo :

https://fullstackdeveloper.guru/2020/12/02/how-to-implement-print-functionality-efficiently-in-javascript/
How To List All Enabled Regions Within An AWS account
Tags: aws, devops
Published: 2020-12-02 12:05:10

Ref: [describe-regions](https://docs.aws.amazon.com/general/latest/gr/rande-manage.html)

####If the Region is enabled by default, the output includes the following:
>"OptInStatus": "opt-in-not-required"

####If the Region is not enabled, the output includes the following:
>"OptInStatus": "not-opted-in"

####After an opt-in Region is enabled, the output includes the following:
>"OptInStatus": "opted-in"

##Pre-required:
1. AWS CLI
2. jq JSON
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zziu04u3pr2pxnzie5yp.jpeg)

##Run
```
aws ec2 describe-regions --all-regions | jq -r '.Regions | .[] | .RegionName + " " + .OptInStatus'  | grep -v not-opted-in | cut -d' ' -f1
eu-north-1                     
ap-south-1                       
eu-west-3                    
eu-west-2      
eu-west-1             
ap-northeast-2           
me-south-1        
ap-northeast-1                                     
sa-east-1                                             
ca-central-1                                 
ap-east-1                                                                                                                                    
ap-southeast-1                          
ap-southeast-2                                 
eu-central-1                               
us-east-1       
us-east-2    
us-west-1    
us-west-2
```
SEO Techniques For High Ranking Blog Posts In Search Engine
Published: 2020-12-02 12:00:58

What is Search Engine Optimization :- Search engine optimization is a way to balance your content by using Keywords, Images and links to help search engines and specially to Google to find your website. Blogs are particularly suited to SEO because each post is easily packed with keywords, links and images. The search engine algorithms crawl the web looking for content and always pay attention to these three clues because these algorithms are programmed with this idea. So by using these three parameters you can easily rank a website to be noticeable.


What is Search engine optimization and techniques

However if you try to jump by using so many Keywords then you might get penalized for spam. SO while SEO is very important as you want the browser to find your content better, always keep in mind that never sacrifice the reader’s experience for SEO. If your posts are pointless and unreadable and too focused on a set of keywords then you really need to rethink your strategy. There are several ways to rank your website or blog to rank in search engines and further into this article I am going to mention these techniques step by step. Read more at - https://www.devopsschool.com/blog/ranking-blog-posts-seo-technique/
Using mkcert for testing
Published: 2021-01-18 21:41:03

---
title: Using mkcert for testing
published: true
date: 2020-12-02 12:00:00 UTC
tags: 
canonical_url: https://www.solarwinter.net/using-mkcert-for-testing/
---

I use [mkcert](https://github.com/FiloSottile/mkcert) and [lvh.me](https://coderwall.com/p/-neplg/use-lvh-me-for-local-subdomain-testing) quite a lot for local web development. To avoid gotchas (and because some libraries require it) I often test using HTTPS locally, which means generating a set of certs for each dev install.

The following `package.json` script will automatically generate cert and key for the domains that you want - set your server to load the same names and cert setup is now a one-liner.

```
"setup:certs": "mkdir -p certs ; mkcert -cert-file certs/appname.lvh.me.pem -key-file certs/appname.lvh.me-key.pem appname.lvh.me localhost"
```

(I'm writing this as much so I've got something to copy/paste next time as anything else!)
I built a web application to help developers work faster
Published: 2020-12-02 11:52:56

Hi everyone,
hope you are having an awesome day?
I am Solarin Olakunle.
I built a web application that enables developers work faster, they fill a form detailing their MVC project.
The app then generates a preview web application for them.
It also generates source code for that application in c# (asp.net, asp.net core), java (spring MVC) and php (laravel) .
Please i would appreciate if you could check it out and let me know areas i could make it better.
The website for the app is at www.codejoh.com, at the site there are links to signup or login to the application.
I also have an article on which might shed some more light on the application at https://lnkd.in/d_DGZ-z
Debouncing and Throttling
Tags: javascript, performance, webdev, devjournal
Published: 2020-12-02 11:51:15

Debouncing and Throttling are two ways to optimize performance of web application by limiting rate of the execution of a function call. It is particularly useful when we are attaching function to DOM events, because in these scenarios we might be invoking unnecessary function calls.

#Debouncing#

The debounce pattern lets us control events that are triggered successively, and if the interval within two events is greater than a certain amount of time, only then the function is called.

###Implementation###

Debounce function takes two arguments - function and delay.
It does not let function make unnecessary calls again and again and will only make function call **if the difference between time Intervals of function calls is greater than the delay**.

{% codepen https://codepen.io/shifali-gupta/pen/QWKjvpx default-tab=js,result %}

#Throttling#

Throttling is a technique in which, no matter how many times the user fires the event, the next function call will be delayed for a certain time Interval.
It restricts the maximum number of times that a function can be called. This method is usually used to control window resizing, scrolling and mouse-related events.

###Implementation###

Throttling function takes two arguments - function and time Interval.
It will check the difference between last function call and the function call. **If the difference between two function calls is a certain time, then only the function is called**.

{% codepen https://codepen.io/shifali-gupta/pen/GRjpEGP default-tab=js,result %}
How to set up HTTPS proxies and SOCKS with Proxifier
Tags: tutorial
Published: 2020-12-02 11:33:32

# Set up proxies and SOCKS with proxifier in minutes. 

## What is Proxifier?
Proxifier is a software that allows you to use HTTPS Proxies and SOCKS on network applications that do not support operating through proxies. 

A proxy server acts as an intermediary between the end users and the visited websites, hiding their original IP replacing it with a new one. This way, you will be protected from potential threats or cyber attacks. 

In 20p0 Protecting your data and information while browsing the internet can be easy and Proxifier allows you to do that on any network applications. 

## How to set up proxies with Proxifier. 
This is a short preview on how to set up proxies in Proxifier if you want to find more information on how the software works check out our article about [a full tutorial on how to set up Proxies and SOCKS5 with Proxifier](https://anonymous-proxies.net/knowledgebase/how-to-use-https-proxies-and-socks-with-proxifier).

In order to set up the proxies, you need to buy them. Check [our website](https://anonymous-proxies.net), create an account or log in if you already have one, select the proxies that you want and add them to cart, check out, choose a payment plan and proceed to payment. 

[Download Proxifier](http://proxifier.com), which is available on both Mac OS and Windows and run it. 

Go to Profile -> Proxy Servers 

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

Press the Add button
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zsf8c8lm2lvug54w1abb.jpg)

Fill in the address and the port of the proxy, select the Protocol (HTTPS, SOCKS  Version 4, SOCKS Version 5), Enable Authentication and fill your username and password, then press ok. 

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

Now your proxy will work as default on any network applications or browsers that you are using, while keeping your information safe. 

With both HTTPS proxies or SOCKS you will go through the same procedure.

While using free proxies the chances of them not to not properly are high, this is why you should buy premium Proxies. Have a quick look on [our website](https://anonymous-proxies.net), we provide high quality dedicated or shared, HTTP or SOCKS version 5, Datacenter or Residential Proxies.
a += b is not the same as a = a + b
Tags: python
Published: 2020-12-02 11:11:33

In python `a += b` is not equivalent as `a = a + b`. They do not behave the same always. Consider the following:

```python
>>> a = [1, 2, 3]
>>> b = a
>>> a += [4, 5, 6]
>>> a
[1, 2, 3, 4, 5, 6]
>>> b
[1, 2, 3, 4, 5, 6]
```
```python
>>> a = [1, 2, 3]
>>> b = a
>>> a = a + [4, 5, 6]
>>> a
[1, 2, 3, 4, 5, 6]
>>> b
[1, 2, 3]
```
What happend here:
* `a += b` modified the list in-place. That means it extended _**a**_ such that _**a**_ and _**b**_ had reference to the same list.
* `a = a + b` expression created a new list and changed _**a**_ 's reference to that new list. And _**b**_ refered to the old list.
Why it happened? Here comes how python implements `+` and `+=` operators. When you use `+` operator python calls the `__add__` special method. On the other hand `+=` operator calls  the `__iadd__` special method, and if `__iadd__` is not available only then it uses `__add__` method. See below:

```python
class MyList (list):
    def __add__ (self, other):
        print ("__add__ has been called")
        return super (MyList, self).__add__ (other)
    
    def __iadd__ (self, other):
        print ("__iadd__ has been called")
        return super (MyList, self).__iadd__ (other)
```

Now, run the below code:
```python
a = MyList ([1, 2, 3])
b = a
a = a + b
```
It gives following output:
```
__add__ has been called
```

Now, run the below code:
```python
a = MyList ([1, 2, 3])
b = a
a += b
```
It gives the following output:
```
__iadd__ has been called
```

The `__iadd__` special method is for an inplace addition. That is it mutates the object that it acts on (in `a += b` `__iadd__` mutates _**a**_). On the other hand,`__add__` method returns a new object (in `a = a + b` we assigned `__add__`'s returned object into _**a**_).

`__iadd__` is only available for mutable types. That's why for immutable types like integers (`int`), strings (`str`) and `tuple` both `+` and `+=` are equivalent as they both calles `__add__`. And this is what lets you use `+=` on immutable types.

Now, let's see another difference between `+` and `+=`. Consider the following:

```python
>>> a = [1, 2, 3]
>>> b = "hello"
>>> a + b
TypeError: can only concatenate list (not "str") to list
>>> a += b
>>> a
[1, 2, 3, 'h', 'e', 'l', 'l', 'o']
```

Here `a + b` gives `TypeError`. Because `+` operator is symmetrical. So, we can't add a `list` and `str`. But `+=` operator is obviously not symmetrical. It is equivalent to `list.extend`, which iterates over the second operand. See below:

```python
class MyStr (str):
    def __iter__ (self):
        print ("__iter__ has been called")
        return super (MyStr, self).__iter__()

a = [1, 2, 3]
b = "hello"
a += b
```
It gives following output:
```
__iter__ has been called
```

So, for types that support both `__add__` and `__iadd__` you therefore have to be careful which one you use.
.Net Core, Single File Executable
Tags: netcore, csharp
Published: 2020-12-02 10:55:49

Look at this nice article, and how to distribute a single Trimmed Self-Contained Single Executable in .NET Core 3.0.

[Create a Trimmed Self-Contained Single Executable in .NET Core 3.0](https://www.talkingdotnet.com/create-trimmed-self-contained-executable-in-net-core-3-0/)
Solving Perl Weekly Challenge 089 -- GCD Sum and the magic square.
Tags: raku
Published: 2020-12-02 10:55:34

---
tags: raku
published: true
title: Solving Perl Weekly Challenge 089 -- GCD Sum and the magic square.
---

We have 2 math puzzles from [Perl Weekly Challenge 089][pwc-089] this time around. Their solution look rather naive.


## TASK #1 › GCD Sum

Submitted by: Mohammad S Anwar

You are given a positive integer $N.

Write a script to sum GCD of all possible unique pairs between 1 and $N.

Example 1:

Input: 3
Output: 3

gcd(1,2) + gcd(1,3) + gcd(2,3)

Example 2:

Input: 4
Output: 7

gcd(1,2) + gcd(1,3) + gcd(1,4) + gcd(2,3) + gcd(2,4) + gcd(3,4)

--------

Quite literally, we could translate the question to Raku code and get a naive solution:

```Raku
(1..$N).combinations(2).map(-> ($a, $b) { $a gcd $b }).sum()
```

# TASK #2 › Magical Matrix

Submitted by: Mohammad S Anwar

Write a script to display matrix as below with numbers 1 - 9. Please make sure numbers
are used once.

    [ a b c ]
    [ d e f ]
    [ g h i ]

So that it satisfies the following:

    a + b + c = 15
    d + e + f = 15
    g + h + i = 15
    a + d + g = 15
    b + e + h = 15
    c + f + i = 15
    a + e + i = 15
    c + e + g = 15

--------

Without doing any prior analysis of 3x3 magic square, a brute-force searching apporach would db to generate all permutations of the list of 1..9, then remove those that violates the 8 conditions above:

```Raku
(1..9).permutations.grep(
    -> ($a, $b, $c, $d, $e, $f, $g, $h, $i) {
        all(
            $a + $b + $c == 15,
            $d + $e + $f == 15,
            $g + $h + $i == 15,
            $a + $d + $g == 15,
            $b + $e + $h == 15,
            $c + $f + $i == 15,
            $a + $e + $i == 15,
            $c + $e + $g == 15,
        )
    }
)
```

The [`.permutations`][method-permutations] subroutine produce an iterator that give us all possible permutations, and since we are permutating 9 numbers, we let the `grep` afterward takes 9 separate parameters, which then makes it easier to just copy those conditions from the body of the question.

[pwc-089]: https://perlweeklychallenge.org/blog/perl-weekly-challenge-089/
[method-permutations]: https://docs.raku.org/routine/permutations#(List)_routine_permutations


----

本文為 [解 Perl Weekly Challenge 089 -- 公因數之和與魔方][gugod-blog-pwc-089] 英文版

[gugod-blog-pwc-089]: https://gugod.org/2020/12/pwc-089/
Pass: the simple CLI password manager
Tags: tooling, tutorial, security
Published: 2020-12-02 10:52:54

Do you use a password manager? If not, you should. But which one should you choose? There are a lot out there and a lot of good free ones such as the Keepass (X, XC etc.) or paying versions such as LastPass (*edit: free for individuals*) or OnePassword. This WIRED [article](https://www.wired.com/story/best-password-managers/) lists some for you. 

Today, I'd like to talk about a really cool, simple, perfect for the CLI dwellers like us, password manager: [pass](https://www.passwordstore.org/)

# Less is more

Pass is a CLI password manager, this means that unless you use one of the [available](https://www.passwordstore.org/#other) interfaces, you will only be working in your terminal. 

Pass works by using a GPG key to encrypt each passwords and stores the results in a Git repository. This means that backups are insanely easy: `git push origin main` and that's it!

In the past years, I have been using Keepass and KeepassXC a lot. I did like the way they worked but I was sometimes annoyed to keep a window open all the time for my passwords. Also, used to break my computers very often, I lost a certain amount of passwords over the time. 

Pass has the usability of any CLI tool and uses the basics of Bash [commands](https://git.zx2c4.com/password-store/about/#COMMANDS) to manage your passwords. It's a dead simple encrypted folder and I have to say that is all I need. 

# Demo

The demo was made on a Linux with [gpg-agent](https://www.gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html) installed.

You would initialize your password repo like this (default location:  `~/.password-store`):

```sh
pass init yourgpgkeyID@securethings.com
```

Then, after signing up for your favorite online service, you can generate or insert a new password:

```sh
pass insert # then type your password
pass generate -c Newsletters/awesomeThing 32 # to generate a 32 random password and copy it to the clipboard
```

After, a couple of days later you can search for your password:

```sh
pass search awesomeThing # and when you found the folder then:
pass -c Newsletters/awesomeThing
# here you will need to decrypt your GPG key
```

Now let's say you want to back all of this on a private Git repo (Github, Gitea, Gitlab...):

```sh
pass git remote add origin URL
pass git push 
```
Each pass command will run the `add` and `commit` for you, so you will only have to `push` to your repo. 

*Keep in mind that your GPG key is not backed up with your repo. You need to do to that separately.*

Do you need to remove a password?

```sh
pass rm Newsletters/awesomeThing
```

Do you need to move a password?

```sh
pass mv Newsletters/awesomeThing Videos/awesomeThing
```

You can also `edit`, `show` and `cp` the passwords. 

Ready to make the move? Check out those [import scripts](https://www.passwordstore.org/#other) on the official website!

Are you ready to use pass? What's your favorite password manager?