technonaturalist

image link to hive image link to ko-fi

webmonkeying

Drupal 7 notes: html5 placeholder text

Fairly straightforward. Mostly here as a reminder for how to do webforms; (example has a theoretical nid of 1 and a theoretical form field called “message” and the “submitted” part stymied me for a bit).

template.php

<?php 
function mytheme_form_webform_client_form_1_alter(&$form, &$form_state, $form_id) {
    $form['submitted']['message']['#attributes']['placeholder'] = t('Type your message here...');
} 
?>

Could also use a switch in hook_form_alter(). One of these days I’ll think about finding out if there’s any difference performance-wise in using a big switch with many form alterations or several smaller hook_form_form_id_alters.

Sprat does not share my scss enthusiasm

[reformatted the code during migration to make it slightly easier to read, this was a copy/paste from some text conversation and all formatting was lost]

ryivhnn 6/04/12 10:23 PM hee hee other cool thing with sass, i do this:

@mixin inline-block {
 display: inline-block;
 margin: 0 -2px;
 vertical-align: top;
}

and then when i need things inline-blocked etc (in a few places) i do:

#container {
    .stuff-what-needs-inlining {
        @include inline-block;
    }
}

Darqx 6/04/12 10:24 PM i look at that and see what looks to be php mixed with css and want to run away screaming

css notes: fixed middle fluid outer column

Also known as: I’m a blithering idiot.

