Skip to content

Instantly share code, notes, and snippets.

View ericjgruber's full-sized avatar

Eric J. Gruber ericjgruber

  • Kansas City, MO
  • 10:19 (UTC -05:00)
View GitHub Profile
@ericjgruber
ericjgruber / Drupal-8-UUID
Last active July 24, 2017 21:08
Get a UUID in Drupal 8
/** @var \Drupal\user\Entity\User $user */
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$uuid = $user->uuid();
@ericjgruber
ericjgruber / netflix.php
Created January 31, 2017 19:46
RESTful PHP example
# Inspirational sources:
# http://netflixroulette.net/api/
# http://www.ivangabriele.com/php-how-to-use-4-methods-delete-get-post-put-in-a-restful-api-client-using-curl/
# https://github.com/toddmotto/public-apis
function netflix_getter() {
$request = 'http://netflixroulette.net/api/api.php';
json_decode($request);
@ericjgruber
ericjgruber / git-object-permission-fix.txt
Created January 12, 2016 20:20
Git object permission fix
sudo chown -R $(whoami) $(git rev-parse --show-toplevel)/.git
@ericjgruber
ericjgruber / clickbounce.js
Created November 6, 2015 04:08
Bounce a div on click
$(document).ready(function() {
$('div').click(function () {
$(this).effect('bounce', {times:3}, 500);
});
});
@ericjgruber
ericjgruber / imgdrop.js
Last active November 6, 2015 04:09
Image drop
$(document).ready(function(){
// Drop an image down from the top over one second interval
$('img').animate({ top: '+=100px'}, 1000 );
});
@ericjgruber
ericjgruber / add_class_d7
Created July 14, 2015 15:37
Add a class to every page in Drupal 7
/**
* Implements hook_preprocess_htm().
*/
function THEME_preprocess_html(&$variables) {
$path = drupal_get_path_alias();
$aliases = explode('/', $path);
foreach($aliases as $alias) {
$variables['classes_array'][] = 'page-alias-' . drupal_clean_css_identifier($alias);
}
}
@ericjgruber
ericjgruber / Viewport metatag
Created July 2, 2015 13:51
Viewport metatag
/**
* Implements hook_preprocess_htm().
*/
function HOOK_preprocess_html(&$variables) {
$viewport = array(
'#tag' => 'meta',
'#attributes' => array(
'name' => 'viewport',
'content' => 'width=device-width, initial-scale=1, maximum-scale=1'));
drupal_add_html_head($viewport, 'viewport');
/* As seen at http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/ */
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
@ericjgruber
ericjgruber / 0_reuse_code.js
Last active August 29, 2015 14:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console