Skip to content

Instantly share code, notes, and snippets.

View kevinvaldek's full-sized avatar

Kevin Valdek kevinvaldek

View GitHub Profile
# lib/mongo_mapper/plugins/callbacks.rb
module MongoMapper
module Plugins
module Callbacks
module InstanceMethods
def self.included(model)
model.class_eval do
extend ActiveModel::Callbacks
// prototype
new Ajax.Request("/your/mom", onSuccess: function(response) { $("lightbox_content").innerHTML = response.responseJSON.contents })
// jquery
$.getJSON("/your/mom", function(json) { $("#lightbox_content").html(json.contents) })
// mootools
new Request.JSON({ url: '/your/mom', onSuccess: function(json) { $('lightbox_content').set('html', json.contents) } })
class Fixnum; undef -; end
3 - 1
=> undefined method '-' for Fixnum (NoMethodError)
class Fixnum; def +(other); 99; end; end
1 + 3
=> 99
1.send :+, 2
=> 3
app.loader.spin();
app.notice.fadeIn(app.i18n['welcome']);
app.confirm('This will open an alert dialog, proceed anyway?', function() { alert('Oh, no!'); });
var app = {
loader: new Loader(),
notice: new Notice(),
confirm: new Confirm(),
i18n: {
welcome: 'Tere tulemast'
}
}
function number_with_delimiter(number, delimiter) {
number = number + '', delimiter = delimiter || ',';
var split = number.split('.');
split[0] = split[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + delimiter);
return split.join('.');
};
// Test drive
<div class="scrollcase" style="width: 3000px;">
<div rel="1st pane title">...</div>
<div rel="2nd pane title">...</div>
<div rel="3rd pane title">...</div>
</div>
<div id="fellows" data-url="/fellows">
<!-- list of fellows -->
</div>