Skip to content

Instantly share code, notes, and snippets.

View mechanicles's full-sized avatar

Santosh Wadghule mechanicles

View GitHub Profile
Vim Tips:
**g-**
There are a lot of better answers already given (".", "*", and "%" are far more useful), but I vote for "g-" because it is relatively new and feels like magic. Somehow, it always seems to go to the exact text state I want.
Basically, if you make a lot of edits, then undo them, then make one more edit, then decide you want the first set of edits back, most editors can't do it. Emacs can, but it's a pain. g- in Vim will usually take you straight there. {not in Vi}
foo_call_back = lambda { |param1, param2| puts "#{param1} #{param2}"}
def new_foo(num1, num2, callback)
result = num1 + num2
if callback && callback.lambda?
callback.call(result, " is the result")
end
end
function fooCallBack(param1, param2) {
window.alert(param1 + param2);
}
function newFoo(num1, num2, callback) {
var result = num1 + num2;
if(callback && typeof callback === 'function') {
callback(result, ' is the result');
}
}
def new_foo(num1, num2, foo)
result = num1 + num2
puts result
if foo && foo.lambda?
foo.call
end
end
new_foo(2, 3, lambda { puts "my callback executed"})
function newFoo(num1, num2, callback) {
var result = num1 + num2;
window.alert(result);
if(callback && typeof callback === 'function') {
callback();
}
}
newFoo(12412, 11, function(){
alert('my callback executed');
def new_foo(num1, num2, foo)
result = num1 + num2
puts result
if foo
foo.call
end
end
new_foo(2, 3, lambda { puts "my callback executed"})
function newFoo(num1, num2, callback) {
var result = num1 + num2;
window.alert(result);
if(callback) {
callback();
}
}
newFoo(12412, 11, function(){
alert('my callback executed');
foo = lambda { |arg| puts arg }
def new_foo(num1, num2, foo)
result = num1 + num2
foo.call(result)
end
new_foo(2, 3, foo)
@mechanicles
mechanicles / gist:7003879
Created October 16, 2013 07:21
What are callback functions?
function foo(arg) {
window.alert(arg);
}
function newFoo(num1, num2, foo) {
var result = num1 + num2;
return foo(result);
}
newFoo(30, 11, foo);
is = { true => 'Yes', false => 'No' }
is[10 > 5] #=> "Yes"
is[20 == 25] #=> "No"