Macbook Pro 2011 defective GPU

GPU recall back in 2015

GPU recall were done back in 2015, and now it failed again.

This is how I fixed the 2011 Macbook pro with defective AMD GPU, boot into command line and remove all those AMD driver, this will force the OS to use the Integrated GPU.

Boot into command line mode CMD+S and entering these commands:

1) fsck -fy (to check a disk)
2) mount -uw / (mount a root filesystem with read/write permissions)
3) sudo mkdir /AMD_Kexts/ (make a directory to store the AMD drivers in case you’ll need them in future)
4) sudo mv /System/Library/Extensions/AMD*.* /AMD_Kexts/ (move the AMD drivers)
5) sudo rm -rf /System/Library/Caches/com.apple.kext.caches/ (remove the AMD drivers cache)
6) sudo mkdir /System/Library/Caches/com.apple.kext.caches/ (just in case OS X will be dumb and will not recreate this directory, I am creating it for OS X)
7) sudo touch /System/Library/Extensions/ (to update the timestamps so that new driver caches – without AMD drivers – will be definitely rebuilt)
8) sudo umount / (umount a partition to guarantee that your changes are flushed to it)
9) sudo reboot

Posted in Development | Tagged , | Leave a comment

Laravel using captcha validation

install captcha dependence with composer

composer require mews/captcha

add the class interface into ‘providers’ section in config/app.php

Mews\Captcha\CaptchaServiceProvider::class,

define alias into the ‘alias’ section

'Captcha' => Mews\Captcha\Facades\Captcha::class,

execute command to create configuration file

php artisan vendor:publish

edit the config file accordingly in config/captcha.php

'default'   => [
    'length'    => 4,   // length of the captcha
    'width'     => 90, // width of the image
    'height'    => 32,  // height of the image
    'quality'   => 90,
],

the code to show the captcha in the form

<img src="{{captcha_src()}}" style="cursor: pointer" onclick="this.src='{{captcha_src()}}'+Math.random()">
Posted in Development | Tagged , , | Leave a comment

PHP convert character encoding to UTF-8

a simply function that detect character code and covert to UTF-8

function convertUTF8($data) {
  if(!empty($data)) {    
    $encodeType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5'));   
    if( $encodeType != 'UTF-8'){   
      $data = mb_convert_encoding($data ,'utf-8' , $encodeType);   
    }   
  }   
  return $data;    
}
Posted in Development | Tagged , , | Leave a comment

Excel mask out card number

The following code will mask out the card number

=LEFT(A1,6)&"******"&RIGHT(A1,4)

Posted in Development | Tagged , | Leave a comment

Convert number into chinese string with php

  1. convert from int to chinese string e.g. 125 -> 一百二十五
 function numToWord($num){
     $chiNum = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
     $chiUni = array('','十', '百', '千', '萬', '十', '百', '千', '億');

     $chiStr = '';
     $num_str = (string)$num;
     $count = strlen($num_str);
     $last_flag = true; // pervious number is 0?
     $zero_flag = true; // first number?
     $temp_num = null;
 
     if ($count == 2) { // 2 digit number
         $temp_num = $num_str[0];
         $chiStr = $temp_num == 1 ? $chiUni[1] : $chiNum[$temp_num].$chiUni[1];
         $temp_num = $num_str[1];
         $chiStr .= $temp_num == 0 ? '' : $chiNum[$temp_num];
     }else if($count > 2){
         $index = 0;
         for ($i=$count-1; $i >= 0 ; $i--) {
                 $temp_num = $num_str[$i];
                 if ($temp_num == 0) {
                     if (!$zero_flag && !$last_flag ) {
                         $chiStr = $chiNum[$temp_num]. $chiStr;
                         $last_flag = true;
                     }
 
                     if($index == 4 && $temp_num == 0){
                         $chiStr = $chiUni[4].$chiStr;
                     }
                 }else{
                     if($i == 0 && $temp_num == 1 && $index == 1 && $index == 5){
                         $chiStr = $chiUni[$index%9] .$chiStr;
                     }else{
                         $chiStr = $chiNum[$temp_num].$chiUni[$index%9] .$chiStr;
                     }
                     $zero_flag = false;
                     $last_flag = false;
                 }
                 $index ++;
         }
     }else{
         $chiStr = $chiNum[$num_str[0]];
     }
     return $chiStr;
 } 

2. convert from chinese string into int, eg. 一百二十五 > 125

 function cn2num($string){
     if(is_numeric($string)){
         return $string;
     }
     // '仟' => '千','佰' => '百','拾' => '十',
     $string = str_replace('仟', '千', $string);
     $string = str_replace('佰', '百', $string);
     $string = str_replace('拾', '十', $string);
     $num = 0;
     $wan = explode('萬', $string);
     if (count($wan) > 1) {
         $num += cn2num($wan[0]) * 10000;
         $string = $wan[1];
     }
     $qian = explode('千', $string);
     if (count($qian) > 1) {
         $num += cn2num($qian[0]) * 1000;
         $string = $qian[1];
     }
     $bai = explode('百', $string);
     if (count($bai) > 1) {
         $num += cn2num($bai[0]) * 100;
         $string = $bai[1];
     }
     $shi = explode('十', $string);
     if (count($shi) > 1) {
         $num += cn2num($shi[0] ? $shi[0] : '一') * 10;
         $string = $shi[1] ? $shi[1] : '零';
     }
     $ling = explode('零', $string);
     if (count($ling) > 1) {
         $string = $ling[1];
     }
     $d = array(
         '一' => '1','二' => '2','三' => '3','四' => '4','五' => '5','六' => '6','七' => '7','八' => '8','九' => '9',
         '壹' => '1','贰' => '2','叁' => '3','肆' => '4','伍' => '5','陆' => '6','柒' => '7','捌' => '8','玖' => '9',
         '零' => 0, '0' => 0, 'O' => 0, 'o' => 0,
         '两' => 2
     );
     return $num + @$d[$string];
 } 
Posted in Development | Tagged , | Leave a comment