This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @user.login_list.each do |n| %> | |
<li><%= n %></li> | |
<% end %> | |
# chain this onto the object | |
def self.last_five(id) | |
where(:id => id).limit(5).sort('descending') | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [] | |
@user.user_logins.each do |x| | |
a << x.created_at | |
end | |
# now a should have all the entries you need | |
a.inspect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# also check out this sweet gem! https://github.com/alexdunae/holidays | |
class Christmas | |
attr_reader :christmastime, :christmas, :usa_thanksgiving | |
def initialize | |
@christmastime = is_christmastime? | |
end | |
def is_christmastime?(seed_date = Date.today, padding = 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assumptions: rails, object responds to errors | |
# in your test use this line where object is the object being validated | |
# :msg => flay_the_errors(__method__).call( object.errors) | |
def flay_the_errors( method ) | |
Proc.new do |x| | |
y = "\n### oh noes #{method} failed! ###\n" | |
y << "Full Inspect:\n" | |
y << x.inspect << "\n" | |
x.each {|k,v| y << "- #{k} #{v}\n"} | |
y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install git | |
sudo apt-get install g++ curl libssl-dev apache2-utils | |
sudo apt-get install git-core | |
# download the Node source, compile and install it | |
git clone https://github.com/joyent/node.git | |
cd node | |
./configure | |
make | |
sudo make install | |
# install the Node package manager for later use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some_string.gsub(/\s+/, "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is how I leveraged twitter bootstrap modals http://twitter.github.com/bootstrap/javascript.html#modals | |
# in Rails 3.2 with bootstrap-sass working. This is HAML syntax. With Twitter Bootstrap > 2.0.3.1. The pictures are | |
# pulled from Google Picasa Web Albums and are the url to the thumbnail image. This also explains the .gsub in the | |
# helper as I swap the thumbnail out out with a larger image. This will give you a thumbnail array similar to the | |
# "more examples" one on this page http://twitter.github.com/bootstrap/components.html#thumbnails | |
# in your helper file. | |
require 'securerandom' | |
def modal_page( image ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= form.input :your_checkbox_variable, :label => false, :require => false do | |
= form.check_box :your_checkbox_variable | |
My Awesome Checkbox |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Authored by Braulio Carreno on railscasts site. Put here mostly as a reference for me. | |
# also remember to replace albino gem with pygments.rb gem | |
module ApplicationHelper | |
class HTMLwithPygments < Redcarpet::Render::HTML | |
def block_code(code, language) | |
Pygments.highlight(code, :lexer => language) | |
end | |
end | |
def markdown(text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def markdown(text) | |
options = {hard_wrap: true, filter_html: true, autolink: true, no_intraemphasis: true, fenced_code: true, gh_blockcode: true} | |
md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = options) | |
syntax_highlighter( md.render(text) ).html_safe | |
end | |
def syntax_highlighter(html) | |
doc = Nokogiri::HTML(html) | |
doc.search("//pre[@lang]").each do |pre| | |
pre.replace Albino.colorize(pre.text.rstrip, pre[:lang]) |