Skip to content

Instantly share code, notes, and snippets.

View newmanbrad's full-sized avatar

Brad Newman newmanbrad

View GitHub Profile
<script>
window.ondevicemotion = function(event) {
if (navigator.platform.indexOf("This device is an iPad") != -1) {
var version = 1;
if (event.acceleration) version += window.devicePixelRatio;
document.getElementById('info').innerHTML = version;
}
window.ondevicemotion = null;
}
</script>
{% extends "base.html" %}
{% load i18n %}
{% block link %}
<script data-require="angular.js@1.2.0-rc3" data-semver="1.2.0-rc3-nonmin" src="http://code.angularjs.org/1.2.0-rc.3/angular.js"></script>
<script src="http://code.angularjs.org/1.2.0-rc.3/angular-sanitize.min.js"></script>
<script src="/angular/myApp.js"></script>
{% endblock link %}
{% block content %}
@newmanbrad
newmanbrad / fixed_verbatim!
Last active August 29, 2015 14:01
fixed_verbatim
{% extends "base.html" %}
{% load i18n %}
{% block link %}
<script data-require="angular.js@1.2.0-rc3" data-semver="1.2.0-rc3-nonmin" src="http://code.angularjs.org/1.2.0-rc.3/angular.js"></script>
<script src="http://code.angularjs.org/1.2.0-rc.3/angular-sanitize.min.js"></script>
<script src="/angular/myApp.js"></script>
{% endblock link %}
{% block content %}
@newmanbrad
newmanbrad / ionicUbuntu
Last active August 29, 2015 14:05
Install Ionic Virtualbox (Ubuntu 14.04)
// Instructions for setting up IONIC on Ubuntu non-numbered step are needed for use of Virtual Box only!
// Revised: 08/22/2014
// Revisor: Brad Newman
// To create your mounted folder:
sharename="whatever.you.want.to.call.it";
sudo mkdir /mnt/$sharename
sudo chmod 777 /mnt/$sharename
sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename
@newmanbrad
newmanbrad / helpfulStuff.js
Last active November 20, 2015 18:43
Sum All Numbers in a Range
function sumAll(arr) {
var sum = 0;
var maxNum = Math.max.apply(null, arr);
var minNum = Math.min.apply(null, arr);
console.log(maxNum);
console.log(minNum);
for(var i = minNum; i <= maxNum; i++){
@newmanbrad
newmanbrad / observableArray.js
Created November 23, 2015 15:47
Custom Observable Array
function ObservableArray(items) {
var _self = this,
_array = [],
_handlers = {
itemadded: [],
itemremoved: [],
itemset: []
};
function defineIndexProperty(index) {
@newmanbrad
newmanbrad / typeAnnotation.ts
Created August 10, 2016 16:43
Typescript: Type Annotation Example
/**
* Example: Type Annotation
*
* Type annotations remove the need for the compiler to infer the type.
*
* Available Types:
* Boolean: simple true/false value
* Number: floating point values
* String: textual data
@newmanbrad
newmanbrad / componentActionExample.ts
Last active September 22, 2016 15:50
Example code showing an NG2 component interacting with Redux.
/***
* Actions Example
*
* Here you can see "addClient" method dispatching a change to the
* Reducers in order the record the new state change.
***/
@Injectable()
export class ClientActions {
constructor(
@newmanbrad
newmanbrad / deepFreezeObject.js
Created December 1, 2016 13:20
Deep Freeze Object Javascript
// Object.freeze() will not freeze nested objects. The function below
// will freeze all nested objects for immutability.
let isObject = (val) => val && typeof val === 'object';
function deepFreezeObject(obj) {
if(isObject(obj) && !Object.isFrozen(obj)){
// Recusively call until all child objects are frozen
Object.keys(obj).forEach(name => deepFreezeObject(obj[name]));
Object.freeze(obj);
}
@newmanbrad
newmanbrad / higherOrderFunctionExample.js
Created December 1, 2016 14:02
Higher Order Function Example
// Because the applyOperation function accepts a function as an argument, it is
// considered a higher order function.
function applyOperation(a, b, opt) {
return opt(a, b);
}
let multiplier = (a, b) => a * b;
applyOperation(2, 3, mulptiplier); // 6