Skip to content

Instantly share code, notes, and snippets.

View andrzejkrzywda's full-sized avatar

Andrzej Krzywda andrzejkrzywda

View GitHub Profile
def get_file_from_disk(self):
first_time = False
if not os.path.exists(CONFIG_DIR):
os.mkdir(CONFIG_DIR)
first_time = True
if not os.path.exists(DIARY_FILE):
file = open(DIARY_FILE, 'w')
file.close()
first_time = True
@andrzejkrzywda
andrzejkrzywda / gist:974275
Created May 16, 2011 11:30
cucumber vs bbq
Scenario: Artist creates an art work
Given I am a registered artist
And I follow the add new artwork link from the dashboard
When I fill the form with the artwork data
And I upload a picture
Then I should see a confirmation message telling me that the artwork was added to my collection
scenario "artist creates an art work" do
artist = TestUser.new
artist.go_to_new_artwork_page
@andrzejkrzywda
andrzejkrzywda / object_key_test.rb
Created July 14, 2011 09:53 — forked from paneq/test.rb
Which version do you prefere?
require 'test/unit'
class KeyTest < Test::Unit::TestCase
def test_key
object = Object.new
assert_equal(:submit, object_key(object))
def object.persisted?; true end
assert_equal(:update, object_key(object))
class Monopoly
constructor: (serverSide, popupsManager) ->
player = new Player(PlayerAttributes)
playerView = new PlayerView
playerController = new PlayerController(player, playerView)
(..)
class PlayerView
update: (player) ->
$("#player_score").text(player.points)
@andrzejkrzywda
andrzejkrzywda / Plea.markdown
Created June 22, 2012 21:19 — forked from justinko/Plea.markdown
Am I doing it wrong?

Here is my solution, based on use-cases and AOP.

  1. you need to separate persistence from your domain
  2. you need to have a proper use-case, not a single request-class, like above.
  3. notifications are notifications (twitter, fb), they are implemented with AOP
  4. spam detection and language detection are separated (discussable) with an aspect.
  5. there is an "app" object that wraps it all together.

The first file is the original example. The second file is mine.

@andrzejkrzywda
andrzejkrzywda / gist:3362567
Created August 15, 2012 18:57
difference in LOC between .coffee files and the generated JS files
pipboy:todomvc-coffee-boxed andrzej$ wc -l src/*
29 src/local_storage.coffee
17 src/todo_app.coffee
77 src/todo_gui.coffee
44 src/todo_use_case.coffee
27 src/utils.coffee
28 src/web_glue.coffee
222 total
pipboy:todomvc-coffee-boxed andrzej$ wc -l release/toaster/*
68 release/toaster/local_storage.js
@andrzejkrzywda
andrzejkrzywda / app.coffee
Created March 2, 2013 11:22
Hexagonaljs TodoMVC example
class WebTodoApp
constructor: ->
useCase = new CompleteTasksUseCase()
window.useCase = useCase
gui = new WebGui()
localStorage = new LocalStorage("todo_app")
glue = new WebGlue(useCase, gui, localStorage)
useCase.showFiltered()
new WebTodoApp()
class ApplicationController < ActionController::Base
protect_from_forgery
def current_buyer
if cookies[:buyer_id].present? && (buyer = Buyer.find(cookies[:buyer_id]))
@current_buyer = buyer
else
@current_buyer = Buyer.create
cookies[:buyer_id] = { value: @current_buyer.id, expires: 1.week.from_now }
end
class Company
def initialize
@employees = []
@roles = {}
end
def delegate(from_employee, task, to_employee)
raise TargetEmployeerDoesntHaveTheRequiredRole if ! has_role?(to_employee, task.required_role)
from_employee.remove_task(task)
to_employee.add_task(task)
@andrzejkrzywda
andrzejkrzywda / 0_reuse_code.js
Created January 12, 2014 13:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console