Skip to content

Instantly share code, notes, and snippets.

@rtekie
rtekie / cap_notify.rb
Created April 2, 2011 16:16
Capistrano deployment email notifier for Rails 3
=begin
Capistrano deployment email notifier for Rails 3
Do you need to send email notifications after application deployments?
Christopher Sexton developed a Simple Capistrano email notifier for rails. You can find details at http://www.codeography.com/2010/03/24/simple-capistrano-email-notifier-for-rails.html.
Here is Rails 3 port of the notifier.
The notifier sends an email after application deployment has been completed.
@rtekie
rtekie / heroku-backup.sh
Created July 10, 2011 17:21
Heroku database backup to development system - add to crontab
#!/bin/bash
echo "Backup started" `date`
APPLICATION_DIR=YOUR_APP_DIRECTORY_GOES_HERE
BACKUP_DIR=YOUR_BACKUP_DIRECTORY_GOES_HERE
cd ${APPLICATION_DIR}
heroku pgbackups:capture --expire
URL=`heroku pgbackups:url`
URL=${URL//\"/}
echo $URL
curl -o $BACKUP_DIR`date +"db_dump_%Y%m%d%H"` ${URL}
@rtekie
rtekie / gist:1132976
Created August 8, 2011 22:59
RightScale script to generate rails database.yml file upon server launch
#!/bin/bash -ex
# Create database.yml for a Ruby on Rails application
# Storing database.yml in a source code control system with its production database credentials creates a security risk.
# Using this script, you can take advantage of RightScale's secure credentials store
# and generate the file when an application server is launched.
#
# If this is a reboot skip this script.
if test "$RS_REBOOT" = "true" ; then
logger -t RightScale "Skip RB create database.yml."
@rtekie
rtekie / database_semaphore.rb
Created October 18, 2011 13:04
Database semaphore mechanism used for example to guarantee that only one instance of a job will run
# Please refer to http://ctoinsights.wordpress.com/2011/10/17/running-distributed-cron-jobs-in-the-cloud/
class DatabaseSemaphore < ActiveRecord::Base
validates_presence_of :name, :message => "can't be blank"
def self.open?(name, lock_duration = 600)
# only one requestor can get open semaphore at a time
# sempahore can be locked in a closed position for lock_duration in seconds
semaphore_open = false
now = Time.now
# insert record if it does not exist yet
@rtekie
rtekie / heroku_manager.rb
Last active September 28, 2015 05:58
Running Heroku workers only when required
# This gist is documented at http://ctoinsights.wordpress.com/2011/11/26/running-heroku-workers-only-when-required/
class HerokuManager
def heroku
@heroku ||= Heroku::API.new
end
def get_workers
heroku.get_ps(HEROKU_APP_NAME).body.count { |p| p["process"] =~ /worker\.\d?/ }
end
@rtekie
rtekie / trac2lighthouse.rb
Created December 27, 2011 15:23
Migrate tickets from a Trac database to LighthouseApp
# Migrate records from a Trac database to LighthouseApp
require 'rubygems'
require 'sqlite3'
require 'lib/lighthouse.rb' # download from https://github.com/Caged/lighthouse-api
# Connect to Lighthouse API
Lighthouse.account = 'YOUR LIGHTHOUSE ACCOUNT'
Lighthouse.token = 'YOUR LIGHTHOUSE API TOKEN'
project = Lighthouse::Project.find(:all).first
puts "MIGRATING TICKETS TO PROJECT: #{project.name}"
@rtekie
rtekie / member_page_1.html
Created April 6, 2012 23:12
LoyaltyPlus Member Page script 1
<script src="https://d3aa0ztdn3oibi.cloudfront.net/javascripts/ff.loyalty.widget.js" type="text/javascript"></script>
<iframe id="ff_member_iframe" style="width:760px;height:1045px;border:0" frameBorder="0"></iframe>
<script type="text/javascript">
_ffLoyalty.initialize( "YOUR_ACCOUNT_ID" );
_ffLoyalty.loadIframe({ email: "CUSTOMER_EMAIL", auth_token: "AUTH_TOKEN", auto_resize: true });
</script>
@rtekie
rtekie / member_page_2.html
Created April 6, 2012 23:14
LoyaltyPlus Member Page script 2
<script src="https://d3aa0ztdn3oibi.cloudfront.net/javascripts/ff.loyalty.widget.js" type="text/javascript"></script>
<iframe id="ff_member_iframe" style="width:760px;height:1045px;border:0" frameBorder="0"></iframe>
<script type="text/javascript">
_ffLoyalty.initialize( "YOUR_ACCOUNT_ID" );
_ffLoyalty.loadIframe({ auto_resize: true });
</script>
@rtekie
rtekie / member_page_sample.php
Created April 6, 2012 23:16
LoyaltyPlus Member Page code sample
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>LoyaltyPlus Member Page Sample</title>
<script src="https://d3aa0ztdn3oibi.cloudfront.net/javascripts/ff.loyalty.widget.js" type="text/javascript"></script>
</head>
<body>
<h1>SINGLE SIGN-ON MEMBER PAGE SAMPLE</h1>
<?php
// get uuid and email
@rtekie
rtekie / api_sample.php
Created April 9, 2012 20:32
LoyaltyPlus API call sample
<?
$secret_key = "SECRET_KEY";
$params = array("email" => "CUSTOMER_EMAIL", "uuid" => "ACCOUNT_ID");
ksort($params);
$string_to_hash = $secret_key;
foreach ($params as $key => $val) {
$string_to_hash .= $key.$val;
}
$params["sig"] = md5($string_to_hash);
$api_url = "http://loyalty.500friends.com/api/enroll.gif?";