Skip to content

Instantly share code, notes, and snippets.

View bryanwb's full-sized avatar

Bryan Berry bryanwb

View GitHub Profile
@bryanwb
bryanwb / testUseMachine.tsx
Created July 9, 2021 12:04
test useMachine in 2 components
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?
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 / test_parse_output.py
Last active November 14, 2016 07:35
parse the ouput of the condor_status command
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
@bryanwb
bryanwb / my-test.el
Last active September 20, 2016 06:37
;; 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)
(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))
import pytest
@pytest.fixture(scope='session')
def fixture1():
return dict()
@pytest.fixture
def fixture2(fixture1):
return id(fixture1)
@bryanwb
bryanwb / my_module.py
Created November 24, 2015 05:00
how to write python unit tests for an ansible module?
def method1():
pass
def method2()
pass
# import module snippets
from ansible.module_utils.basic import *
@bryanwb
bryanwb / README.md
Last active October 3, 2015 02:00
Ze Admin: a tool for collecting shell(ish) scripts

Some ideas

If you're like me, you have to write a fair number of shell scripts as part of your daily work as a developer or sysadmin. It is tempting to write those scripts in Bash but you think better of it, as Bash is a fucking mess that is completely unmanageable once the script is longer than one hundred lines. Further, managing command-line flags to bash scripts is a nightmare. You could write those scripts in a higher-level language like Python or Ruby but something still isn't right. Your scripts have zero type safety and debugging them is a chore for finding even minor typos.

Just as important, I want to organize my scripts logically as subcommands. Once I have written scripts, it can be very hard for me to find them again later and even recall how they work. I need an organizing structure for these scripts.

@bryanwb
bryanwb / bad.yml
Last active September 3, 2015 13:35
modifying a dictionary in a loop
# this fails on the "set" tag
- set_fact: instances="{%- set instances = dict() %}
{%- for group in group_names %}
{%- for host in groups[group] %}
{%- if hostvars[host].get('InstanceId', None) %}
{%- if hostvars[host].get('Platform', None) == 'windows' %}
{%- set tmp = instances.setdefault(host, hostvars[host]['InstanceId']) %}
{%- endif %}
{%- endif %}
{%- endfor %}
@bryanwb
bryanwb / err.msg
Created August 18, 2015 11:31
error message for go vet
hitman@Bryans-MacBook-Pro:~/pr/sellsword$ go vet github.com/bryanwb/sellsword
vet: error walking tree: stat ../go/src/github.com/bryanwb/sellsword/app.go: no such file or directory
vet: error walking tree: stat ../go/src/github.com/bryanwb/sellsword/appset.go: no such file or directory
vet: error walking tree: stat ../go/src/github.com/bryanwb/sellsword/env.go: no such file or directory
vet: ../go/src/github.com/bryanwb/sellsword/app.go: open ../go/src/github.com/bryanwb/sellsword/app.go: no such file or directory
vet: no files checked
exit status 1