University of Oregon

Auto populate from History via up and down arrow keys

I posted a highlight of some bash code that Jason H shared last year in my git_bash_files repo on bitbucket. Auto_populate_from_History_via_up_and_down_arrow_keys

Drupal 7: jQuery and Subtotaling Views Calc Tables

As a follow up to Drupal 6: Using jQuery to pick up where views_calc falls short, I worked on a project this week that used views_calc in D7 and we wanted to leverage the same subtotaling that I demonstrated in D6.

There are a lot of similarities in the code so it didn’t take much tweaking. (more…)

Custom Drupal 6 Module (Hack) to filter TableWizard Data by Dates in Views 2

I use Drupal to do some reporting on non-Drupal data using Views and TableWizard. It works pretty well but there are some serious limitations with relationships and filters.
I use a number of work-arounds for these limitations including referencing Views within Views, custom PHP and jQuery hacks via Views Customfield php fields and now a custom module that allows me to filter on dates.

My recent goal was to filter some external data by a date range. I can filter by my external datetime columns (as text) but Views doesn’t recognize them as valid date fields so Views date filters are unavailable.
So rather than rebuild the entire report in custom php I choose to manipulate the views query and filters. The result is a module/hack that converts the external datetime data to the Drupal friendly date format and then updates the query to filter by those dates.

I’ve been using the module for about a month and it works great. In its current state, the module uses some static code that specifies a view and display to act on and some where clauses to replace.

To work correctly, it requires that the Views display include two date filters (start and end date) both exposed and set to ‘contains’.
The date variable is formatted and then the matching ‘datetime contains’ where clauses (ex:

(datetime.dt_end_date) LIKE ('%%%s%%')

) are replaced with ‘date greater / less than’ clauses (ex:

(datetime.dt_end_date) <= ('%s')

).
I need to check and validate the format of date data several times in the module. So to keep the code clean and non-redundant I added couple of functions: strIsDate($string), dateValidates($dateVal), which you'll see below.
Finally the existing filter fields are changed to make them date_popup fields.
(more…)

Drupal 6: Using jQuery to pick up where views_calc falls short

Views Calc is a great Drupal module but there are a few things it doesn’t do.
It doesn’t:

  1. Accommodate totals by group
  2. Total CCK viewfield field values
  3. Total Views Customfield PHP values

I wanted to fix all three of those issue in a views report I’m using.
To be clear: My solution is uses jQuery as a hack/fix, specifically addressing the fields I want to count and sum. It does not address the inherent issue in views_calc. (more…)

Branching with Git – Follow up on keeping remote and local sync’d

I saw a follow up comment on the article that I built my git-create-branch function on and so I updated the code. *Thanks goes to Olivier Clavel.
Here’s the update: http://www.zorched.net/2008/04/14/start-a-new-branch-on-your-remote-git-repository/comment-page-2/#comment-18065
Here’s my original post: http://pages.uoregon.edu/vid/2012/06/05/branching-with-git-keeping-remote-and-local-syncd/

In addition to updating the git functions used I improved the function itself by adding more feedback to the user.
Here are the new functions: git-create-branch() and git-delete-branch();
(more…)

Drupal 6 – Set the Relative Weight of a Custom Module

I converted a template.tpl.php override to a module override for attachment_links recently. One of the interesting functions I had to use was hook_enable. Hook_enable is handy for setting the module weight and ensuring that my overrides run after the original module.

The default module weight in the system table is 0. In this case, attachement_links uses 99. So rather than set my module’s weight to 100 I thought I’d just reference the other module and increment it’s weight by 1. That way if they change it in the future I’ll be good to go.
(more…)

Drupal 7 Field Collection for build an order form

I’ve been leveraging the Field Collection module in a few projects lately and today I created a quick demo of how it could be used in a print shop order form.
Thanks to Joseph (here at the UO and directcommunities.com) who demonstrated the Field Collection module recently.

The form needed to allow an individual to upload a file and then choose certain options for that file. There is a requirement that the user would be able to upload an infinite number of files and each file can have unique options. This is the current version: image of form fields required

Here’s what my Field Collection option looked like:
Screen shot of form with field collection
(more…)

bash function – cddrush

This is a quick function that reduces the keystrokes for using ‘drush dd’ in a cd command like so:

cd `drush dd @my.site.alias:%site`

Which is great but this is simpler

cddrush my.site.alias

Oh, that’s nice!
(more…)

bash function – git-patch()

We’ve been trying to review more Drupal 8 patches on Drupal.org with this workflow:

$ cd #to your local Drupal 8 Dir.
$ curl https://drupal.org/files/patch_url... | git apply --stat
$ curl https://drupal.org/files/patch_url... | git apply --check
$ curl https://drupal.org/files/patch_url... | git apply
# If no errors occur you can use
$git am --signoff &lt; fix_empty_poster.patch

I found that be cumbersome so I created a bash function to simplify this.
Usage example: $ git-patch stat URL.patch
That triggers a

  • wget to retrieve the file,
  • runs $ git apply –stat
  • and prompts you for the next step.

In addition if you call the function with no vars it returns a simple usage message.
It works great, it’s more efficient and I don’t have to refer back to the patching best-practices if I forget*.
(more…)

bash function – ssh-copy-id for mac

The bash function: ssh-copy-id is a linux script that enables you to copy your public ssh key to a remote server for authenticated but password-less ssh sessions. Apparently it can be installed on a mac but I had no luck, so following the logic found in a comment: https://discussions.apple.com/message/13166537#13166537
I created a mac version of the function to put in .bashrc file.

function ssh-copy-id-mac() { #mac version of ssh-copy-id: cat ~/.ssh/id_rsa.pub | ssh admin@mydomain.net “umask 077; mkdir -p .ssh ; cat >> .ssh/authorized_keys”
#!/bin/sh
#from https://discussions.apple.com/message/13166537#13166537
if [[ ! -n “$1” ]] ; then
echo 1>&2 Usage: $0 user@server
else
cat ~/.ssh/id_rsa.pub | ssh $1 “umask 077; mkdir -p .ssh ; cat >> .ssh/authorized_keys”
fi
}