Skip to content

Instantly share code, notes, and snippets.

View klaasvw's full-sized avatar

Klaas Van Waesberghe klaasvw

View GitHub Profile
@klaasvw
klaasvw / hack.sh
Created April 1, 2012 09:06 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@klaasvw
klaasvw / views-view-grid.tpl.php
Created August 20, 2012 14:27 — forked from jensimmons/views-view-grid.tpl.php
Switching Drupal Views Grid to unordered lists
<?php
/**
* @file views-view-grid.tpl.php
* Default simple view template to display a rows in a grid.
*
* - $rows contains a nested array of rows. Each row contains an array of
* columns.
*
* @ingroup views_templates
*/
@klaasvw
klaasvw / tokens.php
Created September 4, 2012 08:12
Add token support to a form element
<?php
/**
* An example form showing how to use tokens.
*/
function my_token_form($form_state) {
$form = array();
// An example element with a value that accepts tokens.
$form['title_text'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
@klaasvw
klaasvw / focus.js
Created September 7, 2012 07:56
Making any element focusable
/**
* Some elements like headers or divs cannot gain focus. This script shows how you can enable this.
*/
// Set the tabindex to 0 so the element can gain focus. To maintain natural tab flow
// you should use 0.
$('h1').attr('tabindex', '0');
@klaasvw
klaasvw / views_hide_page_title.module
Created September 10, 2012 09:32
Hide a page title on a certain page view.
<?php
/**
* @file
* Hide the page title on a page view snippet.
*/
/**
* Implements template_process_page().
*
* Removes the regular page title from news pages.
@klaasvw
klaasvw / addthis-reset.js
Created September 19, 2012 14:01
Reset addThis widget
// Reset addthis so it can be reloaded.
// This is very useful if you have generated content contain an AddThis widget.
if (window.addthis){
window.addthis = null;
}
@klaasvw
klaasvw / drupal-proxy.php
Created October 10, 2012 06:31
Drupal behind a proxy
/**
* @file
* This snippet shows how you can run drupal from a different host behind a proxy.
* Include this code at the bottom of your settings.php file.
*/
// Set the hosts that are allowed to be proxied to this drupal installation.
$conf['reverse_proxy_addresses'] = array('example.com', 'example2.com');
// If the request was proxied from a different domain we change the internal URL.
if (isset($_SERVER['HTTP_X_FORWARDED_HOST']) && in_array($_SERVER['HTTP_X_FORWARDED_HOST'], $conf['reverse_proxy_addresses'])) {
@klaasvw
klaasvw / varnish-host-proxy.vcl
Created October 10, 2012 06:41
Set up Varnish to proxy to a different host
# Add this code to your VCL configuration.
#
# I assume a default backend has already been configured.
# If different from the default backend, add one for the host to proxy to. Note that these
# values are just examples.
backend proxy_host {
.host = "proxy_host.dev";
.port = "8080";
}
@klaasvw
klaasvw / translation.migrate.php
Created October 17, 2012 08:52
Migrating translations using drupal migrate.
<?php
/**
* Migration class for migrating the source translations.
*/
class MySourceTranslationMigration extends Migration {
// Nothing special here. Just set up a node migration, migrating to nodes
// that will serve as translation sources.
// ...
@klaasvw
klaasvw / nbsp_decode.php
Created November 9, 2012 08:57
Non breaking space, decode_entities and strtotime
<?php
// Replace &nbsp; by a space because decode_entities will replace it by
// ASCII code 160. See http://php.net/manual/en/function.html-entity-decode.php.
// Replacing chr(160) afterwards results in an unknown char for some
// reason.
// Note that strtotime will result in FALSE if ASCII code 160 is present in the string.
$value = str_replace('&nbsp;', ' ', $value);