Skip to content

Instantly share code, notes, and snippets.

View xtfer's full-sized avatar

Christopher Skene xtfer

View GitHub Profile
@xtfer
xtfer / .environment
Last active March 25, 2022 22:13
Install nvm on Platform.sh
# Statements in this file will be executed (sourced) by the shell in SSH
# sessions, in deploy hooks, in cron jobs, and in the application's runtime
# environment.
# This loads nvm for general usage.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
@xtfer
xtfer / shortcuts.sh
Last active June 8, 2017 23:24
Platform.sh shortcuts
# Run a cron command only on a given branch
if [ "$PLATFORM_BRANCH" = master ]; then
bin/console whatever
fi
# And the short version
cmd: '[ "$PLATFORM_BRANCH" = "master" ] && bin/console whatever'
# Test that an environment works before merging
CODE=$(curl -s -w '%{http_code}' $(platform url -e dev --pipe | head -n 1) -o /dev/null)
@xtfer
xtfer / mysql-size.sql
Created October 14, 2016 00:36
Estimate mysql size
SELECT
table_name,
data_length/1048576,index_length/1048576,
(data_length+index_length)/1048576 as data_used,
data_free/1048576 as data_free,
(data_length+index_length+data_free)/1048576 as disk_used
FROM information_schema.tables where table_schema = 'main'
ORDER BY (data_length+index_length+data_free) ASC;
SELECT
git branch -r --merged | grep -v master | sed 's/origin\///' | xargs -n 1 git push --delete origin
@xtfer
xtfer / gist:322fd19a9f17e1c7abe4
Created February 3, 2016 05:16
Globals usage information
<?php
/**
* Get a global value.
*
* A useful shorthand for accessing the Globals object.
*
* @param string $key
* Key to access
*
@xtfer
xtfer / gist:6f601c608154d32803b1
Created April 29, 2015 04:09
Config module usage
<?php
// Load the Config class.
$config = \Drupal\config\Config::load();
// Supports JSON, PHP, and optionally YAML. Want XML? Its extensible.
$parser_type = CONFIG_PARSER_JSON;
// Get the Config.
return $config->getConfig('my_module_name', 'directory_within_module', 'file_within_directory.ext', $parser_type);
@xtfer
xtfer / Example of hook_node_view
Created April 20, 2015 05:51
Example of hook_node_view
<?php
/**
* Hook structure.
*/
function hook_node_view($node, $view_mode, $langcode) {
// Do something here.
}
/**
@xtfer
xtfer / gist:4c444a64df72bd94dc95
Created April 1, 2015 11:10
Fix a bad registry
UPDATE system SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
UPDATE registry SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
UPDATE registry_file SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
@mixin views-responsive-column-settings($column-count, $local-grid-width) {
.views-column-1 {
@include zen-grid-item(1, 1, $zen-float-direction, $column-count, $zen-gutter-width, $local-grid-width);
}
.views-column-2 {
@include zen-grid-item(1, 2, $zen-float-direction, $column-count, $zen-gutter-width, $local-grid-width);
}
@xtfer
xtfer / gist:b7170ba0ebc9a55fa63f
Last active August 29, 2015 14:10
Ghost: Formatter plugins ctools declaration
<?php
/**
* Implements hook_ctools_plugin_directory().
*/
function ghost_formatters_ctools_plugin_directory($owner, $plugin_type) {
if ($owner == 'ghost') {
if ($plugin_type == GHOST_PLUGIN_TYPE_FORMATTER) {