Mengenal Chunk dan Cursor pada Laravel – Penting untuk performance

Function chunk dan cursor ini digunakan untuk get data besar, untuk meminimalkan penggunakan memory ram

Perbandingan performance :

We have a comparison: chunk() vs cursor()

  • cursor(): High Speed
  • chunk(): Constant Memory Usage

10,000 records:

+-------------+-----------+------------+
|             | Time(sec) | Memory(MB) |
+-------------+-----------+------------+
| get()       |      0.17 |         22 |
| chunk(100)  |      0.38 |         10 |
| chunk(1000) |      0.17 |         12 |
| cursor()    |      0.16 |         14 |
+-------------+-----------+------------+

100,000 records:

+--------------+------------+------------+
|              | Time(sec)  | Memory(MB) |
+--------------+------------+------------+
| get()        |        0.8 |     132    |
| chunk(100)   |       19.9 |      10    |
| chunk(1000)  |        2.3 |      12    |
| chunk(10000) |        1.1 |      34    |
| cursor()     |        0.5 |      45    |
+--------------+------------+------------+
  • TestData: users table of Laravel default migration
  • Homestead 0.5.0
  • PHP 7.0.12
  • MySQL 5.7.16
  • Laravel 5.3.22

 

Secara kesimpulan seperti ini :

Therefore, when processing a large amount of data, it seems better to use cursor () when speed is prioritized, and chunk () when memory usage does not exceed a certain value.

 

 

https://stackoverflow.com/questions/45464676/what-is-the-difference-between-laravel-cursor-and-laravel-chunk-method

https://qiita-com.translate.goog/ryo511/items/ebcd1c1b2ad5addc5c9d?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=nui













Running Gitlab on Local with Gitlab Runner

Install GitLab runner with homebrew
https://docs.gitlab.com/runner/install/osx.html#homebrew-installation-alternative

To install GitLab Runner using Homebrew:

  1. Install GitLab Runner.
    brew install gitlab-runner
  2. Install GitLab Runner as a service and start it.
    brew services start gitlab-runner

GitLab Runner is installed and running.

Add a credential to /Users/muhyusuf/.docker/config.json
untuk bisa akses private registry

{
“auths”: {
“registry.gitlab.com”: {
“username”: “iambbb”,
“password” : “password”
}
},
“credsStore”: “desktop”,
“experimental”: “disabled”,
“stackOrchestrator”: “swarm”,
“currentContext”: “default”
}

running gitlab runner dengan stage pilihan
sudo GitLab-runner exec docker unit_test













Backend Development Curriculum

Backend development involves building and maintaining the server-side of a web application. It involves a wide range of skills and technologies, including programming languages, databases, data structures, design patterns, and deployment strategies.

Here is a list of some common topics that may be included in a backend curriculum:

  • Programming languages: Golang is a popular choice for backend development due to its performance and scalability. It is important to understand concepts such as interfaces, pointers, and unit testing in order to write efficient and reliable code in Golang.
  • Concurrency: Concurrency is the ability to run multiple tasks simultaneously. In backend development, this can involve using threads, goroutines, and channels to manage concurrent processes. It is also important to understand concepts such as mutexes, race conditions, and deadlocks in order to avoid common pitfalls when working with concurrency.
  • Data structures: Data structures are used to store and organize data in an efficient manner. Some common data structures used in backend development include hashmaps, sets, priority queues, and trees.
  • Design patterns: Design patterns are reusable solutions to common programming problems. Some design patterns that are commonly used in backend development include builder, dependency injection, template pattern, middleware, adapter, prototype, proxy, composite, command, and observer.
  • Databases: Databases are used to store and retrieve data for a web application. Some common database technologies used in backend development include MySQL, Redis, and Big Query. It is important to understand concepts such as B-Trees, indexing, the CAP theorem, and table normalization in order to design efficient and scalable database systems.
  • APIs: APIs (Application Programming Interfaces) are used to communicate between different software systems. Some common API technologies used in backend development include REST APIs and gRPC. It is important to understand tools such as Postman and BloomRPC in order to test and debug API systems.
  • Scaling: As web applications grow, they may need to be scaled in order to handle increased traffic and data. This can involve strategies such as vertical scaling (adding more resources to a single server) or horizontal scaling (adding more servers). Microservices and containerization technologies such as Docker and Kubernetes can also be used to enable scaling.
  • Deployment: Once a web application is developed, it must be deployed in order to be accessed by users. This can involve using Platform-as-a-Service (PaaS) providers such as Heroku or Infrastructure-as-a-Service (IaaS) providers such as Google Cloud Platform.
  • DevOps: DevOps is the practice of combining development and operations in order to deliver software more efficiently. Tools such as Istio, Kibana, and Grafana can be used to enable observability, logging, and monitoring in a backend system.
  • Security: Backend systems must be secure in order to protect sensitive data and prevent attacks. This can involve implementing authentication, authorization, and protection against vulnerabilities such as CSRF, XSS, and race conditions. It is also important to understand basic Linux security and Docker container security in order to secure backend systems.

