Skip to content

Instantly share code, notes, and snippets.

@jsgandalf
jsgandalf / routes.js
Created March 25, 2016 20:51
Default index routes code
'use strict';
var express = require('express');
var controller = require('./alert.controller');
var auth = require('../../auth/auth.service');
var router = express.Router();
router.get('/', auth.isAuthenticated(), controller.index);
router.get('/:id', auth.isAuthenticated(), controller.show);
@jsgandalf
jsgandalf / gist:66f9454892048fd827d3
Created March 25, 2016 20:50
Deafult controller code
var config = require('../../config/environment');
var Alert = require('./alert.model');
var EmailCampaign = require('../emailCampaign/emailCampaign.model');
var _ = require('lodash');
exports.index = function(req, res) {
Alert.find({ account: req.user.account }).exec()
.then(function(data){
return res.json(200, data);
@jsgandalf
jsgandalf / Purchase Intent Controller
Last active August 29, 2015 14:24
Paypal Rest SDK purchase authorization example
'use strict';
/*
PurchaseIntent Controller - used for paypal transactions
*/
var Q = require('q'),
config = require("../config/config");
@jsgandalf
jsgandalf / Thing.client.controller.js
Last active February 24, 2016 20:28
Asynchronous Pagination with Mongoose and Bootsrap
/* your angular controller file */
angular.module('myApp')
.controller('ThingCtrl', function ($scope, $routeParams, ThingService) {
$scope.maxSize = 20;
$scope.itemsPerPage = 50;
$scope.showView = false;
$scope.findResults = function(){
@jsgandalf
jsgandalf / MediaServie
Created October 9, 2014 20:56
AngularJS file type checker service - If you need to check against file types for image or document uploads
angular.module('myApp').service('MediaService', function($http, $upload, $q) {
//future function isDocument(file){} PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX
var isAudio = function(file){
var returnBool = true;
if (!file || file.size === 0) {
returnBool = false;
// MP3, WAV, AIF, AU, M4A
}else if( file.type !== 'audio/mpeg' &&
file.type !== 'audio/mp3 ' &&
@jsgandalf
jsgandalf / gist:416c473b9f236b6adf18
Last active August 29, 2015 14:07
Photo upload with amazon s3 nodeJS
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Photo = mongoose.model('Photo'),
_ = require('lodash'),
fs = require('fs'),
formidable = require('formidable'),
Q = require('q');
@jsgandalf
jsgandalf / custom-datepicker.html
Last active August 29, 2015 14:07
Bootstrap ui datepicker simplified
<input class="form-control custom-datepicker"
ng-model="myDate"
ng-click="opened = true"
type="text"
datepicker-popup="MM/dd/yyyy"
is-open="opened"
show-button-bar="false"
datepicker-options="{'show-button-bar': false, 'show-weeks':false}"
ng-required="true" />
@jsgandalf
jsgandalf / gist:a05a36da4616cdc48eaa
Created August 18, 2014 14:28
Angular Resource broiler plate code
'use strict';
//Leads service used for leads REST endpoint
angular.module('myApp').factory('Things', ['$resource', function($resource) {
return $resource('api/things/:thingId', {
thingId: '@_id'
}, {
update: {
method: 'PUT'
}
@jsgandalf
jsgandalf / gist:19c4e7c4405656ad5488
Last active August 29, 2015 14:05
Popup.js - angularJS service to simplify bootstrap ui modal service call
'use strict';
// General Modal Service to use for pop-ups
// Example openTemplate: Popup.openTemplate("/views/common/modal.html","","","",function(){alert('hello')});
angular.module('myApp').service('Popup', function($modal) {
//The alert function only has 1 customizable button
var alert = function(title, body, button, cb) {
var contents = {};
@jsgandalf
jsgandalf / gist:7b67762ec773d6e46562
Last active August 29, 2015 14:05
Broiler Plate Code for CRUD AngularJS Controller
'use strict';
angular.module('myApp').controller('exampleCtrl', function ($rootScope, $scope, $stateParams, $location, $http, Things, CourseService) {
$scope.create = function () {
var thing = new Things({
message: this.message
});
thing.$save(function (thing) {
$location.path('/admin');