Skip to content

Instantly share code, notes, and snippets.

View wshayes's full-sized avatar

William Hayes wshayes

View GitHub Profile
@wshayes
wshayes / drupal-debug
Last active December 14, 2015 17:49
Drupal Debugging Snippets
# Needs Devel Module - shows all defined variables on page
<?php
dpm( get_defined_vars() );
?>
Viewing Node Data Structures
The drush command line and/or the Devel module's Execute PHP code block can be used to display data structures. Here are sample commands for displaying a node object:
drush: drush php-eval "print print_r(node_load(12), 1)"
@wshayes
wshayes / dedup_listofdicts
Created August 2, 2013 11:34
De-duplicate python array of dicts
# the idea for this came from the brilliant people on StackOverflow
import json
import hashlib
def dedup_listofdicts(array):
"""De-dup python array of dicts datastructure by converting to ordered JSON dump,
generating a hash of the JSON string and creating a dict of the
hash id and the data structure.
"""
@wshayes
wshayes / testjsonschema.py
Created June 24, 2014 23:58
python jsonschema validation error for top-level oneOf construct
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import jsonschema
schema_json = '''
{
"$schema": "http://json-schema.org/draft-04/schema",
"oneOf": [{
@wshayes
wshayes / app.js
Created August 30, 2015 00:17
Dynamic input list in Aurelia
import {LogManager} from 'aurelia-framework';
let logger = LogManager.getLogger('testItems');
export class App {
constructor () {
this.items = ['one', 'two', 'three', 'four'];
this.items.push('');
}
addBlank(idx, event) {
@wshayes
wshayes / app.html
Created August 30, 2015 00:20
Dynamic input list in Aurelia
<template>
<h1>Testing array of inputs</h1>
<p>Want to be able to have an array of inputs that
automatically extend with a blank input at the end and
allow deletions of any of the members.</p>
<template repeat.for="item of items">
<input type="text" change.delegate="$parent.addBlank($index, $event)" value.bind="item">
<button click.delegate="$parent.removeItem($index)">X</button>
</br>
</template>
@wshayes
wshayes / checkbox.html
Created March 2, 2016 18:49
Aurelia checkbox html example for Firefox
<!-- Have to use change.delegate below due to FF vs all other browsers
issue https://gitter.im/Aurelia/Discuss?at=5639d129a530033014e41607 -->
<input class="searchcheckbox"
id="option"
type="checkbox"
name="field"
value="option"
checked.bind="value.selected"
change.delegate="updateSelectedFacetValue($parent.$index, $index, value)"
@wshayes
wshayes / Readme.md
Created March 6, 2016 17:07 — forked from peisenmann/Readme.md
hover-color Aurelia custom attribute

The important things to note in this gist are:

app.html The usage of the custom attribute hover-color is <div hover-color="special-hover-class"> where special-hover-class is simply a css class that will be applied to all hover-color elements when the given element is hovered.

hover-color.js This is the source code of the custom attribute itself, and is commented to explain what it does. Essentially, if the element is hovered, the custom attribute sends out a message to tell all other hover color elements to change. When the mouse leaves the element, a message is broadcast to tell them all to remove their class change.

@wshayes
wshayes / compositiontransaction.js
Last active March 24, 2016 11:47
Waiting for async event for custom element
import { HttpClient } from 'aurelia-fetch-client';
import { CompositionTransaction } from 'aurelia-framework';
export class YearToDateGauge {
static inject = [HttpClient, CompositionTransaction];
constructor(http, compositionTransaction) {
this.http = http;
this.compositionTransaction = compositionTransaction;
// https://github.com/aurelia/framework/issues/367

Keybase proof

I hereby claim:

  • I am wshayes on github.
  • I am whayes (https://keybase.io/whayes) on keybase.
  • I have a public key whose fingerprint is 4088 6D20 E6F1 86B5 9FA0 7AE2 A8A9 253D C0AF B64B

To claim this, I am signing this object:

@wshayes
wshayes / countries.js
Created March 23, 2017 13:54
ViewEngineHooks Aurelia example
// Here's an example from Rob Eisenberg
// filename: resources/data/countries.js
import {viewEngineHooks} from 'aurelia-templating';
let countries = [
{ abbreviation: "AF", name: "Afghanistan" },
{ abbreviation: "AL", name: "Albania" },
{ abbreviation: "DZ", name: "Algeria" },
...