Here a more:

Golang

  • Interface
  • Pointer
  • Unit Testing
  • Data Structure
  • Callback

Concurency

  • Threads
  • Goroutine
  • Channel
  • Mutex
  • Race Condition
  • Deadlock
  • Delayed Job

 

Data structure

  • Hashmap
  • Set
  • Priority Queue
  • Adjacent List
  • Tree

 

Design pattern

  • Builder
  • Dependency Injection
  • Template Pattern
  • Middleware
  • Adapter
  • Prototype
  • Proxy
  • Composite
  • Command
  • Observer

 

Database

  • BTree
  • Indexing
  • CAP Theorem
  • DB Transaction
  • Table Normalization
  • MySQL
  • Redis
  • Big Query

 

Api

  • REST API
  • gRPC
  • Postman
  • BloomRPC

 

Scalling

  • Vertical vs Horizontal Scaling
  • Microservice
  • Docker
  • Kubernetes

 

Kubernetes

  • Docker Compose
  • Pod
  • Deployment
  • Service
  • Load Balancer

 

Deployment

  • PaaS (Heroku)
  • IaaS (Google Cloud Platform)

 

DevOps

  • Observability: Istio
  • Logging: Kibana
  • Monitoring: Grafana

 

Security

  • Authentication
  • Authorization
  • CSRF
  • XSS
  • Validation
  • Encryption
  • Password
  • Race Condition
  • Linux Basic Security
  • Docker Container Security












PHP versioning di Macbook

PHP is a popular programming language used by many websites and web applications. It is important to keep track of the different versions of PHP as they can affect the compatibility of your code and the functionality of your website. In this article, we will discuss how to manage PHP versioning on a Macbook.

One option for managing PHP versioning on a Macbook is to use the ASDF (Another Version Manager) tool. ASDF allows you to easily switch between different versions of PHP, as well as other languages such as Ruby and Python. To install ASDF, follow the instructions on the ASDF website or refer to the tutorial by Tim Nash.

Another option is to use the PHPBrew tool, which allows you to install and manage multiple versions of PHP on your Macbook. To install PHPBrew, follow the instructions on the PHPBrew website or refer to the tutorial by GetGrav.

Once you have installed either ASDF or PHPBrew, you can easily switch between different versions of PHP by using the appropriate command. For example, with ASDF, you can use the command “asdf global PHP [version]” to switch to a specific version of PHP. With PHPBrew, you can use the command “phpbrew switch [version]” to switch to a specific version of PHP.

It is important to note that you may need to update your Apache configuration in order to use a different version of PHP. This can be done by modifying the “LoadModule” and “AddType” lines in the Apache configuration file. Refer to the Apache documentation or a tutorial such as the one by GetGrav for more information on this process.

