Skip to content

Instantly share code, notes, and snippets.

View Amokrane's full-sized avatar
🎯
Focusing

Amokrane Chentir Amokrane

🎯
Focusing
View GitHub Profile
@Amokrane
Amokrane / PlasticLinearLayout.java
Created October 8, 2011 16:01 — forked from charlieCollins/PlasticLinearLayout.java
Eric Burke's PlasticLinearLayout
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import com.movl.swipeit.R;
@Amokrane
Amokrane / return_value_caching.rb
Created June 15, 2011 23:14
Avoid return value caching for the sake of performance (by @tenderlove)
def some_method
@some_method ||= some_expensive_op
end
@Amokrane
Amokrane / symbol_to_proc.rb
Created June 15, 2011 23:11
Symbol to proc are bad for performance (by @tenderlove)
@list.map(&:to_i)
# vs
@list.map { |x| x.to_i }
@Amokrane
Amokrane / protip_bloc_parameter.rb
Created June 15, 2011 23:09
A #protip given by @tenderlove about passing an optional bloc parameter
def sometimes_block
if block_given?
Proc.new.call
end
end
sometimes_block { puts "hi" }
sometimes_block
@Amokrane
Amokrane / explicit_bloc.rb
Created June 15, 2011 23:08
Explicit bloc parameters are slower than implict ones (by @tenderlove)
class Foo
def explicit & block
yield
end
def implicit
yield
end
end
@Amokrane
Amokrane / define_method.rb
Created June 15, 2011 23:06
define method uses a bloc (by @tenderlove)
class Foo
def foo; end
define_method :bar do; end
class_eval %{ def baz; end }
end
@Amokrane
Amokrane / lambda_vs_callable.rb
Created June 15, 2011 23:05
Lambda Vs callable (by @tenderlove)
lambda {...} # vs
class Callable
def call; .. end
end
@Amokrane
Amokrane / better_inject.rb
Created June 15, 2011 23:03
inject is evil (by @tenderlove)
%w{
Foo
Bar
Baz
}.inject(Object) { |klass, string|
klass.const_get(string.to_sym)
}
values = some_list.map { |val|
[val, some_transform(val)]
}
Hash[values]
@Amokrane
Amokrane / inject.rb
Created June 15, 2011 22:59
inject is evil
some_list.inject({}) do |hash, val|
hash[val] = some_transform(val)
hash
end