Skip to content

Instantly share code, notes, and snippets.

View pedrolopez's full-sized avatar

Pedro López pedrolopez

View GitHub Profile
@pedrolopez
pedrolopez / current_allocation.rb
Created March 23, 2011 17:06
Retrieve last 24 hours 'creative impressions'
def last_impressions(offset, id)
impressions = Impression.where(:creative_id => id, :updated_at.gte => (Time.now - offset.hour)).sum(:impressions)
if impressions.nil? || impressions == 0
then "none"
end
end
def current_allocation(order)
task :deploy do
puts 'Deploying site to Heroku ...'
puts `git push heroku`
puts 'Running database migrations ...'
puts `heroku rake db:migrate`
release_name = "release-#{Time.now.utc.strftime("%Y%m%d%H%M%S")}"
puts "Tagging release as '#{release_name}'"
puts `git tag -a #{release_name} -m 'Tagged release'`
# Usage: rake name:task app_name
task PROD = "appname" # "task" here stubs to prevent rake errors with commandline
task STAGING = "appname-staging"
APP = ARGV[1] || PROD # default app
puts "=== APP #{APP} ==="
namespace :deploy do
#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]
#!/usr/bin/env ruby
# This is a basic deploy script for Heroku apps.
# It provides a structure you can use to expand on
# and add your own prereqs and deploy tasks.
#
# It basically ensures that:
# 1. There are no uncommited files
# 2. You can ssh to github
# 3. You can connect to heroku
** Execute deploy:updated
** Invoke deploy:compile_assets (first_time)
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Execute deploy:compile_assets
** Invoke deploy:assets:precompile (first_time)
** Execute deploy:assets:precompile
DEBUG [2467d36a] Running /usr/bin/env if test ! -d /var/www/videochat/releases/20140331193115; then echo "Directory does not exist '/var/www/videochat/releases/20140331193115'" 1>&2; false; fi on staging.lawdingo.com
DEBUG [2467d36a] Command: if test ! -d /var/www/videochat/releases/20140331193115; then echo "Directory does not exist '/var/www/videochat/releases/20140331193115'" 1>&2; false; fi
DEBUG [2467d36a] Finished in 0.288 seconds with exit status 0 (successful).

Installation

In order to get support for the clipboard and necessary interpreters, we need to compile and install from source.

# install build dependencies for vim:
sudo apt-get -y build-dep vim

# install some additional, necessary tools:
sudo apt-get -y install checkinstall mercurial python-dev python3.3-dev

clone the latest version of vim source:

Ruby, RVM and Mountain Lion

Key problems

Mountain Lion (10.8) has three main difference compared to Lion (10.7):

  • XCode 4.4 does not install Command Line Tools by default
  • X11 isn't available anymore
  • The installed version of OpenSSL has some bugs

How to work around

Implement simple rails store app with abilities to track user's activities
Features:
- product has title, description, price, tags
- pages: list of products, product's detail page
- search by products(use mysql)
- track user's clicks by the product in the search results
- every user should have unique tracking code. Use cookies to set it.
- save product id, user's ip, search keywords, user-agent, user's geo location, user's tracking code
- page: the list of tracking clicks
#!/usr/bin/env ruby
# vim: set syntax=ruby
# Ensures that changes to the Rails schema.rb file may only be committed if a
# migration file is also committed at the same time.
def schema_modified?
%x[ git diff --cached |grep schema.rb ] == ''
end