Skip to main content

Posts

how to setup rails with docker on ubuntu ?

I am assuming that you already know about rails and also have setup docker on your system Create sample app and change directory rails new sample-app cd sample-app Create Dockerfile FROM ruby : 2.5 RUN apt-get update -qq && apt-get install -y nodejs postgresql-client WORKDIR /sampe-app COPY Gemfile /sampe-app/Gemfile COPY Gemfile.lock /sample-app/Gemfile.lock RUN bundle install COPY . /sampe-app COPY entrypoint.sh /usr/bin/ RUN chmod +x /usr/bin/entrypoint.sh ENTRYPOINT [ "entrypoint.sh" ] EXPOSE 3000 CMD [ "rails" , "server" , "-b" , "0.0.0.0" ] Create entrypoint.sh #!/bin/bash set -e # remove potentiallly pre existing server.pid for rails rm -f /sample-app/tmp/pids/server.pid # execute the docker containers main process exec " $@ " Create docker-compose.yml version : "3.9" services : db : image : postgres volumes : - ./tmp/db:/var/lib/postgresql/data envir...

How to add custom ads.txt in blogger site

How to add custom ads.txt in blogger sites? Its super easy, you just need to copy ads.txt content downloaded from adsense Select your blog from dropdown Go to settings Go to monetizatons section Enable checkbox Click on custom ads.txt Add copied content from downloaded ads.txt file and past in this box and press save

How to handle laravel fields error according to data tables editor plugin create & edit

