Skip to content

Instantly share code, notes, and snippets.

@DNNX
DNNX / glob.bat
Created December 15, 2011 14:18
Glob expanding: Windows vs Unix vs PowerShell
SETLOCAL ENABLEDELAYEDEXPANSION
SET FILES=
FOR %%A IN (%1\*.gz) DO ( SET FILES=!FILES! %%A )
echo !FILES!
require 'net/ftp'
require 'timeout'
ftp = Net::FTP.new('ftp.sra.ebi.ac.uk')
ftp.login
puts "connected!"
errors = []
samples = ["SRR016000"]
@DNNX
DNNX / .block
Created February 16, 2018 17:48 — forked from mbostock/.block
Treemap
border: no
height: 600
license: gpl-3.0
@DNNX
DNNX / README.md
Last active January 8, 2016 19:07
Rubocop between-cop interdependencies

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 / out.txt
Last active December 21, 2015 03:39
ruby crash
➜ ~ 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
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 / README.md
Last active November 19, 2015 21:19
Maybe yes, Maybe no

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 / gist:4283465
Created December 14, 2012 07:41
Different behaviour of default initializer in Ruby 1.9.2 and Ruby 1.9.3
➜ ~ 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 / TestWithMRUnit.java
Created November 16, 2011 11:06
How to test Hadoop Mappers with and without MRUnit
@Test
public void shouldMapDocument() throws IOException, InterruptedException {
new MapDriver(new DocumentMapper())
.withInput(createDocumentForTest())
.withOutput(expected0)
.withOutput(expected1)
.runTest();
}
@DNNX
DNNX / erbug.rb
Created September 19, 2011 15:38
ERB+Windows bug (extra newlines)
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