Skip to content

Instantly share code, notes, and snippets.

it('can create a mock with specific body where order of keys does not matter', async () => {
const mock = mockClient(client)
.resource('Blog')
.method('post')
.status(204)
.with({
body: JSON.stringify({
title: 'title',
data: {
nestedItemOne: 1,
@klippx
klippx / useWindowSize.web.js
Created November 12, 2019 13:51
useWindowSize [web]
import { useEffect, useState } from 'react'
const useWindowSize = () => {
const { innerWidth: width, innerHeight: height } = window
const [state, setState] = useState({ width, height })
useEffect(() => {
const handler = () => {
setState({
width: window.innerWidth,
@klippx
klippx / useWindowSize.native.js
Last active November 12, 2019 13:51
useWindowSize [native]
import { useState, useEffect } from 'react'
import { Dimensions } from 'react-native'
const useWindowSize = () => {
const { width, height } = Dimensions.get('window')
const [state, setState] = useState({ width, height })
useEffect(() => {
const handler = result => {
setState({

How to migrate from dashlane to 1password

One does not simply export passwords from dashlane and expect them to be imported into 1password.

But with some DIY attitude it can be done:

  1. Export the Dashlane vault as CSV into a file, e.g. DashlanePrivate.csv
  2. Remove all non-password entries (cards, identities, passports, etc.).
  3. Create the migration script:
@klippx
klippx / .json
Created December 19, 2017 13:29
Issue with v0.5.1 of Ruby Kafka (incorrect offsets and eventual crash)
/** Receiving 1 message
# lag = 0
# fetched from offset = 772029
# first message offset = 772029
# last message offset = 772029
# highwater_mark_offset = 772030
# committed offset = 772030
*/
{"line":{"timestamp":"2017-12-19T00:21:45.780414Z","level":"DEBUG","logger":"RubyKafka","message":"Fetching batch from eu-live.kred.account-events/7 starting at offset 772029"}}
{"line":{"timestamp":"2017-12-19T00:21:55.296350Z","level":"INFO","logger":"Phobos","message":{"message":"Received batch on eu-live.kred.account-events/7","group_id":"account-overview-consumer-production-eu-kred.account-events_1","topic":"eu-live.kred.account-events","partition":7,"first_offset":772029,"last_offset":772029,"offset_lag":0,"highwater_mark_offset":772030,"message_count":1,"client_id":"phobos"}}}
@klippx
klippx / gist:0ca38936059118ecbd8d701b9d7ddb3d
Created November 15, 2017 16:15
Running spec/lib/phobos/listener_spec.rb:54 with ruby kafka 0.5.1
## With Ruby kafka 0.5.1
#
~  src  phobos  debug-0.5.x-issues  docker-compose run -e DEFAULT_TIMEOUT=30 --rm test rspec spec/lib/phobos/listener_spec.rb:54
Starting phobos_zookeeper_1 ... done
Starting phobos_kafka_1 ... done
Run options: include {:locations=>{"./spec/lib/phobos/listener_spec.rb"=>[54]}}
Randomized with seed 7064
Phobos::Listener
@klippx
klippx / gist:a119fcb8225bd9df46f4941562572040
Created November 15, 2017 16:14
Running spec/lib/phobos/listener_spec.rb:54 with ruby kafka 0.4.4
## With ruby kafka 0.4.4
#
~  src  phobos  debug-0.5.x-issues  ✎  docker-compose run -e DEFAULT_TIMEOUT=30 --rm test rspec spec/lib/phobos/listener_spec.rb:54
Starting phobos_zookeeper_1 ... done
Starting phobos_kafka_1 ... done
Run options: include {:locations=>{"./spec/lib/phobos/listener_spec.rb"=>[54]}}
Randomized with seed 16222
Phobos::Listener
@klippx
klippx / from_attachment.rb
Created July 2, 2015 06:55
Final result: FromAttachment
class PouchOrder::FromAttachment
include DatetimeChange
def initialize(attachment: attachment)
@attachment = attachment
@pouch_order = PouchOrder.new(
number: @attachment.header.order_number,
phone_number: @attachment.contact_telephone,
issued_at: @attachment.issued_at,
delivery_at: @attachment.delivery_at,
@klippx
klippx / workflow_manager.rb
Created July 2, 2015 06:53
Final result: PouchOrder::WorkflowManager
module PouchOrder::WorkflowManager
extend ActiveSupport::Concern
included do
include Workflow
workflow_column :status
workflow do
state :new do
event :receive, transitions_to: :received
@klippx
klippx / pouch_order.rb
Created July 2, 2015 06:50
Final result: Pouch Order
# A pouch order is ordered to a ward for a patient from a prescriber. These
# will be produces as pouches through the HD-Medi system.
class PouchOrder < ActiveRecord::Base
# Workflow is handled in library module
include PouchOrder::WorkflowManager
include DatetimeChange
belongs_to :ward
belongs_to :patient