Skip to content

Instantly share code, notes, and snippets.

View remigijusj's full-sized avatar

Remigijus Jodelis remigijusj

View GitHub Profile
@remigijusj
remigijusj / gist:4538360
Created January 15, 2013 12:39
better helper?
# WHICH IS BETTER HELPER?
# -----------------
%Q{
<div class="invitation-info-box clearfix"><p>
#{invite_friends_link}
#{t('app.invitation.info_box_signed_in')}
</p></div>
}.html_safe
# -----------------
@remigijusj
remigijusj / hot-items-queries.sql
Created October 30, 2012 16:26
some hot items SQL
-- ratio with average view count log-trend
SELECT i.id FROM items i
LEFT JOIN global_stats vc ON vc.entry_type=510 AND vc.entry_id = i.id
INNER JOIN user_settings s ON s.user_id = i.user_id
WHERE s.is_publish_photos_agreed = 1 AND is_visible = 1 AND is_replicated = 0 AND is_reserved = 0
AND boutique_id IS NULL
AND created_at >= '2012-10-27'
AND i.catalog_id IN (%cat4%)
AND vc.value / (LN(DATEDIFF(NOW(),created_at)+1)*15.5+12.4) >= 0.8
ORDER BY id DESC
@remigijusj
remigijusj / gist:3927443
Created October 21, 2012 16:26
GIT pre-commit hook to check .rb and .erb syntax
#!/Ruby192/bin/ruby.exe
#
# A hook script to verify that only syntactically valid ruby code is commited.
# Called by git-commit with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# Put this code into a file called "pre-commit" inside your .git/hooks
# directory, and make sure it is executable ("chmod +x .git/hooks/pre-commit")
@remigijusj
remigijusj / gist:1385465
Created November 22, 2011 11:30
ruby-golf
# using Ruby 1.9.2
# Hole 1, 41 chars
def fizzbuzz(n)
"#{n%3<1&&f=:Fizz;n%5<1?"#{f}Buzz":f||n}"
end
# Same as Cyrus's solution, optimized
p fizzbuzz(3) # => "Fizz"
p fizzbuzz(10) # => "Buzz"
@remigijusj
remigijusj / gist:870925
Created March 15, 2011 15:57
dm-redis-adapter with "through" associations
require 'dm-core'
require 'dm-redis-adapter'
DataMapper.setup(:default, {:adapter => "redis"})
class Book
include DataMapper::Resource
property :id, Serial
property :name, String
@remigijusj
remigijusj / gist:860695
Created March 8, 2011 18:19
transfer local variables
class Binding
def publish(vars)
defs = vars.each_with_object("") do |var,str|
str << "define_method(:#{var}) { #{var} }\n"
str << "private :#{var}\n"
end
self.eval "self.class.module_eval { #{defs} }"
end
end