Langsung ke konten utama

Postingan

Semantic commit

Semantic  link  

Check connection db postgres di node js

Install package npm init -y npm i pg dbConfig sesuaikan dengan di localmu const { Client } = require ( ' pg ' ); // Konfigurasi koneksi database PostgreSQL const dbConfig = { user: ' root ' , host: ' 0.0.0.0 ' , database: ' check-db ' , password: ' root ' , port: 5151 , }; // Membuat instance client PostgreSQL const client = new Client (dbConfig); // Fungsi untuk melakukan pengecekan koneksi const init = async () => { try { // Menghubungkan client ke database await client . connect (); console . log ( ' Koneksi ke database berhasil. ' ); // Menutup koneksi client await client . end (); } catch (error) { console . error ( ' Gagal terhubung ke database: ' , error . message ); } }; // Memanggil fungsi untuk melakukan pengecekan koneksi init ();

Install adb on mac os

Delete your old installation (optional)  rm -rf ~/.android-sdk-macosx/ Download  adb   Go folder download  cd Download Unzip file unzip platform-tools-latest*. zip Create and move adb mkdir ~/.android-sdk-macosx mv platform-tools/ ~/.android-sdk-macosx/platform-tools Add platform your path echo 'export PATH=$PATH:~/.android-sdk-macosx/platform-tools/' >> ~/.bash_profile Refresh your bash profile (restart terminal) source ~/.bash_profile Start adb devices adb devices

Setup react native ANDROID_HOME

  Go to android project - cd android Create file local.properties windows  sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk mac sdk.dir = /Users/USERNAME/Library/Android/sdk ubuntu sdk.dir = /home/USERNAME/Android/Sdk

How to use CKEditor in Nuxt Js

Requirement:  Node 14.18.3 NPM 6.14.15 Yarn 1.22.4 yarn add @ckeditor/ckeditor5-vue@23.0.0 yarn add @blowstack/ckeditor5-full-free-build@1.0.2 // plugins/ckeditor.vue import Vue from ' vue ' import CKEditor from ' @ckeditor/ckeditor5-vue ' Vue . use ( CKEditor ) // components/CkEditor.vue < template > < ckeditor : editor = " editor " : value = " value " : config = " config " @ input = " ( event ) => $emit ( ' input ' , event) " /> </ template > < script > let FullFreeBuildEditor; let CKEditor; if (process . client ) { FullFreeBuildEditor = require ( ' @blowstack/ckeditor5-full-free-build ' ); CKEditor = require ( ' @ckeditor/ckeditor5-vue ' ); } else { CKEditor = { component: { template: ' <div></div> ' } }; } export default { name: ' CkEditor ' , components: { ckeditor: CKEditor . component , }, p...

Cara menggunakan lodash di template vue js

