About the Author

Josh Richet

5 Ways Of Getting Your Content Noticed

The internet is a very noisy place. In today’s social media dominated landscape it can be hard to get your unique and interesting content noticed. I might not have the busiest site on the net, but I do get a few hundred visits a month without guest-blogging. Here are a few ways I use to get my content clicked on:

pencils

1. Tweet about your content. Ensure that you participate on twitter by following people with interests relevant to your content. Some will follow you back, and those people will see your tweets. Make sure that you regularily update your followers with links to new content as it is posted. Remember the most successful Twitter accounts are those that make many clever observations about the topic most dear to them.
2. Rock Tumblr. Follow a bunch of people on Tumblr and post links to your content. Ask questions to get a response from your following.
3. Present yourself to Facebook. Maintain your Facebook page consistently and post links to your content. Ask Questions to garner user involvement from your following.
4. Go old-school. Eye-catching posters and flyers in business windows with your content url and/or QRCode are an alright idea. It doesn’t seem to convert well in my experience, but I’m from a small town and I’ve seen some good response to this tactic in bigger cities.
5. Tap into Reddit. Answer a redditor’s question citing your own content as the source. If you use reddit, you likely only consume without posting so that you don’t get in trouble for blogspam. Well if someone is asking a question in https://reddit.com/r/askreddit then your answer has been asked for, and you can usually answer with a post containing a link to your content (as the source of your well-typed answer)

These tips are not the only way to get your content noticed and are meant more to inspire you to find creative ways to use the tools available to you. What do you do to get noticed?

Debug code better, faster and with fewer headaches

Every time you change code, there’s a very good chance that you will have introduced bugs to your existing code. IT’s important to take a methodical approach to squishing these bugs, or you may waste a lot of time hunting down the cause of specific problems. Here are 7 tips to debugging your code faster.

debugging php javascript c++ java

  1. Don’t pretend that this isn’t your fault (or your teams fault). You wrote the code and you made a mistake. Don’t beat yourself up over it, but don’t blame the computer for your mistake. By that same token, dont’ beat yourself up over a bug. Bugs will always happen, just solve it and move on.
  2. Treat every error as an opportunity to learn about yourself. If you think of bugs as a puzzle or mystery to be solved, you won’t find yourself burning out as fast and this will encourage a more patient and relaxed approach to solving errors.
  3. Write tests. Testing is not only great at preventing bugs but also helps a lot in debugging. Testing forces your design to be more or less modular, which makes isolating and replicating problems simpler. The tighter control this provides over the environment will cause fewer surprises. Moreover, once you get a failing test case, you can be reasonably sure that you’ve caught the real reason of the code’s behaviour..
  4. Use a debugger! Don’t avoid stepping through your code with a debugger just because it’s time consuming. Checking every line of your logic will often help you to find better ways to do things and highlight the real cause of errors. I personally really like the built in debuggers in both Netbeans and PHPStorm
  5. Talk about someone about your problem, even if it’s just a rubber duck (I personally use my android figurines from Android TO). Forcing yourself to express the problem you are working on in words really does miracles.
  6. Give yourself a time limit. If for example after 45 minutes you feel you are going nowhere, just switch to other tasks for some time. When you get back to your bug, you’ll hopefully be able to see other possible solutions that you wouldn’t have have considered before.
  7. If you have narrowed it down to two systems that collaborate (for example a PHP back-end and a JavaScript front-end), inspect the messages between the two systems via traffic monitor or log files, and determine which system is behaving correctly and which one is not. If there are more than two systems in the scenario, you can perform pairwise checks and work your way “down” the application stack.

As you can see, debugging code isn’t always an exact science,but by applying the right mindset and techniques, you can speed up the process significantly. Fast debugging isn’t always

Related reading:
Why Programs Fail
The Pragmatic Programmer
Software Entrophy

What is Git and How does it work?

The versioning tool, git is really useful as it essentially provides unlimited undo for your sourcecode. You’ll likely see git in most roles as a web or software developer. This article is written for new developers who know they need to learn git and not much else about it.

What is Git?

Using Git effectively will be easier for you if you have a concrete definition of what git is. First off forget what you know about other versioning tools. Git stores things differently, and you need to know this to use it properly. The best way to explain this is found in the official git documentation:

Git thinks of its data like a set of snapshots of a miniature filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored. Git thinks about its data more like a stream of snapshots.

git checkin visualization

The Three States

There are only 3 states of being as far as git is concerned:committed, modified, and staged. Again, the official documentation describes it well:

Committed means that the data is safely stored in your local database. Modified means that you have changed the file but have not committed it to your database yet. Staged means that you have marked a modified file in its current version to go into your next commit snapshot.

