Skip to content

Instantly share code, notes, and snippets.

View Gwash3189's full-sized avatar

Adam Beck Gwash3189

View GitHub Profile
@Gwash3189
Gwash3189 / FileExtension.js
Created August 9, 2013 02:05
Validating File Extensions with JavaScript
/**
* Checks through a list of fileURI's and compares the
* file extensions of those fileURI's to the acceptedPhotoTypes
* @param files array of objects with a source property, this property is the fileURI location of the photo
* @param acceptedTypes an array of accepted photo types. EG '.jpeg'
* @returns {boolean}
*/
function validateFileExtensions(files, acceptedTypes) {
var passed = false;
@Gwash3189
Gwash3189 / Person.js
Last active December 25, 2015 03:59
Prototypical inheritance in NodeJs
function Person(name){
this.name = name;
}
module.exports = Person;
@Gwash3189
Gwash3189 / app.js
Created October 22, 2013 11:26
Header bar directive for angular js 1.0.7. Takes the route and uses it as a heading. Also takes a persons name, separated by commas and then uses that as the header if available
function clean (array,deleteValue) {
for (var i = 0; i < array.length; i++) {
if (array[i] == deleteValue) {
array.splice(i, 1);
i--;
}
}
return array;
}
@Gwash3189
Gwash3189 / index.html
Last active December 30, 2015 14:09
D&D initiative & health tracker in Angular
<!DOCTYPE html>
<html>
<head>
<script src="http//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="init">
angular.module("test", [])
.controller("testCtrl", function($scope) {
$scope.value = "";
})
.directive('custSrc', function() {
return {
restrict: "A",
scope: {
value: "=custSrc"
},
@Gwash3189
Gwash3189 / mock.ts
Last active August 29, 2015 13:57
Easy mocking with Mock Generic function (Typescipt)
class Person{
private Name: string;
constructor(public Age: number, name: string){
this.Name = name;
}
Older(){
this.Age ++;
}
}
@Gwash3189
Gwash3189 / Validator.ts
Created May 8, 2014 04:19
Recursive object Validation in TS
module PowerLine {
export interface IValidatable {
Validate: (model: any, info: any) => boolean;
}
export class Validator implements IValidatable {
public Validate(info: any) {
var results = [];
for (var key in info) {
if(key !== "constructor" && typeof info[key] !== "function"){
@Gwash3189
Gwash3189 / Pagination.js
Created May 26, 2014 01:04
Pagination in JS
function getPage(page, list, amountPerPage) {
if (page > 0) {
var start = 0;
if (page !== 1) {
start = page;
start = start -1;
}
if (list.length > 0) {
return angular.copy(list).splice((start * amountPerPage), amountPerPage);
}
@Gwash3189
Gwash3189 / hoisting.js
Last active August 29, 2015 14:02
JS Hoisting
function hoist() {
for(var i = 0; i < 10 i++){
var test = "Test";
}
console.log(test);
}
function hoist2() {
var test;
@Gwash3189
Gwash3189 / Validation.js
Created July 14, 2014 07:07
FluentValidation in TypeScript
var Rule = (function () {
function Rule(property, subValidator, instance) {
this.property = property;
this.subValidator = subValidator;
this.instance = instance;
}
return Rule;
})();
var SubValidator = (function () {