Skip to content

Instantly share code, notes, and snippets.

@vrinek
vrinek / avatar.rb
Created June 25, 2009 12:02
attachment_fu custom error messages
class Avatar < ActiveRecord::Base
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => 'c128x128',
:thumbnails => {:tiny => 'c24x24', :small => "c48x48"}
validates_as_attachment
after_validation :greeklize_attachment_errors
<tr class="marked">
<td colspan="5"><pre><a name="line6"></a>6 def toc_for(article)</pre></td>
</tr>
<tr class="uncovered">
<td colspan="5"><pre><a name="line7"></a>7 '<ul id="toc_links">' + article.toc.collect{ |h5|</pre></td>
</tr>
<tr class="uncovered">
<td colspan="5"><pre><a name="line8"></a>8 '<li>' + link_to(h5[:title], url_for_article(article) + '?article_page=' + h5[:page].to_s + '#' + h5[:id]) + '</li>'</pre></td>
</tr>
<tr class="uncovered">
# used for paginations (Model.paginate :page => page_from_params)
# it just makes the WillPaginate::InvalidPage errors go away
def page_from_params
(p = params[:page].to_i) > 0 ? p : 1
end
$$('a[data-remote=true]').each(function(a){
a.onclick = function(){
href = a.getAttribute('href');
url = href.split('?')[0];
params = href.split('?')[1];
newParam = encodeURI(eval(a.getAttribute('data-with')));
if(params){
params = params.split('&');
def all_controller_actions(controller)
(controller.ancestors[1, controller.ancestors.index(ApplicationController)] + [Object]).inject(controller.new.methods) do |methods, ancestor|
methods -= ancestor.new.methods unless ancestor.class == Module
methods
end.reject{|m| m =~ /^_/}.sort.map(&:to_sym)
end
@vrinek
vrinek / gist:990771
Created May 25, 2011 10:46
find out how a file has changed when you get a conflict in "rebase master"
git log -p --color $(git merge-base master branch)...master path/to/file.rb
@vrinek
vrinek / gist:1034044
Created June 19, 2011 10:27
New installation of RVM on a vanilla OSX Snow Leopard
#!/bin/bash
# checks for GCC (installed from Xcode)
if [ "$(which gcc)" = "" ]; then
echo "You don't have Xcode installed. Please install it from http://developer.apple.com/"
exit 0
fi
# checks for git
if [ "$(which git)" = "" ]; then
@vrinek
vrinek / gist:1188161
Created September 2, 2011 08:15
wikileaks decryption key
Gw0whe$PfehwH{W%$%0sfwFGOENqi24yHSFP{NKFwekqzcxGPAEGMq32pfewkjnwrHN}#%Fwedqkdg?WM43\hgwr#$JhowdnwqQELFDWmenhwREWKwqeq$
@vrinek
vrinek / gist:1219113
Created September 15, 2011 12:30
finds focused specs (good for a git hook)
git grep -n ':focus *=> *true' -- $(ruby -e 'puts `ls -d spec/*`.split("\n").reject{|f| f == "spec/spec_helper.rb"}')
ruby ../cleanup_gist/merged_branches.rb > ../cleanup_gist/table.txt && cat ../cleanup_gist/table.txt