Skip to content

Instantly share code, notes, and snippets.

View cesarmiquel's full-sized avatar

Cesar Miquel cesarmiquel

View GitHub Profile
@cesarmiquel
cesarmiquel / script_path.sh
Created July 19, 2017 01:35
Determine the path of the running script in Bash.
#!/bin/bash
#
# Get path to this script:
# http://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself
#
pushd `dirname $0` > /dev/null
SCRIPT_PATH=`pwd -P`
ROOTFS=`dirname "$SCRIPT_PATH"`
popd > /dev/null
@cesarmiquel
cesarmiquel / nginx.conf
Created July 4, 2017 19:56
Config para bloquear robots.txt
## Here's the way to have Nginx return a robots.txt file that disallows all crawling by bots.
## This is useful for development and private sites.
location = /robots.txt {
add_header Content-Type text/plain;
return 200 "User-agent: *\nDisallow: /\n";
}
@cesarmiquel
cesarmiquel / routines.asm
Last active November 9, 2016 01:08
Useful routines / snippets of GB Z80 code
;
; These come from:
; https://github.com/pret/pokered/blob/master/home.asm
;
; ----------------------------------------------------------------------------------------
; Disable LCD
; ----------------------------------------------------------------------------------------
DisableLCD::
xor a
@cesarmiquel
cesarmiquel / view_space.sql
Last active August 16, 2016 22:15
View used table space in Postgres database.
--
-- Source: https://wiki-bsse.ethz.ch/display/ITDOC/Check+size+of+tables+and+objects+in+PostgreSQL+database
--
SELECT
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
FROM
pg_catalog.pg_statio_user_tables
ORDER BY
@cesarmiquel
cesarmiquel / clear-cache.php
Last active August 10, 2016 16:18
Clear de caches
<?php
/**
* Implements hook_cement_publish_page()
*/
function site_home_cement_publish_page($pid, $rev) {
// Hacer un clear cache de home y vivo del cache de paginas
$domains = variable_get('varnish_front_domains', 'desa.eldoce.tv eldoce.tv');
foreach(explode(' ', $domains) as $domain) {
@cesarmiquel
cesarmiquel / d7-add-entity-view-mode.md
Last active January 5, 2016 05:22 — forked from swichers/d7-add-entity-view-mode.md
Drupal 7 - Programmatically add view mode to entity

In a module file:

This will enable an additional view mode for use on the specified entity type(s). Many examples will show the custom settings here being set to TRUE. If TRUE is used then that view mode is added to all entities of the specified type regardless of if it should be on the bundle or not.

/**
 * Implements hook_entity_info_alter().
 */
function HOOK_entity_info_alter(&$entity_info) {
@cesarmiquel
cesarmiquel / sample_db_calls.php
Created November 11, 2015 18:36
Example calls to D7 database API
<?php
// Query and loop over results
$result = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'article')
->condition('uid', array(0,1), 'IN')
->execute();
foreach($result as $row) {
@cesarmiquel
cesarmiquel / kickstart-drupal.sh
Last active August 29, 2015 14:25
Configure a new Drupal site
#!/bin/bash
# ---------------------------------------------------------------------------------------
# Configuration options
# ---------------------------------------------------------------------------------------
DEFAULT_ADMIN_THEME='adminimal' # Other common options: seven - adaptivetheme_admin
DEFAULT_THEME='bartik' # Other common options: omega - zen - bartik
ADMIN_PASSWORD='<strong-password>'
@cesarmiquel
cesarmiquel / entity-metdata-wrapper-examples.md
Last active September 15, 2017 20:16
Entity Metadata Wrapper API examples

Entidades en Drupal 7

En Drupal 7 se 'mergearon' los usuarios, nodos y taxonomías en una entidad. Las entidades pueden tener campos adicionales a los que ya tenían. Adicionalmente, cada campo puede estar traducido y, por lo tanto, tener distintos valores dependiendo del idioma. En general es mejor acceder a los valores de los campos via APIs en lugar de acceder directamente al campo. Listamos algunas de las funciones más útiles y recomendadas para utilizar:

  • entity_load() - permite cargar una entidad. Los tipos de las entidades pueden ser 'node', 'user', etc. Ver: entity_load()
  • field_get_items() - devuelve, dada una entidad y el nombre de un campo la lista de valores que contiene el campo. Ver: field_get_values()
  • field_view_value() - devuelve un array rendereable con el valor. Para obtener HTML hacer drupal_rend
@cesarmiquel
cesarmiquel / drush-create-site.md
Last active August 29, 2015 14:12
Create a Drupal site using drush and an installation profile

How to generate a new Drupal site via drush

  1. Edit your settings.php file and add a database connection setting db, user and pass. For example append the following to your empy settings.php:

      $databases['default']['default'] = array(
        'driver' => 'mysql',
        'database' => '<db>',
        'username' => '<user>',
        'password' => '<pass>',
    

'host' => 'localhost',