Skip to content

Instantly share code, notes, and snippets.

View taq's full-sized avatar

Eustáquio Rangel taq

View GitHub Profile
@taq
taq / lazy.rb
Created November 3, 2012 19:39
Natural numbers enumerator on Ruby 2.0 using lazy evaluation
natural_numbers = Enumerator.new do |yielder|
number = 1
loop do
yielder.yield number
number += 1
end
end
p natural_numbers.lazy.select { |n| n.odd? }.take(5).to_a # => [1, 3, 5, 7, 9]
p natural_numbers.lazy.map { |n| n*2 }.take(5).to_a # => [2, 4, 6, 8, 10]
@taq
taq / enum_perf_small.rb
Created November 3, 2012 19:43
Ruby 2.0 lazy enumerators small collection performance
require "benchmark"
include Benchmark
values = (0..100).to_a
bm(10) do |bench|
bench.report("regular") do
values.map { |x| x * 10 }.select { |x| x > 30 }
end
bench.report("lazy") do
@taq
taq / enum_perf_big.rb
Created November 3, 2012 19:46
Ruby 2.0 lazy enumerators bigger collection performance
require "benchmark"
include Benchmark
values = (0..1000).to_a
bm(10) do |bench|
bench.report("regular") do
values.map { |x| x * 10 }.select { |x| x > 30 }
end
bench.report("lazy") do
#!/bin/bash
if ! which md5sum > /dev/null; then
echo Install md5sum
exit 1
fi
if ! which curl > /dev/null; then
echo Install curl
exit 1
@taq
taq / gist:5413841
Created April 18, 2013 15:52
Overiding == operator in Ruby.
class Pessoa
attr_accessor :nome
def initialize(nome)
self.nome = nome
end
def ==(outra)
outra == self.nome
end
@taq
taq / gist:5413857
Created April 18, 2013 15:53
Using the "starship" operator
class Pessoa
include Comparable
attr_accessor :nome
def initialize(nome)
self.nome = nome
end
def <=>(outra)
return -1 if outra.size<self.nome.size
@taq
taq / gist:5699377
Created June 3, 2013 16:28
Stupid PHP static variables behaviour
<?php
class A {
public static $name = null;
}
A::$name = "a";
class B extends A {
}
B::$name = "b";
@taq
taq / gist:5793430
Created June 16, 2013 20:59
World worst hacker
This is a bunch of stuff relating to the localhost ip taken off bash.org. Apologies to all the non-technically minded people...
#60852
<Numi> hey, can you guys just check a site out and tell me if it's up?
<Haddock> depends, what is it?
<Numi> just my apache server, it works for me but seems to be down for anyone else
<Haddock> alright, what's the address?
<Numi> http://127.0.0.1
<Haddock> ......
<Haddock> ...Yeah, it's up.
@taq
taq / gist:5849586
Last active December 18, 2015 21:48
Is Microsoft abandoning its mobile operating systems?
by Steven J. Vaughan-Nichols, zdnet.com
June 23rd 2013
Summary: In recent weeks Microsoft has been doing some odd things with mobile operating systems, Windows RT, and Windows Phone 8. I think Microsoft is moving towards dropping its mobile OSs in favor of supporting Microsoft applications on other platforms and eventually replacing them with Windows 8.1 on their own devices.
This is not your dad's Microsoft. Microsoft has been refocusing on Web services and devices instead of Windows and software products. One of those changes seems to be that if Microsoft's mobile operating systems can't cut the mustard, Microsoft isn't afraid to cut them off at the knees.
What am I talking about? Let's look at some of Microsoft's mobile news in the last few weeks.
First, some background. Goodness knows Windows 8 has been a market failure, but it's a rip-roaring success compared to Windows RT and Windows Phone 8 (WP8).
@taq
taq / gist:5863818
Created June 26, 2013 00:46
Using Ruby 2.0 TracePoint to simulate an abstract interface
module AbstractInterface
class NotImplementedError < StandardError
def initialize(*methods)
super "You must implement the following methods: #{methods.join(', ')}"
end
end
def AbstractInterface.check_methods(klass,other,methods)
return if other.class==Module
TracePoint.new(:end) do |tp|