Lodash render didalam tag <template>  Jika ingin menggunakan di dalam page (bukan global component) import _startCase from ' lodash/startCase ' <template>      {{ _startCase ('no_access') }} </template> methods: {      _startCase, } Jika ingin global template expression component {{_ . camelCase ( " vue lodash! " )}} import _ from 'lodash'; const VueLodash = { install(Vue, options) { Vue.prototype.$_ = _; Vue.mixin({ mounted() { // Just tell you that it is mounted // console.log('VueLodash'); } }); if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(VueLodash) } } }; export default VueLodash; source:  link

Arrow function

Function declarative function sayHello ( name ) { console . log (` My name is ${ name } `) } sayHello ( ' Ahmad ' ) Bisa diubah menjadi satu baru function const sayHello = ( name ) => console . log (` ${ name } `)  sayHello ( ' Ahmad ' ) Function ditandai dengan () akan tetap case disini bisa juga tanpa menuliskan parameter () const sayHello = name => console . log (` ${ name } `)  sayHello ( ' Ahmad ' )

Function parameter spread operator

Parameter dari fungsi bisa berupa tipe data apapun mulai dari string, number, boolean, array, object ataupun tipe data lainnya bahkan fungsi. function sum ( ... numbers ) { let result = 0 for ( const number of numbers) { result += number } return result } console . log ( sum ( 1 , 3 , 4 , 2 , 5 )) Jika parameter dari sebuah fungsi sebuah object kita manfaatkan destructuring object untuk mendapat nilainya. const user = { id: 24 , displayName: ' Ahmad ' , address: ' Brebes ' } function myName ( { displayName , address } ) { console . log (` ${ displayName } in ${ address } `) } myName (user) Ketika kita memasukan parameter pada fungsi maka wajib baginya ketika mereturn sesuai dengan parameter yang ada. jika tidak maka akan undefined. solusinya kita bisa menambahkan nilai parameter default function exponentsFormula ( baseNumber , exponent = 4 ) { // default value let result = baseNumber ** exponent; console . log (` ${ ba...

Config axios global Vue 3

Tambahkan di main.ts import axios from ' axios ' const pinia = createPinia () const app = createApp (App) . use (IonicVue) . use (router) . use (pinia); const axiosInstance = axios . create ({ withCredentials: true , }) router . isReady () . then ( () => { app . component ( ' Loading ' , Loading) app . config . globalProperties . $axios = { ... axiosInstance } app . mount ( ' #app ' ); }) Tinggal pake di component  async mounted () { await this . $axios . get ( ' //jsonplaceholder.typicode.com/users ' ) }, Sebagai catatan: keyword this gak jalan di setup dan jangan taruh di dalam defineComponent gunakan export default { } biasa

Reusability Vue 3 - Composition API

 Ada 3 pembahasan dalam reusability pada vue js Composable Pada vue application "composable" itu function yang di manfaatkan oleh composition api untuk merangkum dan mengulang kembali stateful logic. Yang biasanya gini  < script setup > import { ref, onMounted, onUnmounted } from " vue " ; const y = ref ( 0 ); const x = ref ( 0 ); function update ( event ) { x . value = event . pageX ; y . value = event . pageY ; } onMounted ( () => window . addEventListener ( " mousemove " , update)); onUnmounted ( () => window . addEventListener ( " mousemove " , update)); </ script > < template > Mouse position {{ x }} , {{ y }}</ template > Ada perubahan di dalam <script> <!-- template/ component --> < script setup > import { useMouse } from " ../composable/mouse " ; const { x , y } = useMouse (); </ script > < template > Mouse position {{ x }} , {{ y }}...

Metode untuk find array di JavaScript

Includes()  Method ini menghasilkan nilai boolean true and false. Basic syntax  arr.includes(valueToFind, [fromIndex]) const kelas = [ " satu " , 80 , " 4 panjang " , " lingkaran " ]; const result = kelas . includes ( " satu " );   document . getElementById ( " demo " ). innerHTML = result;   Find() Beda dengan includes() alligator.find((el, idx) => typeof el === "string" && idx === 2)   const kelas = [ " satu " , 80 , " 4 panjang " , " lingkaran " ]; kelas . find ((el) => el .length < 12 ); indexOf() Resultnya index const kelas = [ " satu " , 80 , " 4 panjang " , " lingkaran " ];   kelas . indexOf ( " lingkaran " ); kelas . lastIndexOf ( 80 ); // returns 4 kelas . indexOf ( 80 , 2 ); // returns 4 kelas . lastIndexOf ( 80 , 4 ); // returns 4 kelas . lastIndexOf ( 80 , 3 ); // returns 1   Filter() const kela...

Get Promise All API

  load () { this . $overlay ( true ) const get = ( type ) => { return this . $axios . get ( ` endpoint/ ${ type } ` ) . then ( ( response ) => { this . count [type] = response . data . data . count }) . catch ( ( err ) => { console . error (err) }) . then ( () => { return Promise . resolve () }) } Promise . all ([ get ( ' register ' ), get ( ' draft ' ), get ( ' verified ' ), get ( ' rejected ' ), ]) . then ( () => { this . $overlay ( false ) }) },

Solusi Beda Node Version NVM Windows Mac

 Jika anda bingung ketika switch node version ini solusinya.  Contoh kasus project lama masih menggunakan versi 10 sedangkan ada project baru yg node versinya 16. awalnya ane pake virtualbox..hehe tp partner ngasih tau bahwa bisa switch node versi pake NVM (Node Version Manager) : Install NVM Mac Kalo belum install dulu nih : ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" Remove jika sudah ada node, installnya nanti dari brew brew uninstall --ignore-dependencies node brew uninstall --force node   Install pake brew brew update   brew install nvm Create a directory for NVM in home mkdir ~/.nvm Configure the required environment variables. Bisa pake vim atau nano, atau editor lain nano ~/.bash_profile   add config export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh Load variables  source ~/.bash_profile Lihat versi node nvm ls-remote Install node nvm install node // latest version nvm install 16 // stable ...

Seeding & Faker Laravel 8

$ php artisan make:seeder UserSeeder Otomatis dibuatkan file UserSeeder.php ada di file database seeder use Illuminate\Support\Str; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Faker\Factory as Faker; $faker = Faker::create('id_ID');         for($i = 1; $i <= 50; $i++){             DB::table('users')->insert([                 'name' => $faker->name,                 'email' => $faker->email.'@gmail.com',                 'password' => Hash::make('password'),             ]);         } $ php artisan db:seed --c...

Error gitlab access denied public key

Git Reset

 Bagi kalian ingin mereset git history commit bisa dengan langkah ini, mungkin sebagai contoh gitignore tidak sengaja kehapus lalu sukses push sedangkan di dalamnya masih ada folder vendor milik php laravel  (composer) dan node_modules milik node javascript (yarn). 1. Cek git history commit    history commit yg akan di aktifkan bukan yang salah ya.. 2. git reset --hard <history commit> 3. git push -f origin HEAD^:master 4. git reset -f --soft HEAD

Verifikasi User Laravel 8 API

Ketika sudah registrasi kita perlu verifikasi user, Untuk akses web apps di pastikan user yang emailnya aktif (Authorized). Setup .env agar bisa kirim melalui gmail MAIL_MAILER = smtp MAIL_HOST = smtp.gmail.com MAIL_PORT = 587 MAIL_USERNAME = youremail@gmail.com MAIL_PASSWORD = yourpassoword MAIL_ENCRYPTION = tls MAIL_FROM_ADDRESS = from@gmail.com MAIL_FROM_NAME = " ${ APP_NAME } " Tambahkan AuthServiceProvider.php use  Illuminate\Auth\Notifications\ VerifyEmail ; use  Illuminate\Notifications\Messages\ MailMessage ;   public   function   boot ()     {          $this -> registerPolicies ();          VerifyEmail :: toMailUsing ( function  ( $notifiable ,  $url ){              $spaUrl   =   $url ;              return ( new ...