Skip to content

Instantly share code, notes, and snippets.

View chasingmaxwell's full-sized avatar
🤘

Peter Sieg chasingmaxwell

🤘
View GitHub Profile
@chasingmaxwell
chasingmaxwell / Drupal7_html5_required.php
Last active September 19, 2017 08:28
Drupal 7: Add HTML5 required attribute to all form elements with '#required' => TRUE.
<?php
/**
* This goes in YOUR_MODULE.module file.
*/
function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {
// Always add the html5 required attribute for required elements.
_YOUR_MODULE_html5_required($form);
}
@chasingmaxwell
chasingmaxwell / makeItFun.js
Last active December 28, 2015 06:59
Bookmarklet that makes reading the news more fun a la http://xkcd.com/1288/. Instructions: Simply copy/paste the code in makeItFunBookmarklet.js into a bookmark in your browser (as the URL), open a news article, and click the bookmark. Yay!
(function() {
'use strict';
var body = document.getElementsByTagName('body')[0].innerHTML,
map = [
[/\bwitnesses\b/g, "these dudes I know"],
[/\bWitnesses\b/g, "These dudes I know"],
[/\ballegedly\b/g, "kinda probably"],
[/\bAllegedly\b/g, "Kinda probably"],
[/\bnew study\b/g, "tumblr post"],
@chasingmaxwell
chasingmaxwell / string_matches_pattern.php
Last active December 29, 2015 11:39
Check that a string matches a pattern in PHP (similar to the html5 pattern attribute). Useful for fallback server-side validation of textfield inputs when the textfield is validated client-side with the html5 pattern attribute.
<?php
/**
* HEADS UP! ---> turns out there is a better way to solve this problem.
* Use ^ and $ to signify the beginning and end in your regex pattern and
* then use preg_match(). It will get you the same result and faster! :)
*/
/**
* Check that a string matches a pattern in PHP (similar to the html5 pattern
@chasingmaxwell
chasingmaxwell / vagrant-anywhere
Created March 11, 2014 16:34
Run the vagrant command for a particular project from anywhere
#!/bin/sh
# Run the vagrant command for a particular project from anywhere.
#
# To use:
# 1. Put this file in ~/bin/ or some other executable path (also make sure the
# file is executable).
# 2. Insert the path to the directory containing your project's Vagrantfile
# where indicated below.
# 3. Rename this file to match the project you're using it for.
@chasingmaxwell
chasingmaxwell / jQueryLatest.js
Created May 13, 2014 20:55
Run latest version of jQuery from console.
/**
* If you're working on a project that doesn't have jQuery or is using an old
* version, you can take advantage of the latest jQuery for debugging and
* troubleshooting from he console!
*
* Enter the following code into the console following the instructions in the
* comments. Once you're done, you should be able to use $l alongside
* any version of jQuery that already exists.
*
* I put this together with help from these posts:
@chasingmaxwell
chasingmaxwell / ajaxInProgress.js
Created July 16, 2014 18:05
Determine whether there is an ajax request in progress managed by Drupal.ajax
(function(){
// Determine if any ajax call is currently in progress.
Drupal.ajaxInProgress = function() {
for (var id in Drupal.ajax) {
if (Drupal.ajax[id].ajaxing === true) {
return true;
}
}
return false;
@chasingmaxwell
chasingmaxwell / test--template.tpl.php
Last active August 29, 2015 14:10
test--template.tpl.php
<?php
/**
* @file
* Test file for phpcs.
*/
?>
<?php if (!empty($actions)): ?>

Keybase proof

I hereby claim:

  • I am chasingmaxwell on github.
  • I am peter4k (https://keybase.io/peter4k) on keybase.
  • I have a public key ASALMLzieyX9HEH2rcYNDl8BfWTcCSpYPHRj7Cm-1k1a0wo

To claim this, I am signing this object:

@chasingmaxwell
chasingmaxwell / lambda-duration
Last active March 10, 2022 03:50
AWS CloudWatch Insight Queries
filter @type = "REPORT"
| stats
avg(@billedDuration) as Average,
percentile(@billedDuration, 99) as NinetyNinth,
percentile(@billedDuration, 95) as NinetyFifth,
percentile(@billedDuration, 90) as Ninetieth
by bin(30m)

Keybase proof

I hereby claim:

  • I am chasingmaxwell on github.
  • I am chasingmaxwell (https://keybase.io/chasingmaxwell) on keybase.
  • I have a public key ASDl1c23JXkhGJWAgdOl3278WFaTeBATR0O7MvtzTKDrzAo

To claim this, I am signing this object: