Skip to content

Instantly share code, notes, and snippets.

View cmcintosh's full-sized avatar
💭
Looking For Projects

Chris McIntosh cmcintosh

💭
Looking For Projects
View GitHub Profile
/**
* Sets expires and max-age for bubbled-up max-age values that are > 0.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The response event.
*
* @throws \Exception
* Thrown when \DateTime() cannot create a new date object from the
* arguments passed in.
*/
/**
* Merges max-age values (expressed in seconds), finds the lowest max-age.
*
* Ensures infinite max-age (Cache::PERMANENT) is taken into account.
*
* @param int $a
* Max age value to merge.
* @param int $b
* Max age value to merge.
*
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return Cache::mergeContexts(parent::getCacheContexts(), [
'user.roles',
'url.path',
'group'
]);
}
@cmcintosh
cmcintosh / gist:a4af632e8747f4874ad02e3d022ef9ab
Last active November 30, 2019 17:58
TempleOfDoomViewsAccess.php
<?php
/**
* @ingroup views_access_plugins
*
* @ViewsAccess(
* id = "temple_of_doom",
* title = @Translation("Temple of Doom"),
* help = @Translation("No bad guys will enter, only Dr Jones may set foot inside.")
* )
<?php
class TempleOfDoomAccessHandler {
public function isJones(AccountInterface $account) { }
public function isBadGuy(AccountInterface $account) { }
public function access(AccountINterface $account, Route $route) {

Create a good backup

Put the site in version control

Create a Github copy of the code if it doesn't already exist. Start your first commit with everything exactly the way it is before you start. If the project already has git, do perserve the git history.

Backup the files and database

Name and Date the backup. Do this before you change anything. Just in case.

void Update() {
if ( UMAAnimator == null ) {
foreach (Transform t in transform)
{
if (t.name == "UMACharacter") {
UMAAnimator = t.gameObject.GetComponent<Animator> ();
m_Animator = UMAAnimator;
m_Animator.applyRootMotion = false;
}
}
@cmcintosh
cmcintosh / Achievement Interface
Created April 28, 2017 16:00
Achievement System for Unity
interface Achievement {
int id; // Public id of this perticular achievement. used to load text.
string label; // This will be loaded and populated from the json file.
bool displayed; // Has been displayed to the user.
bool unlocked; // Has been unlocked by the user.
List<AchievementCondition> conditions[]; // A list of conditions that are required to unlock the Achievement.
void checkAcievementState();
}
@cmcintosh
cmcintosh / gist:93b156eccd73f68364f063bcd2d5165c
Created May 20, 2016 09:00
Custom AJAX Command for events
(function($, Drupal) {
/**
* Add new command for reading a event.
*/
Drupal.AjaxCommands.prototype.getEvents = function(ajax, response, status){
// Place content in current-msg div.
$('#event-msg h2').html(response.subject);
$('#event-msg p').html(response.content);
// Remove from unread list.
$('#event-' + response.mid).remove();
@cmcintosh
cmcintosh / validateEmailAjax
Created May 20, 2016 08:43
buildForm Example
$form['username'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#ajax' => [
'callback' => '::validateEmailAjax',
'event' => 'change',
],
'#suffix' => '<span class="username-available"></span>'
);