Skip to content

Instantly share code, notes, and snippets.

View tomasmalmsten's full-sized avatar

Tomas Malmsten tomasmalmsten

View GitHub Profile
@tomasmalmsten
tomasmalmsten / CleanCodeFunctionsFour.java
Created April 22, 2018 10:58
Clean Code - Functions snippet four
public int compareTo(final Object _other) throws ClassCastException, NullPointerException {
final ExampleClass otherExampleClass= (ExampleClass) _other;
return compareThisTo( otherExampleClass);
}
private int compareThisTo(final ExampleClass _otherExampleClass) {
if(equals(_otherExampleClass)) {
return 0;
}
return compareCreatedDates(_otherExampleClass);
@tomasmalmsten
tomasmalmsten / CleanCodeFunctionsThree.java
Created April 22, 2018 10:57
Clean Code - Functions snippet three
private int compareMeTo(final ExampleClass _otherExampleClass) {
if(equals(_otherExampleClass)) {
return 0;
}
return compareCreatedDates(_otherExampleClass);
}
@tomasmalmsten
tomasmalmsten / CleanCodeFunctionsTwo.java
Created April 22, 2018 10:55
Clean Code - Functions snippet two
public int compareTo(Object _other) throws ClassCastException, NullPointerException {
final ExampleClass otherExampleClass = (ExampleClass) _other;
return compareMeTo(otherExampleClass);
}
@tomasmalmsten
tomasmalmsten / CleanCodeFunctionsOne.java
Last active April 22, 2018 10:56
Clean Code - Functions snippet one
public int compareTo(final Object _other) throws ClassCastException, NullPointerException {
final ExampleClass otherExampleClass = (ExampleClass) _other;
if(equals(otherExampleClass)) {
return 0;
}
if(getCreatedDate() == null) {
if(otherExampleClass.getCreatedDate() == null) {
return 0;
}
return -1;
Verifying I am +tomasmalmsten on my passcard. https://onename.com/tomasmalmsten
@tomasmalmsten
tomasmalmsten / StringMatchesUUIDPattern
Created December 10, 2014 15:15
A hamcrest matcher verifying that a string matches the pattern of a UUID
package com.tomasmalmsten.matchers
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
public class StringMatchesUUIDPattern extends TypeSafeMatcher<String> {
private static final String UUID_REGEX = "[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}";
@tomasmalmsten
tomasmalmsten / keybase.md
Created October 14, 2014 19:14
keybase.md

Keybase proof

I hereby claim:

  • I am tomasmalmsten on github.
  • I am tomasmalmsten (https://keybase.io/tomasmalmsten) on keybase.
  • I have a public key whose fingerprint is 41EF A6F5 5D73 D9D8 1897 E2C1 A8C6 D01F D8E0 4E2B

To claim this, I am signing this object:

@tomasmalmsten
tomasmalmsten / gist:8537309
Created January 21, 2014 09:54
First simple test for Angular application
test('Simple controller test', function() {
ok(scope.nodes.length == 2);
});
@tomasmalmsten
tomasmalmsten / gist:8536986
Created January 21, 2014 09:26
The js/controller.js which will make the first test pass
'use strict';
var freecycleApp = angular.module('freecycleApp', []);
freecycleApp.controller("NodeController", function($scope) {
$scope.nodes = [
{'id': '1122-33-44', 'name': 'MacBook Pro 13" 2010'},
{'id': '4433-2233-454ff', 'name': 'MacBook 13" White'}
];
});
@tomasmalmsten
tomasmalmsten / gist:8536860
Last active January 3, 2016 23:39
Setup of QUnit for Angular application
'use strict';
var injector, ctrl, scope;
module('tests', {
setup: function() {
var appModule = angular.module('freecycleApp');
injector = angular.injector(['ng', 'freecycleApp']);
scope = injector.get('$rootScope').$new();
ctrl = injector.get('$controller')