Skip to content

Instantly share code, notes, and snippets.

@balsama
balsama / twitter-un-filter.php
Created December 4, 2012 08:12
Function to convert all valid twitter usernames into links to their twitter page.
<?php
function twitter_un_filter($string) {
$handles = preg_replace_callback('/@([A-Za-z0-9_]+)/',
create_function(
'$handles',
'
$username = substr($handles[0], 1);
$handles = "<a href=\"https://twitter.com/" . $username . "\" class=\"twitter-un-filter-link\">" . $handles[0] . "</a>";
return $handles;
'
@balsama
balsama / pathauto-207840-25-7.x-1.x-dev.patch
Created December 7, 2012 15:08
Drupal Pathauto Curly Quotes
diff --git a/pathauto.inc b/pathauto.inc
index 42290ca..fcd0276 100644
--- a/pathauto.inc
+++ b/pathauto.inc
@@ -677,6 +677,10 @@ function pathauto_punctuation_chars() {
$punctuation['greater_than'] = array('value' => '>', 'name' => t('Greater-than sign'));
$punctuation['slash'] = array('value' => '/', 'name' => t('Slash'));
$punctuation['back_slash'] = array('value' => '\\', 'name' => t('Backslash'));
+ $punctuation['double_curly_left'] = array('value' => '“', 'name' => t('Double curly left'));
+ $punctuation['double_curly_right'] = array('value' => '”', 'name' => t('Double curly right'));
@balsama
balsama / gist:5221f66d8c7e7ec8cfb3
Last active August 29, 2015 14:01
Track actual browser width (not screen resolution) in Google Analytics.
/**
* Creates a Google Analytics Event on page load that tracks which default
* Bootstrap screen width category the user's browser falls into.
*
* See http://getbootstrap.com/css/#grid-media-queries
*/
var width = window.innerWidth || document.body.clientWidth;
var bootstrapSize = 'Extra Small (xs)';
if (width >= 768) {
bootstrapSize = 'Small (sm)';
@balsama
balsama / import.php
Last active August 29, 2015 14:02
Custom Formatter to display published on date as defined by the "Publication Date" module. (Use this gist as CTools Import Code)
$formatter = new stdClass();
$formatter->disabled = FALSE; /* Edit this to true to make a default formatter disabled initially */
$formatter->api_version = 2;
$formatter->name = 'published_date';
$formatter->label = 'Published Date';
$formatter->description = 'Displays the date that the node was published.';
$formatter->mode = 'php';
$formatter->field_types = 'list_boolean';
$formatter->code = 'if ($variables[\'#items\'][0][\'value\']) {
if (isset($variables[\'#object\']->published_at)) {
@balsama
balsama / import.php
Last active August 29, 2015 14:04
Drupal custom formatter for fields. Easily wrap a field in a div or heading tag with customizable classes. (use this as a ctools import)
$formatter = new stdClass();
$formatter->disabled = FALSE; /* Edit this to true to make a default formatter disabled initially */
$formatter->api_version = 2;
$formatter->name = 'html_element';
$formatter->label = 'HTML Element';
$formatter->description = 'Allows you to wrap fields in HTML element with custom classes.';
$formatter->mode = 'php';
$formatter->field_types = 'text_long, text';
$formatter->code = '$html_element = $variables[\'#display\'][\'settings\'][\'html_element\'];
$classes = $variables[\'#display\'][\'settings\'][\'additional_css_classes\'];
@balsama
balsama / Font sizes with rems
Created July 21, 2014 21:02
Boilerplate for setting up rem-based font sizes.
html {
// Default (Extra small screens). 1rem = 7px
font-size: percentage(7 / 16);
@media (min-width: 768px) {
// Small screens. 1rem = 8px
font-size: percentage(8 / 16);
}
@media (min-width: 992px) {
// Medium screens. 1rem = 9px
font-size: percentage(9 / 16);
@balsama
balsama / gist:561a7246017ec1ac13f3
Last active August 29, 2015 14:06
Force Error Reporting
<?php
// show errors
if (!defined('E_STRICT')) { define('E_STRICT', 2048); }
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
ini_set('track_errors', '1');
ini_set('html_errors', '0');
ini_set('log_errors', '1');
ini_set('error_log', dirname(__FILE__) . '/_php_error.log');
@balsama
balsama / hexagon.scss
Last active August 29, 2015 14:10
SASS Hexagon Mixin
@mixin hexagon-flat-top($width: 60px, $bg-color: black, $text-color: white) {
// We do the calculations first so we can use meaningful variable names.
$hexagon-width: $width;
$sqrt3: 1.74; // Needed to calculate the length of the longer of the
// non-hypotenuse side of the right triangle that results when
// you divide the larger border triangles in two.
$hexagon-border-tb: ($hexagon-width * 0.5) * $sqrt3;
$hexagon-height: $hexagon-border-tb * 2;
$hexagon-border-lr: $hexagon-width / 2;
background-color: $bg-color;
@balsama
balsama / Add class to Drupal menu UL
Created December 15, 2014 15:43
Add class to Drupal menu UL
<?php
/**
* Adds a class to a menu's ul. This snipped should be placed in your theme's
* `template.php` file.
*/
function YOURTHEME_menu_tree__menu_MENU_NAME($variables){
return "<ul class='menu nav nav-pills'>\n" . $variables['tree'] ."</ul>\n";
}
@balsama
balsama / GNUmakefile
Created January 7, 2016 16:51
Makefile for local (OS X) Lightning 8 install
all:
chmod -R 777 docroot
bash ./remove-active-docroot.sh
drush make --concurrency=5 ./build/build-lightning.make.yml docroot; \
drush make build/drupal-org.make.yml docroot/profiles/lightning/ --no-core -y; \
cp build/lightning.* docroot/profiles/lightning/; \
rm -rf docroot/profiles/lightning/modules/lightning_features/*; \
cp -R build/modules/lightning_features/ docroot/profiles/lightning/modules/lightning_features/; \
cd docroot; \
drush site-install lightning -y --account-pass=lightning --site-name='OS X Local Lightning Dev' --db-url=mysql://root:root@127.0.01/lightning; \