Skip to content

Instantly share code, notes, and snippets.

View batandwa's full-sized avatar

Batandwa batandwa

View GitHub Profile
@batandwa
batandwa / closable_accordion.js
Created February 6, 2012 12:24
An accordion that opens on pane at a time but also allows you to close a pane.
$('#accordion .content').hide();
$('#accordion .title').unbind();
$('#accordion .title').click(function() {
$('#accordion .content').slideUp();
if($(this).hasClass('active')) {
$(this).removeClass('active');
return;
}
$(this).addClass('active');
@batandwa
batandwa / drupal6_views_args
Created February 29, 2012 12:13
Drupal 6 views snippet that goes into the header to help you see whic
<h2>Arguments</h2>
<strong>
<?php
$view = views_get_current_view();
print ucwords(str_replace('-', ' ',$view->args[0]));
print ucwords(str_replace('-', ' ',$view->args[1]));
print ucwords(str_replace('-', ' ',$view->args[2]));
//Add more lines and change the $view->args element for more arguments.
?>
</strong>
@batandwa
batandwa / form_id_textfield.php
Last active October 1, 2015 18:07
Drupal 6 - Display the Form ID of every form in the form in a text box.
<?php
$form['form_id_display'] = array(
'#markup' => '<div style="border:1px solid #333; padding: 5px;">' . $form_id . '</div>',
'#value' => '<div style="border:1px solid #333; padding: 5px;">' . $form_id . '</div>',
'#weight' => -999,
'#access' => user_access('administer nodes'),
);
@batandwa
batandwa / errors.php
Last active October 2, 2015 00:18
Display and log PHP errors.
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log_' . date('Ymd') . '.log');
error_reporting(-1);
@batandwa
batandwa / drupal_db.php
Created March 20, 2012 11:40
Drupal database query example
<?php
$values = array(1, 2, 3, 4, 5);
$placeholders = db_placeholders($values);
$result = db_query("SELECT t.s FROM {table} t WHERE t.field IN ($placeholders)", $values);
$items = array();
while ($row = db_fetch_object($result)) {
$items[] = $row->s;
@batandwa
batandwa / print_view.php
Created June 8, 2012 12:20
Drupal - Load and print a view programmatically
<?php
$view_args = array(3);
$view_display_id = 'default';
$view = views_get_view('view_id');
print $view->execute_display($view_display_id, $view_args),
@batandwa
batandwa / change_detector.php
Created June 18, 2012 17:51
Server File Change Detection
<?php
echo 'Hello';
echo '... more junk';
@batandwa
batandwa / drupal-centralise.py
Created June 18, 2012 23:29
Centralise Drupal Modules
#!/usr/bin/env python
import sys
import os
import time
import tempfile
import subprocess
import optparse
import re
import shutil
@batandwa
batandwa / conn
Last active October 6, 2015 08:48
Git - Database dump post-commit hook
DB_HOST='server_name'
DB_USER='user'
DB_PWD='pwd'
DB_NAME='database_name'
DB_TABLE_PREFIX='pref_'
@batandwa
batandwa / odd_class.js
Created July 10, 2012 13:14
jQuery table odd row
$("table tr:odd").addClass("odd");
$("table tr:even").addClass("even");
$("table tr:first-child").addClass("first");
$("table tr:last-child").addClass("last");
$("table td:odd").addClass("odd");
$("table td:even").addClass("even");
$("table td:first-child").addClass("first");
$("table td:last-child").addClass("last");