Skip to content

Instantly share code, notes, and snippets.

View paulhhowells's full-sized avatar

Paul H Howells paulhhowells

  • Shepperton, U.K.
View GitHub Profile
@paulhhowells
paulhhowells / array_numbered_key_elements.drupal.php
Created April 16, 2013 14:49
array_numbered_key_elements() Many Drupal 7 arrays mix numeric and associate keys, and you often need to separate the numerically keyed children from the associatively keyed arrays. This function returns an array containing only the numbered keys ready to be iterated through.
/*
* returns: an array containing only the numbered keys
*
* notes: array_intersect_key() is faster than array_intersect()
*/
function array_numbered_key_elements($array) {
return array_intersect_key($array, element_children($array));
}
@paulhhowells
paulhhowells / Render Tabs D7.php
Last active December 12, 2015 05:38
Render Tabs — don’t print them if you don’t need ’em. Drupal 7.
add to template.php:
/*
* Implements template_preprocess_page
*/
function THEMENAME_preprocess_page(&$variables, $hook) {
// create $render_tabs & $show_render_tabs for page.tpl
$render_tabs = render($variables['tabs']);
$variables['render_tabs'] = $render_tabs;
@paulhhowells
paulhhowells / Theme Bean Block & Display Suite Combo.php
Last active April 6, 2017 20:36
Enable bean blocks to be themed (using a .tpl file) according to bean-type: i.e. block__bean__BEAN-TYPE.tpl
Enable bean blocks to be themed (using a .tpl file) according to bean-type:
i.e. block__bean__BEAN-TYPE.tpl
Why? Combine a Bean Block with Display Suite and the innards of the block will match the DS layout
used, however the outer wrapping of the block must be themed separately. However if you write a
.tpl that matches the block it will take precedence and the DS layout will be lost. This prevents
using a DS layout for each type of Bean while simultaneously having full control over the Bean
Block’s mark-up.
This solution adds a theme hook suggestion so that .tpl files may be written for each type of Bean.
@paulhhowells
paulhhowells / Per node background colour. Drupal 7.
Last active December 12, 2015 03:48
Set a (whole) page’s background colour on a per node basis. A Drupal 7 theme function that adds a class to the body tag.
/*
* Implements template_preprocess_html
*
* requires:
* the content type to have a List[text] field called 'field_bg_colour'
* using Display Suite the field may be Hidden but not Disabled
*/
function THEMENAME_preprocess_html(&$variables) {
// if a background colour has been set within the node,
@paulhhowells
paulhhowells / tinymce-drupal.css
Last active December 10, 2015 12:38
Tinymce css for drupal tinymce wysiwyg profile. (Uses base64 encoded images, so replace with urls that point to image files if your intended user's browsers are old enough to not support base64). Utilises edeverett’s idea of illustrating to rich text editor users the markup they are creating or editing.
/*
* wysiwyg tinymce css for use in Drupal 7
* with the addition of styles based on a great idea by edeverett http://edeverett.co.uk/
* and diagnostic css from Eric Meyer http://meyerweb.com/eric/tools/css/diagnostics/
*
* requires a modern browser (more recent than IE7 anyway ;-) for the base64 encoded images
*
*/
p,
@webchick
webchick / drupal-hooks-by-implementation
Last active April 9, 2020 10:00
A list of hooks in all* Drupal contrib modules (6.x and 7.x), in descending order of how often they're implemented. (Consolidated a few that were renamed between 6 and 7) * Within a rounding error. :P
Array
(
[hook_menu] => 6744
[hook_uninstall] => 4742
[hook_perm(ission)] => 4012
[hook_install] => 3751
[hook_theme] => 3525
[hook_schema] => 3003
[hook_help] => 2465
[hook_form_alter] => 2273
@madrobby
madrobby / gist:4161897
Created November 28, 2012 15:16
Retina screen media query
@media (min--moz-device-pixel-ratio: 1.5),
(-o-min-device-pixel-ratio: 3/2),
(-webkit-min-device-pixel-ratio: 1.5),
(min-device-pixel-ratio: 1.5),
(min-resolution: 144dpi),
(min-resolution: 1.5dppx) {
/* Retina rules! */
}
@Skateside
Skateside / modular.css
Last active July 6, 2016 18:45
Having read up on SMACSS, I put together a basic starting point for all my style sheets. This is that starting point.
/* # Base rules
This style sheet attempts to show how CSS selectors can be limited to no more
than a single class (although there are exceptions). Keeping to such a
restriction helps contain the styling to a module and allows for easier
sub-classes of modules. It also enables the surgical classes (below) to work.
## Universal rules
@bzerangue
bzerangue / mac-trim-support-non-apple-ssd.markdown
Created June 25, 2012 02:39
Enabling TRIM Support on Mac OS X with Non-Apple SSDs

How To: Enable TRIM with Non-Apple SSD

The guide breaks the process down into three steps, all performed via copying and pasting the code snippets through the terminal window. To launch a terminal window, open the Utilities folder inside the Applications folder and select terminal.

The first step makes a backup of the original IOAHCIBlockStorage file called IOAHCIBlockStorage.original. You will be prompted to enter in your system password when using the "sudo" command, since you are modifying system files. Copy and paste the code into the terminal window, a successful or uneventful response is a new blank terminal line.

sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original

Next the code patches the IOAHCIBlockStorage file, removing the requirements that the SSD be made by Apple. Copy and paste t

@trey
trey / happy_git_on_osx.md
Last active March 10, 2025 23:53
Creating a Happy Git Environment on OS X

Creating a Happy Git Environment on OS X

Step 1: Install Git

brew install git bash-completion

Configure things:

git config --global user.name "Your Name"

git config --global user.email "[email protected]"