Skip to content

Instantly share code, notes, and snippets.

@hedleysmith
hedleysmith / jQuery radio input selected & not-selected classes.js
Last active August 29, 2015 14:15
Add selected and not-selected classes to radio inputs parent elements for checked and not-checked radio inputs in jQuery
// Load selected & not-selected classes when page loads
$('input[type=radio]').filter(':checked').parent().addClass('selected');
$('input[type=radio]').filter(':not(":checked")').parent().addClass('not-selected');
// When radio buttons are changed add classes
$('form').once('selected-radio-listen').on(
"change",
"input[type=radio]",
function () {
// Get all related inputs.
@hedleysmith
hedleysmith / Vagrant guest to guest access
Last active August 29, 2015 14:17
Accessing a vagrant vm from another guest (guest to guest vm access)
1. Configure your Vagrant box to use a private network and assign an IP:
config.vm.network 'private_network', ip: 192.168.56.101
2. Open the guest VM and add an entry to the hosts file (/system32/drivers/etc/hosts on Windows)
192.168.156.101 mysite.local
3. You may need to add a hosts-only network adapter to the second guest VM (this can be done in the VirtualBox config for that VM)
This can be very useful for testing a website served by a vagrant box on a Windows VM with Internet Explorer.
@hedleysmith
hedleysmith / Drupal switch theme based on node type.php
Created April 11, 2015 15:45
Switch theme in Drupal when editing or adding a specific node type
<?php
/**
* Implements hook_custom_theme().
* Switch to a custom theme when editing or adding a specific node type.
*/
function MYMODULE_custom_theme() {
$args = arg();
$node_type = 'my_node_type'; // Node type.
$theme = 'mytheme'; // Theme machine name.
if(isset($args[2]) && $args[0] == 'node' && $args[2] == 'edit') {
// Get the value of a field.
$my_field = field_get_items('user', $user, 'field_my_field_name');
$my_field_value = field_view_value('user', $user, 'field_my_field_name', $my_field[0]);
print $my_field_value['#markup'];
// Render a field.
$entity = entity_load('1');
$my_node_field = field_view_field('node', $entity, 'field_my_field_name');
@hedleysmith
hedleysmith / slick.zsh-theme
Created July 14, 2013 21:13
My zsh theme, based on ys
# Clean, simple and slick. All on one line.
# It is recommended to use with a dark background and the font Inconsolata.
# Colors: black, red, green, yellow, *blue, magenta, cyan, and white.
# Based on YS theme
# Machine name.
function box_name {
[ -f ~/.box-name ] && cat ~/.box-name || hostname -s
}
@hedleysmith
hedleysmith / gist:6029421
Created July 18, 2013 13:45
Install Apache Solr (v3.6.0) and Jetty (v6.1) on Ubuntu
#!/bin/bash
# ################################################################################ Apache SolR
# README:
#
# This script will install Apache Solr and run using Jetty
#
HELP="
@hedleysmith
hedleysmith / gist:6542309
Last active December 22, 2015 22:49
Drupal debugging
Useful for anonymous users & debugging Drupal hook_mail and hook_mail_alter. Pretty-prints an object
drupal_set_message('<pre>' . print_r($account, TRUE) . '</pre>');
@hedleysmith
hedleysmith / gist:6549790
Created September 13, 2013 12:03
Drupal 7 Spaces module: Add current space to body as a class
/*
* Implements template_preprocess_html()
*/
function YOURTHEME_preprocess_html(&$variables, $hook) {
// Get the current space and output as a class in the body for use elsewhere
$space = spaces_get_space();
// Works for Taxonomy spaces
if(!empty($space->term->name)) {
// Format nicely
@hedleysmith
hedleysmith / gist:6921874
Created October 10, 2013 17:01
Reset admin password in Drupal 7
cd /path/to/drupal
scripts/password-hash.sh 'mynewpassword'
-> Add hash to user 1 in the DB
@hedleysmith
hedleysmith / gist:7695973
Last active December 29, 2015 16:09
SASS Style Guide / Coding Standards
/**
* Code block comment
*/
$variable: 1;
$variable: 2;
.selector {
@extend %placehold-extender;
@include functionname();