Skip to content

Instantly share code, notes, and snippets.

View mark's full-sized avatar
💭
Smoove

Mark Josef mark

💭
Smoove
View GitHub Profile
@migurski
migurski / gray-scott.py
Created September 9, 2012 02:21
Adaptation of Nicolas P. Rougier’s Gray-Scott implementation with the Glumpy dependencies removed
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright INRIA
# Contributors: Nicolas P. Rougier ([email protected])
#
# DANA is a computing framework for the simulation of distributed,
# asynchronous, numerical and adaptive models.
#
# This software is governed by the CeCILL license under French law and abiding
@wr0ngway
wr0ngway / gc-cow.rb
Created March 23, 2012 17:46
test to see if GC in ruby 2 is truly copy on write friendly
#!/usr/bin/env ruby
rss = '.+?Rss:\s+(\d+)'
share = '.+?Shared_Clean:\s+(\d+)'
share << '.+?Shared_Dirty:\s+(\d+)'
priv = '.+?Private_Clean:\s+(\d+)'
priv << '.+?Private_Dirty:\s+(\d+)'
MEM_REGEXP = /\[heap\]#{rss}#{share}#{priv}/m
def mem_usage_linux
@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active March 23, 2025 21:22
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations

An exploration of "dependency injection" in ruby

I recently came across this reddit, demo'ing "dependency injection and inversion of control" in what I think is C#/.Net?

It resulted in a predictable spate of comments on reddit saying basicaly "oh my gosh, dependency injection is so evil, just look at that."

But it got me thinking about how I'd handle the same issues in ruby, and I think the issues to be handled are real issues. So let's look at that.

I don't understand the (.Net?) framework being used in the original example, and I don't feel like reproducing an app environment that would do similar in ruby, so let's just stick to the heart of the matter. They've got some class (not entirely sure which one it is in their tree) that has a method that processes payments, translating that method into ruby it looks something like this:

@mark
mark / my_date.rb
Created April 13, 2011 15:44
This was the date class I wrote like 5 years ago
class MyDate
include Comparable
MyDatesInMonth = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
MonthsOfYear = [nil, :January, :February, :March, :April, :May, :June,
:July, :August, :September, :October, :November, :December]
MyDatesOfWeek = [:Sunday, :Monday, :Tuesday, :Wednesday, :Thursday, :Friday, :Saturday]
def initialize(year, month, day, fixed = true)
require 'rubygems'
require 'nokogiri'
class MyFilter
def ends_with set, ends
set.map { |x| x.to_s }.join.end_with? ends
end
end
doc = Nokogiri.XML(DATA)