Posts

Showing posts from 2018

Theme basic introductions in style.css file

/* Theme Name: Twenty Fifteen Theme URI: https://wordpress.org/themes/twentyfifteen/ Author: the WordPress team Author URI: https://wordpress.org/ Description: Our 2015 default theme is clean, blog-focused, and designed for clarity. Twenty Fifteen's simple, straightforward typography is readable on a wide variety of screen sizes, and suitable for multiple languages. We designed it using a mobile-first approach, meaning your content takes center-stage, regardless of whether your visitors arrive by smartphone, tablet, laptop, or desktop computer. Version: 2.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: blog, two-columns, left-sidebar, accessibility-ready, custom-background, custom-colors, custom-header, custom-logo, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, threaded-comments, translation-ready Text Domain: twentyfifteen This theme, like WordPres

Shortcut way to get fillable fields from a large table for Laravel Model

SELECT CONCAT('"',COLUMN_NAME,'",') as fillable FROM information_schema.columns WHERE table_name = 'my_table';

MySQL Queries

1. Write the SQL query to get third and fourth highest value from Employee table. 2. Write the SQL query to get duplicate rows from Salary Table with "No of times" duplicate row exists. select *,count(*) as total from salary group by employee_id having total>1; 3. Write a SQL query to view the employee name, salary who get Highest and Lowest salary using Sub-Query. 4. Write a SQL Query to view the number of occurrences of each occupation in Occupations table. Sort the occurrences in ascending order, and output them in the following format: There are a total of [occupation_count] [occupation_name]s. select occupation, count(*) as total from occupations group by occupation order by total; 5. Write a SQL query to find out the employee names where the name starts with "j" and ends with "n" and name exactly has length 4. select * from employee where name like 'j_%_%n';

Keeping second tab active after action

$(document).ready(function(){     var url = document.location.toString();     if (url.match('#')) {         $('.nav-tabs a[href="#' + url.split('#')[1] + '"]').tab('show');         $('.nav-tabs a').removeClass('active');     } });

MySQL for Python in Ubuntu

Install pip and upgrade to the latest version apt-get install python-pip pip install -U pip Next, install the required development packages apt-get install python-dev libmysqlclient-dev then pip install MySQL-python

Email Sending by Python

#Simple email import smtplib server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login("client_email@gmail.com", "password") msg = "Email Sending by python" server.sendmail("from@gmail.com", "to@gmail.com", msg) server.quit() #Email with subject and attachment import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText from email.MIMEBase import MIMEBase from email import encoders fromaddr = "from@gmail.com" toaddr = "to@gmail.com" msg = MIMEMultipart() msg['From'] = fromaddr msg['To'] = toaddr msg['Subject'] = "Subject - Eamil subject" body = "Email body message" msg.attach(MIMEText(body, 'plain')) filename = "File name" attachment = open("file source", "rb") part = MIMEBase('application', 'octet-stream') part.set_payload((at

Getting selected Index text in on change event

$('#visa_type_id').on('change',function(){    var visa_type = this.options[this.selectedIndex].text;    alert(visa_type); });

Problem : Max can not return max value from varchar type field.

Problem : Max can not return max value from varchar type field. ELOQUENT Query : $maxLicence = Agency::where('is_approved',1)->max('license_no'); RAW SQL Query : select max(test_value) from area_info; Solution :  $maxLicence = DB::select("select max(cast(agencys.license_no as int)) as license from agencys");

DB::raw() Query in Eloquent ->get();

ParkInfo::leftJoin('park_block_setup as block','block.park_id','=','park_info.id')     ->where('park_info.is_archive', 0)     ->groupBy('park_info.id')     ->orderBy('park_info.park_name', 'asc')     ->get([         'park_info.*',         DB::raw('ifnull(sum(block.has_land),0) has_land'),         DB::raw('ifnull(sum(block.has_space),0) has_space')     ]);

MySQL Trigger Example

DROP TRIGGER IF EXISTS `park_slap_booking_tmp_after_update`; DELIMITER ;; CREATE TRIGGER `park_slap_booking_tmp_after_update` AFTER UPDATE ON `park_slap_booking_tmp` FOR EACH ROW BEGIN   INSERT INTO `park_slap_booking_tmp_audit` (`id`, `space_level_setup_id`, `space_slap_setup_id`, `slap_name`, `remarks`, `slap_size`, `per_unit_price`, `app_id`, `process_type_id`, `status`, `is_archive`, `created_at`, `created_by`, `updated_at`, `updated_by`, `audit_event`, `audit_timestamp`) VALUES(NEW.`id`, NEW.`space_level_setup_id`, NEW.`space_slap_setup_id`, NEW.`slap_name`, NEW.`remarks`, NEW.`slap_size`, NEW.`per_unit_price`, NEW.`app_id`, NEW.`process_type_id`, NEW.`status`, NEW.`is_archive`, NEW.`created_at`, NEW.`created_by`, NEW.`updated_at`, NEW.`updated_by`, 'update', CURRENT_TIMESTAMP); END;; DELIMITER ;

Laravel Eloquent Joining Query (Multiple clauses of purpose in joining)

return TableA::leftJoin('table_b as b',function($join){                 $join->on('b.foreign_id','=','table_a.id');                 $join->where('b.status','=',1);             })             ->where('table_a.group_name','emmet')             ->groupBy('b.color')             ->get([                 'table_a.*'                 DB::raw('SUM(b.price) as total_price')             ]);

Nav tabs keeping active after saving, among multiple tabs

Tab Selection Button <li>   <a data-toggle="tab" href="#tab_2" aria-expanded="false">       <strong><i class="fa fa-building"></i> Building</strong>   </a> </li> Tab Body <div id="tab_2" class="tab-pane">     <div class="results">         <div class="table-responsive">             <div class="panel panel-default">                 <div class="panel-heading">                     <strong style="line-height: 35px;"><i class="fa fa-home"></i> Park building details</strong>                     <a class="buildingAddButton" data-toggle="modal" data-target="#ParkModal" onclick="openModal('.buildingAddButton', 'modal-content')" href="{{ url('/settings/park/create-building/'.Encryption::encodeI

OnChange (Division->District) [jQuery and AJAX]

$("#division").change(function () {     var divisionId = $('#division').val();     $(this).after('<span class="loading_data">Loading...</span>');     var self = $(this);     $.ajax({         type: "GET",         url: "<?php echo url(); ?>/users/get-district-by-division",         data: {             divisionId: divisionId         },         success: function (response) {             var option = '<option value="">Select One</option>';             if (response.responseCode == 1) {                 $.each(response.data, function (id, value) {                     option += '<option value="' + id + '">' + value + '</option>';                 });             }             $("#district").html(option);             $(self).next().hide();         }     }); }); public function getDistrictByDivision(Request $request)

jQuery Form Validation

$('#form').validate({ errorPlacement:function(error,element){ element.before(error); } }); $('#form').validate({ errorPlacement:function(){ return false; } }); $('#form').validate();

URL Storing

plane.blade.php ________________ if (isset($exception)){             $message = $exception->getMessage();         }else{             $message='Ok';         }         ?>         <script type="text/javascript">             var ip_address = '<?php echo $_SERVER['REMOTE_ADDR'];?>';             var user_id = '<?php echo $user_id;?>';             var message = '<?php echo $message;?>';             var project_name = "MoCAT."+"<?php echo env('SERVER_TYPE', 'unknown');?>";             var token = '{{ csrf_token() }}';         </script>         <script src="{{ asset("assets/scripts/url-webservice.js") }}"></script> url-webservice.js ________________________ $('body a').click(function(e){     var action = $(this).text();     var url = $(this).attr('href');     if(typeof action === "un

Upload file with uploading progress

index.php <script type="text/javascript">     function _(el){         return document.getElementById(el);     }     function uploadFile(){         var file = _("file1").files[0];         var formdata = new FormData();         formdata.append("file1",file);         var ajax = new XMLHttpRequest();         ajax.upload.addEventListener("progress",progressHandler,false);         ajax.addEventListener("load",completeHandler,false);         ajax.addEventListener("error",errorHandler,false);         ajax.addEventListener("abort",abortHandler,false);         ajax.open("POST","server_page.php");         ajax.send(formdata);     }     function progressHandlere(vent){         _("loaded_n_total").innerHTML = "Uploaded "+event.loaded+"bytes of "+event.total;         var persent = (event.loaded/event.total)*100;         _("progressBar").val