In summary, managing PHP versioning on a Macbook can be easily done using tools such as ASDF or PHPBrew. These tools allow you to easily switch between different versions of PHP, ensuring that your code is compatible and your website is functioning properly. Be sure to also update your Apache configuration if necessary in order to use a different version of PHP.

  • https://timnash.co.uk/installing-php-and-other-languages-with-asdf-on-macos-catalina/
  • https://phpbrew.github.io/phpbrew/?fbclid=IwAR0uSnqpi1IYXU_U0NnHjGfDwGmFy5KxPu13WTu_ptBmXqvI2CCiikc28i8
  • https://getgrav.org/blog/macos-monterey-apache-multiple-php-versions?fbclid=IwAR3m86pGoGdrNJRJsfPf8dFUiLz6kibQg0DD5DlJ7A_fA9sztNktz1skg6k












Laradock + mkcert

di folder laradock/certbot/letsencrypt

sudo mkcert -installsudo mkcert dev.jepara.com

edit docker-compose.yml

nginx:build:context: ./nginxargs:- PHP_UPSTREAM_CONTAINER=${NGINX_PHP_UPSTREAM_CONTAINER}- PHP_UPSTREAM_PORT=${NGINX_PHP_UPSTREAM_PORT}- CHANGE_SOURCE=${CHANGE_SOURCE}- http_proxy- https_proxy- no_proxyvolumes:- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}- ${NGINX_HOST_LOG_PATH}:/var/log/nginx- ${NGINX_SITES_PATH}:/etc/nginx/sites-available- ${NGINX_SSL_PATH}:/etc/nginx/ssl- ./data/certbot/certs/:/var/certs- ./certbot/letsencrypt/:/var/www/letsencrypt

edit jepara.conf at nginx/sites

# For https
    listen 443 ssl;
    #listen [::]:443 ssl ipv6only=on;
    ssl_certificate /var/www/letsencrypt/dev.jepara.com.pem;
    ssl_certificate_key /var/www/letsencrypt/dev.jepara.com-key.pem;

setelah itu bisa restart container nginx

docker-compose restart nginx

docker-compose build nginx












Cara install Adonis Js

Framework NodeJs rasa Laravel

Framework ini bisa terbilang sangat baru, dan dibuat sangat penasaran, karna katanya framework ini sangat mirip dengan framework Laravel

Topik kali ini, kita hanya akan melakukan

  • Installing Adonis Js
  • Serve Application

Pertama install dulu AdonisJs cli lewat terminal

npm i -g @adonisjs/cli

kalau sudah berhasil, tinggal bikin applikasi web dari Adonis

adonis new name_application

lalu masuk ke directorynya

dan jalankan applikasi web kita dengan command adonis server — dev

cd name_application
adonis serve --dev

sekarang tinggal buka browser dan akses localhost atau 127.0.0.1 dengan port 3333

http://localhost:3333

Viola, kita sudah berhasil membuat applikasi pertama dengan adonis dan menjalankannya di browser

Struktur Folder

dari struktur foldernya bisa dikatakan sangat mirip dengan laravel

feel like home, buat developer laravel mau mencoba framework NodeJs













Install Yii2 Framework

2 pilihan yang bisa diinstall:

basicadvance

Download from Composer

create-project yiisoft/yii2-app-basic basic 2.0.13

Download file

http://www.yiiframework.com/download/

insert a secret key cookieValidationKey (if it is empty)

bisa ditemukan di

config/web.php

Kalau sudah

Akses ke alamat berikut

localhost/mygreatapp/web
Tampilan awal jika framework Yii2 berhasil diinstall

— PretyURL













Cheat Sheet YII2 Framework

Meta Tag

