Skip to content

Instantly share code, notes, and snippets.

@DNNX
DNNX / .block
Created Feb 16, 2018 — forked from mbostock/.block
Treemap
View .block
border: no
height: 600
license: gpl-3.0
@DNNX
DNNX / README.md
Last active Jan 8, 2016
Rubocop between-cop interdependencies
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.

@DNNX
DNNX / README.md
Last active Nov 19, 2015
Maybe yes, Maybe no
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).

@DNNX
DNNX / out.txt
Last active Dec 21, 2015
ruby crash
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
@DNNX
DNNX / gist:4283465
Created Dec 14, 2012
Different behaviour of default initializer in Ruby 1.9.2 and Ruby 1.9.3
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>'
@DNNX
DNNX / glob.bat
Created Dec 15, 2011
Glob expanding: Windows vs Unix vs PowerShell
View glob.bat
SETLOCAL ENABLEDELAYEDEXPANSION
SET FILES=
FOR %%A IN (%1\*.gz) DO ( SET FILES=!FILES! %%A )
echo !FILES!
@DNNX
DNNX / TestWithMRUnit.java
Created Nov 16, 2011
How to test Hadoop Mappers with and without MRUnit
View TestWithMRUnit.java
@Test
public void shouldMapDocument() throws IOException, InterruptedException {
new MapDriver(new DocumentMapper())
.withInput(createDocumentForTest())
.withOutput(expected0)
.withOutput(expected1)
.runTest();
}
@DNNX
DNNX / erbug.rb
Created Sep 19, 2011
ERB+Windows bug (extra newlines)
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)]
You can’t perform that action at this time.