Skip to main content
#! code

Main navigation

  • Tools
  • Snippets
  • About
  • Contact
  • Services
  • Support Us!
JavaScript Logo

Creating Tic Tac Toe In JavaScript Part 1: The Game

19th March 2023 - 18 minutes read time

Tic Tac Toe (or noughts and crosses) is a good game to create when learning game development as it has simple rules and a known win state. I have created a version of tic tac toe using PHP before, but I wanted to see if I could re-create the game in JavaScript using the canvas element. This is certainly possible to do as everything we need is built into JavaScript itself, which means we don't need to import any packages to get this working.

In this article I will go through the necessary components needed to create a version of tic tac toe using JavaScript and a canvas element.

PHP Logo

Generating Histogram Colour Analysis Graphs From Images In PHP

5th March 2023 - 29 minutes read time

If you've ever looked at the settings in a digital camera, or have experience with image processing programs like GIMP, then you may have seen a colour histogram. This is a simple graph that shows the amount of different shades of colour are present in the image.

They are created by looking at the number of colours in a given image and them mapping their red, green and blue values against a the frequency of their occurrence in the image.

Colour histograms are useful for looking at the overall colour distribution within an image and can also be used to simplify the colours of an image by restricting how much of a certain colour is allowed based on its frequency.

Drupal Logo

Drupal 10: Creating Context Aware Plugins

19th February 2023 - 18 minutes read time

In previous articles I have written about injecting context into context aware plugins and creating custom context providers and wanted to complete the series by writing about creating context aware custom plugins.

The context system in Drupal is a powerful way of injecting dynamic data into plugins without writing code to add that data directly to the plugin itself. Instead of adding custom code to find the current user or the node from the route of the page you can inject the context into the plugin using the context system and add code to make use of that data. Although most commonly used in blocks it can be found in a couple of other plugin types in Drupal core, like the condition plugin for example.

In this article I will go through how to create a context aware plugin, including how to create custom plugins and how to allow that plugin to understand the context_definitions annotation. Once the custom plugin is complete we will render it using a Drupal controller action to prove that the context works correctly.

Drupal Logo

Drupal 10: Migrating Flags With The Migrate Module

5th February 2023 - 16 minutes read time

I've been doing a bit of Drupal migration recently, and one of the tasks I have undertaken is to migrate "likes" from a Drupal 7 site to a Drupal 10 site.

The likes in the old Drupal 7 site were built using a custom module, with the Flag module was selected to provide the new functionality on the new Drupal 10 site. This meant that I needed to migrate the old custom structure into the entity structure provided by the Flag module.

To add further complication, it was possible to add likes to nodes and comments, which meant that the flags on the new side needed to be applied to two different types of entity. This was simple enough to do using two different types of flag entity; one for nodes and one for comments.

Drupal Logo

Drupal 10: Programmatically Injecting Context Into Blocks

29th January 2023 - 10 minutes read time

Context definitions in Drupal are really useful when you want to inject context into your plugins and I have been using them for a little while now. It has made building custom blocks to add content to pages much easier as I don't need to copy the same block of code to find an entity of a particular sort into the block plugin.

One problem I encountered when using this technique was when trying to programmatically create and render a block. The problem was that the context wasn't available in the block when it was used in this way, and it took me a little investigation to find out how to put all of the pieces together.

Rendering a block programmatically is sometimes a necessity to do when you need the block outside of the block's normal region. You might create a block that collects together the output of a number of blocks, which allows you to template them together in a very precise way. You might also need to print out a block without having to create a region on a page.

Drupal Logo

Drupal 10: Creating Custom Context Providers

22nd January 2023 - 26 minutes read time

I previously looked at injecting context providers into context aware plugins. This time I will explore more about creating our own context providers to plug into this system.

The context provider system is an ideal way to provide context to context aware plugins, with blocks being the prime example. You would use a context provider to inject an entity or value into the block so that actions can be taken using that data.

For example, we could load the currently loaded node from the route object using the context so that we didn't have to bake the route provider logic into the block.

