Skip to content

Instantly share code, notes, and snippets.

View cesarmiquel's full-sized avatar

Cesar Miquel cesarmiquel

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / test-react.md
Last active July 28, 2017 04:15
Trying out React

Generate an Docker image with Node and Create React App installed. For this edit a file called Dockerfile with the following content:

FROM node:6-alpine

# Install create-react-app
RUN npm install -g create-react-app

WORKDIR /src

CMD [ "node" ]

@cesarmiquel
cesarmiquel / pm.sh
Created September 22, 2017 21:10
Ubuntu 17.04 worked out of the box, but there was one annoyance: battery life. For some reason, the laptop was using 10 watts at idle. Thanks to some forum posts, I managed to tweak various kernel module options and got idle down to 4 watts. This drastically improved battery life. I then put together a script to enable power savings on startup. …
#!/bin/sh
# Disable the NMI watchdog
echo '0' > '/proc/sys/kernel/nmi_watchdog';
# Runtime power management for I2C devices
for i in /sys/bus/i2c/devices/*/device/power/control ; do
echo auto > ${i}
done
@cesarmiquel
cesarmiquel / drupal-8-cheatsheet.md
Last active July 3, 2025 10:10
Drupal 8/9/10 Cheatsheet

Drupal 8/9/10 Cheatsheet

[Update 2024] - Take a look at Drupal at your fingertips. Lot's of great stuff there.

Files, Images and Media

// Load file object
$file = File::load($fid);