Skip to content

Instantly share code, notes, and snippets.

View 0x0dea's full-sized avatar

D.E. Akers 0x0dea

  • North Carolina, US
View GitHub Profile
@0x0dea
0x0dea / composable_ish.rb
Created June 28, 2015 04:24
Pseudo-class composition in Ruby.
module Composable
extend self
def extended klass
klass.send :attr_reader, :val
end
def method_missing klass
f, g = self, const_get(klass)
@0x0dea
0x0dea / enumerable_all.rb
Created June 17, 2015 12:45
Improved Enumerable#all?
module Enumerable
def all? p = nil
pred = block_given? ? proc : -> x { p ? p === x : x }
each { |obj| return false unless pred[obj] }
true
end
end
@0x0dea
0x0dea / enum.patch
Created June 17, 2015 12:16
Add case equality checks to Enumerable#any?/all?/none?/one?.
diff --git a/enum.c b/enum.c
index 4b1e119..c717540 100644
--- a/enum.c
+++ b/enum.c
@@ -1043,7 +1043,7 @@ enum_sort_by(VALUE obj)
return ary;
}
-#define ENUMFUNC(name) rb_block_given_p() ? name##_iter_i : name##_i
+#define ENUMFUNC(name, argc) argc ? name##_eqq : rb_block_given_p() ? name##_iter_i : name##_i
@0x0dea
0x0dea / datg
Created June 14, 2015 22:27
Download all the gems!
#!/bin/sh
gem search --no-vers | parallel -j0 -I$ 'curl -O `curl https://rubygems.org/api/v1/gems/$.json | jq -r .gem_uri`'
@0x0dea
0x0dea / daily_programmer_210e.rb
Created April 13, 2015 22:19
This script uses 237,267 anonymous functions (and, essentially, only those functions) to determine that 17 and 10 have four bits in common.
$fns = 0
# Automatically curry all functions for slightly greater legibility.
# Keep track of how many functions end up getting created (for laughs).
# Get to use the fancy symbol everywhere.
def λ
$fns += 1
proc.curry
end