Skip to content

Instantly share code, notes, and snippets.

View blaix's full-sized avatar

Justin Blake blaix

View GitHub Profile
class PropertyObserverExample
def number
@number ||= 0
end
def number=(new_number)
old_number = @number
puts "About to change to #{new_number}"
@number = new_number
puts "Just changed from #{old_number} to #{new_number}!"
@blaix
blaix / selenium-download.py
Created October 3, 2014 20:57
Download file in a selenium session that requires a cookie from that session
# http://selenium-python.readthedocs.org/en/latest/api.html?highlight=cookie#selenium.webdriver.remote.webdriver.WebDriver.get_cookie
cookie = driver.get_cookie("cookie_name")
subprocess.check_call(["curl", "--cookie", "cookie_name=%" % cookie["value"], url, "-o", "destination_filename")
class Observable(object):
"""Mixin for use cases that can fire events to be handled by observers"""
def __init__(self):
self._observers = []
def attach_observer(self, observer):
self._observers.append(observer)
def notify_observers(self, event, *args, **kwargs):
def test_subdirectory_gets_linked_to_parent(self):
# When a Site with ResourceDirectories is serialized and passed in for
# duplication, we have to re-link the parent child hierarchy since
# primary keys have changed.
...
jblake@sauron:~$ man help
No manual entry for help
jblake@sauron:~$ help man
-bash: help: no help topics match `man'. Try `help help' or `man -k man' or `info man'.
@blaix
blaix / test.py
Last active August 29, 2015 13:56
def test_returns_2_when_x_is_1_and_y_is_1(self):
self.assertEqual(2, sum(1, 2))
def test_returns_1_when_x_is_2_and_y_is_neg1(self):
self.assertEqual(1, sum(2, -1))
# etc....
# versus:
“Go placidly amid the noise and haste, and remember what peace there may be in silence. As far as possible without surrender be on good terms with all persons. Speak your truth quietly and clearly; and listen to others, even the dull and the ignorant; they too have their story. Avoid loud and aggressive persons, they are vexations to the spirit. If you compare yourself with others, you may become vain and bitter; for always there will be greater and lesser persons than yourself. Enjoy your achievements as well as your plans. Keep interested in your own career, however humble; it is a real possession in the changing fortunes of time. Exercise caution in your business affairs; for the world is full of trickery. But let this not blind you to what virtue there is; many persons strive for high ideals; and everywhere life is full of heroism. Be yourself. Especially, do not feign affection. Neither be cynical about love; for in the face of all aridity and disenchantment it is as perennial as the grass. Take kindly t
1.9.3p484 :008 > require 'set'
=> true
1.9.3p484 :009 > Set.new([1, 2, 3]) ^ Set.new([2, 3, 4])
=> #<Set: {4, 1}>
Judge each day by the seeds you plant, not the harvest you reap. You don't improve when you win. You improve when you practice. Judge yourself by how hard you train, not how well you perform.
@blaix
blaix / handler.rb
Created August 27, 2013 16:09 — forked from vhata/handler.rb
class Chef
class Provider
alias_method :old_converge_by, :converge_by
def converge_by(descriptions, &block)
if descriptions.kind_of? String
run_context.descriptions << descriptions
descriptions = "X #{descriptions}"
elsif descriptions.kind_of? Array
run_context.descriptions.concat(descriptions)
end