Skip to content

Instantly share code, notes, and snippets.

View zsoldosp's full-sized avatar

Peter Zsoldos zsoldosp

View GitHub Profile
@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> ...
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)
// 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) {
@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))
@zsoldosp
zsoldosp / gist:6586803
Created September 16, 2013 21:25
re: ayende challange
def assuming_sorted_input_with_callbacks(sorted_unique_integers, callback_to_invoke_on_each_consecutive_set):
""" context:
"""
if not sorted_unique_integers:
return # empty input
curr_lo = curr_hi = sorted_unique_integers[0]
for num in sorted_unique_integers[1:]:
if curr_hi != (num - 1):
@zsoldosp
zsoldosp / elixir macros-why-error.exs
Created February 8, 2014 19:38
Different errors given for the same elixir code - different scoping between iex and elixir? If so, why?
$ elixir macros-why-error.exs
false
** (UndefinedFunctionError) undefined function: MyMacro.unless/2
MyMacro.unless(false, [do: :ok])
(elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/2
(elixir) lib/code.ex:301: Code.require_file/2
mkdir vagrant-pytest-does-not-recogniz-pytest-django-on-ubuntu-trusty64
cd vagrant-pytest-does-not-recogniz-pytest-django-on-ubuntu-trusty64
vagrant init ubuntu/trusty64
vagrant ssh
Feature: Showing off behave
Scenario: Run a simple test
Given we have behave installed
When we implement 5 tests
Then behave will test them for us!
@zsoldosp
zsoldosp / Vagrantfile
Last active August 29, 2015 14:17
Bugreport - ansible template task fails with Errno 26 when run in a ubuntu/trusty64 host via vagrant from a windows 7 x64 host
# -*- mode: ruby -*-
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision "shell", path: "bootstrap.sh"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "1024"
@zsoldosp
zsoldosp / repro.py
Last active August 29, 2015 14:17
openpyxl decimal/float formatting problem
from openpyxl.workbook import Workbook
from openpyxl.writer.excel import save_virtual_workbook, save_workbook
from openpyxl.reader.excel import load_workbook
from decimal import Decimal
import tempfile
import os
def get_filepath(name):
fh, path = tempfile.mkstemp(prefix=name, suffix='.xlsx')