Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
This gem assigns identities to a variant inside an experiment. It is similar to ab-tests framework.
A triplet - experiment, variants and identities will always produce the same variant outcome even if the test is deleted and rerun.
You can run multiple instances of the framework inside the same application for different adapters.
You can use it wherever you want however you want (you can make a global object for entire application or you can make individual little objects to be used inside methods). It is up to you do decide!
Add this line to your application's Gemfile:
gem 'divisio'
And then execute:
$ bundle
Or install it yourself as:
$ gem install divisio
This is the default adapter
It returns the selected variant, but does not persist any information.
experiment_name = 'experiment1'
variants = [1,2,3]
identity = 'dragos'
Divisio.new.split(experiment_name, variants, identity) # ==>> 1
Requires mongoid v5.0.0 or greater
This adapter will persist the experiment name, identifier, and variant information in a MongoDb collection called experiments
. Note: The variant returned will be cast to a string.
experiment_name = 'experiment1'
variants = [1,2,3]
identity = 'dragos'
Divisio.new(adapter: Divisio::MongoidAdapter).split(experiment_name, variants, identity) # ==>> '1'
You can also specify the default adapter in your initializers as so:
Divisio.default_adapter = Divisio::MongoidAdapter
then
Divisio.new.split(experiment_name, variants, identity) # ==>> '1'
Variants can be weighted by passing a hash of variants mapped to their relative weights, for example:
experiment_name = 'experiment1'
variants = { a: 1, b: 2, c: 3 }
identity = 'dragos'
Divisio.new.split(experiment_name, variants, identity) # ==>> :c
There are three variants in this example: a
, b
, c
Variant a
has a weight of 1, b
has a weight of 2, c
has a weight of 3.
Effectively, this means that the chances of getting the variant b
are twice a likely as getting the variant a
. The chances of getting the variant c
are thrice as likely as getting the variant a
.
You can use what it returns directly, for example if you want to render a partial you could do:
partial = Divisio.new.split('amazing partial', ['partial1', 'partial2'], identity)
render(partial)
If we want to do complex logic based on some idiom, you need to do if/case statements:
# this method could be in a global helper
def enable_partial_quotes
decision = Divisio.new.split('enable_partial_quotes', ['yes', 'no'], identity)
decision == 'yes'
end
# .....
# then somewhere else
# .....
if enable_partial_quotes
# do some stuff
else
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that divisio demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.