Skip to content

Instantly share code, notes, and snippets.

module RoundTo
# def self.included(klass)
# if klass.instance_method(:round)
# klass.class_eval do
# begin
# remove_method :round
# rescue NameError
# end
# end
# super
$.hasData = function(element, settings){
return !!$(element).data(settings.dataName);
}
$.extend($.expr[':'], {
"rotateable": function(a, i, m) {
return $.hasImages(a,{dataName:'images'});
}
});
@tal
tal / header.html
Created March 9, 2010 21:54
Can't get this fbml app to run
<fb:prompt-permission perms="email">
<div>Email you</div>
</fb:prompt-permission>
<div id="other-games">
Play other games
</div>
<div id="progress">
<fb:bookmark />
</div>
@tal
tal / forwardable_question.rb
Created March 18, 2010 17:54
Would something like this work with Forwardable?
class Foo << Sequel::Model
extend Forwardable
def bar
@bar ||= Bar.find(bar_id)
end
def_delegators :bar, :my, :bar, :methods
end
class Sequel::Model
def_dataset_method :random do |*args|
range, size = *args
size ||= 1; raise ArgumentError, 'need to specify a range as the first argument' unless range
limit(size,rand(range))
end
end
update fighters foo
set user_batting_average = (select (sum(`wins`) / sum(`views`))
from fighters bar
where foo.user_id = bar.user_id)
where foo.user_id in (select user_id from fighters)
@tal
tal / gist:340831
Created March 23, 2010 04:08
My sequel model language file
{ scopeName = 'source.ruby.sequel.basic';
fileTypes = ( 'rb' );
patterns = (
{ name = 'meta.function.method.with-arguments.ruby.sequel';
begin = '^\s*(def_dataset_method)\s*';
end = '$';
beginCaptures = {
1 = { name = 'keyword.control.def.ruby';};
};
patterns = ( { include = 'source.ruby'; } );
if Merb.env?('development')
def closure_include file
includes = File.open(Merb.root_path+'/public/javascripts/'+file).inject([]) do |result,line|
if m=line.match(/@code_url (.+)/)
path = m[1].gsub(/http:\/\/pictureclubfiles\.omgpop\.com/,'')
if path =~ /http/
result << %{<script type="text/javascript" src="#{path}"></script>}
else
result << %{<script type="text/javascript" src="#{cdn}/javascripts#{path}?#{cdn_version}"></script>}
<a href="#" clicktoshowdialog="fan-dialog" oncancel="console.log('test')">Fan us!</a>
<fb:dialog id="fan-dialog">
<fb:dialog-title>Fan OUR GAME!</fb:dialog-title>
<fb:dialog-content>
<div id="fan-me">
<fb:iframe scrolling="no" frameborder="0"
src="http://www.facebook.com/connect/connect.php?id=44856213161&connections=0&stream=0&locale=en_US"
allowtransparency="true"
style="border: none; width: 300px; height: 64px;"
height=64
require 'benchmark'
Benchmark.bmbm do |x|
x.report 'each_with_index' do
i = []
[*1..1000].each_with_index do |item, index|
i << item*index
end
end