Inspired from Github Repo / Reddit, this will be a listing what I learned if it's short I will be listing it here but if it's long I'll make it a post.

Laravel

Voyager

Overwriting certain piece of function

Go to vendor file and copy the exact same file from the same directory, if its controller then copy the controller then put it in your controller if model then do the same.
Don't forget to change the namespace and extend it to \TCG\Voyager\Http\Controllers\Controller then in route copy the same specific route then modify the url.

Default Folder and Permission Laravel

cd [..LARAVEL PROJECT ROOT]
sudo find . -type f -exec chmod 644 {} \;
sudo find . -type d -exec chmod 755 {} \;
sudo chmod -R 777 ./storage
sudo chmod -R 777 ./bootstrap/cache/

Rails

ActiveAdmin

Add Custom filter with custom select2

ActiveAdmin comes with default filter with all fields in it but sometimes I need to custom it a bit and when it comes to larger database and need to find the specific filter I need some custom select2 to populate and when searching through dropdown it will find the keyword. this comes with a cost of slowness when it comes to larger database so becareful.

In the Model

filter :campaign_id, as: :searchable_select, collection: -> { Campaign.pluck(:name, :id) }

Don't forget to install this gem for select2

gem 'activeadmin-searchable_select'

NGINX

Add Trailing Slash

I've found out there's 2 way to do this, the first one is to add in the server block section and somehow it works, but there are times when there's a blog on the public block which will messup the blog (wordpress), The other way is to put in the \.php$ block, I've seen it work but when it doesn't work try the solution 2.

Solution 1:

rewrite ^/(.*)/$ /$1 permanent;

Solution 2:

location ~ ^([^.\?]*[^/])$ {
   try_files                 $uri @addslash;
}

location @addslash {
   return                    301 $uri/;
}

Removing Trailing Slash

I learned that in try_files has a role on redirecting too so in below if the second $uri is $uri/ that means you want to redirect that to trailing slash.

location / {
                rewrite ^/(.*)/$ /$1 permanent;
                try_files $uri $uri /index.php?$query_string;
        }

Nuxt Nginx Config

Was new to this, then I found out how to serve the server that points to localhost:3000

location / {
                proxy_pass http://localhost:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

Install PM2 to make yarn start as daemon

sudo npm install pm2 -g

# to start yarn start
pm2 start yarn --interpreter bash --name api -- start

Setting Max-Age Expiry Header

location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
expires max;
}

Gzip Pre-Compression

./configure --with-http_gzip_static_module
make && make install

http {
. . .
gzip_static on;
gzip_http_version 1.1;
..
}

Removing Whitespace

location / {
    strip on;
}

Etags for Static Content

location / {
etag on;
...
}

BASH

Alias

The fastest way to find which folder / file that takes too much space. Add this to your alias

alias ducks='du -cks * | sort -rn | head'

Yarn

Yarn install command error No such file or directory: 'install'

At first I downloaded the main repo and it shows error -

sudo apt remove cmdtest
sudo apt remove yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update  
sudo apt-get install yarn

SEO

Schema Org

I never knew what breadcrump for until I saw the documentation and understood a bit about schema. What I learned was every page need an organization, SiteNavigationElement and BreadCrumpList schema.

Rendering Smartphone

Sometimes we just put css/style.css or js/script.js, to remind myself this need to be fullpath with the domain so the bot crawler see what user see. To test this just copy paste your html to html generator what does it looks like.

Android

cannot fit requested classes in a single dex file

implementation 'com.android.support:multidex:1.0.3

Then in defaultConfig()

multiDexEnabled true

MYSQL

Export mysql using gzip

mysqldump -u root -p databasename | gzip -9 > database.sql.gz

Import mysql using zcat

I thought this would be using mysqldump too but nope...

zcat database.sql.gz | mysql -u username -p databasename