Thursday, 29 November 2018

How to set environment variables in angular 6?



All variables which vary based on the environment, should be placed inside these two files appropriately. Check the examples given below for the API Endpoint.

// environment.ts environment variables
export const environment = {
  production: false,
  BackendAPIEndpoint: "https://dev.endpoint.com"
};

// environment.prod.ts environment variables
export const environment = {
  production: true,
  BackendAPIEndpoint: "https://prod.endpoint.com"
};

To access the variables, import the environment constant, and then use it as follows:

import { environment } from '../environments/environment'; //change path accordingly

Usage:
const BackendAPIEndpoint = environment.BackendAPIEndpoint;

Dealing with 1 or More Environment:

// environment.staging.ts environment variables
export const environment = {
  production: true
  BackendAPIEndpoint: "https://staging.endpoint.com"
};


Next, we need to make configuration changes to our angular.json – at the root of our workspace. This will enable Angular CLI to recognize our two new environments and use the new environment files we created in the previous step.

"configurations": {
   "production": {
       "fileReplacements": [
           {
              "replace": "src/environments/environment.ts",
               "with": "src/environments/environment.prod.ts"
           }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": false,
        "extractCss": true,
        "namedChunks": false,
        "aot": true,
        "extractLicenses": true,
        "vendorChunk": false,
        "buildOptimizer": true,
        "serviceWorker": true
   }
}

Your new configuration for staging environment should look like this:

"configurations": {
   "production": {
        ...
    },
    "staging": {
    "fileReplacements": [
     {
         "replace": "src/environments/environment.ts",
         "with": "src/environments/environment.staging.ts"
     }],
     "optimization": true,
     "outputHashing": "all",
     "sourceMap": true,
     "extractCss": false,
     "namedChunks": false,
     "aot": false,
     "extractLicenses": true,
     "vendorChunk": false,
     "buildOptimizer": true,
     "serviceWorker": true
   }
}

Building your App
Finally, to build your application with the new custom environment, use the –configurations=environment-name flag, as show below:

//for development environment
ng build

//for staging environment
ng build --prod

//for staging environment
ng build --configuration=staging

And that’s it, you can now configure your Angular Application.

Thanks

Saturday, 3 November 2018

Wifi (internet) not working after upgrade from ubuntu 16.04 to ubuntu 18.04?

Hello All,

Do the following on terminal to overcome this issue:

#sudo /etc/resolv.conf

Added nameserver 8.8.8.8

and then

#sudo /etc/init.d/networking restart


Done!!!


How to upgrade ubuntu 14.04 to 18.04

Follow the following steps:

#do-release-upgrade
#lsb_release -a
#apt update
#apt upgrade
#apt dist-upgrade
#apt install update-manager-core
#do-release-upgrade


Thanks

Friday, 24 August 2018

How to Create Dynamic associative array in typescript?

Hello



public data:Array<any> = [
{"id":10, "text": "First"},
{"id":11, "text": "Second"},
{"id":12, "text": "Third"},
{"id":10, "text": "Fourth"},
{"id":11, "text": "Fifth"},
{"id":13, "text": "Sixth"}
];
public array: any[][] = [];

for(let i: number=0;i<this.data.length;i++){
this.array[this.data[i].id] = this.array[this.data[i].id] || [];
this.array[this.data[i].id].push(this.data[i].text);
}

this.array.forEach(element => {
console.log(element);
});

Thursday, 14 June 2018

How to install angular js in ubuntu 14.04

Hello,

Verify that you are running at least Node.js version 8.x or greater and npm version 5.x or greater by running node -v and npm -v in a terminal/console window. 


Then,

npm install -g @angular/cli

Thanks

How to upgrade nodejs and npm version in ubuntu 14.04

Hello,

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

Friday, 14 October 2016

Remove new line or space between tags in xml

<?php
$xml = '<Pages>
<Page Name="test">
<controls><test>this is a test.</test></controls>
</Page>
<page Name="User">
<controls><name>Sunil</name></controls>
</page>
</Pages>';
echo $xml;


$re = '/(?<=\>)(\r?\n)|(\r?\n)(?=\<\/)/';
$substring = '';

$xml = preg_replace($re, $substring, $xml);

echo "The result of the substitution is ".$xml;
?>


Wednesday, 4 November 2015

How to send jQuery POST request on cross-domain

For the specific domain see below:
 
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
   header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); 
   header('Access-Control-Allow-Credentials: true');
   header('Access-Control-Max-Age: 86400');    // cache for 1 day
}
 
 
If you want to allow from any domain see below:

Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Headers "content-type"
 
 
Cheers!!! 