How to handle laravel fields error according to data tables editor plugin create edit Before going to explain lets assume we want to create category and for time being we have one field that is name. And already we have controller,model and route established. For laravel field errors to be compatible with datatables editor we need to do following. Create form request for validation of category creation as below: File location: app / Http / Requests / File name: AddCategoryFormRequest.php File contents: namespace App\Http\Requests; use App\Http\Requests\CustomFormRequest; class AddCategoryFormRequest extends CustomFormRequest { public function rules() { return [ 'name' => 'required|max:255', ]; } } And category datatables and editor configuration as below: var create = new $.fn.dataTable.Editor({ ajax: {url: 'url here',type:'POST'}, table: '#categories-table...

Find UUID

How to find UUID of iPhone using on ubuntu?? This is very easy and can be done by using following command on terminal lsusb-s :`lsusb | grep iPhone | cut -d ' ' -f 4 | sed 's/://'` -v | grep iSerial | awk '{print $3}' This will give you forty 40 charactors long string

How to create virtual host on ubuntu apache2

How to create virtual host on ubuntu? create conf file under /etc/apache2/sites-available/ name it as vhosts.conf and put following contents <VirtualHost 127.0.0.3:80> ServerAdmin webmaster@test.dev ServerName test.dev ServerAlias www.test.dev DocumentRoot /var/www/html/projects/test ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> run following command to enable site sudo a2ensite vhosts.conf run following command to restart apache service sudo service apache2 restart run following command to enable rewrite mode sudo a2enmod rewrite and thats it

GIT Commands

Here some general GIT Commands How to get/show remote URL of cloned repository git remote show origin How to add all changes to git git add -A How to commit changes with message git commit -m "message here" How to push changes to master branch git push origin master How to find difference in file git diff app/helpers.php How to git export git archive master --format=zip --output=/home/jaffarhussain/citytwig_dev.zip How to delete files from git git rm -f *.DS_Store How to show log history git log -p -2

Get Specific Zone Time

Get Specific Zone DateTime from server time function getdateTimeByZone($serverZone , $userZone = 'UTC', $serverDateTime){     //$serverDateTime must be with time     $serverDateTime = date('Y-m-d H:i:s',strtotime($serverDateTime));     $schedule_date = new DateTime($serverDateTime, new DateTimeZone($serverZone));     $schedule_date-&gt;setTimeZone(new DateTimeZone($userZone));     $convertedTime =  $schedule_date-&gt;format('Y-m-d H:i:s');     return $convertedTime; } echo getdateTimeByZone('America/Los_Angeles' , 'Asia/Karachi', '2015/08/20 04:27 AM');

General linux commands

When I have started working on linux platform, i was unable to work. And I m writing this myself actually so that i can get help form this post to know about particular command and this post can also help others. I will be covering all below questions. How to find pid of program like firefox? How to find out the current running kernel version? How to find a file with .txt extension in particular directory? How to find a file containing word 'hello' in particular directory? How to change ownership recursively? How to change permissions on directory recursively? How to login using ssh? How to check if package is installed Let for example if we want to check if apache is installed? How to check for processes listening on port 80? How to check for a procesess files are located? How to Zip a folder in linux? How to remove directory in linux? How to find pid of program like firefox? ps -aux | grep firefox How to find out the current running kernel version? cat /...

Reduce Page Speed

Enable gzip compression <IfModule mod_deflate.c>     AddOutputFilterByType DEFLATE image/png image/gif image/jpeg image/jpg text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript application/json </IfModule> AddType font/ttf .ttf AddType font/eot .eot AddType font/otf .otf AddType font/woff .woff AddType font/svg .svg Leverage Browsing Cache <IfModule mod_expires.c>     ExpiresActive On     ExpiresDefault "access plus 10 days"     ExpiresByType image/png "access plus 10 days"     ExpiresByType image/gif "access plus 10 days"     ExpiresByType image/jpeg "access plus 10 days"     ExpiresByType image/jpg "access plus 10 days"     ExpiresByType text/css "access plus 10 days"     ExpiresByType application/javascript "access plus 10 days"     ExpiresByType applicati...

Regular Expression For Javascript

For Email :   /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/ For Name (Only For Alphabetic) : /^[-_ a-zA-Z]+$/ For Phone Number (Atleast 5 characters,With (+) Sign) : /^[+ 0-9]{5,15}\s*$/ For Textarea or Message : /^[a-zA-Z][;,-_ a-zA-Z0-9]+$/ For Alpha Numeric (Not Allowed Integer) : /^(?![0-9]*$)[-_ a-zA-Z0-9]+$/ For Test: You can store above regression in variable and then check it is valid or not.For example... var letters = /^[-_ a-zA-Z]+$/; if(letters.test(name)) {        return true; }else{       return false; }

ADD CUSTOM FIELD TO SUGARCRM

Create custom/Extension/modules/{module_name}/Ext/Vardefs/Vardefs.php  Here play with dictionary array and define fields accordingly Create file custom/Extension/modules/{module_name}/Ext/Language/en_us.{custom_modulename}.php This is a language file and you have to define variable that actually displays a label, here you have to use modstring array. Create file custom/modules/{module_name}/metadata/detailviewdefs.php place your cusotm fields here if you want to display those fields in detail view of that module. Create file custom/modules/{module_name}/metadata/editviewdefs.php Place your fields here if you want to show these fields in edit view

ADD CHECK BOX IN DEFAULT SEARCH FORM IN SUGARCRM

If you want to search for only customer type of accounts, then follow these steps you will be successful to achieve this functionality Open   SearchFields.php place this code inside this file ‘customer_only’ => array( ‘query_type’=>’default’, ‘db_field’=>array(‘account_type’), ‘operator’=>’in’, ‘closed_values’ => array(‘Customer’), ‘type’=>’bool’, ), Now open searchdefs.php ‘customer_only’ => array ( ‘name’ => ‘customer_only’, ‘label’ => ‘LBL_CUSTOMER_ONLY_FILTER’, ‘type’ => ‘bool’, ‘default’ => false, ‘width’ => ’10%’, ), to be on safer side repair and rebuild and open your account module and check this check box will be there and will be functional.

CUSTOM WHERE CLASS IN SUGARCRM DASHLETS

How to add custom where class in sugar dashlets??? for example if you want to see top opportunities dashlet containing only filtered opportunities on some condition then you can do this as below require_once(‘modules/Opportunities/Dashlets/MyOpportunitiesDashlet/MyOpportunitiesDashlet.php’); class MyOpportunitiesCustomDashlet extends MyOpportunitiesDashlet { function MyOpportunitiesCustomDashlet($id, $def = null) { global $current_user, $app_strings, $dashletData; require(‘modules/Opportunities/Dashlets/MyOpportunitiesDashlet/MyOpportunitiesDashlet.data.php’); parent::MyOpportunitiesDashlet($id, $def); } function process($lvsParams = array()) { $lvsParams = array( ‘custom_select’ => ”, ‘custom_from’ => ”, ‘custom_where’ => ‘ AND opportunities.sales_stage=\’Qualification\”, ‘distinct’ => true ); parent::process($lvsParams); } } these codes are only hints, you should know where these piece of codes should be placed to be working..

AJAX BANNED MODULES

In SugarCRM if you want to ban ajax only for particular modules then go to your config_override.php file and add this code $sugar_config['addAjaxBannedModules'][] = “KReports”; //disable ajaxgui for specific module in config override. Now you have done

SUGARCRM ACL ROLES

If you want to get roles for particular user one of the easiest way is Get user roles global $current_user; require_once(“modules/ACLRoles/ACLRole.php”); $acl_role_obj = new ACLRole(); $user_roles = $acl_role_obj->getUserRoles($current_user->id); // grab a list of the current user’s roles foreach ($user_roles as $role) { $role_to_check=$role; }

CONDITIONAL STATEMENTS

Conditional statement syntax is almost same as in other langauges If condition syntax if (condition) { //Code to let user access the site here; } if else statement syntax if(condition){ //code that should be executed if true }else{ //code that should be executed if condition false } ifelse statement syntax if(condition1){ //code }elseif(condition2){ //code } Switch statement in php switch(variable){ case ‘one’: //code break; case ‘two’: //code here break; default: //default code here break; } note: break statement is very important

LOOPS

for loop: for($start=0; $start < 11; $start++) { echo "for loop test";//text will be printed 11 times } while loop: while (condition) { //statement } do while loop: do statement while (condition) The difference is that your statement gets executed at least once. In a normal while loop, the condition could be met before your statement gets executed.

CONTINUE & BREAK

continue and break statements in php are very importants these are very usefull in loops if you want to skip at any point in loop and you want that after this condition below code should not be executed then use continue example: for($i=0;$i<10;$i++){ if($i==6) break;// loop will be terminated and after 6 it will be outside from loop scope echo "before continue"; continue; echo "after continue";//this will never be executed }