Skip to content

Instantly share code, notes, and snippets.

View davismj's full-sized avatar
🎓
Computing normal vectors.

Matthew James Davis davismj

🎓
Computing normal vectors.
View GitHub Profile
@davismj
davismj / gist:c09e8c3ddd8c9864941d
Last active October 4, 2015 05:34
Demonstration of ES2016 await keyword
var val = await new Promise((res, rej) => {
res('something')
});
// val === 'something'
// this is equivalent to
var val;
new Promise((res, rej) => {
res('something');
import {inject} from 'aurelia-framework';
import $ from 'jQuery'; // i'm not sure about this line, check the jquery site or stack overflow. $ should be defined.
import 'materialize-css'; // this will load the materialize library
@inject(Element)
export class CollapsibleCustomAttribute {
private element;
constructor(element) {
this.element = $(element);
import { inject, Aurelia, View } from 'aurelia-framework';
@inject(Aurelia, Element)
export class DFCustomElement {
constructor(aurelia, element) {
this.container = aurelia.container;
this.element = element;
}
@davismj
davismj / spread-example.js
Created January 25, 2017 08:58
Spread example.
a = [1,2,3] // [1, 2, 3]
b = [4,5] // [4, 5]
c = a.slice() // [1, 2, 3]
c.push(b) // 4
JSON.stringify(c) // "[1,2,3,[4,5]]"
JSON.stringify([...a, ...b]) // "[1,2,3,4,5]"
<template>
<nav class="sidebar ${isOpen ? 'open' : 'closed'}">
<button click.delegate="toggle()">
hamburger
</button>
</nav>
<main class="main"></main>
</template>
import { inject } from 'aurelia-framework';
@inject(Element)
export class CustomDroppableCustomAttribute {
constructor(Element) {
this.element = Element;
}
attached() {
@davismj
davismj / ex1.html
Last active March 22, 2017 10:38
Two more methods of tightly coupled component communication
<template>
<!-- For this specific case, I recommend using a parent css selector. It has nothing to
do with Aurelia, mostly, but it's clean and performant. The isDropping property is set
through the drag event handlers on the row, similar to what you described with
isHoveringSection -->
<style>
dropzone {
display: none;
}
import { inject } from 'aurelia-framework';
import { HttpClient, json } from 'aurelia-http-client';
// Let's build a very basic service to interface with our Places WebApi project.
@inject(HttpClient)
export class PlaceService {
http;
<template>
<div>Book: ${MediaType['Book']}</div>
</template>
@davismj
davismj / get_text_from_file.py
Created February 29, 2016 02:50
get_text_from_file
def get_text_from_file(file_path):
value = None
try:
with open(file_path, mode='r') as file:
value = file.read()
except UnicodeDecodeError:
try:
with open(file_path, mode='rb') as file:
value = file.read()
except: