Category Archives: Uncategorized

Codeigniter bulk insert to database

If you are to insert hundreds or thousands of records, please use bulk insert. Avoid call insert query in loop.

$data = array(
   array(
      'title' => 'My title' ,
      'name' => 'My Name' ,
      'date' => 'My date'
   ),
   array(
      'title' => 'Another title' ,
      'name' => 'Another Name' ,
      'date' => 'Another date'
   )
);

$this->db->insert_batch('mytable', $data); 

There will be limit to how many records can be added at one go.

Some limitations

  1. Limit to 1000 records per insert statement
  2. Check the settings for max_allowed_packet, bulk_insert_buffer_size, key_buffer_size

Generate android bundle/apk for ionic mobile app

  1. open terminal
  2. go to project directory
  3. run – npm update
    1. to make sure all components imported added first
  4. run – ionic build
    1. this will build files in web directory (normally www)
  5. run – ionic cap add android
    1. android directory will be created in ionic project
  6. run – “ionic cap copy android” to copy to android native project. this to run everytime you run “ionic build” to copy latest files to native android project
  7. run – ionic cap open android
    1. will open android studio
    2. this will take quite some time for android to build
  8. in android studio. Go to Build > Build Bundle(s)/APK
  9. APK willl be generated. Click on Locate to show the apk file

Optional

  1. optional – run – ionic cap sync – if you download any plugin to be used in the app

Other notes

  1. I faced issue the “Build Bundle(s)/APK(s)” and “Generate signed Bundle/APK” did not appear in the menu.
  2. To settle this issue, go to Android Studio > Preferences > Appearance and Behavior > System Settings > Android SDK. Choose SDK Tools tab. Tick on SDK Build-Tools and Android SDK Command-line Tools. Then click Apply. Agree to the terms and proceed.

Reference:

  1. https://ionicframework.com/docs/angular/your-first-app/6-deploying-mobile
  2. https://ionicframework.com/docs/developing/android

Add slack notification on gitlab push

How to add slack notification everytime there is push or other activities on selected git repository

  1. Get slack incoming webhook url for a particular channel here
    https://yourslackorganization.slack.com/apps/A0F7XDUAZ-incoming-webhooks (or try search on google to get the page).
  2. Open any gitlab project. Choose settings > integrations. Choose slack notification. Paste the webhook URL and set username (name to send notification in channel)
  3. Click the test button to see if the integration works.
  4. That’s it

Git deploy on runcloud using gitlab

  1. On Runcloud – Get the deploy key in “Deployment Key” for user for the respective web app
  2. On Gitlab – Update deployment key in Settings > Repository > Deploy key
  3. On Runcloud – On the Web Application screen, click on Git to set Git service, repository and branch to clone/pull and click the button at the bottom
  4. Copy the webhook URL
  5. On Gitlab – Update webhook URL in Settings > Webhooks
  6. You are done!

Additional notes on what to change before can use this method (for codeigniter)

  1. Add checking server/localhost to set base_url in config/config.php
  2. Edit path for session files in config/config.php
  3. Add checking to set database to be used in config/database.php

Transfer Divi site to another hosting

If you are building site for customer, you probably want to design it on your own web hosting first. After the design completed, then only you will transfer it to your customer web hosting.

Below are quick steps on how to transfer complete Divi website from one wordpress setup to another (within same server or different server.

1. Export wordpress content
Go to Tools > Export. Choose “All content” then click “Download Export File”

2. Export Divi Theme Options
In navigation menu. Go to Divi > Theme Options.
Click the “arrow up and down” icon at top right.
Then click on “Export Divi Theme Options” button

3. Export Divi Theme Customizer
In navigation menu. Go to Divi > Theme Customizer
Click the “arrow up and down” icon at top left.
Then click on “Export Divi Theme Customizer” button

After setting up new WordPress, don’t forget to do the following steps before importing

  1. Import Divi theme
  2. Activate Divi
  3. Apply api key in Divi > Theme Options > Updates
  4. Set the main static page in Settings > Reading

Once all done and set, you can now start importing all exported files. Start with the 3, 2 and 1.

VS Code Extensions

Some useful extension I’m using

  1. PHPIntelliphense – one of the feature is to show methods and functions in outline (on left bar)
  2. PHP Intellisense
  3. Projects – to quickly switch between projects instead of need to open new window and choose folder from explorer
  4. Auto Close Tag – automatically add close tag (html) when a tag is opened
  5. Bracket Pair Colorizer – easy to detect open and close curly braces
  6. Gitlens
  7. Prettier – code formatter. To enable format on save, go to settings (cmd+,) and search format on save. Tick to enable and prettier will do its job when a file is saved. Or to run it manually go to run (cmd+shift+p), type in Format Document