Blog

  • Drupal: Get full image URL including style name and itok

    $imageURL = image_style_url('YOUR_STYLE_NAME', $content['field_image']['#items'][0]['uri']);
  • Drupal remove white-space from HTML

    Add this simple function into your theme’s template.php in order to strip out unnecessary whitespace and line breaks, saving a bit of file size where possible (I saved 17kb from my homepage). If a page contains a <pre> or <textarea> tag, it is left alone, as to not affect code blocks or text typed in a form.

    // Minify HTML output.
    function sonspring_process_html(&$vars) {
    $before = array(
    "/>\s\s+/",
    "/\s\s+</",
    "/>\t+</",
    "/\s\s+(?=\w)/",
    "/(?<=\w)\s\s+/"
    );

    $after = array('> ', ' <', '> <', ' ', ' ');

    // Page top.
    $page_top = $vars['page_top'];
    $page_top = preg_replace($before, $after, $page_top);
    $vars['page_top'] = $page_top;

    // Page content.
    if (!preg_match('/<pre|<textarea/', $vars['page'])) {
    $page = $vars['page'];
    $page = preg_replace($before, $after, $page);
    $vars['page'] = $page;
    }

    // Page bottom.
    $page_bottom = $vars['page_bottom'];
    $page_bottom = preg_replace($before, $after, $page_bottom);
    $vars['page_bottom'] = $page_bottom . drupal_get_js('footer');
    }

  • Exclude Drupal system CSS for logged-out users

    In your template.php, you can exclude Drupal’s system CSS files, or any CSS file that wasnt added by your theme (this includes CSS added by modules) using this PHP snippet:

    function YOURTHEME_css_alter(&$css) {
      if (!user_is_logged_in()) {
        foreach ($css as $key => $value) {
          if ($value['group'] != CSS_THEME) {
            $exclude[$key] = FALSE;
          }
        }
        $css = array_diff_key($css, $exclude);
      }
    }

     

  • Drupal homepage only CSS

    So you want to have a base.css file on all pages, then a homepage.css file just for the homepage, and non-homepage.css for all other pages? Here’s how:

    In your themes’ .info file, include the base.css file:

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

    In your themes’ template.php file:

    function YOURTHEME_preprocess_page(&$vars) {
      //
      // home/non-home specific css
      //
      $homepage_css_options = array(
        'type' => 'inline',
        'scope' => 'header',
        'group' => CSS_THEME,
        'weight' => 9999,
        'preprocess' => FALSE,
      ); 
      $nothomepage_css_options = array(
        'type' => 'file',
        'scope' => 'header',
        'group' => CSS_THEME,
        'weight' => 9999,
        'preprocess' => TRUE,
      );      
    
      if ($vars['is_front'] == TRUE) {
        //inline the homepage css, minified by Gulp
        drupal_add_css(file_get_contents(drupal_get_path('theme', 'YOURTHEME') . '/css/homepage.min.css'), $homepage_css_options);
      } else {
        //inline css file for all pages except homepage
        drupal_add_css(drupal_get_path('theme', 'YOURTHEME') . '/css/not-homepage.css', $nothomepage_css_options);
      } 
    
    }

    Note: In the code above I have chosen to inline the homepage only CSS.

  • Inductrix & Taranis, using Spektrum DM9 module

    Got lots of money and no patience? You’re in luck, you can get a Spektrum DM9 module for your Taranis quickly, and have it bind to your Inductrix easily.

    Inductrix, Taranis, DM9

    Unfortunately the module is $59 from eBay, …but it arrives within 3 days and it works.

    You’ll need to create a new model on your Taranis, and as shown on the picture below, disable the internal RF module, enable the external RF module, mode on PPM, CH1-8, 22.5ms, 400u, negative polarity.

    Inductrix Taranis Model setup

    Bind

    To bind, follow this sequence:

    • Switch off Taranis
    • Switch on Inductrix and wait for blue LED to flash rapidly
    • Hold down bind button on DM9 module (the only button on it) and keep it held while turning on Taranis
    • DM9 will have a flashing orange LED, then solid orange LED, then go out, now you can let go of the bind button.
    • Blue flashing LED on Inductrix should stop flashing and go solid blue. Now you’re bound.

    If the above doesn’t work, keep trying, remove the module from your Taranis and then put it back in and try again. It took me about 5 attempts. At the moment it appears you have to re-bind every time you reboot, but I’m working on a solution for that. EDIT: Appears to be permanently bound now, maybe you have to rebind a couple of times before it remembers?

    Channel Direction

    My Yaw and Roll channels needed to be reversed within my model setup on the Taranis, there is a nice easy instruction video here: https://www.youtube.com/watch?v=I046G6cW9W8

    Timer

    Within your model setup on the Taranis you can also add a countdown timer, since the inductrix batteries don’t last long. In Timer 1 choose: THs (throttle start) 3:30 (my conservative estimate), minute call: on, countdown: voice.

    Range

    If you experience loss of range, open up the DM9 module and ensure the UFL connector is still plugged in. Mine wasn’t, but it still flew!

    Shout out to JesseP 🙂

  • Essential potty training tip

    Potty training is hard. In order for your son to become interested in doing it, you have to make it fun.

    To do this you need a target to pee on. Whether he is sitting or standing, having a target and making sure to laugh loudly when he hits it, will make him want to use the potty, not reject it or fight it.

    Start with some toilet tissue, and move onto other things to keep him interested, like colored squares of paper. We let our son pick his own color, then sit and pee on it. Potty time is now easy and fast.

    You’re welcome.

  • iPhone input zoom fix – works on iOS9

    /* prevent iphone from zooming in when filling out a form, like login or application */
    @media screen and (-webkit-min-device-pixel-ratio:0) { 
      select,
      textarea,
      input,
      input:focus,
      input:hover {
        font-size: 16px !important;
      }
    }
  • Macbook Pro Pink Screen Fix

    Got a pink screen of dead on your Macbook Pro? (pink links across the screen)

    No problem! Take it to the Apple Store, they will fix it for FREE as part of a special program. Its a known issue with the graphics card, and even my early 2011 Macbook Pro was accepted and fixed, for free. 🙂

     

    Did you find this post useful?

    Tip me some bitcoin:

  • How to add static HTML pages in Drupal

    Sometimes you just need a static HTML page, or a template-less page, in your CMS. There are many ways to do this with Drupal, like creating node specific page templates, with all of the container HTML chopped out.

    However, the quickest and easiest way is to use the Static Page Module

    After installation, do the following:

    • Create a new Content Type, maybe call it “Static HTML”, make sure it has a “Body” field
    • In /admin/config/content/static_page, select the new content type that you created
    • Now create some content!
  • Awesome parenting tips, with examples

    This is my ever growing list of parenting tips, with examples. Enjoy!

    How to foster independence

    Scene: Playground sandbox. A construction toy! It’s a seat with two long handles that work independently of each other to operate a scoop.

    Enter: Boy, age 3. He climbs up onto the seat and eagerly leans toward the handles. He cannot reach.

    Enter: Grandpa. “Here, you pull these handles.” Grandpa pushes them toward the boy. The boy grasps the handles but doesn’t immediately know how they work. “Help him,” Grandma says. Grandpa starts to operate the handles: one to lift and lower the scoop; one to rock the scoop into the sandbox and dump the sand out. When Grandpa lets go, the boy doesn’t quite have it down.
    “Okay,” Grandma says. “We’re going to give someone else a turn, since you can’t do this.”

    Scene: Same morning. Same sandbox. Same toy.

    Enter: Girl, age 3. She climbs up onto the seat and eagerly leans toward the handles. She cannot reach.

    Nearby: Her mother sits with a book. She smiles encouragingly as the girl tries to get at both handles. Another child comes over and pushes one handle toward the girl. She’s able to get the other. The girl grasps the handles but doesn’t immediately know how they work. She tries this and that. “Help me,” she calls to her mother. “Hmm. Try putting your feet here,” her mother says, aiming to improve her leverage. Mom sits back down. The girl starts experimenting with the handles. After a while, she is scooping and dumping sand.

    “Mama, I’m scooping!” she says proudly.

    So how can we foster our little ones’ independence? These playground scenes provide a simple illustration. We can:
    •hang back instead of jump in
    • observe instead of direct
    • step in after being asked instead of before
    • guide lightly instead of grabbing hold
    • smile encouragingly instead of giving up for them, and
    • let our children surprise us

    What do you want to be when you grow up?

    Don’t ask kids what they want to be when they grow up, instead ask what problem do they want to solve? This changes the conversation from “who do i want to work for”, to “what do i need to learn to be able to do that”.