Monday, 23 September 2013

How to configure phpMyAdmin to access multiple servers from phpmyadmin?

Hi Guys,

Open the following URL in editor:

vim /etc/phpmyadmin/config.inc.php

Now,

   $i++;

    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    //if (empty($dbserver))
    $dbserver = 'servername';
    $cfg['Servers'][$i]['host'] = $dbserver;

    if (!empty($dbport)) {
        $cfg['Servers'][$i]['connect_type'] = 'tcp';
        $cfg['Servers'][$i]['port'] = $dbport;
    }
    //$cfg['Servers'][$i]['compress'] = false;
    /* Select mysqli if your server has it */
    $cfg['Servers'][$i]['extension'] = 'mysqli';
   
Cheers!!!

Monday, 16 September 2013

How to count files and line recursively using ubuntu?

Hellos,


How to count number of files recursively?

find . -type f | wc -l


How to count number of lines in files recursively?

wc -l `find  -name '*.php' -o -name '*.html' -o -name '*.xls' -type f`;

Cheers!!!









Thursday, 5 September 2013

How to Remove Save Draft & Preview Buttions.. and also Status: Draft & Visibility: Public in wordpress?

 Hello All,
 Please add below lines in your function.php file 
 
<?php
  add_action('admin_print_styles', 'remove_this_stuff');
  function remove_this_stuff() { ?>
    <style>
       #misc-publishing-actions, #minor-publishing-actions {display:none; }
    </style>
<?php } ?>
 
Cheers!!! 

Friday, 30 August 2013

How to remove admin bar from non admin users in wordpress?

Hi All,

Please add following script into your functions.php file:

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
      show_admin_bar(false);
    }
}

Cheers!

How to add login/logout button in wordpress menu?

Hi All,

Add following script into your functions.php

add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {

        ob_start();
        wp_loginout('index.php');
        $loginoutlink = ob_get_contents();
        ob_end_clean();

        $items .= '<li>'. $loginoutlink .'</li>';

    return $items;
}

Cheers!!!

Thursday, 8 August 2013

How to create cron job in YII framework?

Hi All,

Create cron.php file under project folder and write following:

<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/console.php';

require_once($yii);
Yii::createConsoleApplication($config)->run();

?>


Create console.php file under protected/config folder and write same data as written in main.php. see below:

/ This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'name'=>'My Console Application',

    // preloading 'log' component
    'preload'=>array('log'),
        'import'=>array(
                'application.components.*',
                'application.models.*',
        ),

    // application components
    'components'=>array(
           
        // uncomment the following to use a MySQL database       
        'db'=>array(
            'connectionString' => 'mysql:host=localhost;dbname=bollywood_news',
            'emulatePrepare' => true,
            'username' => $dbUsername,
            'password' => $dbPassword,
            'charset' => 'utf8',
                        'enableProfiling' => true,
        ),
       
        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                                        'logFile'=>'cron.log',
                    'levels'=>'error, warning',
                ),
                                array(
                                        'class'=>'CFileLogRoute',
                                        'logFile'=>'cron_trace.log',
                                        'levels'=>'trace',
                                ),
            ),
                       
        ),
    ),
   
);

Now,

