Skip to content

Instantly share code, notes, and snippets.

View mknparreira's full-sized avatar

Maikon Parreira mknparreira

View GitHub Profile
@mknparreira
mknparreira / mysql-handling-errors-with-laravel.md
Created August 1, 2024 10:22
MySQL | Handling errors with laravel
  Error: MYSQL | SQLSTATE [42000]: Syntax error or access violation: 1118 Row size too large (> 8126)

This error may occur when running the command: php php artisan db:seed resulting on the following message:

 SQLSTATE[42000]: Syntax error or access violation: 1118 Row size too large (> 8126). 
Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. 
@mknparreira
mknparreira / javascript-10-useful-one-liners-that-you-should-know.md
Created August 12, 2021 22:41
Javascript | 10 Useful JavaScript One-Liners That You Should Know

1. Random ID Generation

const a = Math.random().toString(36).substring(2);
console.log(a)
----------------------------
72pklaoe38u

2. Generating a Random Number Within a Range

@mknparreira
mknparreira / postegre-auto-incremeting-primary-key-existing-table.md
Last active August 12, 2021 22:00
PostgreSQL | Add an auto-incrementing primary key to an existing table

MORDERN VERSIONS

   ALTER TABLE test1 ADD COLUMN id SERIAL PRIMARY KEY;

OLD VERSIONS

 ALTER TABLE test1 ADD COLUMN id INTEGER;
  CREATE SEQUENCE test_id_seq OWNED BY test1.id;
 ALTER TABLE test ALTER COLUMN id SET DEFAULT nextval('test_id_seq');
@mknparreira
mknparreira / terminal-discover-what-is-running-on-some-port.md
Last active August 12, 2021 22:01
Terminal | How to discover what is running on the some port

If you want to check if something is running at some port, you may run the following command::

Get-Process -Id (Get-NetTCPConnection -LocalPort 3306).OwningProcess

If an error is returned, then, there is nothing to run on the given port. Otherwise, it displays what the program/service is running.

@mknparreira
mknparreira / golang-understanding-pointers-once-and-for-all.md
Last active August 12, 2021 22:05
Golang | Understanding pointers once and for all
package main

import (
	"fmt"
)

func main() {
	
@mknparreira
mknparreira / golang-problem.md
Last active August 12, 2021 22:05
Golang | This is an simple exemple of Golang problem
package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, playground")
@mknparreira
mknparreira / php-array-pagination.md
Last active August 12, 2021 22:06
PHP | Emulate an pagination using arrays
$page = ! empty( $_GET['page'] ) ? (int) $_GET['page'] : 1;
$total = count( $yourDataArray ); //total items in array    
$limit = 20; //per page    
$totalPages = ceil( $total/ $limit ); //calculate total pages
$page = max($page, 1); //get 1 page when $_GET['page'] <= 0
$page = min($page, $totalPages); //get last page when $_GET['page'] > $totalPages
$offset = ($page - 1) * $limit;
if( $offset &lt; 0 ) $offset = 0;
@mknparreira
mknparreira / laravel-check-if-update-or-create-perfomed-update.md
Last active August 12, 2021 22:07
Laravel | check if updateOrCreate performed update
$tourist = Tourist::updateOrCreate([...]);

if(!$tourist->wasRecentlyCreated && $tourist->wasChanged()){
    // updateOrCreate performed an update
}

if(!$tourist->wasRecentlyCreated && !$tourist->wasChanged()){
    // updateOrCreate performed nothing, row did not change
}
@mknparreira
mknparreira / postegre-row-to-json-example.md
Last active August 12, 2021 22:08
PostegreSQL | row_to_json example
SELECT json_agg(row_to_json(ROW)) AS treeeeeee 
FROM (
   SELECT * FROM table_name					
) row
@mknparreira
mknparreira / postegre-row-to-json-with-nested-joins.md
Last active August 12, 2021 22:09
PostgreSQL | 9.2 row_to_json() with nested joins
SELECT
        json_build_object(
                'id', u.id,
                'name', u.name,
                'email', u.email,
                'user_role_id', u.user_role_id,
                'user_role', json_build_object(
 'id', ur.id,