Skip to content

Instantly share code, notes, and snippets.

@goyalrohit
goyalrohit / dataService.js
Created January 17, 2018 09:15
Angular Factory Service
(function() {
angular.module('app')
.factory('dataService', dataService);
function dataService(logger) {
return {
getAllBooks: getAllBooks,
@goyalrohit
goyalrohit / loggerService.js
Created January 17, 2018 09:17
Angular Service Function
(function() {
angular.module('app')
.service('logger', BookAppLogger);
function LoggerBase() { }
LoggerBase.prototype.output = function(message) {
console.log('LoggerBase: ' + message);
};
@goyalrohit
goyalrohit / detailService.js
Created January 17, 2018 09:18
Angular Constant Function
(function () {
angular.module('app')
.constant('constants', {
APP_TITLE: 'Book Logger',
APP_DESCRIPTION: 'Track which books you read.',
APP_VERSION: '1.0'
});
}());
@goyalrohit
goyalrohit / retrieveService.js
Created January 17, 2018 09:19
Angular Value Function
(function () {
angular.module('app')
.value('badgeService', {
retrieveBadge: retrieveBadge
});
function retrieveBadge(minutesRead) {
var badge = null;
@goyalrohit
goyalrohit / app.js
Created January 17, 2018 09:48
Angular Provider Function
(function() {
var app = angular.module('app', []);
app.config(function($provide)){
$provide.provider('books',function(){
this.$get=function(){
var appName = 'Book Logger';
class LoggingContextManager:
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
return
class LoggingContextManager:
def __enter__(self):
return "You are in a with block"
def __exit__(self, exc_type, exc_val, exc_tb):
return
class LoggingContextManager:
def __enter__(self):
print('LoggingContextManager.__enter__()')
return "You are in a with block"
def __exit__(self, exc_type, exc_val, exc_tb):
print('LoggingContextManager.__exit__({},{},{})'.format(exc_type, exc_val, exc_tb))
return
class LoggingContextManager:
def __enter__(self):
print('LoggingContextManager.__enter__()')
return "You are in a with block"
def __exit__(self, exc_type, exc_val, exc_tb):
print('LoggingContextManager.__exit__({},{},{})'.format(exc_type, exc_val, exc_tb))
return
class LoggingContextManager:
def __enter__(self):
print('LoggingContextManager.__enter__()')
return "You are in a with block"
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is None:
print('LoggingContextManager.__exit__:'
'normal exit detected.')
else: