Move the cursor to the n in name. Enter visual block mode (ctrlv). Press j three times (or 3j). Press I (capital i). Type in vendor_. Press esc.
PHP Forking with child process limit
function runProcessor() { $max_fork = 2; $tasks = [ “test1” => “process1”, “test2” => “process2”, “test3” => “process3”, “test4” => “process4”, “test5” => “process5”, “test6” => “process6”, “test7” => “process7”, “test8” => “process8”, “test9” => “process9”, “test10” => “process10”, ]; $pids = array(); $pid_count = 0; foreach ( $tasks as $seq => $task ) { […]
Jquery Check Device & width of device & check element is in middle of screen when scrolled
<script> if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { var window_width = $(window).width(); if(window_width <= 991){ console.log(“Mobile Devices width is smaller than 991”); var windowHeight = $(window).height(), gridTop = windowHeight * .3, gridBottom = windowHeight * .8; $(window).scroll(function(){ $.each($(“[class$=area]”),function(){ var thisTop = $(this).offset().top – $(window).scrollTop(); if (thisTop > gridTop && (thisTop + $(this).height()) < gridBottom) { if($(this).css(“bottom”) != […]
PHP Curl with attachment ( CurlFile)
Sender PHP Code <form method=”post” action=”<?=$_SERVER[“PHP_SELF”] ?>” enctype=”multipart/form-data”> <input name=”file” type=”file” /> <input type=”submit” value=”Upload” /> </form> <?php if(!empty($_FILES)){ $target=”https://juliusgoh.life/tut/attachment-receiver.php”; echo “<pre>”; print_r($_FILES); echo “</pre>”; # http://php.net/manual/en/curlfile.construct.php // Create a CURLFile object / procedural method $cfile = curl_file_create($_FILES[“file”][“tmp_name”],$_FILES[“file”][“type”],$_FILES[“file”][“name”]); // try adding // Create a CURLFile object / oop method #$cfile = new CURLFile(“resource/test.png”,”image/png”,”testpic”); // uncomment […]
PHP Script uses bash command to find file created within mins ago
$dir = “/home/ec2-user/julius/tmp/”; $file_type = “json”; $min = “5”; #Created How Many Min Ago $output = shell_exec(“find $dir -cmin -$min -type f -name ‘*.$file_type'”); $json_file = explode(“\n”,$output); array_pop($json_file); # To remove last \n if(empty($json_file)){exit();} print_r($json_file);
Jquery UI datepicker with Font awesome calendar
CSS : .my-icon .date { background:#fff url(https://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16×16/calendar_2.png) 93% 50% no-repeat ; } HTML : <div class="my-icon" form-group style="padding-left:0px ;margin-bottom:15px;"> <label>From: </label> <input type="text" name="fromdt" id="fromdt" class="form-control date" value="<?= isset($_POST[‘fromdt’]) ? $_POST[‘fromdt’] : "" ?>" readonly> </div> JS : $(“#fromdt”).datepicker( { dateFormat: ‘yy-mm-dd’, maxDate: ‘+0D’, changeYear: true, changeMonth: true, yearRange: “-100:+0” } );
Bash read txt file into array
declare -a DIRS readarray -t DIRS < /var/www/html/.logPaths.txt let i=0 while (( ${#DIRS[@]} > i )); do #Do Your Stuff done
Check Filesize & Extension before upload (Javascript)
Input <input type=”file” onchange=”ValidateFile(this);” id=”uploaded_file”> Function for checking upon on change for uploaded file function ValidateFile(file){ var FileSize = file.files[0].size / 1024 / 1024; //In MB var filePath = file.files[0].name; var extension = filePath.substr((filePath.lastIndexOf(‘.’) +1)); var allowed_extension = [“jpg”,”png”,”jpeg”]; if (FileSize > 2) { […]
Prevent Direct Calling for PHP scripts, Only Allow Ajax Calling
The Code below is useful to prevent direct calling. #Only Allow Ajax Call if(!($_SERVER[‘HTTP_X_REQUESTED_WITH’] == ‘XMLHttpRequest’ && $_SERVER[‘HTTP_X_REQUESTED_WITH’])) { echo “Access Denied”; exit(); }
SSH Trick
How To SSH run command without key-in password again echo < password > | ssh username@host ‘sudo -S < command >’ Running Two SSH Command line for sqldump ssh -t username@host ‘mysqldump -u {DB_USER} -p”{DB_PASS}” {DB_NAME}’ > dump.sql | ssh -t username@host ‘cat dump.sql’ > local.sql