Skip to content

Instantly share code, notes, and snippets.

View ianwhite's full-sized avatar

Ian White ianwhite

View GitHub Profile
@ianwhite
ianwhite / README.md
Created November 30, 2020 03:11 — forked from leastbad/README.md
Choices.js Stimulus wrapper preview

Choices.js Stimulus wrapper

https://joshuajohnson.co.uk/Choices/

Soon, this will be published as an NPM package, but there's an absence of documentation right now. It supports almost all functions from the original library; soon it will support 100% of them.

This wrapper adds Ajax pre-fetch search. Happens if controller has a data-search-path attribute.

Stimulus controller targets use new v2 syntax. Controller attaches a reference to itself on the element so that you can access the internal state from external scripts.

require 'dry/validation'
# enter two numbers, to guess the rule (their sum must be even)
class EvenContract < Dry::Validation::Contract
params do
required(:arg1).filled(:integer)
required(:arg2).filled(:integer)
end
@ianwhite
ianwhite / composable_contract.rb
Last active February 18, 2024 01:48
Spike for composable contracts in dry.rb (examples below the code)
module ComposableContract
# this is the interface that we care about, we provide the rest of
# result's interface where required
ResultType = Types.Interface(:to_h, :errors)
# this is our representation of a path, we use Schema::Path to
# convert where necessary
PathType = Types::Array.of(Types::Symbol)
CheckType = Types.Interface(:call)
@ianwhite
ianwhite / sphinx.rb
Last active May 12, 2016 14:11 — forked from leemeichin/sphinx.rb
Sphinx 0.9.9 OS X
require 'formula'
class Libstemmer < Formula
# upstream is constantly changing the tarball,
# so doing checksum verification here would require
# constant, rapid updates to this formula.
head 'http://snowball.tartarus.org/dist/libstemmer_c.tgz'
homepage 'http://snowball.tartarus.org/'
end
@ianwhite
ianwhite / no-js.html
Created September 18, 2015 14:29
simple .js/.no-js html5
<head>
<style> .no-js { display:none; } </style>
<noscript>
<style> .no-js { display:block }; .js { display: none } </style>
</noscript>
</head>
describe WarrantyClaimWorkflow do
it "yields a SuccessResult" do
should_receive :succeeded
subject.handle(event_that_succeeds) do |result|
result.on_success { succeeded }
end
end
it "yields a FailureResult" do
should_not_receive :succeeded
ian@i2w:~$ babushka benhoskings:'webserver configured'
Updating /home/ian/.babushka/sources/benhoskings from https://github.com/benhoskings/babushka-deps.git... at b1e8616, done.
/usr/local/babushka/lib/babushka/dep.rb:52:in `initialize': The dep name '☕' contains nonprintable characters.
Check /home/ian/.babushka/sources/benhoskings/deploy.rb:100.
benhoskings:webserver configured <- this dep isn't defined!
@ianwhite
ianwhite / player.rb
Created October 15, 2011 16:12
battleship FAIL
class I2wPlayer
attr_accessor :current_state, :board
attr_reader :shots
def initialize
@shots = []
@board = []
end
def name
"i2w"
(posted at http://groups.google.com/group/cukes/browse_thread/thread/4e01cc6e1a7071d4)
Hi Guys,
I'm the author of pickle, and despite this I broadly agree with Jonas' point of view.
The power of capybara is best realised when you do away with web_steps.rb, and start writing your own steps using capybara's dsl.
In my opinion, pickle is likewise. pickle_steps.rb is a general set of steps to both introduce the dev to the dsl, and enable rapid cuke writing in the early stages of a project.
I agree with Nick - the main point of pickle is to provide a general way of storing models for the lifetime of a scenario, and also to provide a general way of referring to them, so that you don't have to have step defs littered with variable names
@ianwhite
ianwhite / within_steps.rb
Created November 20, 2009 15:49
How to use any cucumber step as a scoped step
# Allow all cucumber steps to be reused as scoped steps, and enable human friendly
# interpretation of selectors.
#
# Found at: http://gist.github.com/gists/239570 - Ian White & Nick Rutherford, Nov 2009
#
# to enable these steps:
#
# the default 'webrat_steps.rb' must
# * have 'response' replaced by 'current_dom'
# * all 'within' steps removed