Thursday, 13 June 2019

Useful terminal commands for MAC, Ubuntu or Windows

Search specific type of file in all folder

  • find ~ -type f -name '*pdf'
  • find ~ -iname '*pdf'

Search specific type of file in current folder
  • find . -iname '*pdf'
Make file executable
  • chmod +x file.xx'
Run PHPFixer on current folder
  • php-cs-fixer fix --diff --dry-run --stop-on-violation -v --using-cache=no
  • php-cs-fixer fix --stop-on-violation -v --using-cache=no
Make your git branch prefix
  • curl https://gist.githubusercontent.com/bartoszmajsak/1396344/raw/bff6973325b159254a3ba13c5cb9ac8fda8e382b/prepare-commit-msg.sh > .git/hooks/prepare-commit-msg && chmod u+x .git/hooks/prepare-commit-msg
Delete node_modules from a certain folder
  • copied from https://stackoverflow.com/questions/42950501/delete-node-modules-folder-recursively-from-a-specified-path-using-command-line
  • find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \; 

Open a very large file like log files
  • tail -500 bigfile | less
Show hidden files in mac
  • defaults write com.apple.Finder AppleShowAllFiles true
  • killall Finder

Add entries to a file by using export
  •   echo 'export PATH="/usr/local/opt/php@8.0/bin:$PATH"' >> ~/.zshrc

      echo 'export PATH="/usr/local/opt/php@8.0/sbin:$PATH"' >> ~/.zshrc


Install Python
  • brew install pyenv
  • pyenv install 2.7.18
  • pyenv global 2.7.18

Share:

Monday, 27 May 2019

Country Package for Laravel

It is often or not we need a country listing in our package to display in the view or dropdown HTML component. Instead of creating table of coutries we could use a proven PHP package library to do that.

I come across this library league/iso3166 and have use it ever since.

Methods you can use are:


   #to define the library 
   use League\ISO3166\ISO3166;

   #to get all countries
   $countries = (new ISO3166())->all();

   #to get a specific country details and currency for Philippines
   $country => (new ISO3166())->alpha3('PHL');

   #to get a specific country name for Philippines
   $country_name' => ((new ISO3166())->alpha3('PHL'))['name'];


Share:

Wednesday, 23 January 2019

PHP Number to Romans Numeral conversion

Just Playing with PHP lately and thought of a Digit to Roman Numerals conversion. This is one of my testing exam before and just recall how I did it.



$romanString = '';
$value = 975;
 do {
   $converted = convertToRoman($value); 
   $value = $converted[0];
   $romanString = $romanString .  $converted[1];
 } while ( $value != 0);

echo $romanString;

 function convertToRoman($number){
    $returnValue = 0;
    $returnString = '';
 $romanArray = [[1000,'M'],[900,'CM'],[100,'C'],[90,'XC'],[50,'L'],[10,'X'],[9,'IX'],[5,'V'],[4,'IV'],[1,'I']];

 foreach ($romanArray as  $value) {
  
       if ($number >= $value[0]) {
            $returnValue = $number - $value[0];
            $returnString = $value[1]; 
            break;
       }        

 }
     
 return array($returnValue,$returnString);
}

Share:

Tuesday, 18 September 2018

Laravel Filtering Eloquent Results and Left Join Example

These scripts join table demographics to countries table by looking into line 2.
Line 7 to 18 shows how can we filter the resulted collection on the results.
Finally, this returns an array of demographics with age, gender, and location as indexes.


       $mixDemographics =DB::table('demographics')
            ->leftJoin('countries', 'demographics.country_id', '=', 'countries.iso_3166_2')
            ->where('user_id',$userId)
            ->get();

        $demographics = [];
        $demographics['age'] = $mixDemographics->filter(function ($demo) {
            return ($demo->metric == 'AGE');
        });

        $demographics['gender'] = $mixDemographics->filter(function ($demo) {
            return ($demo->metric == 'GENDER');
        });


        $demographics['location'] = $mixDemographics->filter(function ($demo) {
            return ($demo->metric == 'COUNTRY');
        });

        return $demographics;



Share:

Tuesday, 17 July 2018

Webpush notifications for Laravel

Here the necessary steps in creating a webpush applications in LARAVEL. Add the library in your composer by checking this site.
In order for you to run this site, you must enforce https on your website by adding this line in you AppServiceProvider.php

    public function boot()
    {
        $this->app['request']->server->set('HTTPS', true);
    }
I wanted to use sqlite in heroku so I need to add the sqlite driver in composer.json then run 'composer update'.

    "require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "~3.3",
        "laravel-notification-channels/webpush": "^3.0",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "pusher/pusher-php-server": "^3.0",
        "ext-pdo_sqlite": "*"
    },
Share:

Monday, 16 July 2018

Return JSON from a Laravel server from a different domain using javascript

Been tinkering for 3 hours how to get the things going. For the javascript side In web.php add the route For the controller make sure you have added ->setCallback($request->input('callback')) at the end of the json response.
Share:

Monday, 9 July 2018

Complete Postgres installation step by step

Homebrew is a popular package manager for OS X. To install Postgres with Homebrew, follow the steps below: The first thing to do is install Homebrew if you haven’t done so already. Homebrew site has a simple command that you have to paste in your terminal to do so. Make sure to accept the command line developer tools installation if prompted. Next, run brew install postgres to install Postgres. It might take a little while to compile and install. After compilation is done, it’ll give you some instructions to finish setting it up. The database will be initialized during installation, so there isn’t a need to run initdb to finish installation of Postgres via Homebrew. Near the end of the installation instructions you should see mention of the command brew services. If you don’t already have brew services installed. It may be installed with this command: brew services stop/start postgresql createuser -s postgres

Remove previous versions of PostgreSQL

brew uninstall --force postgresql
Delete all Files of Postgres

rm -rf /usr/local/var/postgres
Install Postgres using Homebrew

brew install postgres
Start Postgres

pg_ctl -D /usr/local/var/postgres start

or

brew services stop/start postgresql

download pgAdmin https://www.postgresql.org/ftp/pgadmin/pgadmin4/v2.0/macos/
Share:

Popular Posts

Recent Posts

Pages

Powered by Blogger.

About Me

My photo
For the past 10 years, I've been playing with codes using PHP, Java, Rails. I do this for a living and love new things to learn and the challenges that comes with it. Besides programming I love spending time with friends and family and can often be found together catching the latest movie or planning a trip to someplace I've never been before.