Category «Uncategorized»

Find /list all files bigger than 5MB and delete them in command line for linux/mac

find . -type f -size +3000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’ ./Uploads/Page-Photos/About-Us/9653a21167/DSCN1703.JPG: 3.3M ./Uploads/103eca7540/tori.jpg: 4.4M ./Uploads/845d819c4d/FCU-157_master.jpg: 4.1M ./Uploads/PDF-Forms/Annual-Reports/fe6ddf67be/First-Credit-Union-Annual-Report-2015.pdf: 19M ./Uploads/PDF-Forms/Annual-Reports/802f311485/First-Credit-Union-Annual-Report-2018.pdf: 3.0M   $ find . -type f -size +3000k -exec ls -lh {} \; -rw-r–r– 1 xx staff 6.3M 4 Jun 09:21 ./Images/Promotions/eace8a9a35/Staff-1.jpg -rw-r–r– 1 xx …

Run/install compser update/install in a shared hosting space/server

First run these commands to download and install composer: cd ~ mkdir bin mkdir bin/composer curl -sS https://getcomposer.org/installer | php mv composer.phar bin/composer Determine the location of your php-cli (needed later on): which php-cli (If the above fails, use which php) It should return the path, such as /usr/bin/php-cli, /usr/php/54/usr/bin/php-cli, etc. edit ~/.bashrc and make sure …

Install php5.6/7.2/php5.3 different php version via macports

# Install php 5.3 sudo port install php53 php53-curl php53-fpm php53-gd php53-iconv php53-imagick php53-mbstring php53-mcrypt php53-mysql php53-openssl php53-iconv php53-mbstring sudo cp /opt/local/etc/php53/php.ini-development /opt/local/etc/php53/php.ini sudo cp /opt/local/etc/php53/php-fpm.conf.default /opt/local/etc/php53/php-fpm.conf cd /opt/local/etc/php53/ sudo vi php-fpm.conf change listen = 127.0.0.1:9053 start: sudo port load php53-fpm stop : sudo port unload php53-fpm => note, maybe need to change short_open_tag = …

Compress huge image files without suffix via Gulp

var gulp = require(‘gulp’); const imagemin = require(‘gulp-imagemin’); var once = require(‘async-once’); var imageminMozjpeg = require(‘imagemin-mozjpeg’); var rename = require(“gulp-rename”); const del = require(‘del’); var tap = require(“gulp-tap”); var replaceName = require(‘gulp-replace-name’); const source_dir = ‘img_source’; const target_dir = ‘img_gulp’; gulp.task(‘clean’, done => { del(target_dir + ‘/*.jpg’); // returns a promise done(); }); gulp.task(‘prepare’, done …

Sort array by custom string value and number

        // sort function         function wpd_last_name_sort( $a, $b ) {          $a_last = end(explode(‘ ‘, $a->post_title));          $b_last = end(explode(‘ ‘, $b->post_title));              return strcasecmp( $a_last, $b_last );         }         function wpd_menu_order_sort( $a, $b ) {             $a_last = $a->menu_order;          $b_last = $b->menu_order;          return $a_last > $b_last;         }                     // sort posts         $menu_order_tags = [             ‘cardiothoracic-surgery’, …

Install silverstripe4 on mac via composer

composer create–project silverstripe/installer ./my/website/folder Got error: need to install php-intl Solution: change default php7.1 to php7.3 by vi ~/.bash_profile … export PATH=/usr/local/opt/[email protected]/bin:$PATH source ~/.bash_profile now, php -v shows php7.3 php -i | grep intl run composer create–project silverstripe/installer ./my/website/folder again and looks fine Go to http://localhost/install.php shows error says need to set timezone vi php.ini set date.timezone …

How to efficiently update/sync pivot table/join table using PHP with selected multiple checkbox

First, Let’s assume we pass selected multiple checkboxes ids to parameter permissionIds, eg. 4,5,2,12,9 $existsPageIdsAry = array_column($existsPermissions, ‘pageID’); $permissionIdsAry = explode(‘,’,$data[‘permissionIds’]); $pageIdsNeedRemove = array_diff($existsPageIdsAry, $permissionIdsAry); $pageIdsNeedAdd = array_diff($permissionIdsAry, $existsPageIdsAry); Then we can do delete where id in ($pageIdsNeedRemove) and insert pivot table records in $pageIdsNeedAdd

How to insert multiple record using Doctrine

/** * Insert multiple record together * improve speed from 8 seconds to less than 1 second for insert 200 records */ $em = $this->_service->getEntityManager(); foreach ($pageIdsNeedAdd as $pageID ){ $rp = newRolePermission; $rp->pageID = $pageID; $rp->roleID = $data[‘roleID’]; $em->persist($rp); } $em->flush(); $em->clear();

Google reCaptcha V2 & V3 javascript demo and php example code

<?php // google recaptcha v2 $siteKey = ‘siteKey222’; $secret = ‘secret2222’; // google recaptcha v3 $siteKey_v3 = ‘siteKey333’; $secret_v3 = ‘secret3333’; function getRrecaptchaResult($secret_key, $g_recaptcha_response) { $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_URL => ‘https://www.google.com/recaptcha/api/siteverify’, CURLOPT_POSTFIELDS => [ ‘secret’ => $secret_key, ‘response’ => $g_recaptcha_response, ‘remoteip’ => $_SERVER[‘REMOTE_ADDR’] ] ]); $response = …