Instantly share code, notes, and snippets.

View .block
border: no
height: 600
license: gpl-3.0
View README.md

I wrote quick&dirty script to see the dependencies between cops (i.e. when a cop calls config.for_cop(another_cop)).

Strangely enough, Lint/AmbiguousOperator needs everyone else's configs. I excluded it from the diagram in order to keep it clean.

Other than that, the dependency graph has 28 edges.

View README.md

This is another wrong, incomplete implementation of Maybe data type in Ruby. This gist is a full-blown gem. In order to use it, just add the following line to your Gemfile.

gem 'maybe', gist: 'da2aaafdfd71e6ff0ffd'

But WHY?

To my knowledge, all existing gems are too fat and do not provide the ability to configure what values should be treated as Just and what values are Nothing. Some treat [] as Nothing, some treat only nil as Nothing, some rely on truthiness (this is the most reasonable choice in my opinion). In my particular use case, I needed to treat obj as Nothing iff obj.present? is true. Obviously, hard-coding this Railsism into the gem is not an option, so I pass the Nothingness predicate into Maybe data constructor (pardon my French).

View out.txt
➜ ~ ruby -e "def f(*xs); end; f(*(1..130_000))"
-e:1: [BUG] Bus Error
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.2.0]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
View awesome_resources_spec.rb
module AwesomeResource
def initialize(attributes = {})
attributes.each do |key, val|
reader = key
writer = "#{key}="
unless respond_to?(reader)
self.class.send(:attr_reader, key)
end
View gist:4283465
➜ ~ rvm use 1.9.2 && ruby -e 'class A; end; puts A.new(1)'
Using /Users/user/.rvm/gems/ruby-1.9.2-p320
#<A:0x007fcdc204fac8>
➜ ~ rvm use 1.9.3 && ruby -e 'class A; end; puts A.new(1)'
Using /Users/user/.rvm/gems/ruby-1.9.3-p327
-e:1:in `initialize': wrong number of arguments(1 for 0) (ArgumentError)
from -e:1:in `new'
from -e:1:in `<main>'
View glob.bat
SETLOCAL ENABLEDELAYEDEXPANSION
SET FILES=
FOR %%A IN (%1\*.gz) DO ( SET FILES=!FILES! %%A )
echo !FILES!
View TestWithMRUnit.java
@Test
public void shouldMapDocument() throws IOException, InterruptedException {
new MapDriver(new DocumentMapper())
.withInput(createDocumentForTest())
.withOutput(expected0)
.withOutput(expected1)
.runTest();
}
View erbug.rb
require 'erb'
arr = [1,2,3]
context = instance_eval('binding')
src = ::File.binread('template.rb.tt')
content = ERB.new(src, nil, '-', '@output_buffer').result(context)
print content
View CalculatorTest.cs
using NUnit.Framework;
namespace Calculator.Test
{
[TestFixture]
public class CalculatorTest
{
[TestCase( 2, 2, Result = 4)]
[TestCase( -3, -4, Result = -7)]
[TestCase( 0, 0, Result = 0)]