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
module PagesHelper | |
def content_with_ad(content, ad_count=3) | |
p_count = 0 | |
new_content = content.gsub(/(<p(>|\s+[^>]*>).*?<\/p>)/) { |p| | |
p_count = p_count + 1 | |
if p_count == ad_count | |
p + '<div class="above_fold_ad">Ad</div>' | |
else | |
p |
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
SELECT | |
categories.name, | |
MONTHNAME( articles.created_at ) AS month_name, | |
MONTH( articles.created_at ) AS month, | |
YEAR( articles.created_at ) AS year, | |
COUNT( articles.id ) as news_count | |
FROM news_categories categories, news_articles articles | |
WHERE | |
articles.published = 1 | |
AND categories.id = articles.category_id |
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
SELECT | |
news_categories.name AS category, | |
YEAR(news_articles.creation_date) AS year, | |
MONTH(news_articles.creation_date) AS month, | |
MONTHNAME(news_articles.creation_date) AS month_name, | |
COUNT(*) AS total | |
FROM news_articles | |
INNER JOIN news_categories ON news_articles.category_id=news_categories.id | |
WHERE DATE(news_articles.creation_date) >= DATE_SUB(NOW(), INTERVAL 2 YEAR) | |
GROUP BY category, year, month |
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
scp [email protected]:foobar.txt /some/local/directory |
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
class Picture < ActiveRecord::Base | |
belongs_to :imageable, :polymorphic => true | |
attr_accessible :imageable_id, :imageable_type, :name, :url | |
end | |
class Document < ActiveRecord::Base | |
has_many :pictures, :as => :imageable | |
attr_accessible :title, :content | |
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
# gem install Sanitize | |
require 'Sanitize' | |
def generate_keywords(content) | |
# strip HTML tags | |
content = Sanitize.clean content | |
# dump content into array and remove short words | |
words = content.scan /[A-Za-z0-9]{3,}/ |
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
git remote add all [email protected]:repo.git | |
git remote set-url --add all [email protected]:repo.git | |
# now just, $ git push all |
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
$ rvm --use --ruby-version 2.1.1@project |
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
var iterationsData; | |
var results = document.getElementById('results'); | |
(function () { | |
if (!('localStorage' in window)) { | |
results.innerHTML = 'Your browser has no localStorage support.'; | |
return; | |
} |
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
#! /usr/bin/env ruby | |
# Without using any date/time library, write a function or method that accepts | |
# two mandatory arguments. The first argument is a string of the format[H]H:MM | |
# {AM|PM} and the second argument is an integer. Assume the integer is the | |
# number of minutes to add to the string. The return value of the function | |
# should be a string of the same format as the first argument. For example | |
# add_minutes('9:13 AM', 10) would return 9:23 AM. | |
# To run: |