Skip to content

Instantly share code, notes, and snippets.

@gregmercer
gregmercer / jsclosure.js
Created July 24, 2012 21:51
Javascript: closure example
function example() {
var o = {}, i = 0;
for (i = 0; i < 3; i++) {
o[i] = function() {
console.log(i);
};
}
o[0]();
o[1]();
o[2]();
@gregmercer
gregmercer / gist:3309256
Created August 9, 2012 23:55
Drupal: behaviors code
(function ($) {
Drupal.behaviors.<replace with module name> = {
attach: function (context, settings) {
$(document).ready(function() {
... stuff goes here ...
}
}
};
@gregmercer
gregmercer / gist:3309318
Created August 10, 2012 00:04
Drupal: hook_menu example to create a page
/**
* Implements hook_menu().
*/
function <replace with module name>_menu() {
$items['path1/path2'] = array(
'title' => 'some text for the title',
'description' => 'some text for the description',
'page callback' => '<replace with module name>_page',
'page arguments' => array(1),
@gregmercer
gregmercer / gist:3316200
Created August 10, 2012 17:59
Drupal: batch_process() example
$batch = array(
'title' => t('Moving files...'),
'operations' => array(),
'init_message' => t('Finding files to move'),
'progress_message' => t('Processed @current out of @total files.'),
'error_message' => t('An error occurred during processing.'),
'finished' => 'xxx_file_finished',
'progressive' => FALSE,
);
@gregmercer
gregmercer / gist:3317401
Created August 10, 2012 20:03
Drupal: creating a custom block
/**
* Implements hook_theme().
*
* Define custom theme hooks
*/
function <replace with module name>_theme($existing, $type , $theme, $path) {
return array(
'<replace with module name>_<block name>' => array(
'template' => 'templates/<replace with module name>-<block name>',
'file' => '<block name>.theme.inc',
@gregmercer
gregmercer / gist:3318554
Created August 10, 2012 22:10
Linux: ls - list all .pdf files in a directory
# list all .pdf files in a directory
ls | egrep '\.pdf$'
@gregmercer
gregmercer / gist:3318891
Created August 10, 2012 23:11
Linux: find - find excluding some extensions
find /sites/default/files -type f -not -name "*.gif" -not -name "*.jpg" -not -name "*.css" -not -name "*.JPG" -not -name "*.jpeg" -not -name "*.js" -not -name "*.png"
@gregmercer
gregmercer / gsb-panopoly
Created November 8, 2012 19:25
panopoly patch for the gsb_panopoly module
diff --git a/panopoly.info b/panopoly.info
index 3aea3d4..f483782 100644
--- a/panopoly.info
+++ b/panopoly.info
@@ -37,3 +37,6 @@ dependencies[] = panopoly_wysiwyg
dependencies[] = navbar
dependencies[] = devel
dependencies[] = uuid
+
+; GSB Panopoly
@gregmercer
gregmercer / dumppermissions.php
Created December 6, 2012 18:46
Get list of permissions in Drupal
$permissions = test_invoke_all('permission');
foreach ($permissions as $key => $value) {
$title = $value["title"];
$description = "";
$module = $value["module"];
if (isset($value["description"])) {
$description = $value["description"];
}
echo "$module&$key&$title&$description \n";
}
@gregmercer
gregmercer / gist:4227228
Created December 6, 2012 19:05
Get list of modules/hooks in Drupal
// $stuff = module_implements('menu');
//$stuff = module_hook_info();
$sort = TRUE;
$stuff = module_list(FALSE, FALSE, $sort);
dsm($stuff);