Call   0208 3131682   Mon-Fri 9am-6pm
All Posts By

louie171

How to speed up Web Development in Java

By | Uncategorized | No Comments

This is an article I’m currently working on (its just rough notes at the moment).

Java features ( Java 8 and beyond )

eg var for variables in methods

Spring Boot

Can be up and running as fast as a Laravel app ( can even have a prod grade server, so just start server and you’re good)

Spring Dev Tools – Spring fast restrarts

JRebel ( rem costs £400 per year )

Spring STS Eclipse

Clean Code

Make it obvious was code does from variable and function names. Reading less code, saves alot of time.

Testing – use BDD tests

BDD gives the most bang for the buck, when it comes to testing your code works, fine grained TDD tests will slow development.

Lombok

For handy annotations such as @Data to remove boiler plate but will have the relevant stuff compiled into the class (such as getters, setters, toSting ). Automatic getter/setters on wrapper type classes save reading through code.

IDE – use its full power

Some good tips here e.g. save actions ( eg format source on save )

Use the your owe predefined templates for common actions

Setup WordPress WP-CLI on Docker ( the simple way )

By | Uncategorized | No Comments

In this post I’ll run over how to setup WP-CLI on a Docker web server image ( so you can easily use it todo a Database find and replace , would is handy when you need to migrate a site from one place to another ).

This presumes you have PHP setup on the command line (which my image did have ). Anyway here goes:

  1. First in your Docker folder run ‘docker ps’ ( to get the name of the web server image CONTAINER ID )
  2. Pop that into this command e.g. ‘docker exec -it fdghye5742252 bash’
  3. You’ll be in a shell on the web server now
  4. navigate to your web root of the site you want ( my image puts me there already eg /var/www/html )
  5. download wp-cli and install see https://make.wordpress.org/cli/handbook/guides/installing/
    1. you can also do this on a volume if you have your webroot setup as a volume linked to your local hard drive
  6. I didn’t bother with moving it to the bin dir (which would put it on the global path)
  7. I just did ‘mv wp-cli.phar wp’
  8. you can then run eg
    1. ‘./wp –info’
    2.  do your find and replace ‘./wp search-replace ‘https://www.somesite.co.uk’ ‘http://localhost’ –allow-root’

 

Disclaimer – Obviously with anything like this be careful and make sure you have a backup, use at your own risk.

 

 

In WordPress Recent Posts Widget , only show posts tagged with the current page url

By | Uncategorized | No Comments
 

Setting up a Laravel app on Docker

By | Apache, Docker, Laravel, linux | No Comments

Rough notes, will pull this togther in a blog post at later date.

issue:

The requested URL /login/ was not found on this server.

resolution:

add to manually enable mod rewrite on command line in the container:

# launch a terminal in the container

docker exec -it e39431779799 bash

# enable modrewrite

a2enmod rewrite

/etc/init.d/apache2 reload

 

issue:

could not find driver (SQL:

resolution:

Add this to Dockerfile:

RUN docker-php-ext-install mysqli pdo pdo_mysql
run

docker-compose build

then bring it up:

docker-compose up -d

Use anonymous functions sparingly

By | Javascript, Programming Tips and Best Practices | No Comments

This is the first of a bunch of posts I’m going to write on programming tips and best practices.

This one is about Anonymous functions ( a sometimes useful technique if your going to use in one place and throw away ). 

And thats all well and good, however these make code more difficult to understand ( especially large code bases you need to maintain ).

For example imagine some code you need to maintain, lets say it starts off with a long file you need to read through and get a high level understanding of. If its littered with anonymous functions it’s makes it hard to understand (quickly, quickly being the operative word, we’re busy people after all with lots of a new features the boss wants to add).

Is this easier to understand (approach 1)

 

Than this

 

It’s quicker and easier to read and understand the 2nd code ( we don’t even need to read the function ‘toggleDisplayOfControls’ because from its name it’s obvious what it does).

To take this one step further we can nicely comment the function (toggleDisplayOfControls) at the top ( as is standard ) if needed (in my experience anonymous functions are rarely commented).

 

Adding javascript functions to Laravel Mix ( and why you get error Uncaught ReferenceError: function is not defined )

By | Javascript, Laravel, Programming | No Comments

This one had me pulling my hair out the other day. I was using Laravel,  adding a javascript function to the app.js file ( also tried using require in app.js and pulling in my function ). Laravel uses Laravel Mix which is a wrapper for webpack.

Yet with either approach I was getting the javascript error:

Uncaught ReferenceError: testing_helloworld is not defined

It seemed to be working ( had npm run watch , compiling it and doing a view source I could see the function in my javascript app.js file ).

My function source code looked like this:

It seems webpack wraps this in IIFE (see details on mozilla site )

This has the effect of wrapping it in its own scope ( and not in the global scope ).

So to put it in the global scope, so you can call it anywhere, you need to pop the function onto a global such as Window as below:

thanks stack overflow ! 

I’d have read through my app.js file , but it was massive and would have taken me awhile to find this I think ! Hope this helps someone else with Laravel Mix, Webpack and adding your own javascript functions.