Skip to content

Instantly share code, notes, and snippets.

View cored's full-sized avatar
🐽
Hacking Everything

Rafael George cored

🐽
Hacking Everything
View GitHub Profile
irb(main):010:0> -1 % 24
=> 23
> words = "a".split(/\w+|\s/);
[ '', '' ]
> words = "a".split(/\W+|\s);
words = "a".split(/\W+|\s);
^
SyntaxError: Invalid regular expression: missing /
> words = "a".split(/\W+|\s/);
[ 'a' ]
> words = "there's a list of words".split(/\w+|\s/);
lam = lambda { puts "hello world" }
def method(func)
func.call
end
require "minitest/autorun"
module Cipher
extend self
def call(str)
str.gsub(/\s/)
end
end
gem 'minitest', '~> 5.4'
require 'minitest/autorun'
require_relative '../lib/bottles'
class BottlesTest < Minitest::Test
def test_the_first_verse
expected = <<-VERSE
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
VERSE
def node(input, *args)
if input.is_a?(::Symbol)
[type, [name, predicate(input, *args).to_ast]]
elsif input.respond_to?(:rule)
[type, [name, [:type, input]]]
elsif input.is_a?(::Class) && input < ::Dry::Struct
[type, [name, [:schema, Schema.create_class(self, input)]]]
elsif input.is_a?(Schema)
[type, [name, schema(input).to_ast]]
else
context "structs" do
subject(:schema) do
Dry::Validation.Schema do
required(:person).filled(Person)
end
end
class Name < Dry::Struct::Value
attribute :given_name, 'strict.string'
attribute :family_name, 'strict.string'
require "spec_helper"
RSpec.describe SAML::Consumer do
end
// Examples of doing test doubles in Go tests
// Extracted from https://blog.8thlight.com/uncle-bob/2014/05/14/TheLittleMocker.html
type Authorizer interface {
Authorize(username, password string) bool
}
// Dummy: Pass it around when you don't care how it is use
type DummyAuthorizer struct {}
func (da *DummyAuthorizer) Authorize(username, password string) bool {
return false
}
func TestCreateInstanceFromMissingPlaybook(t *testing.T) {
nt := newNotificationTestHelper()
defer nt.Close()
store := store.New()
is := NewInstanceService(store)
i := &instance.Instance{PlaybookID: "vanishing-pb", ID: "gone"}
_, err := is.Create(i)
assert.NotNil(t, err)