Skip to content

Instantly share code, notes, and snippets.

Avatar

Eustáquio Rangel taq

View GitHub Profile
@taq
taq / gist:5793430
Created Jun 16, 2013
World worst hacker
View gist:5793430
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:1ef38725c39c041f59701f29a83c7fa3
Created Oct 11, 2016
Git alias to create a new remote branch based on the current branch
View gist:1ef38725c39c041f59701f29a83c7fa3
Just insert on .gitconfig:
nrb = "!f() { git push -u origin $(git rev-parse --abbrev-ref HEAD):$1; }; f"
And then, when on a local branch and want to push to a new remote branch called, say, 'test':
$ git nbr test
Total 0 (delta 0), reused 0 (delta 0)
To <your remote here>
* [new branch] work -> test
@taq
taq / gist:5863818
Created Jun 26, 2013
Using Ruby 2.0 TracePoint to simulate an abstract interface
View gist:5863818
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|
@taq
taq / enum_perf_small.rb
Created Nov 3, 2012
Ruby 2.0 lazy enumerators small collection performance
View enum_perf_small.rb
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 / lazy.rb
Created Nov 3, 2012
Natural numbers enumerator on Ruby 2.0 using lazy evaluation
View lazy.rb
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 / classvar.rb
Created May 9, 2018
Ruby class variable
View classvar.rb
class Foo
class << self
attr_reader :ivar
end
@ivar = 'Hello!'
end
class Bar < Foo
@ivar = 'World'
end
@taq
taq / gist:5699377
Created Jun 3, 2013
Stupid PHP static variables behaviour
View gist:5699377
<?php
class A {
public static $name = null;
}
A::$name = "a";
class B extends A {
}
B::$name = "b";
@taq
taq / gist:ae0e323786a41cfc237c
Created Sep 17, 2014
Plugins do Vim que eu uso
View gist:ae0e323786a41cfc237c
ag.vim
bufexplorer
camelcasemotion
ctrlp.vim
emmet-vim
L9
limelight.vim
nerdcommenter
nerdtree
syntastic
@taq
taq / sṕreadsheet_test.rb
Last active Jan 14, 2016
Minitest without before_all
View sṕreadsheet_test.rb
require "minitest/autorun"
require "minitest/spec"
require "spreadsheet"
describe 'spreadsheet' do
before do
@doc ||= Spreadsheet.open "spreadsheet.xls"
puts "document object id: #{@doc.object_id}"
end
@taq
taq / refine.rb
Created Dec 26, 2013
Ruby 2.1 refinements
View refine.rb
module TimeExtensions
refine Fixnum do
def min2sec; self * 60; end
end
end
class Minutes
using TimeExtensions
def self.to_sec(min)