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/

Difference between Job and Event

Job

A Job is doing something.

  • RegisterUser
  • UpdateProfile
  • PublishArticle
  • SendReminderEmail

Event

An Event occurs when something happens/happened.

You can think of it as an Event occurs throughout different stages of a Job. In this case, and in most cases, an Event is defined in the past tense.

  • UserHasRegistered
  • ProfileWasUpdated
  • ArticleWasPublished
  • RemiderEmailWasSent

Learn that can't use mutators and accessors when using mass assignment

Example of mass assignment:

$user = new User(Input::all());
$user->save();

Example of not mass assignment:

$user = new User();
$user->name = 'steve';
$user->email = '[email protected]';
$user->password = Hash::make('123');
$user->save();

when using mass assignment, then you can't use mutators and accessors

/** ACCESSOR
     * Get the post title.
     *
     * @param  string  $value
     * @return string
     */
    public function getNameAttribute($value)
    {
        return ucfirst($value);
    }
     
    /** MUTATOR
     * Set the post title.
     *
     * @param  string  $value
     * @return string
     */
    public function setNameAttribute($value)
    {
        $this->attributes['name'] = strtolower($value);
    }

To show error in test

$this->withoutExceptionHandling()

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;
...
}

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

Unknown collation: ‘utf8mb4_unicode_520_ci’

sed -i 's/utf8mb4_unicode_520_ci/utf8mb4_unicode_ci/g' file.sql

Fatal error: Can't open and lock privilege tables: Table 'mysql.db' doesn't exist

sudo mysql_install_db --user=mysql --ldata=/var/lib/mysql

can't login to workbench because need sudo

create a user

CREATE USER 'madindo'@'localhost' IDENTIFIED BY 'madindo123';

GRANT ALL PRIVILEGES ON *.* TO 'madindo'@'localhost' WITH GRANT OPTION;

FLUSH PRIVILEGES;

Downgrade from mysql 8 to 5.5 in ubuntu 20.04

Say no more, I've tried many ways and failed but the last one worked out.

# backup
mysqldump -u root -p --add-drop-table --routines --events --all-databases --force > mysql80.sql

sudo apt-get remove --purge mysql-\* -y
sudo apt-get autoremove -y

wget http://repo.mysql.com/mysql-apt-config_0.8.10-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb
configure to bionic and mysql5.7
sudo apt-get update

sudo apt install -f mysql-client=5.7.32-1ubuntu18.04
sudo apt install -f mysql-community-server=5.7.32-1ubuntu18.04

sudo apt install -f mysql-client=5.7.32-1ubuntu18.04 mysql-community-server=5.7.32-1ubuntu18.04 mysql-server=5.7.32-1ubuntu18.04

The steps above failed, I think I was close but failed at install mysql-community-server, but below doesn't fail me

https://gist.github.com/ahmadhasankhan/48fc9fc9a19807daef1622751a56884b

Update (25 nov 2020) : don't even think on using 5.5 on modern application... hell breaks lose


Ubuntu 20.04

an apparmor policy prevents this sender

  1. Go to Ubuntu Software
  2. Search for the app throwing the error
  3. Click Permissions
  4. Turn ON Read, add, change, or remove saved passwords

After install workbench my text is all squared

So I updated my ubuntu from 18.14 to 20.04, I noticed that my workbench is gone so I installed it from snap after installing all the query and rows is squared

sudo apt --fix-broken install

Wifi adapter is not found in ubuntu 20.04

This is so weird i happened to stumble this incident where the wifi isn't there, just out of the blue. After look around this post helped me

https://askubuntu.com/questions/1249907/ubuntu-20-04-no-wifi-adapter-found-dell

Well my machine is ASUS but still works, just followed all the steps

lspci -knn | grep Net -A3; rfkill list
# shows the specs hard and soft
sudo modprobe wl
# modprobe: FATAL: Module wl not found in directory /lib/modules/5.4.0-37-generic
sudo apt install --reinstall bcmwl-kernel-source
# now this is the solution and dont forget to restart

AWS

IAM User Accessing to Billing

Had trouble on accessing billing as an IAM, Already added an admin group with full access and Billing permission still won't work.

Solution :


Cloudflare

Redirecting the right way using Page Rule

if matches url always use * because if you don't add it it will only match the domain url not the path.

https://www.domain.com/*

when using 301 permanent redirect use $1 to pass the asterisk

https://www.domain.com/$1

Nuxt

Create our own global js

Use plugins, below is example of custom function

import Vue from 'vue'
Vue.mixin({
  methods: {
    truncate (str, noWords) {
      return str.split(' ').splice(0, noWords).join(' ')
    }
  }
})

then add to plugins

plugins: [
    '~/plugins/script',
  ],

Server

Cron - automatically renew certbot

15 1 * * * /usr/bin/certbot renew --noninteractive --quiet --renew-hook "/bin/systemctl reload nginx"

Find folder / file that takes too much space

Add this to your alias

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

Running Composer install to specific version of PHP

lets say you have php version of 7.0 7.1 7.2 7.3 but the composer but default is 7.3 and can't run composer using 7.2

#find where is php
which php
#find if there's another version php
/usr/bin/php7.2 -v
#use this to run composer
/usr/bin/php7.2 composer install

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

Node Sass

(25 nov 2020)

Installing node-sass in ubuntu 20.04

I don't know why unsafe-perm but it'll install...

sudo npm install -g --unsafe-perm node-sass

Example of using Node-sass

node-sass --watch public/frontend/stylesheets/sass/main.scss -o public/frontend/stylesheets/css