Tuesday, June 11, 2019

android studio 3.4.1 and google admob change

In build.gradle (Module:app) change
...
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
...
dependencies {
   implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.android.gms:play-services-ads:17.2.1'

In AndroidManifest.xml add
<manifest>
    <application>
        ...
        <meta-data
            android:name="com.google.android.gms.ads.AD_MANAGER_APP"
            android:value="true"/>
    </application>
</manifest>

Thursday, June 6, 2019

defender locking bignox virtual disk

windows defender sometimes open file in background process, to scan for malicious code. If defender (or other antivirus) open bignox virtual disk it will lock it and cause your emulator crash. You need to exclude virtual disk that used by bignox. Here are the steps you need to do:
  1. Open your windows defender (or your antivirus)
  2. Go to setting "Virus & thread protection settings"
  3. in "Exclusions" click "Add or remove exclusions"
  4. Click "Add an exclusion" and choose "File type"
  5. in "Enter extension" box type "vmdk"
  6. repeat step 4 for file type "vbox" and "vdi"
You may want to increase your emulator by excluding these files:
  1. C:\Program Files (x86)\Bignox\BigNoxVM\RT\NoxVMSVC.exe
  2. C:\Program Files (x86)\Nox\bin\Nox.exe

Thursday, April 25, 2019

Codeigniter: query builder select, insert, update and delete

Query table:
        $this->result = $this->db->get('ca_brand',$mmax, 0);
        if ($this->result) {
            return true;
        } else {
            return false;
        }
Query table with like filter:
        $this->db->like('name', $keyword); // buildin mysql escape
        $this->result = $this->db->get('ca_brand',0, $mmax);
        if ($this->result) {
            return true;
        } else {
            return false;
        }
 Insert row in table:
        // buildin mysql escape character
        $data = array('name' => $name);
        $this->db->insert('ca_brand', $data); // return true on success
        $insert_id = $this->db->insert_id(); // get id

Update row in table for spesific id
        // buildin mysql escape character
        $id = intval($id);
        $data = array ('name' => $name);
        $this->db->where('id', $id);
        //$this->db->update('ca_brand',$data, "id = "$id ); // option 1
        $this->db->update('ca_brand',$data); // // option 2
        $numaffectedrow = $this->db->affected_rows(); // to get nummber affected row
 Delete row:
        $id = intval($id);
        $this->db->where('id', $id);
        $this->db->delete('ca_brand');
        $numaffectedrow = $this->db->affected_rows(); // to get nummber affected row

Php 7.2 and Codeigniter 3.1.10

Codeigniter: check mysql connection

To check error in mysql connection, we need to change ENVIRONMENT to Production. Here is the example:
    //define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
    //define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'testing');
    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production');
There are two ways to catch error in our controller:
1. Using dblib
        $this->load->dbutil();
        if ($this->dbutil->database_exists('myca')) {
            // Connection ok
        } else {
            // Connection fail
        }
2. Checking error in db
        $this->load->database();
        $errhandle = $this->db->error();
        if ($errhandle['code']==0) {
            // Connection ok
        } else {
            // Connection fail
            // to dump error code var_dump( $this->db->error());
        }
Tested on PHP 7.2 and Codigniter 3.1.10

windows: kill process by id using cmd

The most old games do not run on Windows 10. For example Red Alert and GTA San Andreas. Those games require DirectPlay in Windows 10 (legacy feature.
Before you try your old games you need to run cmd in administrator mode. In case the game does not play properly, switch to cmd and stop the game. 
To search pid for RA2
tasklist -v | find "RA2.exe"
tasklist -v | find "GAME.exe"
GAME.EXE                      7356 Console                    4    139,172 K Not Responding  xxx\xxx                                             0:02:48 Red Alert 2
To kill the process
taskkill /F /PID 7356
SUCCESS: The process with PID 7356 has been terminated.