The values we inject also plug into the cache systems and so we don't need to worry about making sure we integrate the cache systems within the block system. That is all taken care of upstream.

Drupal Logo

Drupal 10: Using Context Definitions To Create Context Aware Plugins

8th January 2023 - 12 minutes read time

When developing plugins in Drupal a common task is to inject context so that certain tasks can be performed.

For example, we might have a block plugin that needs to know about the content entity of the page it is currently being rendered on. We could potentially inject the routing system into the plugin and use this to find the currently loaded entity, but there is a drawback to this. There is a fair amount of custom logic involved in finding the content entity from the route and we would need to use this same code every time we want to solve this problem.

This method also hard codes the route into the plugin and so makes it difficult to select any other sort of context. There is also a problem when it comes to caching as you also need to inform the plugin about the use of routing so that the caching layers know how to cache things.

CSS Logo

Creating A Simple Pie Chart With CSS

25th December 2022 - 13 minutes read time

A pie chart is a great way of showing the relationship between numbers, especially when showing percentages. Drawing a pie chart from scratch takes a fair amount of maths to get working and so people usually go for third party charting libraries in order to add charts to the page.

I recently came across a technique that allows you to create a pie chart using just CSS, which means you can create simple charts without including massive charting libraries into your page loads. This makes use of just a few lines of CSS, using conic-gradient() CSS function.

The conic-gradient() CSS function is part of the background style attribute and is part of a family of functions like radial-gradient() and linear-gradient(). It is used to create a gradient rotated around a central point and is opposite the radial-gradient() function that draws the gradients radiating away from the centre.

Drupal Logo

Drupal 9: Loading Configuration Entities Using Entity Query

11th December 2022 - 13 minutes read time

Whilst working on a module I found that I needed to do something that was difficult to find information for. I think part of that is because the solution is simpler than I was thinking, but it did cause me to get lost in source code and internet issues for a while.

What I needed to do was to load in a list of configuration entities that matched certain parameters. The configuration entity I was dealing with was used to manipulate the output of a form, but only if certain conditions were met first. I thought that this information might be useful to others who are looking to load configuration entities.

Drupal Logo

Drupal 9: Extending Drupal Base Classes Without Overriding Constructors

27th November 2022 - 12 minutes read time

I have been using the Drupal dependency injection system for a while now, even giving talks and writing articles on the subject. As the release of Drupal 10 is just around the corner I have been thinking more about how to override dependencies to plugin classes.

I wanted to share a trick to overriding dependency injection that will make your life easier. The Drupal codebase itself does not use this trick, but it seems that many contributed modules have started to use this trick to create plugin classes.

In this article I will go through how to add dependency injection to Drupal classes in two different patterns.

Pagination

  • Current page 1
  • Page 2
  • Page 3
  • Page 4
  • Page 5
  • Page 6
  • Page 7
  • Page 8
  • Page 9
  • …
  • Next page ››
  • Last page Last

Categories

  • Ansible
  • Apache
  • Book Reviews
  • CSS
  • DOS/Windows
  • Docker
  • Drupal
    • Drupal 7
    • Drupal 8
    • Drupal 9
    • Drupal 10
    • SimpleTest
  • Flex/Flash
  • General
  • Git
  • Godot
  • HTML/XHTML
  • JavaScript
    • JavaScript Strings
    • JavaScript Websites
    • JQuery
    • MooTools
    • OpenLayers
    • Script.aculo.us
  • Linux/Unix
  • OSX
  • PHP
    • Phing
    • PHP Arrays
    • PHP Questions
    • PHP Strings
    • PHP Websites
    • Zend Framework
  • Python
  • Regular Expressions
  • SQL
    • MS SQL
    • MySQL
    • PostgreSQL
  • Vagrant
  • Websites
  • WordPress

Footer Social

  • Mastodon
  • Github
  • Drupal
  • Facebook

Footer

  • About
  • Colophon
  • Privacy Policy
  • Support Us
  • Terms And Licence

© 2023 #! code
Hash Bang Code Ltd.
Company Registration No 13867421