Skip to content

Instantly share code, notes, and snippets.

View swichers's full-sized avatar
👻
We must construct additional pylons!

Steven Wichers swichers

👻
We must construct additional pylons!
View GitHub Profile
@swichers
swichers / d7-add-entity-view-mode.md
Last active May 24, 2024 23:39
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) {
@swichers
swichers / drush-skeleton.scr
Created March 14, 2014 18:50
Drush script skeleton
#!/usr/bin/env drush
#<?php
/**
* @file
*
*/
@swichers
swichers / http_cache.module
Last active August 29, 2015 14:05
Caching drupal_http_request()
<?php
/*
This code has been moved into a Drupal module:
https://www.drupal.org/project/http_request_cache
/*
@swichers
swichers / cli.sh
Created September 26, 2014 01:17
Scan directory for large images and size them down
# Command to run on a bash shell
# Adjust as necessary to increase/decrease size of files matched, extensions, exclusions, etc.
# Will find images larger than 500k and not in the styles directory.
find . -regex ".*\.\(jpg\|gif\|png\|JPG\|PNG\|jpeg\)" -type f -size +500k -not -path "./styles/*" -exec image-resize.sh "{}" \;
@swichers
swichers / engineer-skillcheck.md
Created March 9, 2015 23:48
Engineering Skillcheck

Summary:

Using Drupal or Wordpress, create a basic website where the front page contains a simple form to convert a decimal amount of US Dollars to an equivalent amount of BitCoin. Please leverage a third-party API to do so.

Requirements:

  • Select a CMS of your choice - either Drupal or Wordpress.
  • Create a module/plugin that enables a form on the front page of the site that accepts a decimal based argument of a Dollar amount in USD.
  • Submitting the form sends a request to a third-party API to convert the submitted Dollar value into the equivalent amount of BitCoin and displays the result on the page.
@swichers
swichers / composer.json
Last active March 24, 2022 10:58
Capturing STDERR from interactive proc_open call
{
"name": "swichers/passthru_with_errors",
"description": "An enhanced passthru() command that includes error capturing.",
"license": "Apache-2.0",
"authors": [ { "name": "Steven Wichers", "role": "Developer" } ],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"files": ["passthru_with_errors.php"]
@swichers
swichers / README.md
Last active August 29, 2015 14:18
Standalone cmorrell.com fish theme

This is a standalone version of the cmorrell theme available from oh-my-fish.

https://github.com/bpinto/oh-my-fish/tree/master/themes/cmorrell.com

Installation

  1. Place these files in your .config/fish/functions folder.
  2. Edit your .config/fish/config.fish file to set the default user: set -g default_user YOUR_USERNAME
  3. Close and reopen your shell
@swichers
swichers / time-functions.js
Last active August 29, 2015 14:22
Google Spreadsheet script for time functions
/**
* @OnlyCurrentDoc Limits the script to only accessing the current spreadsheet.
*/
/**
* Round time to the nearest interval.
*
* Conversion of
* TIME(HOUR(time), (FLOOR(MINUTE(time)/15)*15/60) * 60, 0)
@swichers
swichers / add-mtime-file-url.php
Created June 19, 2015 23:43
Add mtime to files in Drupal
<?php
/**
* Implements hook_file_url_alter().
*/
function HOOK_file_url_alter(&$uri) {
// Client is complaining about images not refreshing immediately when the user
// changes one image for another (and the filename stays the same). Using the
// image path flush function doesn't trigger a browser cache refresh for the
@swichers
swichers / drupal-block-render.php
Created June 19, 2015 23:49
The proper way to load and render a block in Drupal 7
<?php
// Other methods bypass certain hooks or skip parts of the theme layer.
$block = block_load($module, $delta);
$renderable_block = _block_get_renderable_array(_block_render_blocks(array($block)));