Skip to content

Instantly share code, notes, and snippets.

@clee-jana
clee-jana / Vagrantfile
Last active April 18, 2016 20:03
Provision section of a Vagrant file to spin up graphite
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 5080 # graphite-web
config.vm.network "forwarded_port", guest: 2003, host: 5003 # graphite
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get update
@clee-jana
clee-jana / arrow_support.py
Created February 26, 2016 21:21
how to extend the datastax cassandra driver to support arrow datetimeobjects
session.encoder.mapping.update({
Arrow: self.session.encoder.cql_encode_datetime
})
# source https://github.com/datastax/python-driver/blob/aa8893610247d141708280747fafeeb223dfe345/cassandra/encoder.py#L58-L68
class Encoder(object):
"""
A container for mapping python types to CQL string literals when working
with non-prepared statements. The type :attr:`~.Encoder.mapping` can be
directly customized by users.
"""
mapping = None
@clee-jana
clee-jana / integration_test.py
Last active January 17, 2016 17:06
Example of replacing explicit time.sleep in integration tests
# original
make_request_that_triggers_async_processing()
time.sleep(30)
result = make_request_to_validate_changes()
self.assertEqual(‘new expected value’, result[‘data’])
# better
def check_for_expected_change(retries=5):
result = make_request_to_validate_changes()
if 'new_expected_value' == result[‘data’]:

Challenge:

Create a command line program that will take an internet domain name (i.e. “jana.com”) and print out a list of the email addresses that were found on that website only.

Example:

The following is expected output from jana.com and web.mit.edu, but it should also run on other websites. In the example of jana.com, the program should not crawl other subdomains (blog.jana.com, technology.jana.com).

# These are expected output from www.jana.com
@clee-jana
clee-jana / calculator.rb
Created February 2, 2015 21:12
Blog Post Example Code
describe Calculator do
describe '#add' do
it 'adds two numbers' do
calculator = Calculator.new
expect(calculator.add(2, 2)).to eq(4)
end
it 'raises InvalidInputError if an argument is nil' do
calculator = Calculator.new
expect(calculator.add(nil, 2)).to raise(InvalidInputError)