megacolorboy

Abdush Shakoor's Weblog

Writings, experiments & ideas.

Launched a microblog site

A tiny experiment to see how it could improve my writing productivity.

Ever since I've been working from home (due to COVID19 pandemic), I hardly find time to write any posts on my blog and I felt that it was counter-productive whenever I wanted to start a new one after a long time.

And then, I came across this trend of TIL a.k.a Today I Learned on GitHub and one of my favorite ones is written by Josh Branchaud.

What is this about?

Unlike writing long articles, which takes a lot of time, I believe that by having a microblog and writing short articles could help improve my productivity in writing.

So, I thought of sharing whatever I have learned on a day-to-day basis and accumulate this knowledge in a "repository" where anyone could learn from, thus is why I started this microblog. Besides, as of writing this article, I wrote 25 short articles in a month.

What kind of articles can we expect?

It'd be wonderful to say that I can talk about anything over here but currently, I'm restricting it to Computer Science, Mathematics, Software Engineering and Digital Design.

So what about your main blog?

Oh, I'm not ignoring it! The main blog will be there but now that I have segregated it, it'll allow me to take some time to plan and write content-heavy articles. There'll be more articles coming in a few months time.

Click here to view my microblog and let me know what you think about it! 😄

Stay tuned for more!

Select all elements except the current element

If you don't want the current element to be selected in an array of elements that belongs to same class or type, just use the .not() method like the example below:

$(".btn").click(function(){
    $(".btn").not(this).text('selected');
});

The above code will change the text for all buttons except the current element.

Extract a specific folder from a zipped archive

First, you need to view what's inside of the .zip archive:

unzip -v archive.zip

Once, you've found the folder you wanted to extract, just type this:

unzip archive.zip "folder_to_extract/*" -d .

Remove patterns from multiple files

If you wanted to remove a specific pattern in a list of files, like the ones below:

23_2020_03_01_article-three.md
22_2020_02_01_article-two.md
21_2020_01_01_article-one.md

You can simply do that using Regular Expressions and the rename tool:

rename 's/[0-9]+_[0-9]+_[0-9]+_[0-9]+_//' *.md

Now, the desired output should look like this:

article-three.md
article-two.md
article-one.md

This should come in handy if you're lazy to rename each file manually! :)

Rename extensions of multiple files

In this example, we're going to change a list of .txt files to .md files:

#!/bin/bash

shopt -s nullglob
files=($(ls -v *.txt))

for file in "${files[@]}"
do
    mv ${file} ${file}.md
done

s You can use modify this script to rename any extension you want.

Create a symbolic storage link

When using Laravel, the public directory is used for files that are publicly accessible. By default, it's stored in local and often stored in this storage/app/public directory. You can make it easily accessible by using the following command:

php artisan storage:link

Once, it has been created, you can use access those files using the public_path or asset methods.

<?php
echo public_path('images/sample_1.jpg');
echo asset('images/sample_2.jpg');
?>

Including and excluding files in zip

When zipping a directory or a bunch of files, there'll be a lot of stuff that you want to include and exclude.

To exclude a file:

zip -r files.zip . -x file_1 file_2

Alternatively, you can choose to include files:

zip -r files.zip . -i file_1 file_2

Find a file by extension

This comes in handy whenever I want to look for files that exists with a specific extension in a computer or server:

find . -name "*.ext"

In addition, sometimes, you might want to look for a bunch of files with a specific extension but with matching keywords:

find .name "*.ext" | grep "keyword"

Hope you found this helpful!