Skip to content

Instantly share code, notes, and snippets.

@mrded
mrded / Cheffile
Last active December 20, 2015 21:59
Vagrant box for Ruby on Rails
#!/usr/bin/env ruby
#^syntax detection
site 'http://community.opscode.com/api/v1'
cookbook 'apt'
cookbook 'build-essential'
cookbook 'git'
cookbook 'mysql'
cookbook 'postgresql' #:github => 'express42-cookbooks/postgresql'
@mrded
mrded / drupal7-reset.sh
Last active August 19, 2018 14:39
Drush script for resetting Drupal sandbox.
#!/bin/bash
echo '✩✩✩✩ Update modules ✩✩✩✩'
drush -y up
echo '✩✩✩✩ Reinstall Drupal ✩✩✩✩'
drush -y site-install standard --account-name=admin --account-pass=admin
echo 'Disable modules'
drush -y dis dashboard overlay toolbar
@mrded
mrded / ExampleController.php
Last active December 22, 2015 01:48
Drupal 8 Controller Example
<?php
/**
* @file
* Contains \Drupal\session_test\Controller\ExampleController.
*/
namespace Drupal\example\Controller;
use Drupal\Core\ControllerInterface;
@mrded
mrded / drupal8-reset.sh
Last active December 22, 2015 16:29
Drush script for resetting Drupal 8 sandbox.
#!/bin/bash
DRUPAL_DIR='/Users/mrded/Sites/drupal8'
mysql -uroot -e'DROP DATABASE drupal8; CREATE DATABASE drupal8;'
touch ${DRUPAL_DIR}/sites/default/files/foo
sudo chmod -R 777 ${DRUPAL_DIR}/sites/default/files
rm -rf ${DRUPAL_DIR}/sites/default/files/*
#drush -y -r ${DRUPAL_DIR} site-install standard --account-name=admin --account-pass=admin --sites-subdir=default
@mrded
mrded / attachment.php
Created September 16, 2013 15:29
File attachment VIA Form API
function wj_profile_photo_upload_form() {
$form = array();
$instance = field_info_instance('profile2', 'field_photo', 'profile');
$field = field_info_field('field_photo');
$form['profile_field_photo'] = array(
'#type' => 'managed_file',
'#upload_location' => file_field_widget_uri($field, $instance),
'#upload_validators' => file_field_widget_upload_validators($field, $instance),
@mrded
mrded / email.html
Last active December 24, 2015 09:29
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- If you delete this meta tag, Half Life 3 will never be released. -->
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta property="og:title" content="*|SUBJECT|*">
<title>*|SUBJECT|*</title>
@mrded
mrded / compress_html_css.php
Created October 2, 2013 11:10
Compress HTML and CSS into combined HTML.
$html = "<html><body>...</body></html>";
$css = "a {padding: 5px;}";
$html = mimemail_compress::mimemail_compress($html, $css);
@mrded
mrded / drupal_upload_file.php
Last active December 24, 2015 11:59
Upload a file to Drupal server from an outside URL
function upload_file($path) {
// This is a PHP function to get a string representation of the image file.
$image = file_get_contents($path);
// A stream wrapper path where you want this image to reside on your file system including the desired filename.
$destination = 'public://path/to/store/this/image/name.jpg';
$file = file_save_data($image, $destination, FILE_EXISTS_REPLACE);
if (is_object($file)) { // if you get back a Drupal $file object, everything went as expected so make the status permenant
@mrded
mrded / static_cache.php
Last active December 24, 2015 13:49
Drupal: Static cache example.
<?php
function static_cache($value = NULL) {
$_value = &drupal_static(__FUNCTION__, array());
if (isset($value)) {
$_value = clone $value;
}
return $_value;
@mrded
mrded / drupal_alter.php
Last active September 18, 2019 08:50
Drupal: alter usage example
<?php
drupal_alter('foo', $x, $y);
/**
* Implements hook_foo_alter().
*/
function hook_foo_alter(&$x, &$y) {}