Skip to content

Instantly share code, notes, and snippets.

@caalberts
caalberts / getRSVP.js
Created March 15, 2017 01:34
Retrieve list of RSVPs from Meetup.com
document.querySelectorAll('#rsvp-list .member-name > a').forEach(node => console.log(node.textContent.trim()))
@caalberts
caalberts / pattern_matching.ex
Last active August 11, 2017 03:00
Elixir lunch & learn
case HTTPoison.get(url, headers) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
case Poison.decode(body) do
{:ok, decoded} -> {:ok, decoded}
{:error, error} -> {:error, error}
end
{:ok, %HTTPoison.Response{status_code: status_code}} ->
{:error, status_code}
class Service
def initialize(dependency)
@dependency = dependency
end
def exec()
{
success: true,
data: @dependency.call()
}
describe 'service object' do
let(:data) { { a: 1, b: 2 } }
let(:dependency) { double() }
before do
allow(dependency).to receive(:call).and_return(data)
end
it 'wraps data from dependency into a hash' do
result = Service.new(dependency).exec()
class Service
def exec()
{
success: true,
data: @dependency.call().merge!(hello: 'world')
}
end
end
@caalberts
caalberts / redis.go
Last active December 27, 2017 15:06
func (c *Client) HGetAll(key string) *StringStringMapCmd {}
func (c *Client) HMSet(key string, fields map[string]interface{}) *StatusCmd {}
func (cmd *StringStringMapCmd) Result() (map[string]string, error) {
return cmd.val, cmd.err
}
type RedisProxy interface {
HGetAll(string) (map[string]string, error)
HMSet(string, map[string]interface{}) (string, error)
}
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
type stubRedis struct {
data map[string]string
err error
func TestFetchAccountWhenAccountExists(t *testing.T) {
repository := createRepositoryWithData(fakeData)
account, err := repository.FetchAccount(id)
assert.Equal(t, id, account.Id)
assert.Equal(t, "John Doe", account.Name)
assert.Equal(t, 100, account.Balance)
assert.Nil(t, err)
}