Skip to content

Instantly share code, notes, and snippets.

View Gwash3189's full-sized avatar

Adam Beck Gwash3189

View GitHub Profile
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 () {
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Immutable = (function () {
function Immutable() {
this.objectString = "object";
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script>
window.xinj = function(obj) {
debugger;
@Gwash3189
Gwash3189 / countGroupings.fs
Last active August 29, 2015 14:06
Count occurrences of the starting character in a sequence.
let createGroupings lineSeq =
lineSeq |> Seq.map (fun element -> element.[0])
|> Seq.countBy id
|> Seq.toList
let list = ["asd"; "dsa"]
createGroupings list
@Gwash3189
Gwash3189 / bus.js
Created October 6, 2014 05:35
Event / Subscribable bus system with Ko Subscribables.
window.Bus = function(name, funcs, parent) {
funcs = funcs instanceof Array === true ? funcs : [funcs];
var bus = {};
var sub = new ko.subscribable();
var functionType = "function";
bus.name = name;
bus.children = [];
bus.previousMessages = [];
bus.extend = function(name, funcs) {
var childBus = window.Bus(name, funcs, bus);