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?
View useAccount.ts
/*
context here is
{ mnemonic: string|null}
*/
const compareMnemonic = (prevAcct, nextAcct) => {
return prevAcct === nextAcct;
};
const selectMnemonic = state =>
state.matches('authorized') ? state.context.mnemonic : null;
View gist:7da1686f1671779b381ba58a63286d2a
networks: {
hardhat: {
gasPrice: 470000000000,
chainId: 43113,
accounts: {
count: 10,
initialIndex: 0,
mnemonic,
path: "m/44'/60'/0'/0"
}
View 3box-verification
3Box is a social profiles network for web3. This post links my 3Box profile to my Github account!
✅ did:muport:QmaNJF7dWyYKsFfqTTEmavMBd9RHFuPWuaArrcN4RuseWF ✅
Create your profile today to start building social connection and trust online. https://3box.io/
@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)
@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 *