This leads us to the three main sections of a Git project: the Git directory, the working directory, and the staging area.

The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer.

The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.

The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the “index”, but it’s also common to refer to it as the staging area.

Git 3 states

In Closing

For real kids, the best way to get good at git is to read the official documentation and follow its examples. You can find git’s official documentation at https://git-scm.com/doc

 

Factory Design Pattern In PHP

The factory design pattern solves a common programming problem. When you have a single point of origin for many classes with the same base class, you have need of the factory design pattern. A factory is a class that instantiates one or more of a number of classes that share the same base type, choosing the type of the instantiated object type at runtime without exposing the instantiation logic. You won’t often see this pattern appearing in basic projects, but as you move into enterprise development, it is very common.

In the following example, an object of type ShapeFactory is instantiated by the application code. Then when the getShape() method is called, the ShapeFactory object instantiates a new object which based on the logic in this function chooses which child class of the Shape class will be chosen to hold the new object. This allows a little more freedom in which types we use at runtime.

Factory Design Pattern UML Diagram
Basic Factory Design Pattern UML Diagram

Factory Design Pattern Example In PHP

The factory design pattern is very simple. The simplest example I like to use to describe it using PHP is a basic game with different kinds of enemy ships. In the following example we will start with an enemy class, and a few child classes that extend it like so:

Now if we are playing a game and wanted to call any of the enemy ship types from a single point of origin, we would spawn them using a factory class that looks something like this:

The code that calls the factory looks like this:

With output looking like this:

Let There Be LIFE In JavaScript

screenshot - javascript life simulator

Can you create life in JavaScript?

My new project, LIFE, is a simple javascript life simulator in which each digital citizen moves randomly, socializes, ages and breeds to replace citizens that die up to a maximum of 50 live citizens at a time. There is a limit of 50 citizens to avoid crashing the browser. Each citizen starts as a newborn and grows to adulthood. Citizens turn orange while socializing. When the citizens reach breeding age, there is a chance that socializing will result in a new citizen being born and added to the top of the pile. when citizens leave breeding age, they turn grey. When citizens die they turn black, stop moving and decompose until they are removed from the stack.

check it out here

Regular expression testing tool

If you’re looking for some place to tweak your regex, look no further!

This weekend I built a regex testing tool. This is geared to programmers looking to test a regex against a haystack. it can be found at https://jr1.ca/regextool

WordPress Theme Guide

How do you turn html into a WordPress Theme?

This article is geared towards students and is intended to be a refresher for when you need to translate HTML designs into a WordPress theme in a hurry. My assumptions are that you know enough HTML and PHP to work with WordPress and that you just need to be guided through the steps.
First we start with creating a new folder in the wp-content/themes folder to contain all of our WordPress theme and all of the files mentioned in this article. Our first file in our new WordPress theme is going to be style.css in the root folder you just created. This file is the heart of any theme, containing your custom css stylings and a header comment that credits the author, names the theme and points to your email and/or website.

style.css

The following is an example style.css file header comment. This comment is required and tells WordPress about your custom theme.

functions.php

Next, create functions.php in the root of your and start it with the following code. This code adds your stylesheet to the output of the wp_head() function, and registers our sidebar widget area

index.php

Next create your index.php from the index.html of your design to provide a default template for your site. Replace your content with the relevant php tags. The following is a minimal example that breaks everything into div tags with id attributes all set for styling:

You now need to fill in the blanks of your template by chopping up your design’s index.html into a header, a footer and a sidebar. Save these files as header.php, footer.php and sidebar.php.

header.php

This is the top of the final rendered html documents. it should contain your <!doctype> tag, your <head> tags and usually your top navigation or banner.

footer.php

This is the bottom of your site and should contain copyright info and the wp_footer(); function

sidebar.php

This is a widget area in sidebar form. you registered this widget in functions.php above.

As a final note, custom page themes can be created by copying index.php and adding a comment to the top of the file.

The following is an example custom home page with a blog roll designed to work with Zurb Foundation 5’s grid system which I teach to my students. This is

blog.php

Finally screenshot.png is an image that should be a screenshot of your theme in all it’s glory. WordPress will show this image on the Appearance->Themes page.

The above is the bare minimum you need to put together for a theme in the classes I teach, and should function as a crash course in building a WordPress theme from an html design. Of course WordPress theming is a deep rabbit hole with a lot of options and limitless possibilities, I encourage you to read the WordPress Codex! To get more in depth, check out the codex article on the matter.

How to flip the words in a sentence backwards with PHP

How do you flip the words in a sentence backwards with PHP?