$this->title = 'Hello View - Demo Meta Tags'; 
$this->registerMetaTag(['name' => 'keywords', 'content' => 'yii, framework, php']); 
$this->registerMetaTag(['name' => 'description', 'content' => 'Belajar yii framework. Dipersembahkan oleh Codepolitan.


Load View

return $this->render(‘greeting’, [‘name’=>$name]);

Prety URL

‘urlManager’ => [
 ‘enablePrettyUrl’ => true,
 ‘showScriptName’ => true,
 ‘enableStrictParsing’ => false,
 ‘rules’ => [
 ],

Map Controller

'controllerMap' => [
        'demo' => 'app\controllers\HelloController'
    ],

Redirect

return $this->redirect('/url');

Enable Rewrite Apache

https://askubuntu.com/questions/48362/how-to-enable-mod-rewrite-in-apache
a2enmod rewrite

CKEDITOR YII

http://www.yiiframework.com/extension/yii2-ckeditor-widget/#hh0
https://stackoverflow.com/questions/30979305/how-to-create-ckeditor-in-yii2
composer require 2amigos/yii2-ckeditor-widget












Polymorph Type harusnya menggunakan Int

sekarang penggunakan polymorph laravel, untuk type pasti berbentuk string

untuk indexing string emang mengurangi performance database itu sendiri

 

seperti sumber dari twitter berikut













Contoh Konfigurasi Envoy untuk Proyek Laravel

Envoy adalah alat yang dikembangkan oleh Laravel yang memungkinkan Anda menjalankan perintah server langsung dari aplikasi Laravel Anda. Ini sangat berguna ketika Anda ingin menjalankan tugas-tugas seperti deployment atau migrasi database tanpa harus menggunakan ssh ke server.

Untuk menggunakan Envoy, Anda harus menambahkan file bernama Envoy.blade.php

Berikut adalah contoh konfigurasi Envoy untuk proyek Laravel:

@servers(['web' => '[email protected]'])

@task('deploy', ['on' => 'web'])
cd /var/www/my-project
git pull origin master
php artisan migrate
@endtask

@task('rollback', ['on' => 'web'])
cd /var/www/my-project
git revert HEAD
php artisan migrate:rollback
@endtask

Di sini, kita telah menentukan server dengan nama web yang diakses melalui user user dan IP 192.168.10.10. Kemudian, kita telah mendefinisikan dua tugas, yaitu deploy dan rollback. Tugas deploy akan menjalankan perintah git pull untuk mengambil revisi terbaru dari repository, kemudian menjalankan perintah php artisan migrate untuk menjalankan migrasi database. Tugas rollback akan menjalankan perintah git revert untuk mengembalikan revisi sebelumnya, kemudian menjalankan perintah php artisan migrate:rollback untuk mengembalikan database ke revisi sebelumnya.

Untuk menjalankan tugas ini, Anda hanya perlu menjalankan perintah envoy run deploy atau envoy run rollback di terminal. Envoy akan mengakses server yang telah ditentukan dan menjalankan perintah-perintah yang telah ditentukan di file Envoy.blade.php.

Dengan menggunakan Envoy, Anda dapat dengan mudah menjalankan perintah server dari aplikasi Laravel Anda, sehingga proses deployment atau migrasi database menjadi lebih mudah.

Berikut contoh konfigurasi Envoy yang lain:

@setup
$__container->servers([
    'staging' => 'user@ip_address',
    'production' => ['user@ip_address -p 8288'],
]);
@endsetup

@setup
    $repository = '[email protected]:username/awesome_project_ever.git';
    $releases_dir = '/var/www/html/app/awesome_project_ever/releases';
    $app_dir = '/var/www/html/app/awesome_project_ever';
    $release = date('YmdHis');
    $new_release_dir = $releases_dir .'/'. $release;
    $branch = isset($branch) ? $branch : "master";
    if($server == "staging"){
        $branch = "staging";
    }
@endsetup

@story('deploy',['on' => $server,'parallel' => true])
    clone_repository
    run_composer
    update_symlinks
    deployment_migrate
    deployment_cache
    clean_old_releases
    set_permission_folder
    say_finished
@endstory

@task('clone_repository')
    echo 'Cloning repository'
    [ -d {{ $releases_dir }} ] || mkdir {{ $releases_dir }}
    git clone --depth 1 {{ $repository }} --branch={{ $branch }} {{ $new_release_dir }}
@endtask

@task('run_composer')
    echo "Starting deployment ({{ $release }})"
    cd {{ $new_release_dir }}
    composer install --prefer-dist --no-scripts -q -o
@endtask

@task('update_symlinks')
    echo "Linking storage directory"
    cp -R {{ $new_release_dir }}/storage {{ $app_dir }}
    rm -rf {{ $new_release_dir }}/storage
    ln -nfs {{ $app_dir }}/storage {{ $new_release_dir }}/storage

    cp -R {{ $new_release_dir }}/public {{ $app_dir }}
    rm -rf {{ $new_release_dir }}/public/images
    ln -nfs {{ $app_dir }}/public/images {{ $new_release_dir }}/public/images

    echo 'Linking .env file'
    ln -nfs {{ $app_dir }}/.env {{ $new_release_dir }}/.env

    echo 'Linking current release'
    ln -nfs {{ $new_release_dir }} {{ $app_dir }}/current
@endtask

@task('deployment_migrate')
    echo "Migrating..."
    php {{ $new_release_dir }}/artisan migrate --force --no-interaction
@endtask

@task('deployment_cache')
    echo "clearing cache..."
    php {{ $new_release_dir }}/artisan cache:clear --quiet
    php {{ $new_release_dir }}/artisan config:clear
    echo "Cache cleared"
@endtask

@task('clean_old_releases')
  echo "Cleaning old releases ..."
  rm -rf `ls -dt {{ $app_dir }}/releases/* | tail -n +4`
@endtask

@task('set_permission_folder')
    echo "Set permission folder"
    cd {{ $app_dir }}
    sudo chgrp -R www-data storage public
    sudo chmod -R ug+rwx storage public

    cd {{ $app_dir }}/current
    sudo chgrp -R www-data bootstrap/cache
    sudo chmod -R ug+rwx bootstrap/cache
@endtask


@finished
    @slack('https://hooks.slack.com/services/(Kode)', '#gitlab-activities', "Deployed {$server}")
@endfinished

@task('say_finished')
    echo "Finished..."
@endtask



{{--

create .env
create folder storage
create folder public/images

How to run : 
if staging
envoy run deploy --server=staging

if production
envoy run deploy --server=production

--}}

 

 

 













Using Blade Formatter to Automatically Format All Blade Files

Blade Formatter

Blade-formatter adalah alat yang digunakan untuk memformat template Blade, templating yang digunakan dalam framework PHP Laravel. Ini dirancang untuk membantu supaya para developer menjaga gaya yang konsisten di template Blade mereka.
Untuk menggunakan blade-formatter, Anda harus menginstallnya melalui composer, package manager untuk PHP. Setelah terinstall, Anda dapat menjalankannya dari command line dengan menentukan path ke template Blade Anda.
Secara keseluruhan, blade-formatter adalah alat yang berharga bagi setiap developer yang bekerja dengan template Blade. Ini membantu untuk memastikan bahwa template Anda terformat dengan baik dan bebas dari kesalahan sintaksis, menghemat waktu dan usaha dalam jangka panjang.

Check the package https://github.com/shufo/blade-formatter?utm=github













Intercept Traffic Android Apps with Memu, Http Toolkit, & ADB

Dalam pengembangan aplikasi,terkadang kita ingin debugging semua traffic network di aplikasi mobile. Kita dapat melihat semua itu dengan melakukan intercept pada traffic tersebut.

Steps

  1. Download Memu emulator Android – https://www.memuplay.com/
  2. Download HTTP Toolkit – https://httptoolkit.tech/
  3. Download aplikasi Android HTTP Toolkit di Memu
  4. Download adb toolkit – Download the Android SDK Platform Tools ZIP file for Windows.
  5. Buka Terminal
  6. Masuk ke folder toolkit adb
  7. Running program adb
  8. Konek ke Memu dengan menjalankan perintah berikut: ./adb connect localhost:21503

Jika berhasil, kembali ke HTTP Toolkit. Terhubunglah ke Memu dari HTTP Toolkit dengan menggunakan menu android device yang terhubung melalui ADB.

Referensi : 

  1. https://www.xda-developers.com/install-adb-windows-macos-linux/
  2. https://docs.genymotion.com/desktop/latest/03_Virtual_devices.html#managing-virtual-devices
  3. https://support.genymotion.com/hc/en-us/articles/360002738297-How-to-connect-to-a-Genymotion-Desktop-virtual-device-remotely-with-ADB-