Monday, 4 April 2016

Modulus - Unable to connect to any application instances. SOLVED

OK if like me you are battling with a modulus server not working correctly and getting the above error then you have probably made the same mistake as me when setting up the database user.

I set up the user as an email address and while i could connect to my mongo server with the username being an email address I couldn't from the server.

remove the @ symbol.

Thursday, 14 January 2016

No release history available for 8.x.

Ok I was trying to install a drupal module menu_editor using the following command and I got the following errors

> drush dl menu_editor
No release history available for menu_editor 8.x.          [error]
Could not download requested project(s).                      [error]

this is because I was not in the docroot folder.

Tuesday, 12 January 2016

Drupal 7 - Switch CSS file based on Language

I have the need to load a different css file depending on the language of a drupal 7 site.  This is the hook that I created. hope it helps people.

function hook_css_alter(&$css) {
  global $language;
  $theme_path = "sites/all/themes/mytheme";
  if (file_exists(__DIR__ . "/css/styles-" . $language->language . ".css")) {
    $newKey = $theme_path."/css/styles-" . $language->language . ".css";
    $oldKey = $theme_path."/css/styles.css";
    $css[$newKey] = $css[$oldKey];
    $css[$newKey]['data'] = $newKey;
    $css = array_diff_key($css, Array($oldKey => 1));

The file would have a line like 

stylesheets[all][] = css/styles.css

This line is removed and replaced with a language specific css file  if a language specific version exists.  For example if you have a multilingual site with french the $language->language value might be for example "fr" in which case the file that will be loaded will be styles-fr.css instead of styles.css

Using SASS allows the building and maintaining of site wide css files.

Monday, 29 June 2015

Understanding variables in PHP

PHP defaults to pass by reference instead of pass copy, What this means is that in older versions of PHP passing a variable to a function would have passed a copy of the variable to the function thus using x2 amount of memory.  PHP was updated to pass a reference as default which would only make a copy if you changed the variables content.  To pass an actual reference to a variable you would have to put the & symbol before your variable for example making the scope of the functions variable be external to the function.


The & represents the address of a variable;

a pointer is a number 0...n which when used in conjunction with software development represents a memory address.

so for example

$list = Array(...);

the variable $list holds an Array of information or in other words points to an area of memory

lets say that $list holds 1Mb of information but since that information is really a block of memory (1048576 bytes) and lets say that the first bit of information is in the memory address 1,000,000 and for the purpose of this conversation it is a solid block of memory with no fragmentation so the end point is (1000000+1048576) = 2,048,576

Since php now passes variables by reference

1 $results = fn($list );
3 function fn($val){
4 echo $val;
5 }

the variable $val is a pointer to the same memory space as $list and thus can be said to have a "reference" to the data. So what does this mean?

well instead of php having to have two variables $list & $val both containing 1Mb of data in memory at the same time (said to be a copy) we can pass a 32/64bit pointer which references the original value.

Now the interesting part if we added an additional line between 3&4

$val[count($val)] = 'woo';

this would cause php to make a complete copy of the data at that memory location and then change hte memory location that $val points to. Thus any changes to $val would not effect $list; as it is now a local variable to the function.

if you want changes to be applied the $list variable then change line one to be $result = fn(&$list);

Friday, 20 February 2015

Will Apple launch a games console this year?

Since the moment that Apple announced Metal my first thought was not of the phone but of a fantastic upgrade for an AppleTV.  If Apple added the Latest processor to the Apple TV and allowed apps for your TV.  Then you would just have to add a couple of good game controllers and you have a fantastic media console with Siri and the ability to play console quality games on.  So for £150-£160 you could have a fantastic Gaming machine with two controllers.  Thats cheaper than the Nintendo Wii on launch in 2006.

If you think about it why would Apple want to produce a physical TV unit. My HD TV is 8 years old and I have no intention of replacing it any time soon.  But a new console which would be £100 upgrade every 2-3years  would just blow Sony & Microsoft out of the way.  Not to mention that this would be a great opportunity for indie game developers to get into homes.

Nintendo sold 3.19M Units in the first quarter.  How many people would buy an Apple TV instead of a £400 Playstation or XBox.  After all it's easier to find £150 that £400.

If I knew were to look I would be looking at who makes components for controllers and see if they are buying large quantities.

Fingers crossed.