Skip to content

Instantly share code, notes, and snippets.

View orende's full-sized avatar

orende orende

View GitHub Profile
@orende
orende / service-and-test.js
Last active February 4, 2016 08:23
Example Angular.js unit test for services
//services.js
angular.module('tutorialApp.services', [])
.factory('MyService', ['MyOtherService', function(MyOtherService) {
return {
doWork: function() {
return MyOtherService.doWork();
}
}
}])
.factory('MyOtherService', [function() {
@orende
orende / controller-and-test.js
Last active February 4, 2016 08:20
Example angular.js unit test for controllers
//controller.js
describe('tutorialApp controllers', function() {
beforeEach(module('tutorialApp.controllers'));
describe('TutorialCtrl', function(){
var scope, ctrl;
beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
scope = $rootScope.$new();
@orende
orende / exempel1.kt
Created September 8, 2017 06:59
kotlin-artikel-2.1
val myString: String = null //Error: Null can not be a value of a non-null type String
@orende
orende / exempel2.kt
Created September 8, 2017 07:11
Kotlin arttikel 2.2
val myString: String? = null
val myString: String? = null
println(myString.length) //Error: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
val myString: String? = null
val length = myString?.length
println("Length of myString: $length")
if (person != null && person.getPersonId() != null && person.getPersonId().getId() != null && person.getPersonId().getId().getIntValue() != null) {
} else {
return null;
}
return person.?getPersonId().?getId().?getIntvalue()
String myString = null;
int length = myString != null ? myString.length() : 0;
System.out.println("Length of myString: " + length);
var myString: String? = null
val length = myString?.length ?: 0
println("Length of myString: $length")