Skip to content

Instantly share code, notes, and snippets.

@admataz
admataz / config override.php
Created October 6, 2010 22:25
override settings file with another inc
<?
/**
* override global config settings with local settings - add to the bottom of the global config file
* Server Specfic variables from unversion included file - if it exists
*/
$abspath = dirname(__FILE__);
if(file_exists($abspath.'/settings.local.php')){
include $abspath.'/settings.local.php';
@admataz
admataz / is_xhr.php
Created June 7, 2011 11:41
Function to detect whether the current request is from XMLHTTPREQUEST
<?
/*
* Detect whether the current query is ajax
*
* TODO: check if this works across browsers and ajax libraries
*/
function is_xhr()
{
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
@admataz
admataz / articlesList.js
Created March 9, 2012 12:34
Jquery plugin to replace Drupal Views-based pagination with AJAX loading more button
/**
* -----------------------------
* Articles List (Home Page)
* -----------------------------
*/
;(function($){
$.fn.articlesList = function() {
var articleslist = this;
@admataz
admataz / wp_plugin_boilerplate.php
Created February 14, 2013 15:13
WordPress Plugin Boilerplate
<?php
/*
Plugin Name: Plugin Boilerplate
Version: 0.1-alpha
Description: This is how I like to make sense of the WordPress plugin architecture
Author: Adam Davis
Author URI: http://admataz.com
Plugin URI: http://admataz.com
Text Domain: admataz-plugin-boilerplate
Domain Path: /languages
@admataz
admataz / functions.php
Created February 18, 2013 17:33
Base Starter for a WordPress Theme functions.php file
<?php
new ThemeName();
class ThemeName {
/**
* Starting off…
*/
function __construct() {
//add_editor_style();
@admataz
admataz / jqp.js
Last active December 25, 2015 22:19
Load a locally-scoped version of jquery using AMD/require.js - for when the existing site has an older version, and you need the more recent version for your modules. see http://requirejs.org/docs/jquery.html#noconflictmap.
//define a module that returns a noConflict version of jQuery
define(['jquery'], function (jq) {
return jq.noConflict( true );
});
@admataz
admataz / gist:7cb85499e97d71087270
Created September 10, 2014 13:19
Drupal: Create a node programmatically
<?php
function make_node_programmatically()($title) {
global $user;
$node = new stdClass(); // We create a new node object
$node->type = "pages"; // Or any other content type you want
$node->title = $title;
$node->language = LANGUAGE_NONE;
node_object_prepare($node); // Set some default values.
$node->uid = $user->uid; // Or any id you wish
$node = node_submit($node); // Prepare node for a submit
@admataz
admataz / gist:140def49ef7de3987e30
Created September 22, 2014 16:29
Drupal: useful functions I discover every day
  • usehook_inline_entity_form_table_fields_alter(&amp;$fields, $context) to customise the way it looks in the CMS form
@admataz
admataz / calc_aspect_ratio
Created March 10, 2015 13:14
simple function helps calculate resized dimensions while keeping w/h aspect ratio
<?php
function calc_aspect_ratio($w=0,$h=0,$image_dimensions=array()){
//work out some ratios for the resized dimensions
if($w){
$w_ratio=$w/$image_dimensions[0];
} else {
$w_ratio=1;
}
if($h){
$h_ratio=$h/$image_dimensions[1];
@admataz
admataz / config.js
Last active August 29, 2015 14:21
Using nconf to manage hierarchical configuration
/**
* Using nconf to manage hierarchical configuration
* https://www.npmjs.com/package/nconf
*/
'use strict';
var nconf = require('nconf');
var config = {