Skip to content

Instantly share code, notes, and snippets.

View ms-ati's full-sized avatar

Marc Siegel ms-ati

  • American Technology Innovations
  • Boston, MA
  • X @ms_ati
View GitHub Profile
@ms-ati
ms-ati / Gemfile
Last active December 5, 2015 23:15
An example of using Docile for @lohqua re https://github.com/ms-ati/docile/issues/19
source 'https://rubygems.org'
gem 'docile'
@ms-ati
ms-ati / example_doc_value_class_with_yard.rb
Last active March 15, 2021 11:09
Example: document a Value class with YARD
##
# Examples of trying document classes created with Values gem,
# using YARD.
# https://github.com/tcrayford/Values
##
# Works 100%: Assigning a new Struct class to a constant
# And you can document the fields using `@attr`.
#
# @attr [Array<String>] a names of stuff
@ms-ati
ms-ati / example_multi_level_dsl.rb
Last active February 8, 2019 08:42
Example of a recursive multi-level DSL in Ruby using Docile gem
require 'docile'
# Family tree node, mother and father are Person values as well
Person = Struct.new(:name, :mother, :father)
# Recursive dsl in a mutating builder using Docile
def person(&block)
Docile.dsl_eval(PersonBuilder.new, &block).build
end
@ms-ati
ms-ati / benchmark_rubygems_list.rb
Created March 21, 2015 21:57
Benchmark rubygems list implementations
# A benchmarking script for Rubygems' linked list implementation.
# See https://github.com/rubygems/rubygems/pull/1200
#
# To run, clone the rubygems repo and place this file in the
# root of the checkout. Then run:
#
# ruby ./benchmark_rubygems_list.rb
#
require 'benchmark'
require './lib/rubygems/util/list.rb'
@ms-ati
ms-ati / comment_policy.rb
Created April 30, 2012 00:24
Multiple blog comment validations
require 'pp'
require 'rumonade'
User = Struct.new(:user_id, :name)
Post = Struct.new(:post_id, :text, :comments)
Comment = Struct.new(:user, :post, :text)
Users = [User.new(101, "Dave")]
Posts = [Post.new(201, "Welcome to my blog", [])]
@ms-ati
ms-ati / 3nightclubs.rb
Created April 29, 2012 22:07
A Tale of 3 Nightclubs (ruby port)
####
## Ruby port of "A Tale of 3 Nightclubs"
##
## Based on Scala version here: https://gist.github.com/970717
##
## Demonstrates applicative validation in Ruby, inspired by the blog post:
## "An example of applicative validation in FSharpx"
## (http://bugsquash.blogspot.com/2012/03/example-of-applicative-validation-in.html)
####
@ms-ati
ms-ati / httparty_issue_78_cant_see_bad_json_response.rb
Created March 26, 2011 15:38
HTTParty Issue 78: Can't see Response Body causing Crack::ParseError
#!/usr/bin/env ruby
require 'rubygems'
require 'httparty'
class FakeRestJsonApi
include HTTParty
base_uri 'http://google.com/THIS_IS_A_FAKE_URL'
headers 'Accept' => 'application/json'
default_params :output => 'json'
@ms-ati
ms-ati / Chef_recipe_for_REE_in_RVM.rb
Created March 24, 2011 18:13
Updated to replace system-wide installation, which was removed, with install-as-root
#
# Installs ree using rvm.
#
require_recipe "rvm"
bash "Install ree in rvm" do
user "root"
code "rvm install ree"
not_if "rvm list | grep ree"