Skip to content

Instantly share code, notes, and snippets.

// Intercepting HTTP calls with AngularJS.
angular.module('MyApp', [])
.config(function ($provide, $httpProvider) {
// Intercept http calls.
$provide.factory('MyHttpInterceptor', function ($q) {
return {
// On request success
request: function (config) {
// console.log(config); // Contains the data about the request before it is sent.
var mongoose = require('mongoose');
var repository = function (modelName) {
var self = this;
self.Model = require('../models/' + modelName);
self.FindById = function (id, cb) {
self.FindOne({
@xgrommx
xgrommx / Readme.md
Created December 25, 2013 11:00 — forked from maxpert/Readme.md

Javascript #router. Features:

  • Just 70 lines of code.
  • Router scope can be bound to any object (default window); just change first parameter
  • Triggers custom DOM (Level 2) events on window.document.
  • IE 9+, FF, and Webkit based browsers [Tested only in Chrome and FF].
@echo off
SET st2Path=C:\Program Files\Sublime Text 2\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
package com.SimplyTrackable.logviewer.utils
import scala.concurrent.Future
import rx.Observable
import rx.Observer
import scala.concurrent.Promise
import scala.collection.generic.CanBuildFrom
import scala.concurrent.ExecutionContext
object ObservableExtensions {
function when(x) {
return function () {
for (var i in arguments) {
var result = arguments[i](x);
if (result !== false) {
return result;
}
}
throw "No patterns matched when(" + x + ")";
};
myApp = angular.module 'myApp', []
myApp.service 'FlashMessage', ($rootScope) ->
Flash = () ->
$rootScope.flashes = []
$rootScope.$on '$routeChangeSuccess', () ->
$rootScope.$broadcast 'FlashMessage:reset', $rootScope.flashes = []
return
<!doctype html>
<html ng-app="Demo" ng-controller="AppController">
<head>
<meta charset="utf-8" />
<title>
Lazy Loading Images With AngularJS
</title>
<style type="text/css">
/**
* Decorator to add 'transform' and 'transformError' methods to promises.
* These can manipulate the result without catching errors so the 'then'
* functions will still work as expected.
*/
$provide.decorator('$q', function($delegate) {
var defer = $delegate.defer;
$delegate.defer = function() {
var deferred = defer();
deferred.promise.transform = function(fn) {
@xgrommx
xgrommx / pso.js
Created February 25, 2014 09:23 — forked from adrianseeley/pso.js
// based on http://msdn.microsoft.com/en-us/magazine/hh335067.aspx
// usage example at bottom
function pso (number_of_dimensions, function_to_optimize, number_of_particles, number_of_iterations, fitness_threshold, inertia_weight, cognitive_weight, social_weight) {
var particles = [];
var swarm_best_position = [];
var swarm_best_fitness = null;
for (var p = 0; p < number_of_particles; p++) {
particles.push({
particle_position: [],