Skip to content

Instantly share code, notes, and snippets.

@howardr
howardr / EventManager.js
Created May 27, 2009 14:36
EventManager v1.0.1, an easy custom event manager for javascript
/* EventManager, v1.0.1
*
* Copyright (c) 2009, Howard Rauscher
* Licensed under the MIT License
*/
(function() {
function EventManager() {
this._listeners = {};
@RedBeard0531
RedBeard0531 / functions.js
Created February 22, 2012 20:13
Min, Max, Sum, Count, Avg, and Std deviation using MongoDB MapReduce
// derived from http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm
function map() {
emit(1, // Or put a GROUP BY key here
{sum: this.value, // the field you want stats for
min: this.value,
max: this.value,
count:1,
diff: 0, // M2,n: sum((val-mean)^2)
});
@Mithrandir0x
Mithrandir0x / gist:3639232
Created September 5, 2012 16:15
Difference between Service, Factory and Provider in AngularJS
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@tbeseda
tbeseda / isMobile.js
Last active December 11, 2015 10:48
// Simple method to detect a mobile device
function isMobile(){
return (/iphone|ipod|android|blackberry/).test(navigator.userAgent.toLowerCase());
}
// Example usage:
if(isMobile()){
console.log('This is a mobile device.');
} else {
console.log('This is not a mobile device');
@raix
raix / debugRendered.js
Created May 17, 2013 13:10
Debuggin template rendering in Meteor. I had a template problem when creating a spreatsheet like app - optimizing usage of templates and dependenies is important when going mobile. I created this snippet of code to repport in on Template rendering.
var renderList = [];
var timer = 0;
var timeToLog = 100;
function debugRendered(templateName) {
// init renderList
renderList[templateName] = 0;
@cheeaun
cheeaun / image-processing-services.md
Last active March 3, 2025 01:50
3rd-party image processing/manipulation/upscaling/enlarging services
@hiddentao
hiddentao / gist:7300694
Last active January 22, 2019 05:04
An improvement on the angular.module() API, making it easier to split up modules into multiple files without having to worry about only registering them once.
/**
* Workaround to make defining and retrieving angular modules easier and more intuitive.
*/
(function(angular) {
var origMethod = angular.module;
var alreadyRegistered = {};
/**
@joakimbeng
joakimbeng / router.html
Last active March 15, 2024 06:18
A really simple Javascript router
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Building a router</title>
<script>
// Put John's template engine code here...
(function () {
// A hash to store our routes:

Owin Authentication with Web API 2

Using Microsoft.Owin.Security along with .NET Web API 2 for authentication on Single Page Applications.

My example is split up into 2 different projects, API which is WebAPI2 project and MyProj which is a basic MVC that contains primarily only JavaScript/CSS/etc and the startup classes.

API > AccountController.cs

namespace API

{

@maxbates
maxbates / angular-dynamic-scriptUrl.js
Last active August 29, 2015 13:57
Override the angular script directive (used for templates) with this if you need to use dynamic (e.g. interpolated or put through angular function) URLs in dynamically loaded content
angular.module('myApp')
.run(function ($rootScope) {
$rootScope.mixin = function(urls) {
if (angular.isUndefined(urls) || urls == '') {
return $q.when('no mixin url');
}
var deferred = $q.defer();