Skip to content

Instantly share code, notes, and snippets.

@OzieWest
OzieWest / delay.js
Created July 2, 2014 11:42
Delayed function, throttle
Function.prototype.delayed = function (delay) {
var timer = 0;
var callback = this;
return function() {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
};
document.getElementById('search').addEventListener('keyup',search.delayed(200));
@OzieWest
OzieWest / zone.example.js
Created July 7, 2014 11:59
zone.example.js
var fn1 = function () {
console.log('f1');
var c = 1 + b;
};
var fn2 = function () {
console.log('f2');
setTimeout(fn1, 100);
//fn1();
};
@OzieWest
OzieWest / angular-icheck.js
Created July 18, 2014 06:15
Integration of Angular and JQuery.iCheck
webApp.directive('icheck', function($timeout, $parse) {
return {
require: 'ngModel',
link: function($scope, element, $attrs, ngModel) {
return $timeout(function() {
var value;
value = $attrs['value'];
$scope.$watch($attrs['ngModel'], function(newValue){
$(element).iCheck('update');
@OzieWest
OzieWest / inheritance.js
Created July 31, 2014 10:32
Basic Inheritance with JavaScript Constructors
// base class
function SuperHuman (name, superPower) {
this.name = name;
this.superPower = superPower;
}
SuperHuman.prototype.usePower = function () {
console.log(this.superPower + "!");
};
@OzieWest
OzieWest / singleton.ts
Created August 8, 2014 06:49
[typescript] singleton example
module PATTERN {
export class SingletonClass {
private message: string;
private static _instance:SingletonClass = null;
constructor() {
if(SingletonClass._instance) {
throw console.log('Error: Instantiation failed');
}
@OzieWest
OzieWest / typescript-iterator.ts
Last active August 29, 2015 14:05
[typescript] iterator example
class Iterator<T> {
private count: number = 0;
constructor(private lists: Array<T> = null) {}
hasNext(): boolean {
if(this.count < this.lists.length) {
return true;
}
return false;
@OzieWest
OzieWest / typescript-decorator.ts
Created August 8, 2014 07:09
[typescript] decorator example
module PATTERN {
export interface Precure {
getTitle(): string;
}
export class SweetPrecure implements Precure {
getTitle(): string {
return 'title1';
}
@OzieWest
OzieWest / typescript-factory-method.ts
Created August 8, 2014 07:11
[typescript] factory-method example
module PATTERN {
export class AbstractCreator {
constructor(private name: string) {}
create(): WindInstrumentProduct {
var product: WindInstrumentProduct = this.createInstrument();
this.mark(product);
@OzieWest
OzieWest / angular-token.js
Created October 28, 2014 13:25
angularjs-token-example
appServices.factory('TokenInterceptor', function ($q, $window, $location, AuthenticationService) {
return {
request: function (config) {
config.headers = config.headers || {};
if ($window.sessionStorage.token) {
config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
}
return config;
},
@OzieWest
OzieWest / negate.js
Created January 26, 2015 12:19
Negating Predicate Functions in JavaScript
function negate (predicateFunc) {
return function () {
return !predicateFunc.apply(this, arguments);
};
}
function isSuperStrong (character) {
return character.strength === "Super";
}