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.



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

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


A Job is doing something.

  • RegisterUser
  • UpdateProfile
  • PublishArticle
  • SendReminderEmail


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());

Example of not mass assignment:

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

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

     * 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


Laravel Policy

php artisan make:policy PostPolicy --model=Post

in AuthServiceProvider

protected $policies = [
	Post::class => PostPolicy::class,

in PostPolicy

public function update(User $user, Post $post)
	if (Auth::user()->hasRole('admin')) {
		return true;
	return $user->id === $post-> user_id;

implement in controller

$post = Post::find($id);
$this->authorize('update', $post);

Laravel 8

laravel 8 class controller not found


protected $namespace = 'App\Http\Controllers';


The GET method is not supported for this route - All method is always either GET or POST, Update in file - settings



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'


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;

Client intended to send too large body

http {
    . . .
    client_max_body_size 64M;
    . . .

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;


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.


cannot fit requested classes in a single dex file

implementation '

Then in defaultConfig()

multiDexEnabled true


Incorrect string value: '\xC2\x80\xC2\x9355

    COLLATE utf8mb4_unicode_ci;

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';



can't connect to database server workbench ubuntu 20.04

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

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

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

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

Purging Binary Log

When I failed to import some big imports because there's no more storage, turns out when importing it saves the imports to mysql-bin

MariaDB [(none)]> SHOW BINARY LOGS;
| Log_name         | File_size  |
| mysql-bin.000077 |    2815113 |
| mysql-bin.000078 |        365 |
| mysql-bin.000079 |  296244824 |
| mysql-bin.000080 | 1074274682 |
| mysql-bin.000081 |  127711613 |
| mysql-bin.000082 |        365 |
| mysql-bin.000083 |        342 |
7 rows in set (0.000 sec)

MariaDB [(none)]> PURGE BINARY LOGS BEFORE '2021-03-12 23:00:00';

Mysql Workbench - now() is not working

Use \func in the field

\func now()

Use where on update

db=# UPDATE users SET email = lower(email);
UPDATE 1010000
Time: 1583.935 ms (00:01.584)

db=# UPDATE users SET email = lower(email)
db-# WHERE email != lower(email);
UPDATE 10000
Time: 299.470 ms

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

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

Main setting for Ubuntu 20.04 not working after upgrade

sudo apt-get update
sudo apt-get install --reinstall gnome-control-center


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 :

Lighthouse And EC2 are different parts

I have lighthouse server and was wondering if the server I used in lighthouse were actually ec2 but packed, turns out it's NOT.


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.*

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


Create our own global js

Use plugins, below is example of custom function

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

then add to plugins

plugins: [


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

Make default PHP version

sudo update-alternatives --set php /usr/bin/php7.4

The uploaded file exceeds the upload_max_filesize directive in php.ini.

upload_max_filesize = 256MB
post_max_size = 256M
memory_limit = 512M
max_execution_time = 180


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 | sudo apt-key add -
echo "deb 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


How to reset master to empty commit

git checkout -b my-feature-1 master
git branch -D master
git checkout --orphan master
git reset --hard
git commit --allow-empty -m "Initial commit"
git push origin master:master --force-with-lease

Set password remember for 1 day

git config --global credential.helper "cache --timeout=86400




var count int64

query := p.db.Model(&model.Product{})


var productIds []int
query := p.db.Model(&model.Product{})
query.Pluck("ID", &productIds)

missing go.sum entry for module providing package

go mod tidy

Go not recognizing Goose installed

the installation states only for $PATH, but it also needs $GOPATH also need to set if you have another directory.

export GOPATH=$HOME/codespace/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin


Custom post type

Custom Post Type UI
You can create CRUD with this plugins
Custom Post Type Permalinks
To add category before post slug

Custom Post Type With prefix blog

If you are using custom post types on your site, you need to make sure that ‘rewrite with front’ is disabled for each of your post types. Otherwise your custom post type URLs will also get/blog/ in front of them.

If you use a plugin to register your post types, look for the ‘Rewrite‘ option, and make sure that ‘With Front‘ is unchecked. After saving your settings, go back to the Permalinks Settings and click ‘Save Changes’ (this is necessary so that the new links are generated).

Adding Breadcrumps

if ( function_exists('yoast_breadcrumb') ) {
  yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );

Getting a post by slug

$args = array(
'name'        => $uri_segments[2]
$my_posts = get_posts($args);


Stuck in fullscreen

wmctrl -l
wmctrl -r "Spotify" -b toggle,minimize