Category Archives: Programming

Dam dem node_modules!

If you’ve ever had to create a new project with the node package manager you’ll have seen it install a load of “dependencies” installed onto your simple project.  After a while you’ll end up with multiple projects and multiple folders of “node_modules”. No problem you say, but it will be when you start running out of space!

You can always reinstall them back with a;

npm install

Deletion:
Deleting one of these folders can take a few minutes so imagine having more than one project and “node_modules” for each project.  This can take up to many gigs of space depending on the project.

Solution npkill
this great util will allow you to delete multiple node_modules folders across different projects;

Source:
https://stackoverflow.com/questions/42950501/delete-node-modules-folder-recursively-from-a-specified-path-using-command-line

Simply running this command in the dir where you have many projects with node_modules will allow you to choose which projects you want to remove the installed dependancies from;

npx npkill

How to install two PHP versions in Window XAMPP?

While Xampp with PHP7 is great there are times when you need PHP5 for an old project. I found this great article on medium the other day on how to have two different PHP versions and one Xampp installation. The alternative is a pain as running two Xampp versions is just too much hassle.

The below article allows you to setup xampp to use PHP 5 and 7 when ever you want. So for normal projects you would use the address’s below, basically it makes xammp listen on port 8888 (or whatever u want) for requests and then uses PHP5 to interpret/compile any Php5 code.

PHP 7http://localhost/myproject
PHP 5http://localhost:8888/myproject

Article with details;
https://medium.com/@naingdroid/how-to-install-two-php-versions-in-window-xampp-b1402c23f42

Python Script to Detect Corrupt Image Files (.jpg)

Over the xmas period i  found out that most of the files in my documents folder were corrupt.  I didnt want to delete them all so i decided to see if Python could help and sure enough it did.

So i wrote a script below to;

  • find all images in a folder and sub-dir’s
  • open then with a python library and see if the file is corrupt
  • move them to a folder and rename them

Massive help from people on stackoverflow.com

Laravel Error – SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Im currenlty running my way though Laravel 5 the PHP framework and following some tutorials. If your starting this framework you will most likely run into the error below when you run your migrations;

Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

The fix is simple;

Open the AppServiceProvider file and add the following line to the boot function;

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //add this line to fix the error
        Schema::defaultStringLength(191);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

via;

https://laracasts.com/discuss/channels/laravel/laravel-54-failing-on-php-artisan-migrate-after-php-artisan-makeauth?page=1

Angular 4/5 quick tips

 

 

 

 

 

 

how to add bootstrap:

npm install [email protected] jquery tether --save

add the scripts and styles to your “.angular-cli.json”

add the following the styles and scripts section;

"styles": [
 "styles.css",
 "../node_modules/bootstrap/dist/css/bootstrap.css"
 ],
 "scripts": [
 "../node_modules/jquery/dist/jquery.js",
 "../node_modules/tether/dist/js/tether.js",
 "../node_modules/bootstrap/dist/js/bootstrap.js"

create new project:

ng new myapp

start server:

ng serve

create new component:

ng g component components/mynewcomponent

create new service:

ng g service services/mynewservice

Getting started with Python and the Django Framework part 1

So over the christmas holidays ive been keeping myself busy by learning more about the Python language.

Having learnt a few basics i started to try the Django framework which ive seen mentioned quite a lot.  Im reffering to windows mainly in this case see below for more detailed instructions;
https://docs.djangoproject.com/en/2.0/howto/windows/

Step 1:
Install python from the site below and install the necessary version for your Operating system.
https://www.python.org/downloads/release/python-364/

Step 2:
Once you get that installed, verify that python is installed by typing “python” from the windows command prompt;

 

 

 

 

 

 

Step 3:
Install Django framework via command prompt;

pip install django

Step 4:
Create your first project its best to refer to the offical document and tutorials at;
https://docs.djangoproject.com/en/2.0/intro/tutorial01/

From the offical site;

Creating a project

If this is your first time using Django, you’ll have to take care of some initial setup. Namely, you’ll need to auto-generate some code that establishes a Django project – a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings.

From the command line, cd into a directory where you’d like to store your code, then run the following command:

$ django-admin startproject mysite

This will create a mysite directory in your current directory. If it didn’t work, see Problems running django-admin.

Cakephp 3 – using uuid as primary key

In addition to use an auto-increment key as the primary key, you may also use UUID columns. CakePHP will create a unique 36 character UUID (Cake\Utility\Text::uuid()) whenever you save a new record using the Table::save() method.

From the book;
https://book.cakephp.org/3.0/en/intro/conventions.html#model-and-database-conventions

So if you create your primary key field as char(36) , cakePHP3 will generate unique uuids rather than the stand auto-incremented 1,2,3 4 keys

Credit to stackoverflow again;
http://stackoverflow.com/questions/34519770/cakephp-3-save-function-not-generating-primary-key-for-database

 

CakePHP3 Cache Example – Using Curl to get a Web page contents


Heres a simple example of using the cache feature of cakephp. We want to grab a webpage contents from the web but we only want to do this once otherwise its going to be slow and waste resources.

The basic idea is that we check if the url is saved in cache, if it is then we read it in otherwise we must use curl to grab it.

CakePHP3’s Cache settings are in the config/app.php file;

/**
* Configure the cache adapters.
*/
'Cache' => [
'default' => [
'className' => 'File',
'path' => CACHE,
'url' => env('CACHE_DEFAULT_URL', null),
'duration' => '+60 minutes',//the duration object should cached for
/*'prefix' => 'mycacheprefix_',*/
],

 

 

CakePHP 3 Cache:
https://book.cakephp.org/3.0/en/core-libraries/caching.html

Cakephp 3 Plugin – Changelogs

Ive finally gotten around to releasing this little app i was working on for Cakephp3.  I decided a while ago to abandon Cakephp 2 and go with the new version 3.

Its been a steep learning curve so i wanted to learn as much as i could.  So thats where this app/plugin came in.

The Aim:
The goal of the plugin was to allow a way to simply log tasks, changes or articles about the cakephp project your working on.

If your working on a website/project on your own you need a way to record your changes and tasks so i thought this would be an ideal way to learn and release something. Sure you could do the same with Github and better but i think its better to have something like this integrated into your application.

Screenshot: Version 1
2016-05-25

 

 

 

 

 

Version 2 Screenshot:
changelogseditv2

 

 

 

 


Github & Source:

https://github.com/gerrymcdonnell/cakephp-changelog