Skip to content

Instantly share code, notes, and snippets.

syntax enable
set tabstop=4
set shiftwidth=4
set expandtab
set number
filetype indent on
set autoindent
colorscheme monokai # See https://github.com/ku1ik/vim-monokai
@karelbemelmans
karelbemelmans / power.sh
Created November 22, 2021 14:24
How much power is my Mac using?
system_profiler SPPowerDataType
@karelbemelmans
karelbemelmans / entity_queries.php
Last active March 13, 2017 21:13
Using entity queries in Drupal 7
<?php
// A. The old way using node_load
$nodes = node_load_multiple(NULL, array('type' => 'example_content_type'));
// B. The new way using entity queries.
// The point of entity queries is you can add field filters here before the
// node has to be actually loaded, making your code execution a load lighter.
// Get a list of nids for nodes that match our request
@karelbemelmans
karelbemelmans / docker-compose.yml
Created March 6, 2016 21:46
A Docker compose file to create a Drupal 8 with MySQL stack, useable for local development.
# Basicly taken from:
# https://github.com/docker-library/drupal/issues/3#issuecomment-153775540
#
# Volume containers are the way to go.
version: '2'
services:
drupal:
image: drupal:8
links:
@karelbemelmans
karelbemelmans / gist:9046991
Created February 17, 2014 08:46
setfacl commands
setfacl -R -m o:rwx files-development/
setfacl -dR -m o:rwx files-development/
@karelbemelmans
karelbemelmans / gist:5795324
Last active December 18, 2015 14:09
Memory and time usage for PHP function
<?php
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
@karelbemelmans
karelbemelmans / link_to_link_field.php
Created April 27, 2013 15:52
Add a "Link to Link field" option to image fields. Requires the field_formatter_settings module.
<?php
/**
* Add context 'custom' to your translation strings.
*
* @param $string
* A string containing the English string to translate.
* @param $args
* An associative array of replacements to make after translation. Based
* on the first character of the key, the value is escaped and/or themed.
@karelbemelmans
karelbemelmans / foo.module
Created March 27, 2013 14:38
dpm a $node and its attached $product
<?php
/**
* Implements hook_node_view().
*/
function foo_node_view($node, $view_mode, $langcode) {
if ($node->type == 'product_display') {
$product_id = $node->field_product[LANGUAGE_NONE][0]['product_id'];
$product = commerce_product_load($product_id);
dpm ($node, 'node');
@karelbemelmans
karelbemelmans / attachYoutubeMediaFromURL.php
Created March 25, 2013 14:09
Drupal 7 code to attach a video to a node using the media_youtube code.
<?php
module_load_include('inc', 'media_youtube', 'includes/MediaInternetYouTubeHandler.inc');
$obj = new MediaInternetYouTubeHandler($url);
$file = $obj->getFileObject();
$file->display = 1;
file_save($file);
$product->field_product_video[LANGUAGE_NONE][] = (array) $file;