Skip to content

Instantly share code, notes, and snippets.

@ScottPhillips
ScottPhillips / .htaccess
Created February 2, 2012 04:30
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@DavidWittman
DavidWittman / default.vcl
Created June 1, 2012 19:46
Varnish VCL to detect and redirect file uploads
backend default {
.host = "127.0.0.1";
.port = "8080";
}
backend master {
.host = "10.x.x.x";
.port = "80";
}
sub vcl_recv {
# Any uploads or restarts should go to the master backend
@fideloper
fideloper / config.app.php
Created July 18, 2012 18:26
Master-Slave database in CodeIgniter
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//Create a new config file
/*
|--------------------------------------------------------------------------
| Number of databases in use
|--------------------------------------------------------------------------
|
| Using a Master and Slave. The Slave doubles as a read-only database.
@petecoop
petecoop / compareimage.php
Last active May 16, 2023 08:53
Using PHP's GD library compares the similarity between 2 images with the same dimensions. This is based on the colour's in spread out positions and returns a rating out of 100.
<?php
function compareImages($imagePathA, $imagePathB, $accuracy){
//load base image
$bim = imagecreatefromjpeg($imagePathA);
//create comparison points
$bimX = imagesx($bim);
$bimY = imagesy($bim);
$pointsX = $accuracy*5;
$pointsY = $accuracy*5;
$sizeX = round($bimX/$pointsX);
@aderowbotham
aderowbotham / purge-ban-domain-varnish.md
Last active May 24, 2022 19:55
Purge (ban) an entire domain in Varnish Cache 3

How to purge ('ban') an entire domain in Varnish Cache 3

#####EDIT: NB Ban is technically different from Purge. Banned objects remain in memory but banning is faster than purging. Read the Varnish 3 documentation here and here.

Purge may be a more appropriate action for your use-case; although the examples in the gist below work, it's not necessarily the best way of doing this.


@juampynr
juampynr / mymodule.info
Last active June 9, 2023 21:53
Drupal 7 Views 3 custom field handler
dependencies[] = ctools
; Views Handlers
files[] = views/mymodule_handler_handlername.inc
@fabarea
fabarea / FeatureContext.php
Created July 18, 2013 11:42
Behat - step for browsing all pages of site map
<?php
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
@kevin-smets
kevin-smets / iterm2-solarized.md
Last active June 24, 2024 19:36
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@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) {
@jemond
jemond / example.drush.inc
Last active February 27, 2023 18:45
A custom Drush command to make your Drupal site ready for local development: http://www.thirdandgrove.com/blog/2013/08/custom-drush-command.html
<?php
/**
* @file
* Custom Drush integration.
*/
/**
* Implements hook_drush_command().
*
* @return