Skip to content

Instantly share code, notes, and snippets.

View cesarmiquel's full-sized avatar

Cesar Miquel cesarmiquel

View GitHub Profile
@cesarmiquel
cesarmiquel / import-translations.php
Last active August 29, 2015 14:04
Import translations into Drupal from a .po file
<?php
//
// This code uses the _locale_import_po() function call from includes/locale.inc. This
// is a private function so use with care. Here's the function:
// https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_po/7
//
// example usage:
$translation_filepath = drupal_get_path('module', '<module>') . '/translations-es.po';
@cesarmiquel
cesarmiquel / add_nodes_to_nodequeue.php
Last active August 29, 2015 14:03
Add nodes to a Drupal nodequeue programatically
<?php
// List of nids of the nodes to add
$nids = array(6474, 6475);
// Get queue and subqueue information
$queue_machine_name = 'queuename';
$queue = nodequeue_load_queue_by_name( $queue_machine_name );
// Get subqueues
@cesarmiquel
cesarmiquel / row-count-2.sql
Last active December 6, 2019 17:57
Show all tables (and their row count) for tables with more than 10000 rows for MySQL. Taken from: http://stackoverflow.com/questions/286039/get-record-counts-for-all-tables-in-mysql-database. The second version from here: https://www.lullabot.com/articles/importing-huge-databases-faster
SELECT table_name, table_rows, data_length, index_length,
round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "drupal"
ORDER BY round(((data_length + index_length) / 1024 / 1024),2) DESC
LIMIT 0,30;
@cesarmiquel
cesarmiquel / solr-test-query.php
Created May 25, 2014 04:41
Call Apache Solr usings the apachesolr Drupal module and parse the response.
<?php
// -------------------------------------------------------------------------
//
// Taken from:
// http://worldofdrupal.blogspot.com.ar/2014/01/drupal-7-apache-solr-custom-query.html
//
// -------------------------------------------------------------------------
// Search parameters
@cesarmiquel
cesarmiquel / module.js
Last active August 29, 2015 13:57
This is a basic pattern for an extensible JavaScript module. This example is based off: http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html where you can find several more snippets.
var UTIL = (function (my, $) {
// private variables
var privateVariable = 1;
// private methods
function privateMethod() {
// ...
}
@cesarmiquel
cesarmiquel / module.install.php
Last active August 29, 2015 13:55
Sample .install file which enables/disables modules, features, etc.
<?php
/**
* Update site to ...
*
* First comment is used when displaying updates to perform. Implementation of
* hook_update_N().
*/
function xxxx_update_700X() {
@cesarmiquel
cesarmiquel / module.info
Created January 30, 2014 15:05
A stub Drupal .info file. Complete options here: https://drupal.org/node/542202
name = Really Neat Widget
description = Provides a really neat widget for your site's sidebar.
core = 7.x
package = Views
dependencies[] = views
dependencies[] = panels
files[] = tests/example.test
configure = admin/config/content/example
@cesarmiquel
cesarmiquel / create-node.php
Last active January 2, 2016 02:39
Create a Drupal node with path
<?php
// Create a node by code
$newNode = new stdClass();
$newNode->type = 'page';
node_object_prepare($newNode);
$newNode->title = 'This is the title of the new node';
$newNode->status = 1;
$newNode->comment = 1;
@cesarmiquel
cesarmiquel / create-palette.php
Created December 23, 2013 05:15
Create a color palette from an image.
<?php
$img = imagecreatefrompng ( '/tmp/image.png' );
$palette = build_palette($img, 20, 20);
$unique_colors = array();
foreach($palette as $row) {
foreach($row as $col) {
$rgb = sprintf('%02x%02x%02x', $col['r'], $col['g'], $col['b']);
if (!isset($unique_colors[$rgb])) {
@cesarmiquel
cesarmiquel / gist:8091980
Last active January 1, 2016 04:29
Blue / Orange color palette. Result can be previewed here: http://jsfiddle.net/FS9S8/1/embedded/result/
<div class="container">
<div class="box" style="background-color:#04263c"></div>
<div class="box" style="background-color:#042e3c"></div>
<div class="box" style="background-color:#043644"></div>
<div class="box" style="background-color:#044254"></div>
<div class="box" style="background-color:#045264"></div>
<div class="box" style="background-color:#045664"></div>
<div class="box" style="background-color:#042e44"></div>
<div class="box" style="background-color:#043a4c"></div>
<div class="box" style="background-color:#043e4c"></div>