Skip to content

Instantly share code, notes, and snippets.

View zsoldosp's full-sized avatar

Peter Zsoldos zsoldosp

View GitHub Profile
@explained # adding it by AOP at startup or by codegen or whatever
def transient_condition(self, user)
character = random_character
return user.first_name.start_with?(random_character), "Checking if first_name:#{user.first_name} starts with character:#{character}"
end
def explained(wrapped, *args, **kwargs):
log.info('entering %s with params %s, %s' % (wrapped.__name__, args, kwargs))
result, explanation = wrapped(*args, **kwargs)
log.info('exiting %s with params %s, %s - return value is %s because %s' % (wrapped.__name, args, kwargs, result, explanation))
// re: for http://codemanship.co.uk/parlezuml/blog/?postid=1149
// original code, called from inside the method:
Customer customer = DataRepository.GetCustomer(customerId);
// to enable the creation of the regression suite,
// I extract the implementation of DataRepository.GetCustomer into its own methpd
class DataRepository {
public static Customer GetCustomer(customerId) {
class ShouldReturnUnalteredUrl(TestCase):
def test__root_without_trailing_slash(self): self.assert_unchanged('http://www.example.com')
def test__root_with_trailing_slash(self): self.assert_unchanged('http://www.example.com/')
def test__explicit_html_page(self): self.assert_unchanged('http://www.example.com/page.html')
def test__root_with_querystring(self): self.assert_unchanged('http://www.example.com/?foo=bar')
def test__root_with_querystring_and_hash(self): self.assert_unchanged('http://www.example.com/?foo=bar#frag')
def assert_unchanged(self, url):
actual = add_query_args(url)
assert url != actual, 'expected %s, got %s' % (url, actual)
@zsoldosp
zsoldosp / UnderflowOverflowCalculationWithAnonymousClass.java
Created March 31, 2011 11:49
comment for http://jamesshore.com/Blog/Lets-Play/Episode-98.html - making calculations look nicer (sad, no lambdas in java)
package com.jamesshore.finances.domain;
// import ....
public class ValidDollars extends Dollars {
public static final double MAX_VALUE = 1000000000d; // one beeeellion dollars!
public static final double MIN_VALUE = -1000000000d;
private double amount;
// ... <snip> ...