I spent way too long overthinking this problem and only finding solutions with floats (I have very specific cases where I’ll use floats for layout, also I could have missed anything that didn’t use floats for layout as I was stupidly staying up way too late when working on this). The way to do it is actually embarrassingly easy. I’ll be using it for the header and footer (after I’ve installed Sassy, prepro and phpsass.

theAbysmal Calendar Drupal module

I think it’s done now.

  • fixed an issue where the years weren’t being calculated properly (?!)
  • I may be slightly out of sync with the official documentation, at least according to the tests I’ve done on my local so far. This year should match up, and so will key dates (New Year Day and Leap Day). I’ve shifted leap years to fall on multiples of 4 so calculating would be a simple case of if mod 4 is 0, it’s a leap year, if mod 128 is 0, it’s not a leap year, so some of my years will be a day or two out

theabysmal_calendar.info

name = theAbysmal Calendar 
description = Converts Gregorian date to theAbysmal date 
core = 7.x 
package = Date/Time

theabysmal_calendar.module

<?php
/**
* @file
* Converts date from Gregorian to theAbysmal Calendar
* 
* theAbysmal Calendar in depth: http://theabysmal.wordpress.com/theabysmal-calendar/
* Currently uses months from the Tranquility Calendar 
* (http://www.mithrandir.com/tranquility/tranquility.html) and days in
* highly informal/bastardised lojban as that's how I use it.
* 
* @author ryivhnn
*/

/**
* Implements hook_help.
*
* Displays help and module information.
*
* @param path
*   Which path of the site we're using to display help
* @param arg
*   Array that holds the current path as returned from arg() function
*/

function theabysmal_calendar_help($path, $arg) {
switch ($path) {
    case "admin/help#theabysmal_calendar" :
    return '<p>' . t("Converts date to theAbysmal Calendar") . '</p><p>&nbsp;</p><p>';
    break; 
    } 
} 

function node_created_date() { 
    // grab node create date 
    $query = db_select('node', 'n') -> fields('n', array('nid', 'created')) -> condition('nid', arg(1)) -> condition('status', 1) -> execute() -> fetchAssoc(); 
    $date = $query['created']; 
    return $date; 
} 

function today() { 
    // grab today's date 
    $date = time(); 
    return $date; 
} 

function date_converter($date_ce) { 
/** 
    * doing the calendar converty magic 
    * owe the algorithm to the software engineer husband 
    */
    
// set the zero date and time for theAbysmal Calendar 
$zero_date = mktime(0, 0, 0, 12, 21, 2012); 

// this is New Year Day on theAbysmal Calendar 
$zero_day = date('z', mktime(0, 0, 0, 12, 22, 2012)); 

// this is first day which is counted from 0 
// calculate theAbysmal year 
if ((date('m', $date_ce) == 12) && (date('d', $date_ce) > 20)) { 
    $year = date('Y', $date_ce) - date('Y', $zero_date); 
} 
else { 
    $year = (date('Y', $date_ce) - date('Y', $zero_date)) - 1; 
} 

/** 
    * I think theAbysmal Calendar may be following Gregorian leap years to a degree. 
    * I couldn't find anything explicit in the documentation on the website. 
    * Because it counts from 0 every 4th number ends up being slightly weird (3, 7, 11, 15). 
    * I've decided to modify slightly to make leap years occur on multiples of 4 like they do 
    * on the Gregorian which then makes the not observing the leap year every 128 years 
    * slightly easy to remember, and also takes an operator out of the maths. 
    * Yes I can write an entire rationale in the comments but cbf putting in one extra operator. 
    */ 

if ($year % 4 == 0) { 
    $ly = 1; 
    
    if ($year % 128 == 0) 
    { $ly = 0; 
    } 
} 
else { 
    $ly = 0; 
} 

// because the leap years are different, we need to do maths with Gregorian 
$gly = date('L', $date_ce); 

// "buffers" for the leap year calculations 
if ($ly == 0 && $gly == 0) { 
    /** 
        * the way the $year_length calculation works, years where it's not a Gregorian 
        * or theAbysmal leap year come up a bit short, so this pads it out 
        */ 
        
    $leap_buffer = 1; 
}
elseif ($ly == 1 &amp;&amp; $gly == 1) { 
    /** 
        * conversely if the leap years coincide it makes the $year_length a bit longer 
        * than it should be, so this adjusts 
        */ 
        
    $leap_buffer = -1; 
} 
else { 
    $leap_buffer = 0; 
} 

/** 
    * working out how long the year is 
    * need to +1 to make it an absolute value 
    * add theAbysmal leap year and subtract the Gregorian leap year as required 
    */ 
    
$year_length = date('z', mktime(0, 0, 0, 12, 31, $year_ce)) + $ly - $gly + $leap_buffer + 1; 

// what day number are we up to in the Gregorian, + theAbysmal leap year + the leap buffer 
$gregorian_day_of_year = date('z', $date_ce) + $ly + $leap_buffer; 

// how many days have passed since theAbysmal start date, plus tA leap year day, less Gregorian leap year day 
$days_from_start = ($gregorian_day_of_year - $zero_day + $year_length) % $year_length; 

// theAbysmal month converted to an integer 
$month_number = intval($days_from_start / 28); 

// what day in the month it is 
$mday = $days_from_start % 28; 

// lojban day names assigned to month names 
$days = array( 
    'xundei' => array('0', '7', '14', '21'), 
    'najdei' => array('1', '8', '15', '22'), 
    'peldei' => array('2', '9', '16', '23'), 
    'ri\'ordei' => array('3', '10', '17', '24'), 
    'cicnydei' => array('4', '11', '18', '25'), 
    'bladei' => array('5', '12', '19', '26'), 
    'zirdei' => array('6', '13', '20', '27'), 
); 

foreach($days as $key =&gt; $value) {
    if (in_array($mday, $value)) { 
        $weekday = $key; 
    } 
} 

// Tranquility calendar month names 
// the 14th "month" is a 2 day intercalary period for New Year Day and Leap Year Day 
$months = array( 
    '0' => 'Archimedes',
    '1' => 'Brahe',
    '2' => 'Copernicus', 
    '3' => 'Darwin',
    '4' => 'Einstein', 
    '5' => 'Faraday',
    '6' => 'Galileo', 
    '7' => 'Hippocrates',
    '8' => 'Imhotep', 
    '9' => 'Jung', 
    '10' => 'Kepler', 
    '11' => 'Lavoisier', 
    '12' => 'Mendel', 
    '13' => '', 
); 

foreach ($months as $key =&gt; $value) { 
    if ($key == $month_number) { 
        $month = $value; 
    } 
} 

/* 
    * intercalary days 
    * 
    * check to see if it's December Solstice (Dec 21) 
    * if it is, it's New Year Day 
    * if not, it's a weekday 
    * 
    * if it's a leap year, Dec 20 is Leap Year Day 
    */
    
if ($month == '') { 
    $weekday = ''; 
    
    if (date('d', $date_ce) == 21 && date('m', $date_ce) == 12) { 
        $mday = "New Year Day"; 
    } 
    
    if ($ly == 1 && date('d', $date_ce) == 20 && date('m', $date_ce) == 12) { 
        $mday = "Leap Day"; 
    } 
} 

// leading zero silliness 
$yrabs = abs($year); 
$yrlen = strlen($yrabs); 

if ($date_ce < $zero_date) { 
    $era = 'btAT'; 
} 
elseif ($year == '0000') { 
    $era = 'tAT'; 
} 
else { 
    $era = 'tAT'; 
} 

if ($yrlen == 1) { 
    $year = '000' . $yrabs; 
} 
elseif ($yrlen == 2) { 
    $year = '00' . $yrabs; 
} 
elseif ($yrlen == 3) { 
    $year = '0' . $yrabs; 
} 

$daylen = strlen($mday); 

    if ($daylen == 1) { 
        $mday = '0' . $mday; 
    } 

    return $year . $era . ' ' . $month . ' ' . $mday . ' ' . $weekday; 
}

function date_shorten($date) { 
    /** 
     * can't help but feel this may be unnecessarily long winded :) 
     * 
     * Months and days are put into an array 
     * the first letter in each is grabbed 
     * the $date string is searched and the full name replaced with the letter 
     * then spaces are stripped 
     * 
     * I also continued with negative years in the array even though Not Jack 
     * isn't a huge fan og negative years as the $era was making my short dates 
     * longer :) 
     */
     
    if ($era = 'btAT') { 
        $neg = '-'; 
    } 
    
    $month = array( 
        'Archimedes', 
        'Brahe', 
        'Copernicus', 
        'Darwin', 
        'Einstein', 
        'Faraday', 
        'Galileo', 
        'Hippocrates', 
        'Imhotep', 
        'Jung', 
        'Kepler', 
        'Lavoisier', 
        'Mendel', 
    ); 
    
    foreach ($month as $value) { 
        $m = $value[0]; 
        $date = str_replace($value, $m, $date); 
    } 
    
    $wday = array( 
        'xundei', 
        'najdei', 
        'peldei', 
        'ri\'ordei', 
        'cicnydei', 
        'bladei', 
        'zirdei', 
    ); 
    
    foreach ($wday as $value) { 
        $wd = $value[0]; 
        $date = str_replace($value, $wd, $date); 
    } 
    
    $date = str_replace(' ', '', $date); 
    $date = str_replace('btAT', '', $date); 
    
    return $neg . $date; 
}

/** 
 * implements hook_block_info() 
 */
 
 function theabysmal_calendar_block_info() { 
    $blocks['today'] = array( 
        'info' => t('Today\'s theAbysmal date'), 
        'cache' => DRUPAL_NO_CACHE, 
    ); 
    
    $blocks['posted'] = array( 
        'info' => t('Converted post date'), 
    ); 
    
    return $blocks;
}

/** 
 * implements hook_block_view() 
 */ 
 
 function theabysmal_calendar_block_view($delta = '') { 
    $block = array(); 
    
    switch ($delta) { 
        case 'today': $block['subject'] = t('Today\'s theAbysmal date'); 
            if (user_access('access content')) { 
                $date_ce = today(); 
                $block['content'] = date_converter($date_ce); 
            } 
        break; 
        case 'posted': $block['subject'] = t('Converted post date'); 
            if (user_access('access content')) { 
                $date_ce = node_created_date(); 
                $date = date_converter($date_ce); 
                $block['content'] = date_shorten($date); 
            } 
        break; 
    } 
    
    return $block; 
}
?>

Usage instructions

  • create a folder called theabysmal_calendar in sites/all/modules
  • copy theabysmal_calendar.info and theabysmal_calendar.module to files of the same name and save them into the folder you created. Dicth the closing php tags in the module file
  • if you don’t like the month and week days I’m using, change them to whatever you like in the days and month arrays (two of each, just be aware that the date shortening as it is may look odd with week day and month names that start with the same letter, the date formats can be changed easily enough)
  • go to the modules page (I think it’s Admin >> Modules, I use the admin toolbar and it’s just there), scroll down to Date/Time and check theAbysmal Calendar on
  • go to Admin >> Structure >> Blocks and activate and position the blocks you want. There are two provided, one converts today’s date and the other converts and shortens a post date. I’m using <?php echo render[$block['content']; ?> to spit the shortened date into the top of the blog posts

If anyone knows how to write Wordpress plugins and feels like converting it, go nuts.  Then tell Not Jack so theAbysmal Calendar blog can have an Abysmal Calendar :)

Musings on The Cloud

[minor pseudonymising edits during Drupal to hugo migration for all the good that will do now]

clouds

clouds (Photo credit: Extra Medium)

And Zemanta gives me pretty cloud pictures like this one.

I’m actually talking about that cloud computing “fad” (seen the term tossed around to describe it, wonder if it’s a fad like Facebook and the internet in general is a fad).

A friend from work recently asked if I had a Dropbox account. I didn’t, so he asked if would create one so we could collaborate on some work I’m helping him out with (and as a bonus he’d get extra space for the referral). The Cloud is something I’ve been aware of but otherwise generally ignored until I had it almost literally shoved in my face by my Android tablet asking me if I would like to sync contacts and calendars and files into the cloud (both from Google and from ASUS, I said no). I ruminated a bit on it and then said yeh sure.

Not on track. Don't panic.

The scripts are still done (it’s been months and I still haven’t changed/edited).

I don’t know if I’m on track to be able to start animating by the end of the year. Just thought about the amount of work involved, there’s sound and voice actors and…I have a low level panic attack happening in the back of my brain somewhere which is making me think about hyperventilating but up here on the surface I’m calm and all is well and I just keep plugging and thinking about writing reviews for Lightwave 11 (I got a free upgrade because I bought 10 a couple of months ago which I thought was very awesome of NewTek) and gIMP.

Playing catchup

I am all over the joint! So what else is new.

Now according to the provider the backup malarky was caused by me having a duplicate account on another server, probably from when I got my ssl certificate and needed to be moved to a server that could handle that. The duplicate has been removed and miscellaneous fallout resulting from that dealt with. Unfortunately it means November posts and users from here, Red Planet and WANLN are now completely gone. I can repair the blog thanks to the Artician feed, can’t do anything about lost blog comments or the other two and that makes me very sad.

Family themed photos and miscellaneous ramblings

[minor pseudonymising edits during Drupal to hugo migration for all the good that will do now]

Yesterday, we went out for a drive. Christmas Island isn’t the biggest island in the world, if you point the car’s nose down the road and drive without stopping along any major track you’ll end up back where you started in about half an hour.

We went out in an exploratory mood and took many photos. Of course all the photos JJ took while we were out and about were with Kerchunk and nothing on Snap so there’s nothing I can post. We’ll just have to go out again and take more when the battery charger arrives.

Backup malarky and prelimary theAbysmal scripts

If this post disappears, it’s entirely my fault as I told the provider that this site could just be rolled back to the last backup (assuming the last backup he had was more recent than the one I had).

What happened with the backups? It’s a long and sordid story.

Actually it’s not that long, just slightly confusing. See the provider does scheduled backups as all decent providers should. But last month and earlier this month something very strange happened. Three of my sites (this one, Red Planet and WANLN) lost a month’s worth of posts. It’s entirely possible the other ones rolled back as well but these ones were the most noticable as they get updated constantly.

What to do when .gitignore doesn't

So. At work we’ve switched from using svn to git (and GitHub).

Difference: decentralised, therefore “commit” commits it to the local repo rather than the remote/centralised one, and you have to “commit” then “push” to the remote.

Problem: .gitignore was not gitignoring some files (settings.php and .htaccess which I had to change to make it work on my local) which it was supposed to be gitignoring.

Solution as per RobWilkerson.org:

Do: git status which should spit up a list of modified files since lasy commit/sync/something (shut up I’m still working git out ;)