Create CronjobCommand.php file under protected/commands folder. Here cronjob is a command.

<?php

class CronjobCommand extends CConsoleCommand {

    public function run($args) {
        // your code will come here...
    }

}

Now,

You have two ways to run your command:

Go to your project folder and write following:

a. php cron.php cronjob
b. php protected/yiic cronjob


Cheers!!!





?>

Wednesday, 7 August 2013

How to take backup of log files in symfony 1.4?

Hi All,

Execute following command on your project root folder:

php symfony log:rotate frontend prod --period=1 --history=5


In above command,
period 1 means:
    frontend_prod.log contains 1 day log data and very next day backup of same file will be saved under log/history folder and also empty it.
history 5 means:
    Under log/history folder, backup of 5 days will be stored only.


Cheers!!!

Friday, 12 July 2013

How to send mail from shell scirpt?


Hi All,

First of all we will create a sh file and write script see example below:

vim notificationFailedCron.sh

Write down the following code in the above file:

#!/bin/bash
dt=`date +%F`
echo $dt
passwd="pwd"
count=`mysql -uipay_read -p$passwd -h localhost -D database_name -B --skip-column-names -e "select count(*) from tablename where last_execution_status = 'notexecuted' AND date(created_at) = '$dt';"`
if [ $count -ge 5 ]; then

echo $count;
mail   -s "$count Payment notifications are getting failed."  abc@abc.com  <<< 'There are $count notifications are pending due to cron job failure'
fi


Now setting cronjob which will run every minute:

* * * * * /path/to/file/ipay4me_cronJob/notificationFailedCron.sh /usr/bin/php Asia/Calcutta >/dev/null 2>&1



Cheers!

Thursday, 4 July 2013

How to create cron in symfony?


Hi All,

First of all create task using the below command:

 
php symfony generate:task [your task] 



for example:

php symfony generate:task notificationFailed

After executing above command you will see that following file has been created.

Creating "/var/www/archive/ipay4me_zen/lib/task /notificationFailedTask.class.php" task file


Now,

change the following variable in above created file:

$this->namespace        = 'project';
$this->name             = '[name-for-your-task]';
$this->briefDescription = '[some short explanation of what your task does]';


You will see another method called execute() given below:

protected function execute($arguments = array(), $options = array())
{
 // initialize the database connection
 $databaseManager = new sfDatabaseManager($this->configuration);
 $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();

 // add your code here

 echo "I just did nothing at all, but at least I did it successfully!\n\n";
}


Let’s give it a test run. Open your command line and enter

php symfony project:[your task]


if everything is fine then you will see "I just did nothing at all, but at least I did it successfully!" otherwise correct error and run again.

If you see the expected output you’re then ready to go to the next step.


Note: if you want to access your app.yml variable here then you have to write following line:

$this->createConfiguration('frontend', 'prod')

or

$this->createConfiguration('frontend', 'dev')

Cron Setup:

* * * * * cd [YOUR SF APP DIR] && /usr/bin/symfony project:[YOUR TASK] >>[YOUR SF APP DIR]/log/crontab.log
e.g,

* * * * * cd /var/www/archive/ipay4me_new && /usr/bin/php symfony project:notificationFailed >>/var/www/archive/ipay4me_new/log/crontab.log


Cheers!!!

Wednesday, 22 May 2013

How to create session in zend framework 1.12?

Hi All,

Use following script to create session:

$mysession = new Zend_Session_Namespace('mysession');   
$mysession->counter = 1000;

Regards,

Thursday, 16 May 2013

How to open crontab in VI editor?

Hi  All,

Please write the following command to see crontab in Vi editor:

VISUAL=vi crontab -e

Cheers!!

Wednesday, 30 January 2013

How to change extension from upper to lower case in ubuntu?

Dear All,


rename 's/\.JPG$/\.jpg/' *.JPG

The above command will convert all JPG to jpg.


Cheers!