Skip to content

Instantly share code, notes, and snippets.

@tastywheat
tastywheat / taskQueue.js
Last active December 28, 2015 00:29
process n number of async functions in order. used when promises aren't viable e.g. cross file or service calls.
//process n number of async functions in order. used when promises aren't viable e.g. cross file or service calls.
var TaskQueue = function(){
var queue = [],
isProcessingQueue = false,
commonState = { task: 0 };
function add(fn){
queue.push(fn);
@tastywheat
tastywheat / AngularExtendedDirective.js
Last active December 28, 2015 03:38
extending an angular directive
.directive('smelly', function(){
return {
restrict: 'E',
controller: function(){
this.doWork = function(){
alert('smelly work');
};
},
link: function($scope, $element, $attributes, controller){
$element.bind('click',function(){
@tastywheat
tastywheat / AngularProviderExample.html
Last active December 28, 2015 03:39
angular provider
<html ng-app="mymodule">
<head></head>
<body ng-controller="AppController">
</body>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.min.js"></script>
<script>
//http://stackoverflow.com/questions/15666048/angular-js-service-vs-provider-vs-factory
angular.module( 'mymodule', [])
@tastywheat
tastywheat / AngularTranscludeExample.js
Last active December 28, 2015 05:59
angular transclude
.directive('stinky', function(){
return {
transclude: true,
template: "<div>hello <span ng-transclude></span></div>",
link: function($scope, $element, $attributes, $compile){
}
};
})
@tastywheat
tastywheat / HTML5CanvasDrawingExample.js
Last active December 28, 2015 06:09
html5 canvas drawing
var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
var started = false;
var crayonTextureImage = new Image();
function init () {
canvas.addEventListener('mousemove', mousemove, false);
canvas.addEventListener('mousedown', mousedown, false);
canvas.addEventListener('mouseup', mouseup, false);
crayonTextureImage.src = "Penguins.jpg";
@tastywheat
tastywheat / CSSStarRatingExample.html
Last active December 28, 2015 06:09
css star rating
<style>
.rating {
unicode-bidi: bidi-override;
direction: rtl;
}
.rating > span {
display: inline-block;
position: relative;
width: 1.1em;
}
@tastywheat
tastywheat / NodejsExpressWebserver.js
Created November 13, 2013 20:06
nodejs express webserver
var express = require('express');
var app = express();
var oneDay = 0;//86400000;
app.configure(function(){
app.use(express.compress());
app.use(express.static(__dirname + '/public', { maxAge: oneDay }));
app.use(express.bodyParser());
app.use(express.cookieParser('some secret'));
});
@tastywheat
tastywheat / NodejsReverseProxy.js
Created November 13, 2013 20:21
nodejs reverse proxy
var httpProxy = require('http-proxy');
var options = {
pathnameOnly: true,
// this list is processed from top to bottom, so '.*' will go to
// '127.0.0.1:3000' if the Host header hasn't previously matched
router : {
'/api': '127.0.0.1:4271',
//'': '127.0.0.1:3002',
//'^.*\.sample\.com': '127.0.0.1:3002',
@tastywheat
tastywheat / CallControllerMethodViaDirectiveAttribute.js
Last active December 28, 2015 06:19
angular - call controller method via directive attribute
.controller( 'AboutCtrl', function AboutCtrl( $scope ) {
$scope.doWork = function(){
alert('working');
};
})
.directive('stinky', function(){
return {
link: function($scope, $element, $attributes, $compile){
$element.bind("click", function(){
$scope.$apply($attributes.stinky);
@tastywheat
tastywheat / ddd.js
Last active December 28, 2015 12:19
ddd example
/*
High level directory structure
root/
application/ (configuration)
domain/ (business logic)
Entities/ (User, Article, Image, Video)
Aggregates/ (UserProfile, UserHistory)
ValueObjects/
dataAccess/ (repositories for data retrieval/persistance)