This is one of those tests programmers like to give in interviews, at first it seems like you could just use the strrev() function, but it actually reverses the characters in a string which makes the words all show up backwards and so would only work for sentences made of palindromes. The actual answer is to blow the string up into an array of words using the explode() function, then reverse the order of the array with the array_reverse function, then use the implode()  function to glue the array back into a string.

The code looks like this:

I hope this is useful to you. Good luck in that interview.

Set up Linux LAMP server with WordPress

As a web developer it’s handy to have a personal web server that you can have full control over for hosting your PHP code. Alternatively, if you are looking to learn about Linux for the first time, I recommend setting up your first couple servers on a virtualbox installation. This article is a list of steps to help your set up a Linux Apache MySQL and PHP (LAMP) server quickly.

The target audience of this article is post-secondary web development students and new web developers who have need of a custom server for prototyping or hosting web sites and applications on or offline.

Steps

Download a Debian Linux installer from Debian.org. It’s important that you get the right image. The easiest of these to use are the CD or usb stick netinstall images. Ensure that you select the right image for your processor (i86 if you’re using virtualbox).

Install to your server or virtualbox. Mount the iso you downloaded from debian.org into virtualbox or burn it to a disc and boot your server from it. Keep it light, and try to avoid installing too many things you don’t need.

Screen Shot 2016-02-29 at 12.12.48 PMScreen Shot 2016-02-29 at 12.14.33 PM

Follow the Debian installer:

  • Select your language (English for me)
  • Select your country (Canada for me)
  • Select your keymap (American English for me)
  • set up your root user and your new user. I reccomend writing down these passwords.
  • select your timezone
  • Set up your disk. (use entire disk for me, then enter and yes for all options until the base system starts to install.)
  • Select your Debian mirror (Canada and ftp.debian.ca for me)
  • When it comes to package selection, the following options are what I select for a basic webserver with an ssh server and standard system utilities
  • Screen Shot 2016-02-29 at 12.28.30 PMInstall grub to root of dev/sda
  • remove the disc or unmount the iso
  • boot into your new debian server and login with the user info you wrote down.

When your linux is ready, install sudo via the apt installer tool:

Edit sudoers file, adding your username & permissions then reboot

Log back into your system’s command line

Download wordpress from wordpress.org

Unzip the zip file

Copy the files to your webroot at /var/www/html

Set up a new user with a database in your mysql installation:

If you are using a hosting provider, you may already have a WordPress database set up for you, or there may be an automated setup solution to do so. Check your hosting provider’s support pages or your control panel for clues about whether or not you’ll need to create one manually.

If you determine that you’ll need to create one manually, follow the instructions for accessing phpMyAdmin on various servers, or follow the instructions for Using Plesk, Using cPanel or Using phpMyAdmin below.

If you are installing WordPress on your own web server, follow the Using phpMyAdmin or Using the MySQL Client instructions below to create your WordPress username and database.

If you have only one database and it is already in use, you can install WordPress in it – just make sure to have a distinctive prefix for your tables to avoid over-writing any existing database tables.

https://codex.wordpress.org/Installing_WordPress

get the ip of your virtual server

Type the IP of your virtualbox installation into your browser on your PC or Mac to start the WordPress installer

Complete the WordPress installer, and voila your server is running wordpress.

There’s a lot more your Linux server can do, you just need to do some research and bam you can have fantastic results.

WordPress Custom Slider Tutorial

If you’ve been following my blog, you’ve seen that I’ve been rebuilding JoshRichet.com as a tool for teaching my class about WordPress. Sometimes creating a great plugin for your WordPress site takes a little rough groundwork laid out by someone with a little more experience. This plugin was intended to be a rough framework for building image-based plugins that insert into WordPress themes or pages easily.

This plugin provides one admin-controlled Zurb Foundation Orbit Slider for your template and assumes that your theme already includes Zurb Foundation like the parent theme used as an example in my classroom.

This plugin provides the WordPress shortcode [jr_custom_slider], and  the PHP function, bg_header_slider() so that it can be inserted into a template or a page with one line.

in a post or page simply insert the following:

In a theme to get the same output as the shortcode, insert the following:

Here is the plugin code:


Notice: Use of undefined constant WP_PB_URL_AUTHOR - assumed 'WP_PB_URL_AUTHOR' in /app/wp-content/plugins/adsense-box/includes/widget.php on line 164

Notice: Use of undefined constant WP_PB_URL_AUTHOR - assumed 'WP_PB_URL_AUTHOR' in /app/wp-content/plugins/adsense-box/includes/widget.php on line 164

Notice: Use of undefined constant WP_PB_URL_AUTHOR - assumed 'WP_PB_URL_AUTHOR' in /app/wp-content/plugins/adsense-box/includes/widget.php on line 164
Please wait...

Subscribe

Want to be notified when a new article is published? Enter your email address and name below to be the first to know.