University of Oregon

git branch – auto setup rebase = always

I was revisiting Randy Fay’s Rebase Workflow post and went down the ‘rebase’ rabbit hole again. Each time I learn a little more. Probably because I understand a little more…

This time I landed here: ‘Simpler Rebasing …’ http://www.randyfay.com/node/103 and as a result I’ve updated my git config to rebase on pull:
git config –global branch.autosetuprebase always

Note: this use of rebase isn’t the history altering version, rather an adjustment to the order of operations when pulling from a remote repo. The goal being to lay your local changes on top of the remote code each time you pull.

Here’s how it looks in my git config now:

[branch]
  autosetuprebase = always #Ref: http://www.randyfay.com/node/103 #alternatively use: git config --global branch.autosetuprebase always

We’ll see how it goes. I’ll add this to my public git_bash_files repository if I like it.

Clean up your curl – fixing relative links in scraped content

A few years ago I Added jQuery browser check for ODT and Skillport eLearning. This week I updated that functionality and noticed a relative link in some remote content I was scraping via cURL.
The problem being that the relative link needed to be fully qualified.

Here’s the old table that I cURL from the Skillport support site:
Screen Shot of the old compatibility table

Here’s the updated table:
a view of the table pulled in from skillport
The culprit is the “Click here to view Skillsoft’s Browser Support Statement” at the top of the table. “here” links to /44007.htm which isn’t helpful.
(more…)

Re-wrap a modified JS function

The question came up recently about the possibility of modifying an existing javascript without duplicating it. Yesterday, I found out that it’s indeed possible. The key to the solutions is to re-wrap an existing function with it’s modifications in an ‘anonymous function.’
Here’s the scenario:
I have a page where I check for some required browser plugins before sending users on to our eLearning site; Adobe Flash, Reader and Java.

I also check for optimal OS / browser combinations.

So in this scenario I was leveraging available JS & jQuery functions as much as possible but in one particular case I need to accurately display the users browser but jQuery.brower treats all webkit browsers as Safari.

So instead of installing a new jQuery plug in or write a script to parse the user’s browser info I took advantage of a function in the Java detection script I pulled in.
(more…)

Drupal 7 – resizing the content area based on publish date

I was asked to look at a site where the content created before Jan. 15th 2013 was crafted to display nicely in a 600px wide area.
New content is being added with a much wider area and with some thought given to the possibility of a fluid width (potentially responsive).

So while setting a fixed width isn’t ideal I came up with a proof of concept that demonstrated the possibility using jQuery to resize the content area on page load.
The content in question has two key elements to identify for jQuery:

  1. The publish date:
    $('.field-name-field-publish-date .date-display-single')
  2. The content area:
    $('.field-name-body')

Here’s a sample of the code that could re-format the older content based on the published date:
$(‘.field-name-field-publish-date .date-display-single’).length
//if( (currentContentDate < narrowContentCutOffDate)) { if ( ( new Date($('.field-name-field-publish-date .date-display-single').text()).getTime() < new Date('January 15, 2013').getTime() ) ) { $('.field-name-body').css('width','600px'); }//end if [/code] Wrapped in a Drupal.behaviors function it could be added to the site in a js file like so, to run once on each page load: (more…)

Drupal 6 – Pre-Popluate Menu Parents with jQuery

Here’s a fun one.
I wanted the menu parent to be pre-populated on node creation.

Use case:

  • When a content editor creates a new ‘Electronic Flyer’ it will be added to the per-determined menu: Primary Links >> Resources >> Electronic Flyers.

Here’s a screenshot demonstrating the pre-filled out menu parent: (more…)

Drupal 7 Views – Manipulating Args with php

I wanted to pass a string to a view that only accepts an entity id as an argument.
I the past I’d been able to use a string based argument after adding relationships but that wasn’t possible in this case.

So I decided to override the incoming argument during validation and replacing the string with the relevant entity id.

The use case:

I mentioned that the view only takes a entity id (nid) as an argument. That nid isn’t available to me when I call the view, but I do know a ‘location’ that I can associate with entities.
Ideally the town name “Eugene” is passed to the view but the entity id (237) is what’s used in the view.

The key was to call another view from within my contextual filter argument validation field.
There I pass the ‘location’ name argument to another view (nid_from_townname) using php and the views_get_view() function.
That view returns the nid for the entity in question. So then I override the original view’s argument with the nid and we’re in business.

Here’s a screenshot of the (view display’s contextual filter argument) validation field: (more…)

Drupal 7 – list taxonomy terms

I’m running some tests and thought I’d post the php code to display the terms for a taxonomy:

<?php
$terms = taxonomy_get_tree(taxonomy_vocabulary_machine_name_load('temp_auth_temp_agency')->vid);
if ($terms) {
  foreach ($terms as $term) {
    $options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
  }
}
echo '<pre>$options: '. print_r($options,true) . '</pre>';

/* Returns:
$options: Array
(
    [439] => DePaul
    [441] => Express
    [440] => Galt Foundation
    [442] => Kelly Services
    [443] => Manpower
    [444] => Personnel Source
)
*/
?>

At the moment I’m considering leveraging the benefits of CCK Select Other for ease of entry with taxonomies for term management. Not sure if it’ll be worth it but this was an interesting code hunt.
(more…)

Bash – Add drupal site name to PS1

I updated my bash prompt (PS1) the other day. Now it displays what site I’m in.
I recently posted my former change: An improved PS1 for Git in Bash.
Now I added an extra bit of code that inserts the current ‘site’.
It looks like this:

vid@server:(prod.mydomain.com) currentdir (origin [master])$ 

(more…)

An improved PS1 for Git in Bash

Last year I updated my bash prompt (PS1) to include the active git branch name.
A few months ago I added to the the active repository name.
So here’s an example of my PS1 when I’m in a git tracked directory on the master branch:

vid@server mydirectory (origin [master])$ 

And here it is when I have other remote repositories for the same project (bronze and heuristics);

vid@server mydirectory (bronze | heuristics | origin [master])$ 

And now once more when I’m on a branch (devel) that doesn’t exist on the available remotes:

vid@server mydirectory (bronze | origin [devel])$ 

That’s achieved with these functions: parse_git_branch and show-git-current-remotes-short.
(more…)

Reset a password on a Parallels VM

I forgot the password to a RedHat 6 Parallels VM recently.

It’s a VM that we use to test changes to Aegir prior to working on the live hub.

Max Bronsema created and shared this VM a few years ago.
Unfortunately for me, I changed the original password at some point and now I’m locked out. But not to fret; the good news comes in the form of parallels control commands:

$ prlctl set ... --userpasswd ...

Here were my steps to reset the two user passwords (Note: names and ID’s have been changed to protect the some-such or another); Ref: http://kb.parallels.com/en/114193

  • Open the Red Hat Enterprise Linux 6 (1) VM
  • Open Terminal
  • Reset the password for Admin and then AegirUser
    # prlctl = parallels control
    # list all running vm’s
    $ prlctl list –all | grep running
  • You may see something like this:
    {3e21f02b-9d52-4ebe-a079-675dc822d723} running - Red Hat Enterprise Linux 6 (1)
  • Use that machine ID to reset the passwords for your user accounts:
    $ prlctl set INSERT_MACHINE_ID –userpasswd Admin:tempPassWord
    authentication tokens updated successfully.
    $ prlctl set INSERT_MACHINE_ID –userpasswd AegirUser:tempPassWord
    authentication tokens updated successfully.
  • Then login as each user and reset their password

That’s a handy tool. Thanks Parallels!