Skip to content

Instantly share code, notes, and snippets.

Avatar

Bryan Berry bryanwb

View GitHub Profile
@bryanwb
bryanwb / testUseMachine.tsx
Created Jul 9, 2021
test useMachine in 2 components
View testUseMachine.tsx
const machine = createMachine(/* details elided */);
const Component1 = () => {
const [state, send] = useMachine(machine);
setInterval(() => send({type: 'LOGIN', password: 'foobar'}), 500
return null;
}
const Component1 = () => {
const [state, send] = useMachine(machine);
// will this have the password foobar?
View gist:4c24a0b7575ed2e04bb2392213c6a0e5
const machine = createMachine(/* details elided */);
const Component1 = () => {
const [state, send] = useMachine(machine);
setInterval(() => send({type: 'LOGIN', password: 'foobar'}), 500
return null;
}
const Component1 = () => {
const [state, send] = useMachine(machine);
// will this have the password foobar?
@bryanwb
bryanwb / my_module.py
Created Nov 24, 2015
how to write python unit tests for an ansible module?
View my_module.py
def method1():
pass
def method2()
pass
# import module snippets
from ansible.module_utils.basic import *
@bryanwb
bryanwb / test_parse_output.py
Last active Nov 14, 2016
parse the ouput of the condor_status command
View test_parse_output.py
from fn.monad import Option
from toolz.itertoolz import get
example1 = '''Name OpSys Arch State Activity LoadAv Mem ActvtyTime
gce-xxxxx LINUX X86_64 Unclaimed Idle 0.010 3700 0+00:00:02
gce-xxxx LINUX X86_64 Unclaimed Idle 0.000 3700 0+00:00:02
Total Owner Claimed Unclaimed Matched Preempting Backfill
X86_64/LINUX 2 0 0 2 0 0 0
View my-test.el
;; use-region-p returns nil even though it is mocked using cl-flet
;; why?
(defun bwb-gitlab--get-line-nums ()
"Return line number(s) if applicable.
If region selected, returns range in url form"
(if (null (use-region-p))
(message "use-region-p is nil"))
(cond ((not (gitlab--viewing-filep)) "")
((use-region-p)
View term-custom.el
(defun term-toggle-mode ()
(interactive)
(if (term-in-line-mode)
(term-char-mode)
(term-line-mode)))
(add-hook 'term-mode-hook
(lambda ()
(defmacro term-in-char-mode () '(eq (current-local-map) term-raw-map))
View pytest fixtures within fixtures
import pytest
@pytest.fixture(scope='session')
def fixture1():
return dict()
@pytest.fixture
def fixture2(fixture1):
return id(fixture1)
View aws_vagrant_kitchen.yml
---
platforms:
- name: vagrant-ubuntu-12.04
driver_config:
box: opscode-ubuntu-12.04
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
require_chef_omnibus: true
customize:
memory: 1024
network:
@bryanwb
bryanwb / default.rb
Created Jul 31, 2013
prototype for build lwrp
View default.rb
# this is an example of the build LWRP
# based on the configuration DSL from https://github.com/opscode/omnibus-ruby
# and to be used together w/ thunderball
# thunderball downloads from a pre-configured s3 bucket, node[:thunderball][:bucket]
thunderball "nginx" do
url 'nginx-1.2.3.tgz'
end
# simplest example
@bryanwb
bryanwb / default.rb
Created Jul 31, 2013
prototype for build lwrp
View default.rb
# this is an example of the build LWRP
# based on the configuration DSL from https://github.com/opscode/omnibus-ruby
# and to be used together w/ thunderball
# thunderball downloads from a pre-configured s3 bucket, node[:thunderball][:bucket]
thunderball "nginx" do
url 'nginx-1.2.3.tgz'
end
# simplest example