Skip to content

Instantly share code, notes, and snippets.

;(function($) {
function Tooltip(elem, conf) {
// Create tooltip
var tooltip = $('<div></div>')
.addClass(conf.className)
.html(elem.attr('title'))
.insertAfter(elem);
tooltip.hide();
// Remove the browser tooltip
@grom358
grom358 / obj_to_array.php
Last active August 29, 2015 14:19
Convert PHP object to array
<?php
function object_to_array($data, $visited = array()) {
if (!is_array($data) and !is_object($data)) {
return $data;
}
if (is_object($data)) {
// Detect object cycles, overwise recursion occurs.
$hash = spl_object_hash($data);
if (isset($visited[$hash])) {
return '** RECURSION **';
@grom358
grom358 / indexer.md
Last active August 29, 2015 14:19
Index Features
  • Query what source code files exist in the codebase
  • Query what classes/traits/interfaces exist. eg. $index->getClasses() returns fully qualified list of class names
  • Query what functions exist. eg. $index->getFunctions() returns fully qualified list of function names
  • On a class/trait/interface can find what methods/properties/constants exist
  • On a class/interface can inspect the parent class/interface
  • On a class/trait inspect what interfaces are implemented
  • For a class find subclasses
  • For a trait find trait usages
  • For an interface find class/traits that implement the interface
  • For an interface find interfaces which extend it
@grom358
grom358 / generate_dep.php
Last active August 29, 2015 14:11
Generate dependency listing for install profile
<?php
/**
* Root directory of Drupal installation.
*/
define('DRUPAL_ROOT', getcwd());
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
<?php
class Dep {
protected $name;
protected $dependencies = [];
public function __construct($name) {
$this->name = $name;
}
@grom358
grom358 / BrowserTestCase.php
Last active August 29, 2015 14:06
BrowserTestCase
<?php
use Behat\Mink\Mink;
use Behat\Mink\Selector\CssSelector;
use Behat\Mink\Session;
use Behat\Mink\Element\Element;
use Behat\Mink\Element\NodeElement;
abstract class BrowserTestCase extends PHPUnit_Framework_TestCase {
/**
"use strict";
/**
* High performance Vector library.
*
* Constructing vectors is expensive and therefore these functions take
* the required operands and a parameter to output the result into.
*/
var Vector = {};
<?php
function argToString($arg, $maxLength = false) {
if (is_null($arg)) {
return 'null';
} elseif (is_array($arg)) {
return 'Array';
} elseif (is_object($arg)) {
return 'Object(' . get_class($arg) . ')';
} elseif (is_bool($arg)) {
return $arg ? 'true' : 'false';
<?php
/**
* Alters a multi search query to add node access checks.
*
* @param SearchApiMultiQueryInterface $query
* The executed search query.
*/
function hook_search_api_multi_query_alter(SearchApiMultiQueryInterface $query) {
global $user;
$indexes = $query->getIndexes();
@grom358
grom358 / array_syntax_convert.php
Created April 28, 2014 23:40
Convert from old array syntax array(...) to the new shorter array syntax [...]
<?php
require_once 'vendor/autoload.php';
// Import the Pharborist classes
use Pharborist\Filter;
use Pharborist\Node;
use Pharborist\Parser;
use Pharborist\TokenNode;
use Pharborist\TopNode;